mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: add test for VDOC_SORT=false ./v doc file.v
This commit is contained in:
parent
b40aa4ffa9
commit
822acd78cb
8
cmd/tools/vdoc/tests/testdata/unsorted/main.out
vendored
Normal file
8
cmd/tools/vdoc/tests/testdata/unsorted/main.out
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
module main
|
||||
|
||||
const omega = 3 // should be first
|
||||
const alpha = 5 // should be in the middle
|
||||
const beta = 2 // should be at the end
|
||||
fn abc()
|
||||
fn def()
|
||||
fn xyz()
|
11
cmd/tools/vdoc/tests/testdata/unsorted/main.unsorted.out
vendored
Normal file
11
cmd/tools/vdoc/tests/testdata/unsorted/main.unsorted.out
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
module main
|
||||
|
||||
const omega = 3 // should be first
|
||||
const alpha = 5 // should be in the middle
|
||||
const beta = 2 // should be at the end
|
||||
fn def()
|
||||
def - should be first
|
||||
fn xyz()
|
||||
xyz - should be in the middle
|
||||
fn abc()
|
||||
abc - should be last
|
20
cmd/tools/vdoc/tests/testdata/unsorted/main.v
vendored
Normal file
20
cmd/tools/vdoc/tests/testdata/unsorted/main.v
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
pub const omega = 3 // should be first
|
||||
|
||||
pub const alpha = 5 // should be in the middle
|
||||
|
||||
pub const beta = 2 // should be at the end
|
||||
|
||||
// def - should be first
|
||||
pub fn def() {
|
||||
println(1)
|
||||
}
|
||||
|
||||
// xyz - should be in the middle
|
||||
pub fn xyz() {
|
||||
println(2)
|
||||
}
|
||||
|
||||
// abc - should be last
|
||||
pub fn abc() {
|
||||
println(3)
|
||||
}
|
@ -30,42 +30,35 @@ fn get_main_files_in_dir(dir string) []string {
|
||||
}
|
||||
|
||||
fn check_path(vexe string, dir string, tests []string) int {
|
||||
mut nb_fail := 0
|
||||
mut total_fails := 0
|
||||
paths := vtest.filter_vtest_only(tests, basepath: vroot)
|
||||
for path in paths {
|
||||
mut fails := 0
|
||||
program := path
|
||||
print(path + ' ')
|
||||
res := os.execute('${os.quoted_path(vexe)} doc ${os.quoted_path(program)}')
|
||||
if res.exit_code < 0 {
|
||||
panic(res.output)
|
||||
}
|
||||
mut expected := os.read_file(program.replace('main.v', 'main.out')) or { panic(err) }
|
||||
expected = clean_line_endings(expected)
|
||||
found := clean_line_endings(res.output)
|
||||
if expected != found {
|
||||
print_compare(expected, found)
|
||||
}
|
||||
|
||||
res_comments := os.execute('${os.quoted_path(vexe)} doc -comments ${os.quoted_path(program)}')
|
||||
if res_comments.exit_code < 0 {
|
||||
panic(res_comments.output)
|
||||
}
|
||||
mut expected_comments := os.read_file(program.replace('main.v', 'main.comments.out')) or {
|
||||
panic(err)
|
||||
}
|
||||
expected_comments = clean_line_endings(expected_comments)
|
||||
found_comments := clean_line_endings(res_comments.output)
|
||||
if expected_comments != found_comments {
|
||||
print_compare(expected_comments, found_comments)
|
||||
}
|
||||
|
||||
if expected == found && expected_comments == found_comments {
|
||||
fails += check_output(
|
||||
program: program
|
||||
cmd: '${os.quoted_path(vexe)} doc ${os.quoted_path(program)}'
|
||||
out_filename: 'main.out'
|
||||
)
|
||||
fails += check_output(
|
||||
program: program
|
||||
cmd: '${os.quoted_path(vexe)} doc -comments ${os.quoted_path(program)}'
|
||||
out_filename: 'main.unsorted.out'
|
||||
should_sort: false
|
||||
)
|
||||
fails += check_output(
|
||||
program: program
|
||||
cmd: '${os.quoted_path(vexe)} doc -comments ${os.quoted_path(program)}'
|
||||
out_filename: 'main.comments.out'
|
||||
)
|
||||
total_fails += fails
|
||||
if fails == 0 {
|
||||
println(term.green('OK'))
|
||||
} else {
|
||||
nb_fail++
|
||||
}
|
||||
flush_stdout()
|
||||
}
|
||||
return nb_fail
|
||||
return total_fails
|
||||
}
|
||||
|
||||
fn print_compare(expected string, found string) {
|
||||
@ -90,3 +83,37 @@ fn clean_line_endings(s string) string {
|
||||
res = res.trim('\n')
|
||||
return res
|
||||
}
|
||||
|
||||
[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
|
||||
}
|
||||
|
||||
fn check_output(params CheckOutputParams) int {
|
||||
out_file_path := params.program.replace(params.main_filename, params.out_filename)
|
||||
if !os.exists(out_file_path) {
|
||||
return 0
|
||||
}
|
||||
mut fails := 0
|
||||
mut expected := os.read_file(out_file_path) or { panic(err) }
|
||||
expected = clean_line_endings(expected)
|
||||
|
||||
os.setenv('VDOC_SORT', params.should_sort.str(), true)
|
||||
res := os.execute(params.cmd)
|
||||
|
||||
if res.exit_code < 0 {
|
||||
panic(res.output)
|
||||
}
|
||||
found := clean_line_endings(res.output)
|
||||
if expected != found {
|
||||
print_compare(expected, found)
|
||||
eprintln('>>> out_file_path: ${out_file_path}')
|
||||
eprintln('>>> cmd: VDOC_SORT=${params.should_sort} ${params.cmd}')
|
||||
fails++
|
||||
}
|
||||
return fails
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user