Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Commit

Permalink
Add basic tests and some code which accidentally passes them
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed Sep 15, 2012
1 parent 38f666a commit fa5e4b6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/BreakDancer.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module BreakDancer;
use Shell::Command;

my $basedir = 'www';

multi gen($path, &code) is export {
mkpath "$basedir/$path";
given open("$basedir/$path/index.htm", :w) {
.say: &code();
.close;
}
}

multi gen($path is copy, %args, &code) is export {
mkpath "$basedir/$path";
for %args.kv -> $k, $v {
my $p = "$basedir/$path/$k";
mkpath $p;
given open("$p/index.htm", :w) {
.say: &code($k, $v);
.close;
}
}
}
33 changes: 33 additions & 0 deletions t/01-basic.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use v6;
use BreakDancer;
use Test;
use Shell::Command;

my %modules =
foo => [1, 'asd'],
bar => [2, 'fasada']
;

# argumentless form?
gen '/', sub {
return "lalala"
}

gen '/module', %modules, sub ($mod, $args) {
return "$mod: " ~ $args[1] x $args[0];
}

my $basedir = 'www'; # or maybe 'gen'?

ok "$basedir/index.htm".IO.f;
is slurp("$basedir/index.htm").chomp, 'lalala';

for %modules.kv -> $k, $v {
ok "$basedir/module/$k/index.htm".IO.f;
is slurp("$basedir/module/$k/index.htm").chomp,
("$k: " ~ $v[1] x $v[0]);
}

rm_rf $basedir; # cleanup

done;

0 comments on commit fa5e4b6

Please sign in to comment.