mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
vdoc,tests: detect expected files from input instead of hardcoding names (#21074)
This commit is contained in:
parent
af71cb0dff
commit
dbdbfe24a5
4 changed files with 28 additions and 56 deletions
|
@ -1,4 +1,4 @@
|
||||||
module main
|
module basic
|
||||||
|
|
||||||
const source_root = 'temp' // some const
|
const source_root = 'temp' // some const
|
||||||
const another = int(5)
|
const another = int(5)
|
|
@ -1,4 +1,4 @@
|
||||||
module main
|
module basic
|
||||||
|
|
||||||
const source_root = 'temp' // some const
|
const source_root = 'temp' // some const
|
||||||
const another = int(5)
|
const another = int(5)
|
|
@ -1,3 +1,5 @@
|
||||||
|
module basic
|
||||||
|
|
||||||
pub const source_root = 'temp' // some const
|
pub const source_root = 'temp' // some const
|
||||||
|
|
||||||
pub const another = int(5)
|
pub const another = int(5)
|
|
@ -4,12 +4,10 @@ import term
|
||||||
import v.util.vtest
|
import v.util.vtest
|
||||||
import v.util.diff
|
import v.util.diff
|
||||||
|
|
||||||
const vexe = os.quoted_path(@VEXE)
|
const vexe_path = @VEXE
|
||||||
|
const vexe = os.quoted_path(vexe_path)
|
||||||
const vroot = @VMODROOT
|
const vroot = os.dir(vexe_path)
|
||||||
|
|
||||||
const diff_cmd = find_diff_cmd()
|
const diff_cmd = find_diff_cmd()
|
||||||
|
|
||||||
const should_autofix = os.getenv('VAUTOFIX') != ''
|
const should_autofix = os.getenv('VAUTOFIX') != ''
|
||||||
|
|
||||||
fn find_diff_cmd() string {
|
fn find_diff_cmd() string {
|
||||||
|
@ -62,45 +60,22 @@ fn check_path(dir string, tests []string) int {
|
||||||
for path in paths {
|
for path in paths {
|
||||||
mut fails := 0
|
mut fails := 0
|
||||||
qpath := os.quoted_path(path)
|
qpath := os.quoted_path(path)
|
||||||
|
path_no_ext := path.all_before_last('.')
|
||||||
print(path + ' ')
|
print(path + ' ')
|
||||||
fails += check_output(
|
fails += check_output('${vexe} doc ${qpath}', path_no_ext + '.out')
|
||||||
program: path
|
fails += check_output('${vexe} doc -comments ${qpath}', '${path_no_ext}.unsorted.out',
|
||||||
cmd: '${vexe} doc ${qpath}'
|
|
||||||
out_filename: 'main.out'
|
|
||||||
)
|
|
||||||
fails += check_output(
|
|
||||||
program: path
|
|
||||||
cmd: '${vexe} doc -comments ${qpath}'
|
|
||||||
out_filename: 'main.unsorted.out'
|
|
||||||
should_sort: false
|
should_sort: false
|
||||||
)
|
)
|
||||||
fails += check_output(
|
fails += check_output('${vexe} doc -comments ${qpath}', '${path_no_ext}.comments.out')
|
||||||
program: path
|
fails += check_output('${vexe} doc -readme -comments ${qpath}', '${path_no_ext}.readme.comments.out')
|
||||||
cmd: '${vexe} doc -comments ${qpath}'
|
|
||||||
out_filename: 'main.comments.out'
|
|
||||||
)
|
|
||||||
fails += check_output(
|
|
||||||
program: path
|
|
||||||
cmd: '${vexe} doc -readme -comments ${qpath}'
|
|
||||||
out_filename: 'main.readme.comments.out'
|
|
||||||
)
|
|
||||||
// test the main 3 different formats:
|
// test the main 3 different formats:
|
||||||
program_dir := os.quoted_path(if os.is_file(path) { os.dir(path) } else { path })
|
program_dir := os.quoted_path(if os.is_file(path) { os.dir(path) } else { path })
|
||||||
fails += check_output(
|
fails += check_output('${vexe} doc -f html -o - -html-only-contents -readme -comments ${program_dir}',
|
||||||
program: path
|
'${path_no_ext}.html')
|
||||||
cmd: '${vexe} doc -f html -o - -html-only-contents -readme -comments ${program_dir}'
|
fails += check_output('${vexe} doc -f ansi -o - -html-only-contents -readme -comments ${program_dir}',
|
||||||
out_filename: 'main.html'
|
'${path_no_ext}.ansi')
|
||||||
)
|
fails += check_output('${vexe} doc -f text -o - -html-only-contents -readme -comments ${program_dir}',
|
||||||
fails += check_output(
|
'${path_no_ext}.text')
|
||||||
program: path
|
|
||||||
cmd: '${vexe} doc -f ansi -o - -html-only-contents -readme -comments ${program_dir}'
|
|
||||||
out_filename: 'main.ansi'
|
|
||||||
)
|
|
||||||
fails += check_output(
|
|
||||||
program: path
|
|
||||||
cmd: '${vexe} doc -f text -o - -html-only-contents -readme -comments ${program_dir}'
|
|
||||||
out_filename: 'main.text'
|
|
||||||
)
|
|
||||||
//
|
//
|
||||||
total_fails += fails
|
total_fails += fails
|
||||||
if fails == 0 {
|
if fails == 0 {
|
||||||
|
@ -136,24 +111,19 @@ fn clean_line_endings(s string) string {
|
||||||
|
|
||||||
@[params]
|
@[params]
|
||||||
struct CheckOutputParams {
|
struct CheckOutputParams {
|
||||||
program string = 'some/dir/main.v'
|
should_sort bool = true
|
||||||
cmd string = 'v doc'
|
|
||||||
main_filename string = 'main.v'
|
|
||||||
out_filename string = 'main.out'
|
|
||||||
should_sort bool = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_output(params CheckOutputParams) int {
|
fn check_output(cmd string, out_path string, opts CheckOutputParams) int {
|
||||||
out_file_path := params.program.replace(params.main_filename, params.out_filename)
|
if !os.exists(out_path) {
|
||||||
if !os.exists(out_file_path) {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
mut fails := 0
|
mut fails := 0
|
||||||
mut expected := os.read_file(out_file_path) or { panic(err) }
|
mut expected := os.read_file(out_path) or { panic(err) }
|
||||||
expected = clean_line_endings(expected)
|
expected = clean_line_endings(expected)
|
||||||
|
|
||||||
os.setenv('VDOC_SORT', params.should_sort.str(), true)
|
os.setenv('VDOC_SORT', opts.should_sort.str(), true)
|
||||||
res := os.execute(params.cmd)
|
res := os.execute(cmd)
|
||||||
|
|
||||||
if res.exit_code < 0 {
|
if res.exit_code < 0 {
|
||||||
panic(res.output)
|
panic(res.output)
|
||||||
|
@ -161,13 +131,13 @@ fn check_output(params CheckOutputParams) int {
|
||||||
found := clean_line_endings(res.output)
|
found := clean_line_endings(res.output)
|
||||||
if expected != found {
|
if expected != found {
|
||||||
print_compare(expected, found)
|
print_compare(expected, found)
|
||||||
eprintln('>>> cmd: VDOC_SORT=${params.should_sort} ${params.cmd}')
|
eprintln('>>> cmd: VDOC_SORT=${opts.should_sort} ${cmd}')
|
||||||
eprintln('>>> out_file_path: `${out_file_path}`')
|
eprintln('>>> out_file_path: `${out_path}`')
|
||||||
eprintln('>>> fix: VDOC_SORT=${params.should_sort} ${params.cmd} > ${out_file_path}')
|
eprintln('>>> fix: VDOC_SORT=${opts.should_sort} ${cmd} > ${out_path}')
|
||||||
fails++
|
fails++
|
||||||
}
|
}
|
||||||
if should_autofix {
|
if should_autofix {
|
||||||
os.write_file(out_file_path, res.output) or {}
|
os.write_file(out_path, res.output) or {}
|
||||||
}
|
}
|
||||||
return fails
|
return fails
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue