v2 / cmd / tools / vfmt_test.v
25 lines · 19 sloc · 730 bytes · a31f559d0a63c6373f4496f7553197342869a434
Raw
1import os
2
3const vexe = @VEXE
4const vfmt_test_tdir = os.join_path(os.vtmp_dir(), 'vfmt_test_25005')
5
6fn testsuite_begin() {
7 os.rmdir_all(vfmt_test_tdir) or {}
8 os.mkdir_all(vfmt_test_tdir)!
9}
10
11fn testsuite_end() {
12 os.rmdir_all(vfmt_test_tdir) or {}
13}
14
15fn test_fmt_keeps_invalid_assert_source_unchanged() {
16 source_path := os.join_path(vfmt_test_tdir, 'invalid_assert_message.v')
17 original := "fn main() {\n\tassert false 'bye'\n}\n"
18 os.write_file(source_path, original)!
19
20 res := os.execute('${os.quoted_path(vexe)} fmt -w ${os.quoted_path(source_path)}')
21
22 assert res.exit_code != 0, res.output
23 assert res.output.contains('unexpected string `bye`, expecting `,`'), res.output
24 assert os.read_file(source_path)! == original
25}
26