Skip to content

Commit 5f0f70b

Browse files
authored
Merge pull request #2897 from GaijinEntertainment/bbatkin/dastest-preserve-pre-dashdash-flags
dastest: preserve every pre-`--` daslang flag in isolated-mode subprocess cmd
2 parents ed10ff7 + b444beb commit 5f0f70b

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

dastest/dastest.das

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,27 @@ def main() : int {
390390
// Without this, the post-`--` slice in the child loses --headless and any
391391
// playwright/harness that depends on it reverts to windowed mode.
392392
let headlessFlag = find_index(raw_args, "--headless") >= 0 ? " --headless" : ""
393+
// Preserve EVERY pre-`--` arg (daslang flags + script path), not just
394+
// raw_args[0..1]. With raw_args = [daslang, -load_module, <path>,
395+
// dastest.das, --, ...], the old "raw_args[0] raw_args[1]" reconstruction
396+
// produced "daslang -load_module" — losing the flag value, breaking
397+
// local runs that point dastest at an external module via -load_module.
398+
// Find index of `--` ≥ 0 always (dastest was invoked with `--` to receive
399+
// its own args); fall back to all raw_args if not, matching the old
400+
// 2-arg implicit assumption. Quote any arg containing a space so paths
401+
// like `C:/Program Files/...` survive popen's shell-split on the other
402+
// side; both cmd.exe and /bin/sh honor double-quote-wrapped args.
403+
let dashdash = find_index(raw_args, "--")
404+
let launchPrefix = build_string() $(var w) {
405+
let n = dashdash > 0 ? dashdash : length(raw_args)
406+
for (i in range(n)) {
407+
if (i > 0) w |> write(" ")
408+
let needs_quote = raw_args[i] |> contains(" ")
409+
if (needs_quote) w |> write("\"")
410+
w |> write(raw_args[i])
411+
if (needs_quote) w |> write("\"")
412+
}
413+
}
393414
log::info("Running {totalFiles} tests in isolated mode with {totalThreads} threads\n")
394415
with_channel(totalFiles) $(inputChannel) {
395416
with_channel(totalFiles) $(outputChannel) {
@@ -458,7 +479,7 @@ def main() : int {
458479
let jitstr = jit_enabled() ? "-jit" : ""
459480
let aotstr = is_in_aot() ? "-use-aot" : ""
460481
let benchstr = ctx.bench_enabled ? "--bench" : ""
461-
let singleTest = "{raw_args[0]} {raw_args[1]} {jitstr} {aotstr} -- --run {file} {benchstr} {log::useTtyColors ? " --color" : ""}{headlessFlag}"
482+
let singleTest = "{launchPrefix} {jitstr} {aotstr} -- --run {file} {benchstr} {log::useTtyColors ? " --color" : ""}{headlessFlag}"
462483
inputChannel |> push_clone(IsoInput(uri = clone_string(uri), cmd = clone_string(singleTest)))
463484
inputChannel |> notify()
464485
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
options gen2
2+
3+
require dastest/testing_boost public
4+
require strings
5+
6+
// This fixture asserts that a daslang flag passed BEFORE the dastest.das
7+
// script (e.g. `daslang -dasroot <path> dastest.das -- ...`) is preserved
8+
// through dastest's isolated-mode singleTest cmd reconstruction. The outer
9+
// test_isolated_mode.das spawns dastest with a pre-`--` `-dasroot` flag;
10+
// this fixture runs in the spawned subprocess and checks that `-dasroot`
11+
// is in its own raw argv (because dastest preserved it via launchPrefix).
12+
[test]
13+
def test_preserved_flag_round_trip(tt : T?) {
14+
tt |> run("dastest preserves pre-`--` daslang flags in isolated-mode subprocess argv") <| @(t : T?) {
15+
let argv <- get_command_line_arguments()
16+
let idx = find_index(argv, "-dasroot")
17+
t |> success(idx >= 0, "expected -dasroot in argv, got argv={argv}")
18+
if (idx < 0) {
19+
return
20+
}
21+
t |> success(idx + 1 < length(argv), "-dasroot has no following path arg in argv")
22+
}
23+
}

dastest/tests/test_isolated_mode.das

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ def fixture_dir() : string {
1515
return "{dastest_root()}/tests/_isolated_fixture"
1616
}
1717

18-
def run_isolated(var output : string&; var exit_code : int&) {
19-
let exe = get_command_line_arguments()[0]
20-
let cmd = "{exe} {dastest_root()}/dastest.das -- --test {fixture_dir()} --isolated-mode --isolated-mode-threads 4"
18+
def fixture_dir_pre_dashdash() : string {
19+
return "{dastest_root()}/tests/_isolated_fixture_pre_dashdash"
20+
}
21+
22+
def run_dastest(cmd : string; var output : string&; var exit_code : int&) {
2123
output = ""
2224
unsafe {
2325
exit_code = popen(cmd) $(f) {
@@ -33,9 +35,26 @@ def run_isolated(var output : string&; var exit_code : int&) {
3335
[test]
3436
def test_isolated_mode(tt : T?) {
3537
tt |> run("isolated mode spawns 4 workers, fixture suite all passes, --worker-index round-trips") <| @(t : T?) {
38+
let exe = get_command_line_arguments()[0]
39+
let cmd = "{exe} {dastest_root()}/dastest.das -- --test {fixture_dir()} --isolated-mode --isolated-mode-threads 4"
40+
var output : string
41+
var exit_code : int
42+
run_dastest(cmd, output, exit_code)
43+
t |> equal(exit_code, 0)
44+
t |> success(output |> contains("SUCCESS"), "expected SUCCESS in dastest output, got:\n{output}")
45+
}
46+
47+
tt |> run("isolated mode preserves pre-`--` daslang flags (-dasroot) in singleTest cmd") <| @(t : T?) {
48+
// Pass `-dasroot {existing-dasroot}` — a no-op pre-`--` flag — to the outer
49+
// dastest. Pre-fix, dastest's singleTest reconstruction used
50+
// `raw_args[0] raw_args[1]` which dropped everything between exe and
51+
// dastest.das. The fixture test under fixture_dir_pre_dashdash() asserts
52+
// -dasroot survives into the spawned subprocess's argv.
53+
let exe = get_command_line_arguments()[0]
54+
let cmd = "{exe} -dasroot {get_das_root()} {dastest_root()}/dastest.das -- --test {fixture_dir_pre_dashdash()} --isolated-mode --isolated-mode-threads 1"
3655
var output : string
3756
var exit_code : int
38-
run_isolated(output, exit_code)
57+
run_dastest(cmd, output, exit_code)
3958
t |> equal(exit_code, 0)
4059
t |> success(output |> contains("SUCCESS"), "expected SUCCESS in dastest output, got:\n{output}")
4160
}

0 commit comments

Comments
 (0)