| 1 | import os |
| 2 | |
| 3 | const vexe = @VEXE |
| 4 | |
| 5 | fn test_parse_text_in_stdout_mode_unwinds_caller_defer() { |
| 6 | tmp_dir := os.join_path(os.vtmp_dir(), 'v_parser_issue_14438') |
| 7 | os.mkdir_all(tmp_dir) or { panic(err) } |
| 8 | program_path := os.join_path(tmp_dir, 'issue_14438.v') |
| 9 | program := "import v.ast\nimport v.parser\nimport v.pref\n\nconst bad_source = 'fn main() {\\n\\tx := 1 +\\n}\\n'\n\nfn run_parse() {\n\tmut table := ast.new_table()\n\tmut prefs := pref.new_preferences()\n\tprefs.output_mode = .stdout\n\tdefer {\n\t\tprintln('<defer-ran>')\n\t}\n\tfile := parser.parse_text(bad_source, 'bad.v', mut table, .skip_comments, prefs)\n\tif file.errors.len == 0 {\n\t\texit(2)\n\t}\n\tprintln('<after-parse>')\n}\n\nfn main() {\n\trun_parse()\n}\n" |
| 10 | os.write_file(program_path, program) or { panic(err) } |
| 11 | res := os.execute('${os.quoted_path(vexe)} run ${os.quoted_path(program_path)}') |
| 12 | assert res.exit_code == 0, 'expected parser.parse_text to return normally, output:\n${res.output}' |
| 13 | assert res.output.contains('error:'), 'expected a parser error, output:\n${res.output}' |
| 14 | assert res.output.contains('<defer-ran>'), 'expected defer to run, output:\n${res.output}' |
| 15 | assert res.output.contains('<after-parse>'), 'expected execution to continue after parse_text, output:\n${res.output}' |
| 16 | } |
| 17 | |