/
basic.t
114 lines (90 loc) · 3.08 KB
/
basic.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use v6;
use fatal;
use lib 't/lib';
use Test;
use Build::Graph;
use Shell::Command;
use File::Temp;
my $graph = Build::Graph.new;
$graph.load-plugin('Basic');
# pre-v2017.09.84.gb.02.da.4.d.1.a Rakudos have it as $*INITTIME
my $INIT-TIME = $*INIT-INSTANT // $*INITTIME;
my $dirname = tempdir(:unlink);
my $dir = $dirname.IO;
END { rm_rf($dirname) with $dirname }
signal(SIGINT).act: { rm_rf($dirname) with $dirname; die "Interrupted!\n" };
my $source1 = ~$dir.child('source1');
$graph.add-file($source1, :action[ 'Basic/spew', '$(target)', 'Hello' ]);
my $source2 = ~$dir.child('source2');
$graph.add-file($source2, :action[ 'Basic/spew', '$(target)', 'World' ], :dependencies[ $source1 ]);
$graph.add-wildcard('foo-files', :dir("$dirname/"), :pattern(/.*\.foo/));
$graph.add-subst('bar-files', 'foo-files', :trans[ 'Basic/s-ext', 'foo', 'bar', '$(source)' ], :action[ 'Basic/spew', '$(target)', '$(source)' ]);
my $source3_foo = ~$dir.child('source3.foo');
$graph.add-file($source3_foo, :action[ 'Basic/spew', '$(target)', 'foo' ]);
my $source3_bar = ~$dir.child('source3.bar');
$graph.add-phony('build', :action[ 'Basic/noop', '$(target)' ], :dependencies[ $source1, $source2, $source3_bar ]);
$graph.add-phony('test', :action[ 'Basic/noop', '$(target)' ], :dependencies[ 'build' ]);
$graph.add-phony('install', :action[ 'Basic/noop', '$(target)' ], :dependencies[ 'build' ]);
my @sorted = $graph._sort-nodes('build');
my @full = ($source1, $source2, $source3_foo, $source3_bar, 'build');
is-deeply(@sorted, @full, 'topological sort is ok');
my @runs = <build test install>;
my %expected = (
build => [
[ @full ],
[ 'build' ],
sub { rm_rf $dirname },
[ @full ],
[ 'build' ],
sub { unlink $source2 or die "Couldn't remove $source2: $!" },
[ $source2, 'build'],
[ 'build' ],
sub { utime(0, $INIT-TIME - 1, $source3_bar) },
[ $source3_bar, 'build' ],
[ 'build' ],
sub { unlink $source3_foo; utime(0, $INIT-TIME - 1, $source3_bar) },
[ $source3_foo, $source3_bar, 'build' ],
[ 'build' ],
sub { unlink $source3_bar },
[ $source3_bar, 'build' ],
[ 'build' ],
sub { unlink $source1; utime(0, $INIT-TIME - 1, $source2) },
[ $source1, $source2, 'build'],
[ 'build' ],
],
test => [
[ |@full, 'test' ],
[ qw/build test/ ],
],
install => [
[ |@full, 'install' ],
[ qw/build install/ ],
],
);
my $clone = Build::Graph.from-hash($graph.to-hash);
is-deeply($clone.to-hash, $graph.to-hash, 'Clone serialization equals original');
my $is-clone = 0;
my @desc = <original clone>;
for $graph, $clone -> $current {
for %expected.keys.sort -> $runner {
rm_rf $dirname;
my $count = 1;
for @( %expected{$runner} ) -> $runpart {
if $runpart ~~ Callable {
$runpart.();
}
else {
my @expected = @($runpart).map: { $*SPEC.catfile($^part.split('/')) };
my @*collector;
$current.run($runner, :verbosity);
is-deeply(@*collector, @expected, "\@got is @expected in run $runner-@desc[$is-clone]-$count");
$count++;
}
}
}
$is-clone++;
}
done-testing();
sub utime(0, Instant $time, Str $filename) {
run('touch', '-d', DateTime.new($time).Str, $filename);
}