mirror of
https://github.com/vlang/v.git
synced 2025-09-09 23:39:39 -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) {
|
fn print_compare(expected string, found string) {
|
||||||
diff_cmd := diff.find_working_diff_command() or { return }
|
|
||||||
println(term.red('FAIL'))
|
println(term.red('FAIL'))
|
||||||
println('============')
|
println('============')
|
||||||
println('expected:')
|
if diff_ := diff.compare_text(expected, found) {
|
||||||
println(expected)
|
println('diff:')
|
||||||
println('============')
|
println(diff_)
|
||||||
println('found:')
|
println('============\n')
|
||||||
println(found)
|
} else {
|
||||||
println('============\n')
|
println('expected:')
|
||||||
println('diff:')
|
println(expected)
|
||||||
println(diff.color_compare_strings(diff_cmd, rand.ulid(), expected, found))
|
println('============')
|
||||||
println('============\n')
|
println('found:')
|
||||||
|
println(found)
|
||||||
|
println('============\n')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
|
@ -15,11 +15,6 @@ const fpref = &pref.Preferences{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_bin2v_formatting() {
|
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)!
|
os.mkdir_all(tmpfolder)!
|
||||||
defer {
|
defer {
|
||||||
os.rmdir_all(tmpfolder) or {}
|
os.rmdir_all(tmpfolder) or {}
|
||||||
@ -33,8 +28,8 @@ fn test_bin2v_formatting() {
|
|||||||
expected_ocontent := os.read_file(b2v_keep_path)!
|
expected_ocontent := os.read_file(b2v_keep_path)!
|
||||||
if expected_ocontent != result_ocontent {
|
if expected_ocontent != result_ocontent {
|
||||||
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${ifilename}')
|
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${ifilename}')
|
||||||
os.write_file(vfmt_result_file, result_ocontent) or { panic(err) }
|
os.write_file(vfmt_result_file, result_ocontent)!
|
||||||
eprintln(diff.color_compare_files(diff_cmd, b2v_keep_path, vfmt_result_file))
|
println(diff.compare_files(b2v_keep_path, vfmt_result_file)!)
|
||||||
exit(1)
|
exit(1)
|
||||||
} else {
|
} else {
|
||||||
assert true
|
assert true
|
||||||
|
@ -30,7 +30,6 @@ fn run_fmt(mut input_files []string) {
|
|||||||
mut fmt_bench := benchmark.new_benchmark()
|
mut fmt_bench := benchmark.new_benchmark()
|
||||||
fmt_bench.set_total_expected_steps(input_files.len + 1)
|
fmt_bench.set_total_expected_steps(input_files.len + 1)
|
||||||
tmpfolder := os.temp_dir()
|
tmpfolder := os.temp_dir()
|
||||||
diff_cmd := diff.find_working_diff_command() or { '' }
|
|
||||||
for istep, ipath in input_files {
|
for istep, ipath in input_files {
|
||||||
fmt_bench.cstep = istep + 1
|
fmt_bench.cstep = istep + 1
|
||||||
fmt_bench.step()
|
fmt_bench.step()
|
||||||
@ -45,13 +44,9 @@ fn run_fmt(mut input_files []string) {
|
|||||||
if expected_ocontent != result_ocontent {
|
if expected_ocontent != result_ocontent {
|
||||||
fmt_bench.fail()
|
fmt_bench.fail()
|
||||||
eprintln(fmt_bench.step_message_fail('file ${ipath} after formatting, does not look as expected.'))
|
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)}')
|
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) }
|
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
|
continue
|
||||||
}
|
}
|
||||||
fmt_bench.ok()
|
fmt_bench.ok()
|
||||||
|
@ -21,7 +21,6 @@ fn run_fmt(mut input_files []string) {
|
|||||||
fmt_message := 'vfmt tests'
|
fmt_message := 'vfmt tests'
|
||||||
eprintln(term.header(fmt_message, '-'))
|
eprintln(term.header(fmt_message, '-'))
|
||||||
tmpfolder := os.temp_dir()
|
tmpfolder := os.temp_dir()
|
||||||
diff_cmd := diff.find_working_diff_command() or { '' }
|
|
||||||
assert input_files.len > 0
|
assert input_files.len > 0
|
||||||
input_files = vtest.filter_vtest_only(input_files)
|
input_files = vtest.filter_vtest_only(input_files)
|
||||||
if input_files.len == 0 {
|
if input_files.len == 0 {
|
||||||
@ -51,13 +50,9 @@ fn run_fmt(mut input_files []string) {
|
|||||||
if expected_ocontent != result_ocontent {
|
if expected_ocontent != result_ocontent {
|
||||||
fmt_bench.fail()
|
fmt_bench.fail()
|
||||||
eprintln(fmt_bench.step_message_fail('file ${ipath} after formatting, does not look as expected.'))
|
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)}')
|
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) }
|
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
|
continue
|
||||||
}
|
}
|
||||||
fmt_bench.ok()
|
fmt_bench.ok()
|
||||||
|
@ -50,13 +50,9 @@ fn test_vlib_fmt() {
|
|||||||
if expected_ocontent != result_ocontent {
|
if expected_ocontent != result_ocontent {
|
||||||
fmt_bench.fail()
|
fmt_bench.fail()
|
||||||
eprintln(fmt_bench.step_message_fail('file ${ipath} after formatting, does not look as expected.'))
|
eprintln(fmt_bench.step_message_fail('file ${ipath} after formatting, does not look as expected.'))
|
||||||
if diff_cmd == '' {
|
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${os.file_name(ipath)}')
|
||||||
eprintln('>> sorry, but no working "diff" CLI command can be found')
|
os.write_file(vfmt_result_file, result_ocontent)!
|
||||||
continue
|
println(diff.compare_files(opath, vfmt_result_file) or { err.msg() })
|
||||||
}
|
|
||||||
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))
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt_bench.ok()
|
fmt_bench.ok()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import rand
|
|
||||||
import time
|
import time
|
||||||
import term
|
import term
|
||||||
import v.util.diff
|
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 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 show_compilation_output = os.getenv('VTEST_SHOW_COMPILATION_OUTPUT').int() == 1
|
||||||
|
|
||||||
const user_os = os.user_os()
|
const user_os = os.user_os()
|
||||||
@ -89,16 +86,16 @@ fn test_out_files() {
|
|||||||
}
|
}
|
||||||
if expected != found {
|
if expected != found {
|
||||||
println('${term.red('FAIL')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
|
println('${term.red('FAIL')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
|
||||||
println(term.header('expected:', '-'))
|
if diff_ := diff.compare_text(expected, found) {
|
||||||
println(expected)
|
|
||||||
println(term.header('found:', '-'))
|
|
||||||
println(found)
|
|
||||||
if diff_cmd != '' {
|
|
||||||
println(term.header('difference:', '-'))
|
println(term.header('difference:', '-'))
|
||||||
println(diff.color_compare_strings(diff_cmd, rand.ulid(), expected, found))
|
println(diff_)
|
||||||
} else {
|
} else {
|
||||||
println(term.h_divider('-'))
|
println(term.header('expected:', '-'))
|
||||||
|
println(expected)
|
||||||
|
println(term.header('found:', '-'))
|
||||||
|
println(found)
|
||||||
}
|
}
|
||||||
|
println(term.h_divider('-'))
|
||||||
total_errors++
|
total_errors++
|
||||||
} else {
|
} else {
|
||||||
println('${term.green('OK ')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
|
println('${term.green('OK ')} C:${compile_ms:6}ms, R:${run_ms:2}ms ${label}')
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import term
|
import term
|
||||||
import rand
|
|
||||||
import v.util.vtest
|
import v.util.vtest
|
||||||
import v.util.diff
|
import v.util.diff
|
||||||
|
|
||||||
@ -75,14 +74,16 @@ fn check_path(dir string, tests []string) !int {
|
|||||||
if expected != found {
|
if expected != found {
|
||||||
println(term.red('FAIL'))
|
println(term.red('FAIL'))
|
||||||
println('============')
|
println('============')
|
||||||
println('expected ${program_out} content:')
|
if diff_ := diff.compare_text(expected, found) {
|
||||||
println(expected)
|
println('diff:')
|
||||||
println('============')
|
println(diff_)
|
||||||
println('found:')
|
} else {
|
||||||
println(found)
|
println('expected ${program_out} content:')
|
||||||
println('============\n')
|
println(expected)
|
||||||
println('diff:')
|
println('============')
|
||||||
println(diff.color_compare_strings(diff_cmd, rand.ulid(), expected, found))
|
println('found:')
|
||||||
|
println(found)
|
||||||
|
}
|
||||||
println('============\n')
|
println('============\n')
|
||||||
nb_fail++
|
nb_fail++
|
||||||
} else {
|
} else {
|
||||||
|
@ -34,11 +34,6 @@ pub fn full_path_to_v(dirs_in int) string {
|
|||||||
return vexec
|
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 {
|
pub fn run_repl_file(wd string, vexec string, file string) !string {
|
||||||
vexec_folder := os.dir(vexec) + os.path_separator
|
vexec_folder := os.dir(vexec) + os.path_separator
|
||||||
fcontent := os.read_file(file) or { return error('Could not read repl file ${file}') }
|
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)!
|
os.rm(input_temporary_filename)!
|
||||||
if result != output {
|
if result != output {
|
||||||
file_result := '${file}.result.txt'
|
return diff_error(file, output, result)
|
||||||
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 file.replace('./', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_prod_file(wd string, vexec string, file string) !string {
|
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', '')
|
result := r.output.replace('\r', '')
|
||||||
if result != expected_content {
|
if result != expected_content {
|
||||||
file_result := '${file}.result.txt'
|
return diff_error(file, expected_content, result)
|
||||||
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 'Prod file ${file} is OK'
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_options() RunnerOptions {
|
pub fn new_options() RunnerOptions {
|
||||||
@ -150,3 +121,21 @@ pub fn new_prod_options() RunnerOptions {
|
|||||||
files: files
|
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