aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2018-08-27 00:53:58 +0200
committerPatrick Spek <p.spek@tyil.nl>2018-08-27 00:53:58 +0200
commit72881bc589e8e8d6fec21c0b6fbf7ea0c2bf6d99 (patch)
tree0b588d9465fe467781319adc3f0a40915b70c163
parent0dafc26068d2726857cf3743aa2e5111de1c8af7 (diff)
downloadApp::Assixt-72881bc589e8e8d6fec21c0b6fbf7ea0c2bf6d99.tar.gz
App::Assixt-72881bc589e8e8d6fec21c0b6fbf7ea0c2bf6d99.tar.bz2
Cleanup Commands::Touch::Resource
-rw-r--r--lib/App/Assixt/Commands/Touch/Resource.pm664
-rw-r--r--t/02-command-touch-resource.t29
2 files changed, 44 insertions, 49 deletions
diff --git a/lib/App/Assixt/Commands/Touch/Resource.pm6 b/lib/App/Assixt/Commands/Touch/Resource.pm6
index 0e346d6..2e3c077 100644
--- a/lib/App/Assixt/Commands/Touch/Resource.pm6
+++ b/lib/App/Assixt/Commands/Touch/Resource.pm6
@@ -5,37 +5,37 @@ use v6.c;
use Config;
use Dist::Helper::Meta;
-class App::Assixt::Commands::Touch::Resource
-{
- method run(
- "resource",
- Str:D $resource,
- Config:D :$config,
- ) {
- my %meta = get-meta;
-
- mkdir "resources" unless "resources".IO.d;
- chdir "resources";
-
- my $path = ".".IO.add($resource);
-
- # Check for duplicate entry
- if (%meta<resources> ∋ $path.relative) {
- note "A $resource already exists in {%meta<name>}";
- return;
- }
-
- # Create the resource
- my $parent = $path.parent.absolute;
-
- mkdir $parent unless $parent.IO.d;
- spurt($path, "") unless $path.IO.e;
-
- # Add the resource to the META6.json
- %meta<resources>.push: $path.relative;
- put-meta(:%meta, path => "..");
-
- # User-friendly output
- say "Added resource $resource to {%meta<name>}";
+unit class App::Assixt::Commands::Touch::Resource;
+
+method run(
+ Str:D $resource,
+ Config:D :$config,
+) {
+ my %meta = get-meta($config<cwd>);
+ my IO::Path $resources = $config<cwd>.add("resources");
+
+ mkdir $resources unless $resources.d;
+
+ my IO::Path $path = $resources.add($resource);
+
+ # Check for duplicate entry
+ if (%meta<resources> ∋ $path.relative($resources)) {
+ note "A $resource already exists in {%meta<name>}";
+ return;
}
+
+ # Create the resource
+ my $parent = $path.parent;
+
+ mkdir $parent unless $parent.d;
+ spurt($path, "");
+
+ # Add the resource to the META6.json
+ %meta<resources>.push: $path.relative($resources);
+ put-meta(%meta, $config<cwd>);
+
+ # User-friendly output
+ say "Added resource $resource to {%meta<name>}";
+
+ $resource;
}
diff --git a/t/02-command-touch-resource.t b/t/02-command-touch-resource.t
index 3e22cc2..6e6f007 100644
--- a/t/02-command-touch-resource.t
+++ b/t/02-command-touch-resource.t
@@ -6,19 +6,19 @@ use Test;
BEGIN plan :skip-all<set AUTHOR_TESTING=1 to run bin tests> unless %*ENV<AUTHOR_TESTING>;
+use App::Assixt::Commands::Touch::Resource;
+use App::Assixt::Config;
use App::Assixt::Test;
+use Config;
use Dist::Helper::Meta;
use File::Temp;
-my $assixt = $*CWD;
-my $root = tempdir;
+plan 1;
-chdir $root;
-
-plan 2;
-
-ok create-test-module($assixt, "Local::Test::Touch::Resource"), "assixt new Local::Test::Touch::Resource";
-chdir "$root/perl6-Local-Test-Touch-Resource";
+my IO::Path $module = create-test-module("Local::Test::Touch::Resource", tempdir.IO);
+my Config $config = get-config.read: %(
+ cwd => $module,
+);
subtest "Touch unit files", {
my @tests = <
@@ -27,19 +27,14 @@ subtest "Touch unit files", {
third/level/test
>;
- my $module-dir = "$root/perl6-Local-Test-Touch-Resource";
-
- plan 4 × @tests.elems;
+ plan 3 × @tests.elems;
for @tests -> $test {
- chdir $module-dir;
-
- ok get-meta()<resources> ∌ $test, "META6.json does not contain $test yet";
- ok run-bin($assixt, « touch resource $test »), "assixt touch resource $test";
+ ok get-meta($module)<resources> ∌ $test, "META6.json does not contain $test yet";
- chdir $module-dir;
+ App::Assixt::Commands::Touch::Resource.run($test, :$config);
- my %new-meta = get-meta;
+ my %new-meta = get-meta($module);
ok %new-meta<resources> ∋ $test, "$test exists in META6.json<provides>";
ok "resources/$test", "Resource $test exists";