1 module tests.binary; 2 3 import reggae; 4 import unit_threaded; 5 6 7 class FooException: Exception { 8 this(string msg = "") { super(msg); } 9 } 10 11 class BarException: Exception { 12 this(string msg = "") { super(msg); } 13 } 14 15 bool fooCalled; 16 bool barCalled; 17 18 void resetCalls() { fooCalled = false; barCalled = false;} 19 void foo(in string[] inputs, in string[] outputs) { 20 fooCalled = true; 21 } 22 23 void bar(in string[] inputs, in string[] outputs) { 24 barCalled = true; 25 } 26 27 @HiddenTest 28 void testTargetSelection() { 29 const foo = Target("foo", &foo, Target("foo.d")); 30 const bar = Target("bar", &bar, Target("bar.d")); 31 const binary = Binary(Build(foo, bar), "/path/to"); 32 33 { 34 scope(exit) resetCalls; 35 binary.run(["prog"]); 36 fooCalled.shouldBeTrue; 37 barCalled.shouldBeTrue; 38 } 39 40 { 41 scope(exit) resetCalls; 42 binary.run(["prog", "foo", "bar"]); 43 fooCalled.shouldBeTrue; 44 barCalled.shouldBeTrue; 45 } 46 47 { 48 scope(exit) resetCalls; 49 binary.run(["prog", "foo"]); 50 fooCalled.shouldBeTrue; 51 barCalled.shouldBeFalse; 52 } 53 54 { 55 scope(exit) resetCalls; 56 binary.run(["prog", "bar"]); 57 fooCalled.shouldBeFalse; 58 barCalled.shouldBeTrue; 59 } 60 61 { 62 scope(exit) resetCalls; 63 binary.run(["prog", "nonexistent"]).shouldThrow; 64 fooCalled.shouldBeFalse; 65 barCalled.shouldBeFalse; 66 } 67 } 68 69 void testTopLevelTargets() { 70 const foo = Target("foo", &foo, Target("foo.d")); 71 const bar = Target("bar", &bar, Target("bar.d")); 72 const binary = Binary(Build(foo, bar), "/path/to"); 73 binary.topLevelTargets(["foo"]).shouldEqual([foo]); 74 binary.topLevelTargets(["bar"]).shouldEqual([bar]); 75 binary.topLevelTargets([]).shouldEqual([foo, bar]); 76 binary.topLevelTargets(["oops"]).shouldEqual([]); 77 }