2020-04-10 11:59:07 +03:00
|
|
|
import os
|
2021-04-05 22:57:53 +03:00
|
|
|
import rand
|
2020-04-10 11:59:07 +03:00
|
|
|
import term
|
2021-06-22 18:52:34 +03:00
|
|
|
import v.util.diff
|
2020-08-05 19:34:27 +03:00
|
|
|
import v.util.vtest
|
2020-08-07 16:44:49 +03:00
|
|
|
import time
|
|
|
|
import runtime
|
|
|
|
import benchmark
|
|
|
|
|
2021-01-13 22:27:24 +03:00
|
|
|
const skip_files = [
|
2021-08-28 12:51:37 +03:00
|
|
|
'non_existing.vv', // minimize commit diff churn, do not remove
|
2021-03-31 12:07:12 +03:00
|
|
|
]
|
2021-01-13 22:27:24 +03:00
|
|
|
|
2022-05-18 20:04:59 +03:00
|
|
|
const skip_on_cstrict = [
|
|
|
|
'vlib/v/checker/tests/missing_c_lib_header_1.vv',
|
|
|
|
'vlib/v/checker/tests/missing_c_lib_header_with_explanation_2.vv',
|
|
|
|
]
|
|
|
|
|
2021-01-21 13:09:19 +03:00
|
|
|
const skip_on_ubuntu_musl = [
|
2021-03-31 12:07:12 +03:00
|
|
|
'vlib/v/checker/tests/vweb_tmpl_used_var.vv',
|
2022-05-18 20:04:59 +03:00
|
|
|
'vlib/v/checker/tests/vweb_routing_checks.vv',
|
2021-03-31 12:07:12 +03:00
|
|
|
]
|
2021-01-21 13:09:19 +03:00
|
|
|
|
2022-05-18 11:30:28 +03:00
|
|
|
const vexe = os.getenv('VEXE')
|
|
|
|
|
2021-01-13 22:27:24 +03:00
|
|
|
const turn_off_vcolors = os.setenv('VCOLORS', 'never', true)
|
|
|
|
|
2022-05-18 11:30:28 +03:00
|
|
|
const show_cmd = os.getenv('VTEST_SHOW_CMD') != ''
|
|
|
|
|
2021-12-16 16:59:46 +03:00
|
|
|
// This is needed, because some of the .vv files are tests, and we do need stable
|
|
|
|
// output from them, that can be compared against their .out files:
|
|
|
|
const turn_on_normal_test_runner = os.setenv('VTEST_RUNNER', 'normal', true)
|
|
|
|
|
2021-01-13 22:27:24 +03:00
|
|
|
const should_autofix = os.getenv('VAUTOFIX') != ''
|
2020-09-15 19:56:46 +03:00
|
|
|
|
2021-01-31 20:22:42 +03:00
|
|
|
const github_job = os.getenv('GITHUB_JOB')
|
|
|
|
|
2022-05-18 11:30:28 +03:00
|
|
|
const v_ci_ubuntu_musl = os.getenv('V_CI_UBUNTU_MUSL').len > 0
|
|
|
|
|
2022-05-18 20:04:59 +03:00
|
|
|
const v_ci_cstrict = os.getenv('V_CI_CSTRICT').len > 0
|
|
|
|
|
2020-08-07 16:44:49 +03:00
|
|
|
struct TaskDescription {
|
|
|
|
vexe string
|
2022-01-23 00:45:48 +03:00
|
|
|
evars string
|
2020-08-07 16:44:49 +03:00
|
|
|
dir string
|
|
|
|
voptions string
|
|
|
|
result_extension string
|
|
|
|
path string
|
|
|
|
mut:
|
2021-01-31 20:22:42 +03:00
|
|
|
is_error bool
|
|
|
|
is_skipped bool
|
|
|
|
is_module bool
|
|
|
|
expected string
|
|
|
|
expected_out_path string
|
|
|
|
found___ string
|
|
|
|
took time.Duration
|
|
|
|
cli_cmd string
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Tasks {
|
|
|
|
vexe string
|
|
|
|
parallel_jobs int // 0 is using VJOBS, anything else is an override
|
|
|
|
label string
|
|
|
|
mut:
|
|
|
|
show_cmd bool
|
|
|
|
all []TaskDescription
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
2020-04-10 11:59:07 +03:00
|
|
|
|
|
|
|
fn test_all() {
|
2020-04-29 11:48:51 +03:00
|
|
|
vroot := os.dir(vexe)
|
2021-08-28 12:51:37 +03:00
|
|
|
os.chdir(vroot) or {}
|
2020-10-24 10:13:58 +03:00
|
|
|
checker_dir := 'vlib/v/checker/tests'
|
|
|
|
parser_dir := 'vlib/v/parser/tests'
|
2021-01-23 01:24:48 +03:00
|
|
|
scanner_dir := 'vlib/v/scanner/tests'
|
2020-10-24 10:13:58 +03:00
|
|
|
module_dir := '$checker_dir/modules'
|
|
|
|
global_dir := '$checker_dir/globals'
|
2021-06-26 01:18:51 +03:00
|
|
|
global_run_dir := '$checker_dir/globals_run'
|
2020-10-24 10:13:58 +03:00
|
|
|
run_dir := '$checker_dir/run'
|
2021-02-05 18:17:17 +03:00
|
|
|
skip_unused_dir := 'vlib/v/tests/skip_unused'
|
2022-08-18 11:45:37 +03:00
|
|
|
trace_calls_dir := 'vlib/v/tests/trace_calls'
|
2020-10-24 10:13:58 +03:00
|
|
|
//
|
|
|
|
checker_tests := get_tests_in_dir(checker_dir, false)
|
|
|
|
parser_tests := get_tests_in_dir(parser_dir, false)
|
2021-01-23 01:24:48 +03:00
|
|
|
scanner_tests := get_tests_in_dir(scanner_dir, false)
|
2020-09-20 20:51:14 +03:00
|
|
|
global_tests := get_tests_in_dir(global_dir, false)
|
2021-06-26 01:18:51 +03:00
|
|
|
global_run_tests := get_tests_in_dir(global_run_dir, false)
|
2020-10-15 15:54:44 +03:00
|
|
|
module_tests := get_tests_in_dir(module_dir, true)
|
2020-09-20 20:51:14 +03:00
|
|
|
run_tests := get_tests_in_dir(run_dir, false)
|
2021-02-05 18:17:17 +03:00
|
|
|
skip_unused_dir_tests := get_tests_in_dir(skip_unused_dir, false)
|
2022-08-18 11:45:37 +03:00
|
|
|
trace_calls_dir_tests := get_tests_in_dir(trace_calls_dir, false)
|
2021-01-31 20:22:42 +03:00
|
|
|
mut tasks := Tasks{
|
|
|
|
vexe: vexe
|
|
|
|
label: 'all tests'
|
|
|
|
}
|
2022-05-18 12:34:22 +03:00
|
|
|
tasks.add('', parser_dir, '', '.out', parser_tests, false)
|
|
|
|
tasks.add('', checker_dir, '', '.out', checker_tests, false)
|
|
|
|
tasks.add('', scanner_dir, '', '.out', scanner_tests, false)
|
2021-04-28 07:44:28 +03:00
|
|
|
tasks.add('', checker_dir, '-enable-globals run', '.run.out', ['globals_error.vv'],
|
2020-12-20 19:27:42 +03:00
|
|
|
false)
|
2021-06-26 01:18:51 +03:00
|
|
|
tasks.add('', global_run_dir, '-enable-globals run', '.run.out', global_run_tests,
|
|
|
|
false)
|
2021-04-28 07:44:28 +03:00
|
|
|
tasks.add('', global_dir, '-enable-globals', '.out', global_tests, false)
|
2021-01-31 20:22:42 +03:00
|
|
|
tasks.add('', module_dir, '-prod run', '.out', module_tests, true)
|
|
|
|
tasks.add('', run_dir, 'run', '.run.out', run_tests, false)
|
2021-02-06 11:08:59 +03:00
|
|
|
tasks.run()
|
|
|
|
//
|
2021-02-05 21:03:16 +03:00
|
|
|
if os.user_os() == 'linux' {
|
2021-02-06 11:08:59 +03:00
|
|
|
mut skip_unused_tasks := Tasks{
|
|
|
|
vexe: vexe
|
|
|
|
parallel_jobs: 1
|
|
|
|
label: '-skip-unused tests'
|
|
|
|
}
|
|
|
|
skip_unused_tasks.add('', skip_unused_dir, 'run', '.run.out', skip_unused_dir_tests,
|
|
|
|
false)
|
|
|
|
skip_unused_tasks.add('', skip_unused_dir, '-d no_backtrace -skip-unused run',
|
|
|
|
'.skip_unused.run.out', skip_unused_dir_tests, false)
|
|
|
|
skip_unused_tasks.run()
|
2022-08-18 11:45:37 +03:00
|
|
|
//
|
|
|
|
mut trace_calls_tasks := Tasks{
|
|
|
|
vexe: vexe
|
|
|
|
parallel_jobs: 1
|
|
|
|
label: '-trace-calls tests'
|
|
|
|
}
|
|
|
|
trace_calls_tasks.add('', trace_calls_dir, '-trace-calls run', '.run.out', trace_calls_dir_tests,
|
|
|
|
false)
|
|
|
|
trace_calls_tasks.run()
|
2021-02-05 21:03:16 +03:00
|
|
|
}
|
2021-02-06 11:08:59 +03:00
|
|
|
//
|
2021-02-06 14:07:15 +03:00
|
|
|
if github_job == 'ubuntu-tcc' {
|
|
|
|
// This is done with tcc only, because the error output is compiler specific.
|
2022-03-06 20:01:22 +03:00
|
|
|
// Note: the tasks should be run serially, since they depend on
|
2021-02-06 14:07:15 +03:00
|
|
|
// setting and using environment variables.
|
2021-01-31 20:22:42 +03:00
|
|
|
mut cte_tasks := Tasks{
|
|
|
|
vexe: vexe
|
|
|
|
parallel_jobs: 1
|
|
|
|
label: 'comptime env tests'
|
|
|
|
}
|
|
|
|
cte_dir := '$checker_dir/comptime_env'
|
|
|
|
files := get_tests_in_dir(cte_dir, false)
|
|
|
|
cte_tasks.add('', cte_dir, '-no-retry-compilation run', '.run.out', files, false)
|
2022-01-23 00:45:48 +03:00
|
|
|
cte_tasks.add_evars('VAR=/usr/include', '', cte_dir, '-no-retry-compilation run',
|
2021-01-31 20:22:42 +03:00
|
|
|
'.var.run.out', ['using_comptime_env.vv'], false)
|
2022-01-23 00:45:48 +03:00
|
|
|
cte_tasks.add_evars('VAR=/opt/invalid/path', '', cte_dir, '-no-retry-compilation run',
|
2021-02-06 14:07:15 +03:00
|
|
|
'.var_invalid.run.out', ['using_comptime_env.vv'], false)
|
2021-01-31 20:22:42 +03:00
|
|
|
cte_tasks.run()
|
|
|
|
}
|
2021-03-07 13:42:30 +03:00
|
|
|
mut ct_tasks := Tasks{
|
|
|
|
vexe: vexe
|
|
|
|
parallel_jobs: 1
|
|
|
|
label: 'comptime define tests'
|
|
|
|
}
|
2021-03-31 12:07:12 +03:00
|
|
|
ct_tasks.add_checked_run('-d mysymbol run', '.mysymbol.run.out', [
|
|
|
|
'custom_comptime_define_error.vv',
|
|
|
|
])
|
|
|
|
ct_tasks.add_checked_run('-d mydebug run', '.mydebug.run.out', [
|
|
|
|
'custom_comptime_define_if_flag.vv',
|
|
|
|
])
|
|
|
|
ct_tasks.add_checked_run('-d nodebug run', '.nodebug.run.out', [
|
|
|
|
'custom_comptime_define_if_flag.vv',
|
|
|
|
])
|
2021-03-07 13:42:30 +03:00
|
|
|
ct_tasks.add_checked_run('run', '.run.out', ['custom_comptime_define_if_debug.vv'])
|
2021-09-21 16:20:09 +03:00
|
|
|
ct_tasks.add_checked_run('-g run', '.g.run.out', [
|
|
|
|
'custom_comptime_define_if_debug.vv',
|
|
|
|
])
|
|
|
|
ct_tasks.add_checked_run('-cg run', '.cg.run.out', [
|
|
|
|
'custom_comptime_define_if_debug.vv',
|
|
|
|
])
|
|
|
|
ct_tasks.add_checked_run('-d debug run', '.debug.run.out', [
|
|
|
|
'custom_comptime_define_if_debug.vv',
|
|
|
|
])
|
2021-03-31 12:07:12 +03:00
|
|
|
ct_tasks.add_checked_run('-d debug -d bar run', '.debug.bar.run.out', [
|
|
|
|
'custom_comptime_define_if_debug.vv',
|
|
|
|
])
|
2021-03-07 13:42:30 +03:00
|
|
|
ct_tasks.run()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut tasks Tasks) add_checked_run(voptions string, result_extension string, tests []string) {
|
|
|
|
checker_dir := 'vlib/v/checker/tests'
|
|
|
|
tasks.add('', checker_dir, voptions, result_extension, tests, false)
|
2020-05-16 17:12:23 +03:00
|
|
|
}
|
|
|
|
|
2021-01-31 20:22:42 +03:00
|
|
|
fn (mut tasks Tasks) add(custom_vexe string, dir string, voptions string, result_extension string, tests []string, is_module bool) {
|
2022-01-23 00:45:48 +03:00
|
|
|
tasks.add_evars('', custom_vexe, dir, voptions, result_extension, tests, is_module)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut tasks Tasks) add_evars(evars string, custom_vexe string, dir string, voptions string, result_extension string, tests []string, is_module bool) {
|
2020-12-20 19:27:42 +03:00
|
|
|
paths := vtest.filter_vtest_only(tests, basepath: dir)
|
2020-07-09 10:26:14 +03:00
|
|
|
for path in paths {
|
2021-01-31 20:22:42 +03:00
|
|
|
tasks.all << TaskDescription{
|
2022-01-23 00:45:48 +03:00
|
|
|
evars: evars
|
2022-05-18 11:30:28 +03:00
|
|
|
vexe: if custom_vexe != '' { custom_vexe } else { tasks.vexe }
|
2020-08-07 16:44:49 +03:00
|
|
|
dir: dir
|
|
|
|
voptions: voptions
|
|
|
|
result_extension: result_extension
|
|
|
|
path: path
|
2020-09-20 20:51:14 +03:00
|
|
|
is_module: is_module
|
2020-05-16 17:12:23 +03:00
|
|
|
}
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
2020-10-24 10:13:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bstep_message(mut bench benchmark.Benchmark, label string, msg string, sduration time.Duration) string {
|
|
|
|
return bench.step_message_with_label_and_duration(label, msg, sduration)
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// process an array of tasks in parallel, using no more than vjobs worker threads
|
2021-01-31 20:22:42 +03:00
|
|
|
fn (mut tasks Tasks) run() {
|
2022-05-18 11:30:28 +03:00
|
|
|
if tasks.all.len == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tasks.show_cmd = show_cmd
|
2021-01-31 20:22:42 +03:00
|
|
|
vjobs := if tasks.parallel_jobs > 0 { tasks.parallel_jobs } else { runtime.nr_jobs() }
|
2020-08-07 16:44:49 +03:00
|
|
|
mut bench := benchmark.new_benchmark()
|
2021-01-31 20:22:42 +03:00
|
|
|
bench.set_total_expected_steps(tasks.all.len)
|
2022-05-18 11:30:28 +03:00
|
|
|
mut work := chan TaskDescription{cap: tasks.all.len}
|
|
|
|
mut results := chan TaskDescription{cap: tasks.all.len}
|
2020-12-20 19:27:42 +03:00
|
|
|
mut m_skip_files := skip_files.clone()
|
2022-05-18 11:30:28 +03:00
|
|
|
if v_ci_ubuntu_musl {
|
2021-01-21 13:09:19 +03:00
|
|
|
m_skip_files << skip_on_ubuntu_musl
|
|
|
|
}
|
2022-05-18 20:04:59 +03:00
|
|
|
if v_ci_cstrict {
|
|
|
|
m_skip_files << skip_on_cstrict
|
|
|
|
}
|
2020-09-15 19:56:46 +03:00
|
|
|
$if noskip ? {
|
|
|
|
m_skip_files = []
|
|
|
|
}
|
2020-10-17 18:27:06 +03:00
|
|
|
$if tinyc {
|
2022-03-06 20:01:22 +03:00
|
|
|
// Note: tcc does not support __has_include, so the detection mechanism
|
2020-10-17 18:27:06 +03:00
|
|
|
// used for the other compilers does not work. It still provides a
|
|
|
|
// cleaner error message, than a generic C error, but without the explanation.
|
|
|
|
m_skip_files << 'vlib/v/checker/tests/missing_c_lib_header_1.vv'
|
|
|
|
m_skip_files << 'vlib/v/checker/tests/missing_c_lib_header_with_explanation_2.vv'
|
|
|
|
}
|
2021-03-08 21:52:13 +03:00
|
|
|
$if msvc {
|
2021-03-17 03:43:17 +03:00
|
|
|
m_skip_files << 'vlib/v/checker/tests/asm_alias_does_not_exist.vv'
|
2021-03-31 12:07:12 +03:00
|
|
|
m_skip_files << 'vlib/v/checker/tests/asm_immutable_err.vv'
|
2021-03-08 21:52:13 +03:00
|
|
|
// TODO: investigate why MSVC regressed
|
|
|
|
m_skip_files << 'vlib/v/checker/tests/missing_c_lib_header_1.vv'
|
2021-03-31 12:07:12 +03:00
|
|
|
m_skip_files << 'vlib/v/checker/tests/missing_c_lib_header_with_explanation_2.vv'
|
2021-03-08 21:52:13 +03:00
|
|
|
}
|
2022-01-27 16:38:52 +03:00
|
|
|
$if windows {
|
|
|
|
m_skip_files << 'vlib/v/checker/tests/modules/deprecated_module'
|
|
|
|
}
|
2021-01-31 20:22:42 +03:00
|
|
|
for i in 0 .. tasks.all.len {
|
|
|
|
if tasks.all[i].path in m_skip_files {
|
|
|
|
tasks.all[i].is_skipped = true
|
2020-09-15 19:56:46 +03:00
|
|
|
}
|
2022-05-18 11:30:28 +03:00
|
|
|
work <- tasks.all[i]
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
2020-08-10 15:21:34 +03:00
|
|
|
work.close()
|
2020-08-07 16:44:49 +03:00
|
|
|
for _ in 0 .. vjobs {
|
2022-05-18 11:30:28 +03:00
|
|
|
go work_processor(work, results)
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
2021-03-31 12:07:12 +03:00
|
|
|
if github_job == '' {
|
|
|
|
println('')
|
|
|
|
}
|
|
|
|
mut line_can_be_erased := true
|
2020-08-13 12:57:16 +03:00
|
|
|
mut total_errors := 0
|
2021-01-31 20:22:42 +03:00
|
|
|
for _ in 0 .. tasks.all.len {
|
2020-08-07 16:44:49 +03:00
|
|
|
mut task := TaskDescription{}
|
2022-05-18 11:30:28 +03:00
|
|
|
task = <-results
|
2020-08-07 16:44:49 +03:00
|
|
|
bench.step()
|
2020-09-15 19:56:46 +03:00
|
|
|
if task.is_skipped {
|
|
|
|
bench.skip()
|
2020-10-24 10:13:58 +03:00
|
|
|
eprintln(bstep_message(mut bench, benchmark.b_skip, task.path, task.took))
|
2021-03-31 12:07:12 +03:00
|
|
|
line_can_be_erased = false
|
2020-09-15 19:56:46 +03:00
|
|
|
continue
|
2020-10-15 15:54:44 +03:00
|
|
|
}
|
2020-08-07 16:44:49 +03:00
|
|
|
if task.is_error {
|
2020-08-13 12:57:16 +03:00
|
|
|
total_errors++
|
2020-08-07 16:44:49 +03:00
|
|
|
bench.fail()
|
2020-10-24 10:13:58 +03:00
|
|
|
eprintln(bstep_message(mut bench, benchmark.b_fail, task.path, task.took))
|
2020-05-16 17:12:23 +03:00
|
|
|
println('============')
|
2021-01-31 20:22:42 +03:00
|
|
|
println('failed cmd: $task.cli_cmd')
|
|
|
|
println('expected_out_path: $task.expected_out_path')
|
|
|
|
println('============')
|
2020-05-16 17:12:23 +03:00
|
|
|
println('expected:')
|
2020-08-07 16:44:49 +03:00
|
|
|
println(task.expected)
|
2020-05-16 17:12:23 +03:00
|
|
|
println('============')
|
|
|
|
println('found:')
|
2020-08-07 16:44:49 +03:00
|
|
|
println(task.found___)
|
2020-05-16 17:12:23 +03:00
|
|
|
println('============\n')
|
2020-08-07 16:44:49 +03:00
|
|
|
diff_content(task.expected, task.found___)
|
2021-03-31 12:07:12 +03:00
|
|
|
line_can_be_erased = false
|
2020-05-16 17:12:23 +03:00
|
|
|
} else {
|
2020-08-07 16:44:49 +03:00
|
|
|
bench.ok()
|
2021-12-16 16:59:46 +03:00
|
|
|
assert true
|
2021-01-31 20:22:42 +03:00
|
|
|
if tasks.show_cmd {
|
2022-05-18 12:34:22 +03:00
|
|
|
eprintln(bstep_message(mut bench, benchmark.b_ok, '$task.cli_cmd', task.took))
|
2021-01-31 20:22:42 +03:00
|
|
|
} else {
|
2021-03-31 12:07:12 +03:00
|
|
|
if github_job == '' {
|
|
|
|
// local mode:
|
|
|
|
if line_can_be_erased {
|
|
|
|
term.clear_previous_line()
|
|
|
|
}
|
|
|
|
println(bstep_message(mut bench, benchmark.b_ok, task.path, task.took))
|
|
|
|
}
|
2021-01-31 20:22:42 +03:00
|
|
|
}
|
2021-03-31 12:07:12 +03:00
|
|
|
line_can_be_erased = true
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bench.stop()
|
|
|
|
eprintln(term.h_divider('-'))
|
2021-01-31 20:22:42 +03:00
|
|
|
eprintln(bench.total_message(tasks.label))
|
2021-01-13 22:27:24 +03:00
|
|
|
if total_errors != 0 {
|
|
|
|
exit(1)
|
|
|
|
}
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// a single worker thread spends its time getting work from the `work` channel,
|
|
|
|
// processing the task, and then putting the task in the `results` channel
|
2022-05-18 11:30:28 +03:00
|
|
|
fn work_processor(work chan TaskDescription, results chan TaskDescription) {
|
2020-08-07 16:44:49 +03:00
|
|
|
for {
|
2022-05-18 11:30:28 +03:00
|
|
|
mut task := <-work or { break }
|
2021-07-20 11:17:08 +03:00
|
|
|
sw := time.new_stopwatch()
|
2020-08-07 16:44:49 +03:00
|
|
|
task.execute()
|
|
|
|
task.took = sw.elapsed()
|
2022-05-18 11:30:28 +03:00
|
|
|
results <- task
|
2020-08-07 16:44:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-06 20:01:22 +03:00
|
|
|
// actual processing; Note: no output is done here at all
|
2020-08-07 16:44:49 +03:00
|
|
|
fn (mut task TaskDescription) execute() {
|
2020-09-15 19:56:46 +03:00
|
|
|
if task.is_skipped {
|
2020-10-15 15:54:44 +03:00
|
|
|
return
|
|
|
|
}
|
2020-08-25 18:14:06 +03:00
|
|
|
program := task.path
|
2022-01-23 00:45:48 +03:00
|
|
|
cmd_prefix := if task.evars.len > 0 { '$task.evars ' } else { '' }
|
|
|
|
cli_cmd := '$cmd_prefix${os.quoted_path(task.vexe)} $task.voptions ${os.quoted_path(program)}'
|
2021-03-08 21:52:13 +03:00
|
|
|
res := os.execute(cli_cmd)
|
2021-01-03 20:00:34 +03:00
|
|
|
expected_out_path := program.replace('.vv', '') + task.result_extension
|
2021-01-31 20:22:42 +03:00
|
|
|
task.expected_out_path = expected_out_path
|
|
|
|
task.cli_cmd = cli_cmd
|
2021-01-21 16:48:57 +03:00
|
|
|
if should_autofix && !os.exists(expected_out_path) {
|
2021-09-10 16:07:39 +03:00
|
|
|
os.create(expected_out_path) or { panic(err) }
|
2021-01-21 16:48:57 +03:00
|
|
|
}
|
2021-03-01 02:18:14 +03:00
|
|
|
mut expected := os.read_file(expected_out_path) or { panic(err) }
|
2020-08-07 16:44:49 +03:00
|
|
|
task.expected = clean_line_endings(expected)
|
|
|
|
task.found___ = clean_line_endings(res.output)
|
2020-09-20 20:51:14 +03:00
|
|
|
$if windows {
|
|
|
|
if task.is_module {
|
|
|
|
task.found___ = task.found___.replace_once('\\', '/')
|
|
|
|
}
|
|
|
|
}
|
2020-08-07 16:44:49 +03:00
|
|
|
if task.expected != task.found___ {
|
|
|
|
task.is_error = true
|
2021-01-03 20:00:34 +03:00
|
|
|
if should_autofix {
|
2021-03-01 02:18:14 +03:00
|
|
|
os.write_file(expected_out_path, res.output) or { panic(err) }
|
2021-01-03 20:00:34 +03:00
|
|
|
}
|
2020-05-14 08:20:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn clean_line_endings(s string) string {
|
2020-07-09 10:26:14 +03:00
|
|
|
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
|
2020-05-14 08:20:38 +03:00
|
|
|
}
|
2020-07-26 10:47:55 +03:00
|
|
|
|
2020-10-15 15:54:44 +03:00
|
|
|
fn diff_content(s1 string, s2 string) {
|
2021-06-22 18:52:34 +03:00
|
|
|
diff_cmd := diff.find_working_diff_command() or { return }
|
2021-01-13 22:27:24 +03:00
|
|
|
println(term.bold(term.yellow('diff: ')))
|
2021-06-22 18:52:34 +03:00
|
|
|
println(diff.color_compare_strings(diff_cmd, rand.ulid(), s1, s2))
|
2020-07-26 10:47:55 +03:00
|
|
|
println('============\n')
|
2020-07-27 13:15:29 +03:00
|
|
|
}
|
2020-08-07 16:44:49 +03:00
|
|
|
|
2020-09-20 20:51:14 +03:00
|
|
|
fn get_tests_in_dir(dir string, is_module bool) []string {
|
2021-03-01 02:18:14 +03:00
|
|
|
files := os.ls(dir) or { panic(err) }
|
2020-12-20 19:27:42 +03:00
|
|
|
mut tests := files.clone()
|
2020-09-20 20:51:14 +03:00
|
|
|
if !is_module {
|
|
|
|
tests = files.filter(it.ends_with('.vv'))
|
|
|
|
} else {
|
|
|
|
tests = files.filter(!it.ends_with('.out'))
|
|
|
|
}
|
2020-08-07 16:44:49 +03:00
|
|
|
tests.sort()
|
|
|
|
return tests
|
|
|
|
}
|