1 /** 2 Tests for runtime arguments. 3 */ 4 module it.c.compile.runtime_args; 5 6 7 import it; 8 9 @("include paths") 10 @safe unittest { 11 with(immutable IncludeSandbox()) { 12 writeFile("includes/hdr.h", 13 q{ 14 int add(int i, int j); 15 }); 16 writeFile("main.dpp", 17 ` 18 #include "hdr.h" 19 void main() { 20 int ret = add(2, 3); 21 } 22 `); 23 runPreprocessOnly( 24 "--include-path", 25 inSandboxPath("includes"), 26 "main.dpp", 27 ); 28 29 shouldCompile("main.d"); 30 } 31 } 32 33 @("rewritten module name") 34 @safe unittest { 35 with(immutable IncludeSandbox()) { 36 writeFile("pretend-windows.h", 37 ``); 38 writeFile("hdr.h", 39 ` 40 #include "pretend-windows.h" 41 `); 42 writeFile("main.dpp", 43 ` 44 #include "hdr.h" 45 void main() { 46 writeln(""); // should have imported by include translation 47 } 48 `); 49 runPreprocessOnly( 50 "--prebuilt-header", 51 "pretend-windows.h=std.stdio", 52 "main.dpp", 53 ); 54 55 shouldCompile("main.d"); 56 } 57 } 58 59 @("ignored paths") 60 @safe unittest { 61 with(immutable IncludeSandbox()) { 62 writeFile("pretend-windows.h", 63 ` 64 #define foo "foo" 65 `); 66 writeFile("hdr.h", 67 ` 68 #include "pretend-windows.h" 69 `); 70 writeFile("main.dpp", 71 ` 72 #include "hdr.h" 73 void main() { 74 static assert(!is(typeof(foo))); 75 } 76 `); 77 runPreprocessOnly( 78 "--ignore-path", 79 "*pretend-windows.h", 80 "main.dpp", 81 ); 82 83 shouldCompile("main.d"); 84 } 85 } 86 87 @("ignored system paths") 88 @safe unittest { 89 with(immutable IncludeSandbox()) { 90 writeFile("main.dpp", 91 ` 92 #include <stdio.h> 93 // since the system path is ignored, the declarations 94 // should NOT have been generated here 95 void main() { 96 static assert(!is(typeof(printf))); 97 } 98 `); 99 runPreprocessOnly( 100 "--ignore-system-paths", 101 "main.dpp", 102 ); 103 104 shouldCompile("main.d"); 105 } 106 }