1 module tests.cpprules; 2 3 4 import reggae; 5 import unit_threaded; 6 7 8 void testNoIncludePaths() { 9 const build = Build(objectFile("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 ["DEPFILE = $out.dep"]), 14 ]); 15 } 16 17 18 void testIncludePaths() { 19 const build = Build(objectFile("path/to/src/foo.cpp", "", ["path/to/src", "other/path"])); 20 const ninja = Ninja(build, "/tmp/myproject"); 21 ninja.buildEntries.shouldEqual( 22 [NinjaEntry("build path/to/src/foo.o: _cppcompile /tmp/myproject/path/to/src/foo.cpp", 23 ["includes = -I/tmp/myproject/path/to/src -I/tmp/myproject/other/path", 24 "DEPFILE = $out.dep"]), 25 ]); 26 } 27 28 29 void testFlagsCompileC() { 30 const build = Build(objectFile("path/to/src/foo.c", "-m64 -fPIC -O3")); 31 const ninja = Ninja(build, "/tmp/myproject"); 32 ninja.buildEntries.shouldEqual( 33 [NinjaEntry("build path/to/src/foo.o: _ccompile /tmp/myproject/path/to/src/foo.c", 34 ["flags = -m64 -fPIC -O3", 35 "DEPFILE = $out.dep"]), 36 ]); 37 } 38 39 void testFlagsCompileCpp() { 40 const build = Build(objectFile("path/to/src/foo.cpp", "-m64 -fPIC -O3")); 41 const ninja = Ninja(build, "/tmp/myproject"); 42 ninja.buildEntries.shouldEqual( 43 [NinjaEntry("build path/to/src/foo.o: _cppcompile /tmp/myproject/path/to/src/foo.cpp", 44 ["flags = -m64 -fPIC -O3", 45 "DEPFILE = $out.dep"]), 46 ]); 47 } 48 49 void testCppCompile() { 50 const mathsObj = objectFile(`src/cpp/maths.cpp`, `-m64 -fPIC -O3`, [`headers`]); 51 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"); 52 } 53 54 void testCCompile() { 55 const mathsObj = objectFile(`src/c/maths.c`, `-m64 -fPIC -O3`, [`headers`]); 56 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"); 57 }