From f4b110b1a4882fb55e7b516d9e56e9ebfccfb7e8 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 29 Dec 2022 17:30:25 +0800 Subject: [PATCH] vrepl: fix $tmpl('hello.txt') (fix #16789) (#16793) --- vlib/v/parser/parser.v | 1 + vlib/v/tests/repl/comptime_tmpl.repl | 3 +++ vlib/v/tests/repl/runner/runner.v | 3 +++ vlib/v/tests/repl/tmpl/hello.txt | 1 + 4 files changed, 8 insertions(+) create mode 100644 vlib/v/tests/repl/comptime_tmpl.repl create mode 100644 vlib/v/tests/repl/tmpl/hello.txt diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 97ec3cd7eb..1132d5334f 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -811,6 +811,7 @@ fn (mut p Parser) other_stmts(cur_stmt ast.Stmt) ast.Stmt { } p.open_scope() + p.cur_fn_name = 'main.main' mut stmts := []ast.Stmt{} if cur_stmt != ast.empty_stmt { stmts << cur_stmt diff --git a/vlib/v/tests/repl/comptime_tmpl.repl b/vlib/v/tests/repl/comptime_tmpl.repl new file mode 100644 index 0000000000..b04d501aa9 --- /dev/null +++ b/vlib/v/tests/repl/comptime_tmpl.repl @@ -0,0 +1,3 @@ +$tmpl('./tmpl/hello.txt') +===output=== +hello diff --git a/vlib/v/tests/repl/runner/runner.v b/vlib/v/tests/repl/runner/runner.v index f4f36e0fc6..49ee3507f6 100644 --- a/vlib/v/tests/repl/runner/runner.v +++ b/vlib/v/tests/repl/runner/runner.v @@ -49,6 +49,9 @@ pub fn run_repl_file(wd string, vexec string, file string) !string { input_temporary_filename := os.real_path(os.join_path(wd, 'input_temporary_filename.txt')) os.write_file(input_temporary_filename, input) or { panic(err) } os.write_file(os.real_path(os.join_path(wd, 'original.txt')), fcontent) or { panic(err) } + os.cp_all('vlib/v/tests/repl/tmpl', os.real_path(os.join_path(wd, 'tmpl')), true) or { + panic(err) + } rcmd := '${os.quoted_path(vexec)} repl -replfolder ${os.quoted_path(wd)} -replprefix "${fname}." < ${os.quoted_path(input_temporary_filename)}' r := os.execute(rcmd) if r.exit_code != 0 { diff --git a/vlib/v/tests/repl/tmpl/hello.txt b/vlib/v/tests/repl/tmpl/hello.txt new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/vlib/v/tests/repl/tmpl/hello.txt @@ -0,0 +1 @@ +hello