1 module tests.cpprules; 2 3 4 import reggae; 5 import unit_threaded; 6 7 8 void testNoIncludePaths() { 9 const build = Build(cppCompile("path/to/src/foo.cpp")); 10 const ninja = Ninja(build, "/tmp/myproject"); 11 ninja.buildEntries.shouldEqual( 12 [NinjaEntry("build path/to/src/foo.o: _cppcompile /tmp/myproject/path/to/src/foo.cpp", 13 ["includes = ", 14 "flags = ", 15 "DEPFILE = path/to/src/foo.o.dep"]), 16 ]); 17 } 18 19 20 void testIncludePaths() { 21 const build = Build(cppCompile("path/to/src/foo.cpp", "", ["path/to/src", "other/path"])); 22 const ninja = Ninja(build, "/tmp/myproject"); 23 ninja.buildEntries.shouldEqual( 24 [NinjaEntry("build path/to/src/foo.o: _cppcompile /tmp/myproject/path/to/src/foo.cpp", 25 ["includes = -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path", 26 "flags = ", 27 "DEPFILE = path/to/src/foo.o.dep"]), 28 ]); 29 } 30 31 32 33 void testNoSrcFileSelection() { 34 selectSrcFiles([], [], []).shouldEqual([]); 35 } 36 37 38 void testSrcFileSelection() { 39 auto dirFiles = ["src/foo.d", "src/bar.d", "weird/peculiar.d"]; 40 auto extraSrcs = ["extra/toto.d", "extra/choochoo.d"]; 41 auto excludeSrcs = ["weird/peculiar.d"]; 42 43 selectSrcFiles(dirFiles, extraSrcs, excludeSrcs).shouldEqual( 44 ["src/foo.d", "src/bar.d", "extra/toto.d", "extra/choochoo.d"]); 45 } 46 47 48 void testFlagsCompileC() { 49 const build = Build(cCompile("path/to/src/foo.c", "-m64 -fPIC -O3")); 50 const ninja = Ninja(build, "/tmp/myproject"); 51 ninja.buildEntries.shouldEqual( 52 [NinjaEntry("build path/to/src/foo.o: _ccompile /tmp/myproject/path/to/src/foo.c", 53 ["includes = ", 54 "flags = -m64 -fPIC -O3", 55 "DEPFILE = path/to/src/foo.o.dep"]), 56 ]); 57 } 58 59 void testFlagsCompileCpp() { 60 const build = Build(cppCompile("path/to/src/foo.cpp", "-m64 -fPIC -O3")); 61 const ninja = Ninja(build, "/tmp/myproject"); 62 ninja.buildEntries.shouldEqual( 63 [NinjaEntry("build path/to/src/foo.o: _cppcompile /tmp/myproject/path/to/src/foo.cpp", 64 ["includes = ", 65 "flags = -m64 -fPIC -O3", 66 "DEPFILE = path/to/src/foo.o.dep"]), 67 ]); 68 } 69 70 void testCppCompile() { 71 const mathsObj = cppCompile(`src/cpp/maths.cpp`, `-m64 -fPIC -O3`, [`headers`]); 72 mathsObj.shellCommand("/path/to").shouldEqual("g++ -m64 -fPIC -O3 -I/path/to/headers -MMD -MT src/cpp/maths.o -MF src/cpp/maths.o.dep -o src/cpp/maths.o -c /path/to/src/cpp/maths.cpp"); 73 } 74 75 void testCCompile() { 76 const mathsObj = cCompile(`src/c/maths.c`, `-m64 -fPIC -O3`, [`headers`]); 77 mathsObj.shellCommand("/path/to").shouldEqual("gcc -m64 -fPIC -O3 -I/path/to/headers -MMD -MT src/c/maths.o -MF src/c/maths.o.dep -o src/c/maths.o -c /path/to/src/c/maths.c"); 78 }