| 1 | import os |
| 2 | |
| 3 | const vexe = @VEXE |
| 4 | |
| 5 | fn test_print_backtrace_does_not_pass_a_bare_main_binary_name_to_addr2line() { |
| 6 | base_dir := os.join_path(os.vtmp_dir(), 'backtrace_addr2line_path_test_${os.getpid()}') |
| 7 | bin_dir := os.join_path(base_dir, 'bin') |
| 8 | run_dir := os.join_path(base_dir, 'run') |
| 9 | source_path := os.join_path(base_dir, 'backtrace_addr2line_probe.v') |
| 10 | exe_name := 'backtrace_addr2line_probe' |
| 11 | exe_path := os.join_path(bin_dir, exe_name) |
| 12 | old_path := os.getenv('PATH') |
| 13 | old_wd := os.getwd() |
| 14 | os.rmdir_all(base_dir) or {} |
| 15 | os.mkdir_all(bin_dir)! |
| 16 | os.mkdir_all(run_dir)! |
| 17 | defer { |
| 18 | os.chdir(old_wd) or {} |
| 19 | os.setenv('PATH', old_path, true) |
| 20 | os.rmdir_all(base_dir) or {} |
| 21 | } |
| 22 | helper_source := [ |
| 23 | 'fn main() {', |
| 24 | "\teprintln('backtrace_addr2line_probe')", |
| 25 | '\tprint_backtrace()', |
| 26 | '}', |
| 27 | ].join_lines() |
| 28 | os.write_file(source_path, helper_source)! |
| 29 | compile_cmd := '${os.quoted_path(vexe)} -g -o ${os.quoted_path(exe_path)} ${os.quoted_path(source_path)}' |
| 30 | compile_res := os.execute(compile_cmd) |
| 31 | assert compile_res.exit_code == 0, 'compilation failed: ${compile_res.output}' |
| 32 | os.setenv('PATH', '${bin_dir}${os.path_delimiter}${old_path}', true) |
| 33 | os.chdir(run_dir)! |
| 34 | run_res := os.execute('${exe_name} 2>&1') |
| 35 | assert run_res.exit_code == 0, 'execution failed: ${run_res.output}' |
| 36 | assert run_res.output.contains('backtrace_addr2line_probe') |
| 37 | assert !run_res.output.contains('addr2line:'), run_res.output |
| 38 | assert !run_res.output.contains('No such file'), run_res.output |
| 39 | } |
| 40 | |