mirror of
https://github.com/vlang/v.git
synced 2025-09-09 07:15:50 -04:00
v: utilize new diff functions p2 (#21434)
This commit is contained in:
parent
a4cdc48542
commit
a1f36240b0
@ -115,18 +115,20 @@ fn test_out_path() {
|
||||
}
|
||||
|
||||
fn print_compare(expected string, found string) {
|
||||
diff_cmd := diff.find_working_diff_command() or { return }
|
||||
println(term.red('FAIL'))
|
||||
println('============')
|
||||
println('expected:')
|
||||
println(expected)
|
||||
println('============')
|
||||
println('found:')
|
||||
println(found)
|
||||
println('============\n')
|
||||
println('diff:')
|
||||
println(diff.color_compare_strings(diff_cmd, rand.ulid(), expected, found))
|
||||
println('============\n')
|
||||
if diff_ := diff.compare_text(expected, found) {
|
||||
println('diff:')
|
||||
println(diff_)
|
||||
println('============\n')
|
||||
} else {
|
||||
println('expected:')
|
||||
println(expected)
|
||||
println('============')
|
||||
println('found:')
|
||||
println(found)
|
||||
println('============\n')
|
||||
}
|
||||
}
|
||||
|
||||
@[params]
|
||||
|
@ -15,11 +15,6 @@ const fpref = &pref.Preferences{
|
||||
}
|
||||
|
||||
fn test_bin2v_formatting() {
|
||||
diff_cmd := diff.find_working_diff_command() or { '' }
|
||||
if diff_cmd == '' {
|
||||
eprintln('>> sorry, but no working "diff" CLI command can be found')
|
||||
exit(0)
|
||||
}
|
||||
os.mkdir_all(tmpfolder)!
|
||||
defer {
|
||||
os.rmdir_all(tmpfolder) or {}
|
||||
@ -33,8 +28,8 @@ fn test_bin2v_formatting() {
|
||||
expected_ocontent := os.read_file(b2v_keep_path)!
|
||||
if expected_ocontent != result_ocontent {
|
||||
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${ifilename}')
|
||||
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
|
||||
eprintln(diff.color_compare_files(diff_cmd, b2v_keep_path, vfmt_result_file))
|
||||
os.write_file(vfmt_result_file, result_ocontent)!
|
||||
println(diff.compare_files(b2v_keep_path, vfmt_result_file)!)
|
||||
exit(1)
|
||||
} else {
|
||||
assert true
|
||||
|
@ -30,7 +30,6 @@ fn run_fmt(mut input_files []string) {
|
||||
mut fmt_bench := benchmark.new_benchmark()
|
||||
fmt_bench.set_total_expected_steps(input_files.len + 1)
|
||||
tmpfolder := os.temp_dir()
|
||||
diff_cmd := diff.find_working_diff_command() or { '' }
|
||||
for istep, ipath in input_files {
|
||||
fmt_bench.cstep = istep + 1
|
||||
fmt_bench.step()
|
||||
@ -45,13 +44,9 @@ fn run_fmt(mut input_files []string) {
|
||||
if expected_ocontent != result_ocontent {
|
||||
fmt_bench.fail()
|
||||
eprintln(fmt_bench.step_message_fail('file ${ipath} after formatting, does not look as expected.'))
|
||||
if diff_cmd == '' {
|
||||
eprintln('>> sorry, but no working "diff" CLI command can be found')
|
||||
continue
|
||||
}
|
||||
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${os.file_name(ipath)}')
|
||||
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
|
||||
eprintln(diff.color_compare_files(diff_cmd, ipath, vfmt_result_file))
|
||||
println(diff.compare_files(ipath, vfmt_result_file) or { err.msg() })
|
||||
continue
|
||||
}
|
||||
fmt_bench.ok()
|
||||
|
@ -21,7 +21,6 @@ fn run_fmt(mut input_files []string) {
|
||||
fmt_message := 'vfmt tests'
|
||||
eprintln(term.header(fmt_message, '-'))
|
||||
tmpfolder := os.temp_dir()
|
||||
diff_cmd := diff.find_working_diff_command() or { '' }
|
||||
assert input_files.len > 0
|
||||
input_files = vtest.filter_vtest_only(input_files)
|
||||
if input_files.len == 0 {
|
||||
@ -51,13 +50,9 @@ fn run_fmt(mut input_files []string) {
|
||||
if expected_ocontent != result_ocontent {
|
||||
fmt_bench.fail()
|
||||
eprintln(fmt_bench.step_message_fail('file ${ipath} after formatting, does not look as expected.'))
|
||||
if diff_cmd == '' {
|
||||
eprintln('>> sorry, but no working "diff" CLI command can be found')
|
||||
continue
|
||||
}
|
||||
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${os.file_name(ipath)}')
|
||||
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
|
||||
eprintln(diff.color_compare_files(diff_cmd, opath, vfmt_result_file))
|
||||
println(diff.compare_files(opath, vfmt_result_file) or { err.msg() })
|
||||
continue
|
||||
}
|
||||
fmt_bench.ok()
|
||||
|
@ -50,13 +50,9 @@ fn test_vlib_fmt() {
|
||||
if expected_ocontent != result_ocontent {
|
||||
fmt_bench.fail()
|
||||
eprintln(fmt_bench.step_message_fail('file ${ipath} after formatting, does not look as expected.'))
|
||||
if diff_cmd == '' {
|
||||
eprintln('>> sorry, but no working "diff" CLI command can be found')
|
||||
continue
|
||||
}
|
||||
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${ifilename}')
|
||||
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
|
||||
eprintln(diff.color_compare_files(diff_cmd, opath, vfmt_result_file))
|
||||
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${os.file_name(ipath)}')
|
||||
os.write_file(vfmt_result_file, result_ocontent)!
|
||||
println(diff.compare_files(opath, vfmt_result_file) or { err.msg() })
|
||||
continue
|
||||
}
|
||||
fmt_bench.ok()
|
||||
|
@ -1,5 +1,4 @@
|
||||
import os
|
||||
import rand
|
||||
import time
|
||||
import term
|
||||
import v.util.diff
|
||||
@ -11,8 +10,6 @@ const vroot = os.real_path(@VMODROOT)
|
||||
|
||||
const testdata_folder = os.join_path(vroot, 'vlib', 'v', 'gen', 'c', 'testdata')
|
||||
|
||||
const diff_cmd = diff.find_working_diff_command() or { '' }
|
||||
|
||||
const show_compilation_output = os.getenv('VTEST_SHOW_COMPILATION_OUTPUT').int() == 1
|
||||
|
||||
const user_os = os.user_os()
|
||||
@ -89,16 +86,16 @@ fn test_out_files() {
|
||||
}
|
||||
if expected != found {
|
||||
println('${term.red('FAIL')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
|
||||
println(term.header('expected:', '-'))
|
||||
println(expected)
|
||||
println(term.header('found:', '-'))
|
||||
println(found)
|
||||
if diff_cmd != '' {
|
||||
if diff_ := diff.compare_text(expected, found) {
|
||||
println(term.header('difference:', '-'))
|
||||
println(diff.color_compare_strings(diff_cmd, rand.ulid(), expected, found))
|
||||
println(diff_)
|
||||
} else {
|
||||
println(term.h_divider('-'))
|
||||
println(term.header('expected:', '-'))
|
||||
println(expected)
|
||||
println(term.header('found:', '-'))
|
||||
println(found)
|
||||
}
|
||||
println(term.h_divider('-'))
|
||||
total_errors++
|
||||
} else {
|
||||
println('${term.green('OK ')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
|
||||
|
@ -1,6 +1,5 @@
|
||||
import os
|
||||
import term
|
||||
import rand
|
||||
import v.util.vtest
|
||||
import v.util.diff
|
||||
|
||||
@ -75,14 +74,16 @@ fn check_path(dir string, tests []string) !int {
|
||||
if expected != found {
|
||||
println(term.red('FAIL'))
|
||||
println('============')
|
||||
println('expected ${program_out} content:')
|
||||
println(expected)
|
||||
println('============')
|
||||
println('found:')
|
||||
println(found)
|
||||
println('============\n')
|
||||
println('diff:')
|
||||
println(diff.color_compare_strings(diff_cmd, rand.ulid(), expected, found))
|
||||
if diff_ := diff.compare_text(expected, found) {
|
||||
println('diff:')
|
||||
println(diff_)
|
||||
} else {
|
||||
println('expected ${program_out} content:')
|
||||
println(expected)
|
||||
println('============')
|
||||
println('found:')
|
||||
println(found)
|
||||
}
|
||||
println('============\n')
|
||||
nb_fail++
|
||||
} else {
|
||||
|
@ -34,11 +34,6 @@ pub fn full_path_to_v(dirs_in int) string {
|
||||
return vexec
|
||||
}
|
||||
|
||||
fn diff_files(file_result string, file_expected string) string {
|
||||
diffcmd := diff.find_working_diff_command() or { return err.msg() }
|
||||
return diff.color_compare_files(diffcmd, file_result, file_expected)
|
||||
}
|
||||
|
||||
pub fn run_repl_file(wd string, vexec string, file string) !string {
|
||||
vexec_folder := os.dir(vexec) + os.path_separator
|
||||
fcontent := os.read_file(file) or { return error('Could not read repl file ${file}') }
|
||||
@ -67,22 +62,9 @@ pub fn run_repl_file(wd string, vexec string, file string) !string {
|
||||
}
|
||||
os.rm(input_temporary_filename)!
|
||||
if result != output {
|
||||
file_result := '${file}.result.txt'
|
||||
file_expected := '${file}.expected.txt'
|
||||
os.write_file(file_result, result) or { panic(err) }
|
||||
os.write_file(file_expected, output) or { panic(err) }
|
||||
diff_ := diff_files(file_expected, file_result)
|
||||
return error('Difference found in REPL file: ${file}
|
||||
====> Expected :
|
||||
|${output}|
|
||||
====> Got :
|
||||
|${result}|
|
||||
====> Diff :
|
||||
${diff_}
|
||||
')
|
||||
} else {
|
||||
return file.replace('./', '')
|
||||
return diff_error(file, output, result)
|
||||
}
|
||||
return file.replace('./', '')
|
||||
}
|
||||
|
||||
pub fn run_prod_file(wd string, vexec string, file string) !string {
|
||||
@ -101,20 +83,9 @@ pub fn run_prod_file(wd string, vexec string, file string) !string {
|
||||
}
|
||||
result := r.output.replace('\r', '')
|
||||
if result != expected_content {
|
||||
file_result := '${file}.result.txt'
|
||||
os.write_file(file_result, result) or { panic(err) }
|
||||
diff_ := diff_files(file_result, file_expected)
|
||||
return error('Difference found in test: ${file}
|
||||
====> Got :
|
||||
|${result}|
|
||||
====> Expected :
|
||||
|${expected_content}|
|
||||
====> Diff :
|
||||
${diff_}
|
||||
')
|
||||
} else {
|
||||
return 'Prod file ${file} is OK'
|
||||
return diff_error(file, expected_content, result)
|
||||
}
|
||||
return 'Prod file ${file} is OK'
|
||||
}
|
||||
|
||||
pub fn new_options() RunnerOptions {
|
||||
@ -150,3 +121,21 @@ pub fn new_prod_options() RunnerOptions {
|
||||
files: files
|
||||
}
|
||||
}
|
||||
|
||||
fn diff_error(file string, expected string, found string) IError {
|
||||
header := 'Difference found in REPL file: ${file}'
|
||||
details := if diff_ := diff.compare_text(expected, found) {
|
||||
'
|
||||
====> Diff :
|
||||
${diff_}
|
||||
'
|
||||
} else {
|
||||
'
|
||||
====> Expected :
|
||||
|${expected}|
|
||||
====> Got :
|
||||
|${found}|
|
||||
'
|
||||
}
|
||||
return error(header + details)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user