| 17 | | writeln("d_do_test <input_dir> <test_name> <test_extension>" |
|---|
| 18 | | "" |
|---|
| 19 | | " input_dir: one of: compilable, fail_compilation, runnable" |
|---|
| 20 | | " test_name: basename of test case to run" |
|---|
| 21 | | " test_extension: one of: d, html, or sh" |
|---|
| 22 | | "" |
|---|
| 23 | | " example: d_do_test runnable pi d" |
|---|
| 24 | | "" |
|---|
| 25 | | " relevant environment variables:" |
|---|
| 26 | | " ARGS: set to execute all combinations of" |
|---|
| 27 | | " DMD: compiler to use, ex: ../src/dmd" |
|---|
| 28 | | " OS: win32, linux, freebsd, osx" |
|---|
| 29 | | " RESULTS_DIR: base directory for test results" |
|---|
| 30 | | " windows vs non-windows portability env vars:" |
|---|
| 31 | | " DSEP: \\\\ or /" |
|---|
| 32 | | " SEP: \\ or /" |
|---|
| 33 | | " OBJ: .obj or .o" |
|---|
| 34 | | " EXE: .exe or <null>"); |
|---|
| | 17 | write("d_do_test <input_dir> <test_name> <test_extension>\n" |
|---|
| | 18 | "\n" |
|---|
| | 19 | " input_dir: one of: compilable, fail_compilation, runnable\n" |
|---|
| | 20 | " test_name: basename of test case to run\n" |
|---|
| | 21 | " test_extension: one of: d, html, or sh\n" |
|---|
| | 22 | "\n" |
|---|
| | 23 | " example: d_do_test runnable pi d\n" |
|---|
| | 24 | "\n" |
|---|
| | 25 | " relevant environment variables:\n" |
|---|
| | 26 | " ARGS: set to execute all combinations of\n" |
|---|
| | 27 | " DMD: compiler to use, ex: ../src/dmd\n" |
|---|
| | 28 | " OS: win32, linux, freebsd, osx\n" |
|---|
| | 29 | " RESULTS_DIR: base directory for test results\n" |
|---|
| | 30 | " windows vs non-windows portability env vars:\n" |
|---|
| | 31 | " DSEP: \\\\ or /\n" |
|---|
| | 32 | " SEP: \\ or /\n" |
|---|
| | 33 | " OBJ: .obj or .o\n" |
|---|
| | 34 | " EXE: .exe or <null>\n"); |
|---|
| 66 | 67 | } |
|---|
| 67 | 68 | |
|---|
| 68 | 69 | bool findTestParameter(string file, string token, ref string result) |
|---|
| 69 | 70 | { |
|---|
| 70 | 71 | auto tokenStart = std.string.indexOf(file, token); |
|---|
| 71 | 72 | if (tokenStart == -1) return false; |
|---|
| 72 | 73 | |
|---|
| 73 | 74 | auto lineEndR = std.string.indexOf(file[tokenStart .. $], "\r"); |
|---|
| 74 | 75 | auto lineEndN = std.string.indexOf(file[tokenStart .. $], "\n"); |
|---|
| 75 | 76 | auto lineEnd = lineEndR == -1 ? |
|---|
| 76 | 77 | (lineEndN == -1 ? file.length : lineEndN) : |
|---|
| 77 | 78 | (lineEndN == -1 ? lineEndR : min(lineEndR, lineEndN)); |
|---|
| 78 | 79 | |
|---|
| 79 | 80 | //writeln("found ", token, " in line: ", file.length, ", ", tokenStart, ", ", tokenStart+lineEnd); |
|---|
| 80 | 81 | //writeln("found ", token, " in line: '", file[tokenStart .. tokenStart+lineEnd], "'"); |
|---|
| 81 | 82 | |
|---|
| 82 | 83 | result = strip(file[tokenStart+token.length .. tokenStart+lineEnd]); |
|---|
| 83 | 84 | // skips the :, if present |
|---|
| 84 | 85 | if (result.length > 0 && result[0] == ':') |
|---|
| 85 | 86 | result = strip(result[1 .. $]); |
|---|
| 227 | 228 | { |
|---|
| 228 | 229 | if (args.length != 4) |
|---|
| 229 | 230 | { |
|---|
| 230 | 231 | usage(); |
|---|
| 231 | 232 | return 1; |
|---|
| 232 | 233 | } |
|---|
| 233 | 234 | |
|---|
| 234 | 235 | string input_dir = args[1]; |
|---|
| 235 | 236 | string test_name = args[2]; |
|---|
| 236 | 237 | string test_extension = args[3]; |
|---|
| 237 | 238 | |
|---|
| 238 | 239 | EnvData envData; |
|---|
| 239 | 240 | envData.all_args = getenv("ARGS"); |
|---|
| 240 | 241 | envData.results_dir = getenv("RESULTS_DIR"); |
|---|
| 241 | 242 | envData.sep = getenv("SEP"); |
|---|
| 242 | 243 | envData.dsep = getenv("DSEP"); |
|---|
| 243 | 244 | envData.obj = getenv("OBJ"); |
|---|
| 244 | 245 | envData.exe = getenv("EXE"); |
|---|
| 245 | 246 | envData.os = getenv("OS"); |
|---|
| 246 | 247 | envData.dmd = replace(getenv("DMD"), "/", envData.sep); |
|---|
| 247 | 249 | |
|---|
| 248 | 250 | string input_file = input_dir ~ envData.sep ~ test_name ~ "." ~ test_extension; |
|---|
| 249 | 251 | string output_dir = envData.results_dir ~ envData.sep ~ input_dir; |
|---|
| 250 | 252 | string output_file = envData.results_dir ~ envData.sep ~ input_dir ~ envData.sep ~ test_name ~ "." ~ test_extension ~ ".out"; |
|---|
| 251 | 253 | string test_app_dmd_base = output_dir ~ envData.sep ~ test_name ~ "_"; |
|---|
| 252 | 254 | |
|---|
| 253 | 255 | TestArgs testArgs; |
|---|
| 254 | 256 | |
|---|
| 255 | 257 | switch (input_dir) |
|---|
| 256 | 258 | { |
|---|
| 257 | 259 | case "compilable": testArgs.mode = TestMode.COMPILE; break; |
|---|
| 258 | 260 | case "fail_compilation": testArgs.mode = TestMode.FAIL_COMPILE; break; |
|---|
| 259 | 261 | case "runnable": testArgs.mode = TestMode.RUN; break; |
|---|
| 260 | 262 | } |
|---|
| 261 | 263 | |
|---|
| 262 | 264 | gatherTestParameters(testArgs, input_dir, input_file, envData); |
|---|
| 263 | 265 | |
|---|
| 264 | 266 | writefln(" ... %-30s %s%s(%s)", |
|---|
| 265 | 267 | input_file, |
|---|
| 266 | 268 | testArgs.requiredArgs, |
|---|
| 271 | 273 | std.file.remove(output_file); |
|---|
| 272 | 274 | |
|---|
| 273 | 275 | auto f = File(output_file, "a"); |
|---|
| 274 | 276 | |
|---|
| 275 | 277 | foreach(i, c; combinations(testArgs.permuteArgs)) |
|---|
| 276 | 278 | { |
|---|
| 277 | 279 | string[] toCleanup; |
|---|
| 278 | 280 | |
|---|
| 279 | 281 | string test_app_dmd = test_app_dmd_base ~ to!string(i) ~ envData.exe; |
|---|
| 280 | 282 | |
|---|
| 281 | 283 | try |
|---|
| 282 | 284 | { |
|---|
| 283 | 285 | if (!testArgs.compileSeparately) |
|---|
| 284 | 286 | { |
|---|
| 285 | 287 | string objfile = output_dir ~ envData.sep ~ test_name ~ "_" ~ to!string(i) ~ envData.obj; |
|---|
| 286 | 288 | toCleanup ~= objfile; |
|---|
| 287 | 289 | |
|---|
| 288 | 290 | if (testArgs.mode == TestMode.RUN) |
|---|
| 289 | 291 | toCleanup ~= test_app_dmd; |
|---|
| 290 | 292 | |
|---|
| 292 | 294 | testArgs.requiredArgs, c, output_dir, |
|---|
| 293 | 295 | (testArgs.mode == TestMode.RUN ? test_app_dmd : objfile), |
|---|
| 294 | 296 | (testArgs.mode == TestMode.RUN ? "" : "-c "), |
|---|
| 295 | 297 | join(testArgs.sources, " ")); |
|---|
| 296 | 298 | version(Windows) command ~= " -map nul.map"; |
|---|
| 297 | 299 | execute(f, command, testArgs.mode != TestMode.FAIL_COMPILE); |
|---|
| 298 | 300 | } |
|---|
| 299 | 301 | else |
|---|
| 300 | 302 | { |
|---|
| 301 | 303 | foreach (filename; testArgs.sources) |
|---|
| 302 | 304 | { |
|---|
| 303 | 305 | string newo= envData.results_dir ~ envData.sep ~ |
|---|
| 304 | 306 | replace(replace(filename, ".d", envData.obj), envData.sep~"imports"~envData.sep, envData.sep); |
|---|
| 305 | 307 | toCleanup ~= newo; |
|---|
| 306 | 308 | |
|---|
| 316 | 318 | version(Windows) command ~= " -map nul.map"; |
|---|
| 317 | 319 | |
|---|
| 318 | 320 | // add after building the command so that before now, it's purely the .o's involved |
|---|
| 319 | 321 | toCleanup ~= test_app_dmd; |
|---|
| 320 | 322 | |
|---|
| 321 | 323 | execute(f, command, true); |
|---|
| 322 | 324 | } |
|---|
| 323 | 325 | } |
|---|
| 324 | 326 | |
|---|
| 325 | 327 | if (testArgs.mode == TestMode.RUN) |
|---|
| 326 | 328 | { |
|---|
| 327 | 329 | string command = test_app_dmd; |
|---|
| 328 | 330 | if (testArgs.executeArgs) command ~= " " ~ testArgs.executeArgs; |
|---|
| 329 | 331 | |
|---|
| 330 | 332 | execute(f, command, true); |
|---|
| 331 | 333 | } |
|---|
| 332 | 334 | |
|---|
| 333 | 335 | if (testArgs.postScript) |
|---|
| 334 | 336 | { |
|---|
| 335 | 337 | f.write("Executing post-test script: "); |
|---|