Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add basic tests and some code which accidentally passes them

  • Loading branch information...
commit fa5e4b6f33593ab448e37c86fd91f51eaf1d087d 1 parent 38f666a
Tadeusz Sośnierz tadzik authored
Showing with 57 additions and 0 deletions.
  1. +24 −0 lib/BreakDancer.pm
  2. +33 −0 t/01-basic.t
24 lib/BreakDancer.pm
View
@@ -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 t/01-basic.t
View
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.