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 another = int(5)
|
|
@ -1,4 +1,4 @@
|
|||
module main
|
||||
module basic
|
||||
|
||||
const source_root = 'temp' // some const
|
||||
const another = int(5)
|
|
@ -1,3 +1,5 @@
|
|||
module basic
|
||||
|
||||
pub const source_root = 'temp' // some const
|
||||
|
||||
pub const another = int(5)
|
|
@ -4,12 +4,10 @@ import term
|
|||
import v.util.vtest
|
||||
import v.util.diff
|
||||
|
||||
const vexe = os.quoted_path(@VEXE)
|
||||
|
||||
const vroot = @VMODROOT
|
||||
|
||||
const vexe_path = @VEXE
|
||||
const vexe = os.quoted_path(vexe_path)
|
||||
const vroot = os.dir(vexe_path)
|
||||
const diff_cmd = find_diff_cmd()
|
||||
|
||||
const should_autofix = os.getenv('VAUTOFIX') != ''
|
||||
|
||||
fn find_diff_cmd() string {
|
||||
|
@ -62,45 +60,22 @@ fn check_path(dir string, tests []string) int {
|
|||
for path in paths {
|
||||
mut fails := 0
|
||||
qpath := os.quoted_path(path)
|
||||
path_no_ext := path.all_before_last('.')
|
||||
print(path + ' ')
|
||||
fails += check_output(
|
||||
program: path
|
||||
cmd: '${vexe} doc ${qpath}'
|
||||
out_filename: 'main.out'
|
||||
)
|
||||
fails += check_output(
|
||||
program: path
|
||||
cmd: '${vexe} doc -comments ${qpath}'
|
||||
out_filename: 'main.unsorted.out'
|
||||
fails += check_output('${vexe} doc ${qpath}', path_no_ext + '.out')
|
||||
fails += check_output('${vexe} doc -comments ${qpath}', '${path_no_ext}.unsorted.out',
|
||||
should_sort: false
|
||||
)
|
||||
fails += check_output(
|
||||
program: path
|
||||
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'
|
||||
)
|
||||
fails += check_output('${vexe} doc -comments ${qpath}', '${path_no_ext}.comments.out')
|
||||
fails += check_output('${vexe} doc -readme -comments ${qpath}', '${path_no_ext}.readme.comments.out')
|
||||
// test the main 3 different formats:
|
||||
program_dir := os.quoted_path(if os.is_file(path) { os.dir(path) } else { path })
|
||||
fails += check_output(
|
||||
program: path
|
||||
cmd: '${vexe} doc -f html -o - -html-only-contents -readme -comments ${program_dir}'
|
||||
out_filename: 'main.html'
|
||||
)
|
||||
fails += check_output(
|
||||
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'
|
||||
)
|
||||
fails += check_output('${vexe} doc -f html -o - -html-only-contents -readme -comments ${program_dir}',
|
||||
'${path_no_ext}.html')
|
||||
fails += check_output('${vexe} doc -f ansi -o - -html-only-contents -readme -comments ${program_dir}',
|
||||
'${path_no_ext}.ansi')
|
||||
fails += check_output('${vexe} doc -f text -o - -html-only-contents -readme -comments ${program_dir}',
|
||||
'${path_no_ext}.text')
|
||||
//
|
||||
total_fails += fails
|
||||
if fails == 0 {
|
||||
|
@ -136,24 +111,19 @@ fn clean_line_endings(s string) string {
|
|||
|
||||
@[params]
|
||||
struct CheckOutputParams {
|
||||
program string = 'some/dir/main.v'
|
||||
cmd string = 'v doc'
|
||||
main_filename string = 'main.v'
|
||||
out_filename string = 'main.out'
|
||||
should_sort bool = true
|
||||
should_sort bool = true
|
||||
}
|
||||
|
||||
fn check_output(params CheckOutputParams) int {
|
||||
out_file_path := params.program.replace(params.main_filename, params.out_filename)
|
||||
if !os.exists(out_file_path) {
|
||||
fn check_output(cmd string, out_path string, opts CheckOutputParams) int {
|
||||
if !os.exists(out_path) {
|
||||
return 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)
|
||||
|
||||
os.setenv('VDOC_SORT', params.should_sort.str(), true)
|
||||
res := os.execute(params.cmd)
|
||||
os.setenv('VDOC_SORT', opts.should_sort.str(), true)
|
||||
res := os.execute(cmd)
|
||||
|
||||
if res.exit_code < 0 {
|
||||
panic(res.output)
|
||||
|
@ -161,13 +131,13 @@ fn check_output(params CheckOutputParams) int {
|
|||
found := clean_line_endings(res.output)
|
||||
if expected != found {
|
||||
print_compare(expected, found)
|
||||
eprintln('>>> cmd: VDOC_SORT=${params.should_sort} ${params.cmd}')
|
||||
eprintln('>>> out_file_path: `${out_file_path}`')
|
||||
eprintln('>>> fix: VDOC_SORT=${params.should_sort} ${params.cmd} > ${out_file_path}')
|
||||
eprintln('>>> cmd: VDOC_SORT=${opts.should_sort} ${cmd}')
|
||||
eprintln('>>> out_file_path: `${out_path}`')
|
||||
eprintln('>>> fix: VDOC_SORT=${opts.should_sort} ${cmd} > ${out_path}')
|
||||
fails++
|
||||
}
|
||||
if should_autofix {
|
||||
os.write_file(out_file_path, res.output) or {}
|
||||
os.write_file(out_path, res.output) or {}
|
||||
}
|
||||
return fails
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue