1 module tests.ut.serialisation; 2 3 4 import reggae; 5 import reggae.options; 6 import reggae.path: buildPath; 7 import unit_threaded; 8 9 @safe: 10 11 12 @("Shell command") unittest { 13 { 14 const command = Command("dmd -of$out -c $in"); 15 ubyte[] bytes = command.toBytes; 16 Command.fromBytes(bytes).shouldEqual(command); 17 } 18 19 { 20 const command = Command("g++ -o $out -c $in"); 21 ubyte[] bytes = command.toBytes; 22 Command.fromBytes(bytes).shouldEqual(command); 23 } 24 } 25 26 27 @("Builtin command") unittest { 28 { 29 const command = Command(CommandType.compile, assocListT("foo", ["lefoo", "dasfoo"])); 30 Command.fromBytes(command.toBytes).shouldEqual(command); 31 } 32 { 33 const command = Command(CommandType.compile, assocListT("bar", ["lebar", "dasbar"])); 34 Command.fromBytes(command.toBytes).shouldEqual(command); 35 } 36 } 37 38 39 @trusted 40 @("Target") unittest { 41 import reggae.config: gDefaultOptions; 42 auto target = Target("foo.o", "dmd -of$out -c $in", Target("foo.d")); 43 auto bytes = target.toBytes(gDefaultOptions.withProjectPath("/path/to")); 44 enum srcPath = buildPath("/path/to/foo.d"); 45 Target.fromBytes(bytes).shouldEqual( 46 Target("foo.o", "dmd -offoo.o -c " ~ srcPath, Target(srcPath))); 47 } 48 49 @trusted 50 @("Build") unittest { 51 import reggae.config: gDefaultOptions; 52 auto foo = Target("foo.o", "dmd -of$out -c $in", Target("foo.d")); 53 auto bar = Target("bar.o", "dmd -of$out -c $in", Target("bar.d")); 54 auto build = Build(foo, bar); 55 auto bytes = build.toBytes(gDefaultOptions.withProjectPath("/path/to")); 56 enum srcFoo = buildPath("/path/to/foo.d"); 57 enum srcBar = buildPath("/path/to/bar.d"); 58 Build.fromBytes(bytes).shouldEqual( 59 Build(Target("foo.o", "dmd -offoo.o -c " ~ srcFoo, Target(srcFoo)), 60 Target("bar.o", "dmd -ofbar.o -c " ~ srcBar, Target(srcBar)))); 61 }