Skip to content

Commit b444beb

Browse files
committed
dastest: quote spaced args in launchPrefix + regression test + typo (Copilot)
Address Copilot review on PR #2897: 1. Quoting (#3308736517): launchPrefix builds singleTest as a space-joined string. When any preserved pre-`--` arg contains a space (e.g. `-load_module "C:\Program Files\daslang/dasImgui"`), popen's shell-split on the other side breaks the boundary. Pre-fix this was a latent risk on raw_args[0]/raw_args[1] too; extending preservation to all pre-`--` args makes it more likely. Wrap each space-containing arg in double quotes — both cmd.exe and /bin/sh honor double-quote-wrapped args. 2. Regression test (#3308736537): add a second subtest in test_isolated_mode that spawns dastest with a pre-`--` `-dasroot {get_das_root()}` (no-op value) and runs against a new _isolated_fixture_pre_dashdash/ subdir whose fixture test asserts -dasroot is in get_command_line_arguments(). Catches any regression of the launchPrefix reconstruction. 3. Typo (#3308736556): "Findex" → "Find index" in the launchPrefix comment. Verified: full dastest sweep 9/9 pass (was 8/8, +1 new subtest).
1 parent 335e173 commit b444beb

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

dastest/dastest.das

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,20 @@ def main() : int {
395395
// dastest.das, --, ...], the old "raw_args[0] raw_args[1]" reconstruction
396396
// produced "daslang -load_module" — losing the flag value, breaking
397397
// local runs that point dastest at an external module via -load_module.
398-
// Findex of `--` ≥ 0 always (dastest was invoked with `--` to receive
398+
// Find index of `--` ≥ 0 always (dastest was invoked with `--` to receive
399399
// its own args); fall back to all raw_args if not, matching the old
400-
// 2-arg implicit assumption.
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.
401403
let dashdash = find_index(raw_args, "--")
402404
let launchPrefix = build_string() $(var w) {
403405
let n = dashdash > 0 ? dashdash : length(raw_args)
404406
for (i in range(n)) {
405407
if (i > 0) w |> write(" ")
408+
let needs_quote = raw_args[i] |> contains(" ")
409+
if (needs_quote) w |> write("\"")
406410
w |> write(raw_args[i])
411+
if (needs_quote) w |> write("\"")
407412
}
408413
}
409414
log::info("Running {totalFiles} tests in isolated mode with {totalThreads} threads\n")
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)