2020-07-19 20:58:34 +03:00
|
|
|
import os
|
|
|
|
import term
|
2020-08-05 19:34:27 +03:00
|
|
|
import v.util.vtest
|
2021-01-10 19:48:39 +03:00
|
|
|
import v.util
|
|
|
|
|
|
|
|
const diff_cmd = find_diff_cmd()
|
|
|
|
|
|
|
|
fn find_diff_cmd() string {
|
|
|
|
res := util.find_working_diff_command() or { '' }
|
|
|
|
return res
|
|
|
|
}
|
2020-07-19 20:58:34 +03:00
|
|
|
|
|
|
|
fn test_vet() {
|
|
|
|
vexe := os.getenv('VEXE')
|
|
|
|
vroot := os.dir(vexe)
|
|
|
|
os.chdir(vroot)
|
2021-01-09 17:11:49 +03:00
|
|
|
test_dir := 'cmd/tools/vvet/tests'
|
2020-07-19 20:58:34 +03:00
|
|
|
tests := get_tests_in_dir(test_dir)
|
2020-08-12 20:33:51 +03:00
|
|
|
fails := check_path(vexe, test_dir, tests)
|
|
|
|
assert fails == 0
|
2020-07-19 20:58:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_tests_in_dir(dir string) []string {
|
2021-03-01 02:18:14 +03:00
|
|
|
files := os.ls(dir) or { panic(err) }
|
2020-07-19 20:58:34 +03:00
|
|
|
mut tests := files.filter(it.ends_with('.vv'))
|
|
|
|
tests.sort()
|
|
|
|
return tests
|
|
|
|
}
|
|
|
|
|
2020-10-15 23:12:59 +03:00
|
|
|
fn check_path(vexe string, dir string, tests []string) int {
|
2020-07-19 20:58:34 +03:00
|
|
|
mut nb_fail := 0
|
2020-12-04 12:22:26 +03:00
|
|
|
paths := vtest.filter_vtest_only(tests, basepath: dir)
|
2020-07-19 20:58:34 +03:00
|
|
|
for path in paths {
|
2020-08-25 18:46:33 +03:00
|
|
|
program := path
|
2020-07-19 20:58:34 +03:00
|
|
|
print(path + ' ')
|
2021-01-10 19:48:39 +03:00
|
|
|
// -force is needed so that `v vet` would not skip the regression files
|
2021-03-25 00:53:44 +03:00
|
|
|
res := os.execute('$vexe vet -force -nocolor $program')
|
2021-03-08 21:52:13 +03:00
|
|
|
if res.exit_code < 0 {
|
|
|
|
panic(res.output)
|
|
|
|
}
|
2021-03-01 02:18:14 +03:00
|
|
|
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err) }
|
2020-07-19 20:58:34 +03:00
|
|
|
expected = clean_line_endings(expected)
|
|
|
|
found := clean_line_endings(res.output)
|
|
|
|
if expected != found {
|
|
|
|
println(term.red('FAIL'))
|
|
|
|
println('============')
|
|
|
|
println('expected:')
|
|
|
|
println(expected)
|
|
|
|
println('============')
|
|
|
|
println('found:')
|
|
|
|
println(found)
|
|
|
|
println('============\n')
|
2021-01-10 19:48:39 +03:00
|
|
|
println('diff:')
|
2021-01-25 14:08:43 +03:00
|
|
|
println(util.color_compare_strings(diff_cmd, found, expected))
|
2021-01-10 19:48:39 +03:00
|
|
|
println('============\n')
|
2020-07-19 20:58:34 +03:00
|
|
|
nb_fail++
|
|
|
|
} else {
|
|
|
|
println(term.green('OK'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nb_fail
|
|
|
|
}
|
|
|
|
|
|
|
|
fn clean_line_endings(s string) string {
|
|
|
|
mut res := s.trim_space()
|
|
|
|
res = res.replace(' \n', '\n')
|
|
|
|
res = res.replace(' \r\n', '\n')
|
|
|
|
res = res.replace('\r\n', '\n')
|
|
|
|
res = res.trim('\n')
|
|
|
|
return res
|
|
|
|
}
|