1 module tests.range; 2 3 import reggae; 4 import unit_threaded; 5 import std.array; 6 7 8 void testDepFirstLeaf() { 9 DepthFirst(Target("letarget")).array.shouldEqual([]); 10 } 11 12 void testDepthFirstOneDependencyLevel() { 13 auto target = Target("letarget", "lecmdfoo bar other", [Target("foo"), Target("bar")]); 14 auto depth = DepthFirst(target); 15 depth.array.shouldEqual([target]); 16 } 17 18 19 void testDepthFirstTwoDependencyLevels() { 20 auto fooObj = Target("foo.o", "gcc -c -o foo.o foo.c", [Target("foo.c")]); 21 auto barObj = Target("bar.o", "gcc -c -o bar.o bar.c", [Target("bar.c")]); 22 auto header = Target("hdr.h", "genhdr $in", [Target("hdr.i")]); 23 auto impLeaf = Target("leaf"); 24 //implicit dependencies should show up, but only if they're not leaves 25 auto target = Target("app", "gcc -o letarget foo.o bar.o", [fooObj, barObj], [header, impLeaf]); 26 auto depth = DepthFirst(target); 27 depth.array.shouldEqual([fooObj, barObj, header, target]); 28 } 29 30 31 void testDepthFirstProtocolExample() { 32 const protoSrcs = Target([`$builddir/gen/protocol.c`, `$builddir/gen/protocol.h`], 33 `./compiler $in`, 34 [Target(`protocol.proto`)]); 35 const protoObj = Target(`$builddir/bin/protocol.o`, 36 `gcc -o $out -c $builddir/gen/protocol.c`, 37 [], [protoSrcs]); 38 const protoD = Target(`$builddir/gen/protocol.d`, 39 `echo "extern(C) " > $out; cat $builddir/gen/protocol.h >> $out`, 40 [], [protoSrcs]); 41 const app = Target(`app`, 42 `dmd -of$out $in`, 43 [Target(`src/main.d`), protoObj, protoD]); 44 DepthFirst(app).array.shouldEqual( 45 [protoSrcs, protoObj, protoSrcs, protoD, app]); 46 } 47 48 49 void testByDepthLevelLeaf() { 50 ByDepthLevel(Target("letarget")).array.shouldEqual([]); 51 } 52 53 54 void testByDepthLevelOneLevel() { 55 const target = Target("letarget", "lecmdfoo bar other", [Target("foo"), Target("bar")]); 56 auto byLevel = ByDepthLevel(target); 57 byLevel.array.shouldEqual([[target]]); 58 } 59 60 void testByDepthLevelTwoDependencyLevels() { 61 auto fooC = Target("foo.c"); 62 auto barC = Target("bar.c"); 63 auto fooObj = Target("foo.o", "gcc -c -o foo.o foo.c", [fooC]); 64 auto barObj = Target("bar.o", "gcc -c -o bar.o bar.c", [barC]); 65 auto hdrI = Target("hdr.i"); 66 auto header = Target("hdr.h", "genhdr $in", [hdrI]); 67 auto impLeaf = Target("leaf"); 68 69 //implicit dependencies should show up, but only if they're not leaves 70 auto target = Target("app", 71 "gcc -o letarget foo.o bar.o", 72 [fooObj, barObj], 73 [header, impLeaf]); 74 75 auto rng = ByDepthLevel(target); 76 77 //reverse order should show up: first level 1, then level 0 78 //level 2 doesn't show up since they're all leaves (fooC, barC, hdrI) 79 rng.array.shouldEqual( 80 [ 81 [fooObj, barObj, header], //level 1 82 [target], //level 0 83 ]); 84 }