aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2018-08-27 00:46:21 +0200
committerPatrick Spek <p.spek@tyil.nl>2018-08-27 00:46:21 +0200
commit0dafc26068d2726857cf3743aa2e5111de1c8af7 (patch)
tree0ad590a2adac865618e29280006d1fc63b79ad34
parent2ecfe0f8a26034d9d308d9c190e7050d392e6b42 (diff)
downloadApp::Assixt-0dafc26068d2726857cf3743aa2e5111de1c8af7.tar.gz
App::Assixt-0dafc26068d2726857cf3743aa2e5111de1c8af7.tar.bz2
Cleanup Commands::Touch::Test
-rw-r--r--lib/App/Assixt/Commands/Touch/Test.pm654
-rw-r--r--t/02-command-touch-test.t25
2 files changed, 39 insertions, 40 deletions
diff --git a/lib/App/Assixt/Commands/Touch/Test.pm6 b/lib/App/Assixt/Commands/Touch/Test.pm6
index c67566c..6e9b321 100644
--- a/lib/App/Assixt/Commands/Touch/Test.pm6
+++ b/lib/App/Assixt/Commands/Touch/Test.pm6
@@ -6,31 +6,33 @@ use Config;
use Dist::Helper::Meta;
use Dist::Helper::Template;
-class App::Assixt::Commands::Touch::Test
-{
- method run(
- "test",
- Str $test,
- Config:D :$config,
- ) {
- my %meta = get-meta;
- my $path = "./t".IO;
-
- $path = $path.add($test);
- $path = $path.extension("t", parts => 0);
-
- if ($path.e) {
- die "File already exists at {$path.absolute}";
- }
-
- my %context = %(
- perl => %meta<perl>,
- vim => template("vim-line/$config<style><indent>", context => $config<style>).trim-trailing,
- );
-
- template("module/test", $path, :%context);
-
- # Inform the user of success
- say "Added test $test to {%meta<name>}";
+unit class App::Assixt::Commands::Touch::Test;
+
+method run (
+ Str:D $test,
+ Config:D :$config,
+) {
+ my %meta = get-meta($config<cwd>);
+ my $path = $config<cwd>.add("t").add($test).extension("t", :0parts);
+
+ if ($path.e) {
+ note qq:to/EOF/;
+ A file already exists at {$path.absolute}. Remove it, or run this
+ command again with `--force` to ignore this error.
+ EOF
+
+ return;
}
+
+ my %context = %(
+ perl => %meta<perl>,
+ vim => template("vim-line/$config<style><indent>", context => $config<style>).trim-trailing,
+ );
+
+ template("module/test", $path, :%context);
+
+ # Inform the user of success
+ say "Added test $test to {%meta<name>}";
+
+ $path;
}
diff --git a/t/02-command-touch-test.t b/t/02-command-touch-test.t
index f2d20ae..3dfab7e 100644
--- a/t/02-command-touch-test.t
+++ b/t/02-command-touch-test.t
@@ -6,18 +6,18 @@ use Test;
BEGIN plan :skip-all<set AUTHOR_TESTING=1 to run bin tests> unless %*ENV<AUTHOR_TESTING>;
+use App::Assixt::Commands::Touch::Test;
+use App::Assixt::Config;
use App::Assixt::Test;
+use Config;
use File::Temp;
-my $assixt = $*CWD;
-my $root = tempdir;
+plan 1;
-chdir $root;
-
-plan 2;
-
-ok create-test-module($assixt, "Local::Test::Touch::Test"), "assixt new Local::Test::Touch::Test";
-chdir "$root/perl6-Local-Test-Touch-Test";
+my IO::Path $module = create-test-module("Local::Test::Touch::Test", tempdir.IO);
+my Config $config = get-config.read: %(
+ cwd => $module,
+);
subtest "Touch test files", {
my @tests = <
@@ -25,15 +25,12 @@ subtest "Touch test files", {
01-basic
>;
- my $module-dir = "$root/perl6-Local-Test-Touch-Test";
-
- plan 2 × @tests.elems;
+ plan @tests.elems;
for @tests -> $test {
- chdir $module-dir;
+ App::Assixt::Commands::Touch::Test.run($test, :$config);
- ok run-bin($assixt, « touch test $test »), "assixt touch test $test";
- ok "$module-dir/t/$test.t".IO.e, "t/$test.t exists";
+ ok $module.add("t").add("$test.t").e, "t/$test.t exists";
}
}