1 /** 2 Tests for runtime arguments. 3 */ 4 module it.c.compile.runtime_args; 5 6 7 import it; 8 9 10 @("include paths absolute") 11 @safe unittest { 12 with(immutable IncludeSandbox()) { 13 writeFile("includes/hdr.h", 14 q{ 15 int add(int i, int j); 16 }); 17 writeFile("main.dpp", 18 ` 19 #include "hdr.h" 20 void main() { 21 int ret = add(2, 3); 22 } 23 `); 24 runPreprocessOnly( 25 "--include-path", 26 inSandboxPath("includes"), 27 "main.dpp", 28 ); 29 30 shouldCompile("main.d"); 31 } 32 } 33 34 35 @("include paths relative") 36 @safe unittest { 37 with(immutable IncludeSandbox()) { 38 writeFile("includes/hdr.h", 39 q{ 40 int add(int i, int j); 41 }); 42 writeFile("main.dpp", 43 ` 44 #include "hdr.h" 45 void main() { 46 int ret = add(2, 3); 47 } 48 `); 49 runPreprocessOnly( 50 "--include-path", 51 "includes", // notice the lack of `inSandboxPath` 52 "main.dpp", 53 ); 54 55 shouldCompile("main.d"); 56 } 57 } 58 59 @("--ignore-macros") 60 @safe unittest { 61 with(immutable IncludeSandbox()) { 62 writeFile("includes/hdr.h", 63 q{ 64 int add(int i, int j); 65 }); 66 writeFile("main.dpp", 67 ` 68 #include "hdr.h" 69 void main() { 70 int ret = add(10, 20); 71 } 72 `); 73 runPreprocessOnly( 74 "--include-path", 75 "includes", 76 "--ignore-macros", 77 "main.dpp", 78 ); 79 80 shouldCompile("main.d"); 81 } 82 } 83 84 85 @("src output path") 86 @safe unittest { 87 with(immutable IncludeSandbox()) { 88 writeFile("hdr.h", 89 q{ 90 int add(int i, int j); 91 }); 92 writeFile("main.dpp", 93 ` 94 #include "hdr.h" 95 void main() { 96 int ret = add(2, 3); 97 } 98 `); 99 runPreprocessOnly( 100 "--source-output-path", 101 inSandboxPath("foo/bar"), 102 "main.dpp", 103 ); 104 105 shouldCompile(inSandboxPath("foo/bar/main.d")); 106 } 107 } 108 109 110 @("rewritten module name") 111 @safe unittest { 112 with(immutable IncludeSandbox()) { 113 writeFile("pretend-windows.h", 114 ``); 115 writeFile("hdr.h", 116 ` 117 #include "pretend-windows.h" 118 `); 119 writeFile("main.dpp", 120 ` 121 #include "hdr.h" 122 void main() { 123 writeln(""); // should have imported by include translation 124 } 125 `); 126 runPreprocessOnly( 127 "--prebuilt-header", 128 "pretend-windows.h=std.stdio", 129 "main.dpp", 130 ); 131 132 shouldCompile("main.d"); 133 } 134 } 135 136 137 @("ignored paths") 138 @safe unittest { 139 with(immutable IncludeSandbox()) { 140 writeFile("pretend-windows.h", 141 ` 142 #define foo "foo" 143 `); 144 writeFile("hdr.h", 145 ` 146 #include "pretend-windows.h" 147 `); 148 writeFile("main.dpp", 149 ` 150 #include "hdr.h" 151 void main() { 152 static assert(!is(typeof(foo))); 153 } 154 `); 155 runPreprocessOnly( 156 "--ignore-path", 157 "*pretend-windows.h", 158 "main.dpp", 159 ); 160 161 shouldCompile("main.d"); 162 } 163 } 164 165 166 @("ignored system paths") 167 @safe unittest { 168 with(immutable IncludeSandbox()) { 169 writeFile("main.dpp", 170 ` 171 #include <stdio.h> 172 // since the system path is ignored, the declarations 173 // should NOT have been generated here 174 void main() { 175 static assert(!is(typeof(printf))); 176 } 177 `); 178 runPreprocessOnly( 179 "--ignore-system-paths", 180 "main.dpp", 181 ); 182 183 shouldCompile("main.d"); 184 } 185 }