| 1 | import os |
| 2 | |
| 3 | const vexe = os.getenv('VEXE') |
| 4 | const vroot = os.dir(vexe) |
| 5 | |
| 6 | // strip_tcc_fallback_warning removes the noisy macOS-only `warning: tcc compilation |
| 7 | // failed, falling back to cc` line that v emits to stderr and that os.execute folds |
| 8 | // into the captured output. The CI path-with-spaces+comma jobs trigger this fallback, |
| 9 | // which would otherwise prefix the program output and break starts_with assertions. |
| 10 | fn strip_tcc_fallback_warning(output string) string { |
| 11 | mut s := output |
| 12 | for s.contains('tcc compilation failed') { |
| 13 | nl := s.index('\n') or { return s } |
| 14 | s = s[nl + 1..] |
| 15 | } |
| 16 | return s |
| 17 | } |
| 18 | |
| 19 | fn test_v_run_simple() { |
| 20 | echo_os_args := os.join_path(vroot, 'cmd/tools/test_os_args.v') |
| 21 | res123 := os.execute('${os.quoted_path(vexe)} run ${os.quoted_path(echo_os_args)} 1 2 3') |
| 22 | println(res123) |
| 23 | assert res123.exit_code == 0 |
| 24 | assert strip_tcc_fallback_warning(res123.output).starts_with("['1', '2', '3']") |
| 25 | } |
| 26 | |
| 27 | fn test_v_run_quoted_args_with_spaces() { |
| 28 | echo_os_args := os.join_path(vroot, 'cmd/tools/test_os_args.v') |
| 29 | res := os.execute('${os.quoted_path(vexe)} run ${os.quoted_path(echo_os_args)} 1 "Learn V" 3') |
| 30 | println(res) |
| 31 | assert res.exit_code == 0 |
| 32 | assert strip_tcc_fallback_warning(res.output).starts_with("['1', 'Learn V', '3']") |
| 33 | } |
| 34 | |
| 35 | fn test_v_run_quoted_args_with_spaces__use_os_system_to_run() { |
| 36 | echo_os_args := os.join_path(vroot, 'cmd/tools/test_os_args.v') |
| 37 | res := |
| 38 | os.execute('${os.quoted_path(vexe)} -use-os-system-to-run run ${os.quoted_path(echo_os_args)} 1 "Learn V" 3') |
| 39 | println(res) |
| 40 | assert res.exit_code == 0 |
| 41 | assert strip_tcc_fallback_warning(res.output).starts_with("['1', 'Learn V', '3']") |
| 42 | } |
| 43 | |
| 44 | fn test_v_run_file_from_path_with_spaces() { |
| 45 | echo_os_args := os.join_path(vroot, 'cmd/tools/test_os_args.v') |
| 46 | spaced_dir := os.join_path(os.vtmp_dir(), 'v run path with spaces') |
| 47 | spaced_echo_os_args := os.join_path(spaced_dir, 'test os args.v') |
| 48 | os.rmdir_all(spaced_dir) or {} |
| 49 | os.mkdir_all(spaced_dir)! |
| 50 | defer { |
| 51 | os.rmdir_all(spaced_dir) or {} |
| 52 | } |
| 53 | os.cp(echo_os_args, spaced_echo_os_args)! |
| 54 | res := |
| 55 | os.execute('${os.quoted_path(vexe)} run ${os.quoted_path(spaced_echo_os_args)} 1 "Learn V" 3') |
| 56 | println(res) |
| 57 | assert res.exit_code == 0 |
| 58 | assert strip_tcc_fallback_warning(res.output).starts_with("['1', 'Learn V', '3']") |
| 59 | } |
| 60 | |