| 1 | import os |
| 2 | import term |
| 3 | import v.util.diff |
| 4 | |
| 5 | const vroot = os.real_path(@VMODROOT) |
| 6 | const tmp_dir = os.real_path(os.temp_dir()) |
| 7 | |
| 8 | const text_file = os.join_path(vroot, 'vlib', 'v', 'tests', 'vls', 'struct_text.vv') |
| 9 | |
| 10 | fn testsuite_begin() { |
| 11 | eprintln('testsuite_begin, text_file = ${text_file}') |
| 12 | } |
| 13 | |
| 14 | fn testsuite_end() { |
| 15 | } |
| 16 | |
| 17 | struct TestData { |
| 18 | cmd string |
| 19 | output string |
| 20 | } |
| 21 | |
| 22 | const 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 | |
| 29 | fn 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 | |