1 module tests.ut.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 auto protoSrcs = Target([`$builddir/gen/protocol.c`, `$builddir/gen/protocol.h`], 33 `./compiler $in`, 34 [Target(`protocol.proto`)]); 35 auto protoObj = Target(`$builddir/bin/protocol.o`, 36 `gcc -o $out -c $builddir/gen/protocol.c`, 37 [], [protoSrcs]); 38 auto protoD = Target(`$builddir/gen/protocol.d`, 39 `echo "extern(C) " > $out; cat $builddir/gen/protocol.h >> $out`, 40 [], [protoSrcs]); 41 auto 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 auto 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 [barObj, fooObj, header], //level 1 82 [target], //level 0 83 ]); 84 } 85 86 void testLeavesEmpty() { 87 Leaves(Target("leaf")).array.shouldEqual([Target("leaf")]); 88 } 89 90 91 void testLeavesTwoLevels() { 92 auto fooC = Target("foo.c"); 93 auto barC = Target("bar.c"); 94 auto fooObj = Target("foo.o", "gcc -c -o foo.o foo.c", [fooC]); 95 auto barObj = Target("bar.o", "gcc -c -o bar.o bar.c", [barC]); 96 auto hdrI = Target("hdr.i"); 97 auto header = Target("hdr.h", "genhdr $in", [hdrI]); 98 auto impLeaf = Target("leaf"); 99 100 //implicit dependencies should show up, but only if they're not leaves 101 auto target = Target("app", 102 "gcc -o letarget foo.o bar.o", 103 [fooObj, barObj], 104 [header, impLeaf]); 105 106 Leaves(target).array.shouldEqual([fooC, barC, hdrI, impLeaf]); 107 }