2020-07-19 19:58:34 +02:00
|
|
|
import os
|
|
|
|
import term
|
2020-08-05 18:34:27 +02:00
|
|
|
import v.util.vtest
|
2021-01-10 17:48:39 +01: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 19:58:34 +02:00
|
|
|
|
|
|
|
fn test_vet() {
|
|
|
|
vexe := os.getenv('VEXE')
|
|
|
|
vroot := os.dir(vexe)
|
|
|
|
os.chdir(vroot)
|
2021-01-09 15:11:49 +01:00
|
|
|
test_dir := 'cmd/tools/vvet/tests'
|
2020-07-19 19:58:34 +02:00
|
|
|
tests := get_tests_in_dir(test_dir)
|
2020-08-12 19:33:51 +02:00
|
|
|
fails := check_path(vexe, test_dir, tests)
|
|
|
|
assert fails == 0
|
2020-07-19 19:58:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_tests_in_dir(dir string) []string {
|
2021-02-28 21:20:21 +01:00
|
|
|
files := os.ls(dir) or { panic(err.msg) }
|
2020-07-19 19:58:34 +02:00
|
|
|
mut tests := files.filter(it.ends_with('.vv'))
|
|
|
|
tests.sort()
|
|
|
|
return tests
|
|
|
|
}
|
|
|
|
|
2020-10-15 22:12:59 +02:00
|
|
|
fn check_path(vexe string, dir string, tests []string) int {
|
2020-07-19 19:58:34 +02:00
|
|
|
mut nb_fail := 0
|
2020-12-04 10:22:26 +01:00
|
|
|
paths := vtest.filter_vtest_only(tests, basepath: dir)
|
2020-07-19 19:58:34 +02:00
|
|
|
for path in paths {
|
2020-08-25 17:46:33 +02:00
|
|
|
program := path
|
2020-07-19 19:58:34 +02:00
|
|
|
print(path + ' ')
|
2021-01-10 17:48:39 +01:00
|
|
|
// -force is needed so that `v vet` would not skip the regression files
|
2021-02-28 21:20:21 +01:00
|
|
|
res := os.exec('$vexe vet -force $program') or { panic(err.msg) }
|
|
|
|
mut expected := os.read_file(program.replace('.vv', '') + '.out') or { panic(err.msg) }
|
2020-07-19 19:58:34 +02: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 17:48:39 +01:00
|
|
|
println('diff:')
|
2021-01-25 12:08:43 +01:00
|
|
|
println(util.color_compare_strings(diff_cmd, found, expected))
|
2021-01-10 17:48:39 +01:00
|
|
|
println('============\n')
|
2020-07-19 19:58:34 +02: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
|
|
|
|
}
|