v2 / vlib / v / tests / vls / struct_check_test.v
61 lines · 53 sloc · 1.26 KB · 245d025c2082fdc59d3edee16ebe7206c4f6ece2
Raw
1import os
2import term
3import v.util.diff
4
5const vroot = os.real_path(@VMODROOT)
6const tmp_dir = os.real_path(os.temp_dir())
7
8const text_file = os.join_path(vroot, 'vlib', 'v', 'tests', 'vls', 'struct_text.vv')
9
10fn testsuite_begin() {
11 eprintln('testsuite_begin, text_file = ${text_file}')
12}
13
14fn testsuite_end() {
15}
16
17struct TestData {
18 cmd string
19 output string
20}
21
22const test_data = [
23 TestData{
24 cmd: 'v -w -check -vls-mode ${os.quoted_path(text_file)}'
25 output: '' // for a struct with `mut:` in it, should report no error
26 },
27]
28
29fn test_main() {
30 mut total_errors := 0
31
32 for t in test_data {
33 res := os.execute(t.cmd)
34 if res.exit_code < 0 {
35 println('fail execute ${t.cmd}')
36 panic(res.output)
37 }
38 res_output := $if windows {
39 res.output.replace('\r\n', '\n')
40 } $else {
41 res.output
42 }
43 if t.output != res_output {
44 println('${term.red('FAIL')} ${t.cmd}')
45 if diff_ := diff.compare_text(t.output, res_output) {
46 println(term.header('difference:', '-'))
47 println(diff_)
48 } else {
49 println(term.header('expected:', '-'))
50 println(t.output)
51 println(term.header('found:', '-'))
52 println(res_output)
53 }
54 println(term.h_divider('-'))
55 total_errors++
56 } else {
57 println('${term.green('OK ')} ${t.cmd}')
58 }
59 }
60 assert total_errors == 0
61}
62