tests: add ability to check the output of commands for .starts_with, .ends_with and .contains strings, in `v test-all`
parent
b43c538bc0
commit
81963b51ab
|
@ -49,6 +49,12 @@ enum RunCommandKind {
|
||||||
|
|
||||||
const expect_nothing = '<nothing>'
|
const expect_nothing = '<nothing>'
|
||||||
|
|
||||||
|
const starts_with_nothing = '<nothing>'
|
||||||
|
|
||||||
|
const ends_with_nothing = '<nothing>'
|
||||||
|
|
||||||
|
const contains_nothing = '<nothing>'
|
||||||
|
|
||||||
struct Command {
|
struct Command {
|
||||||
mut:
|
mut:
|
||||||
line string
|
line string
|
||||||
|
@ -59,6 +65,9 @@ mut:
|
||||||
rmfile string
|
rmfile string
|
||||||
runcmd RunCommandKind = .system
|
runcmd RunCommandKind = .system
|
||||||
expect string = expect_nothing
|
expect string = expect_nothing
|
||||||
|
starts_with string = starts_with_nothing
|
||||||
|
ends_with string = ends_with_nothing
|
||||||
|
contains string = contains_nothing
|
||||||
output string
|
output string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +108,14 @@ fn get_all_commands() []Command {
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: 'Hello, World!\n'
|
expect: 'Hello, World!\n'
|
||||||
}
|
}
|
||||||
|
res << Command{
|
||||||
|
line: '$vexe interpret examples/hanoi.v'
|
||||||
|
okmsg: 'V can interpret hanoi.v'
|
||||||
|
runcmd: .execute
|
||||||
|
starts_with: 'Disc 1 from A to C...\n'
|
||||||
|
ends_with: 'Disc 1 from A to C...\n'
|
||||||
|
contains: 'Disc 7 from A to C...\n'
|
||||||
|
}
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '$vexe -o - examples/hello_world.v | grep "#define V_COMMIT_HASH" > /dev/null'
|
line: '$vexe -o - examples/hello_world.v | grep "#define V_COMMIT_HASH" > /dev/null'
|
||||||
okmsg: 'V prints the generated source code to stdout with `-o -` .'
|
okmsg: 'V prints the generated source code to stdout with `-o -` .'
|
||||||
|
@ -252,23 +269,56 @@ fn (mut cmd Command) run() {
|
||||||
spent := sw.elapsed().milliseconds()
|
spent := sw.elapsed().milliseconds()
|
||||||
//
|
//
|
||||||
mut is_failed := false
|
mut is_failed := false
|
||||||
|
mut is_failed_expected := false
|
||||||
|
mut is_failed_starts_with := false
|
||||||
|
mut is_failed_ends_with := false
|
||||||
|
mut is_failed_contains := false
|
||||||
if cmd.ecode != 0 {
|
if cmd.ecode != 0 {
|
||||||
is_failed = true
|
is_failed = true
|
||||||
}
|
}
|
||||||
if cmd.expect != expect_nothing {
|
if cmd.expect != expect_nothing {
|
||||||
if cmd.output != cmd.expect {
|
if cmd.output != cmd.expect {
|
||||||
is_failed = true
|
is_failed = true
|
||||||
|
is_failed_expected = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cmd.starts_with != starts_with_nothing {
|
||||||
|
if !cmd.output.starts_with(cmd.starts_with) {
|
||||||
|
is_failed = true
|
||||||
|
is_failed_starts_with = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cmd.ends_with != ends_with_nothing {
|
||||||
|
if !cmd.output.ends_with(cmd.ends_with) {
|
||||||
|
is_failed = true
|
||||||
|
is_failed_ends_with = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cmd.contains != contains_nothing {
|
||||||
|
if !cmd.output.contains(cmd.contains) {
|
||||||
|
is_failed = true
|
||||||
|
is_failed_contains = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
run_label := if is_failed { term.failed('FAILED') } else { term_highlight('OK') }
|
run_label := if is_failed { term.failed('FAILED') } else { term_highlight('OK') }
|
||||||
println('> Running: "$cmd.line" took: $spent ms ... $run_label')
|
println('> Running: "$cmd.line" took: $spent ms ... $run_label')
|
||||||
//
|
//
|
||||||
if is_failed && cmd.expect != expect_nothing {
|
if is_failed && is_failed_expected {
|
||||||
if cmd.output != cmd.expect {
|
|
||||||
eprintln('> expected:\n$cmd.expect')
|
eprintln('> expected:\n$cmd.expect')
|
||||||
eprintln('> output:\n$cmd.output')
|
eprintln('> output:\n$cmd.output')
|
||||||
}
|
}
|
||||||
|
if is_failed && is_failed_starts_with {
|
||||||
|
eprintln('> expected to start with:\n$cmd.starts_with')
|
||||||
|
eprintln('> output:\n${cmd.output#[..cmd.starts_with.len]}')
|
||||||
|
}
|
||||||
|
if is_failed && is_failed_ends_with {
|
||||||
|
eprintln('> expected to end with:\n$cmd.ends_with')
|
||||||
|
eprintln('> output:\n${cmd.output#[-cmd.starts_with.len..]}')
|
||||||
|
}
|
||||||
|
if is_failed && is_failed_contains {
|
||||||
|
eprintln('> expected to contain:\n$cmd.contains')
|
||||||
|
eprintln('> output:\n$cmd.output')
|
||||||
}
|
}
|
||||||
if vtest_nocleanup {
|
if vtest_nocleanup {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue