mirror of
https://github.com/vlang/v.git
synced 2025-09-16 07:52:32 +03:00
tests: add v test-all
, move v test-fixed
to v test-compiler-full
This commit is contained in:
parent
e4850cd6dd
commit
460f32baf2
14 changed files with 226 additions and 166 deletions
|
@ -28,9 +28,9 @@ const (
|
|||
)
|
||||
|
||||
struct App {
|
||||
diff_cmd string
|
||||
is_verbose bool
|
||||
modules []string
|
||||
diff_cmd string
|
||||
is_verbose bool
|
||||
modules []string
|
||||
mut:
|
||||
api_differences map[string]int
|
||||
}
|
||||
|
@ -40,9 +40,7 @@ fn main() {
|
|||
vroot := os.dir(vexe)
|
||||
util.set_vroot_folder(vroot)
|
||||
os.chdir(vroot)
|
||||
cmd := util.find_working_diff_command() or {
|
||||
''
|
||||
}
|
||||
cmd := util.find_working_diff_command() or { '' }
|
||||
mut app := App{
|
||||
diff_cmd: cmd
|
||||
is_verbose: os.getenv('VERBOSE').len > 0
|
||||
|
@ -63,7 +61,7 @@ fn main() {
|
|||
}
|
||||
howmany := app.api_differences.len
|
||||
eprintln('NB: please, do run `git clean -xf` after this tool, or at least `find thirdparty/ |grep .o$|xargs rm`')
|
||||
eprintln('otherwise, `./v test-fixed` may show false positives, due to .o files compiled with a cross compiler.')
|
||||
eprintln('otherwise, `./v test-compiler-full` may show false positives, due to .o files compiled with a cross compiler.')
|
||||
if howmany > 0 {
|
||||
eprintln(term.header('Found $howmany modules with different APIs', '='))
|
||||
for m in app.api_differences.keys() {
|
||||
|
@ -105,7 +103,7 @@ fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string {
|
|||
for s in f.stmts {
|
||||
if s is ast.FnDecl {
|
||||
if s.is_pub {
|
||||
fn_signature := s.stringify(b.table, mod_name, map[string]string)
|
||||
fn_signature := s.stringify(b.table, mod_name, map[string]string{})
|
||||
fn_mod := s.modname()
|
||||
if fn_mod == mod_name {
|
||||
fline := '$fn_mod: $fn_signature'
|
||||
|
|
|
@ -53,8 +53,7 @@ const (
|
|||
'bin2v',
|
||||
'test',
|
||||
'test-fmt',
|
||||
'test-compiler',
|
||||
'test-fixed',
|
||||
'test-compiler-full',
|
||||
'test-cleancode',
|
||||
'repl',
|
||||
'complete',
|
||||
|
@ -283,7 +282,7 @@ compdef _v v
|
|||
mut lines := []string{}
|
||||
list := auto_complete_request(sub_args[1..])
|
||||
for entry in list {
|
||||
lines << "compadd -U -S \"\" -- '$entry';"
|
||||
lines << 'compadd -U -S' + '""' + ' -- ' + "'$entry';"
|
||||
}
|
||||
println(lines.join('\n'))
|
||||
}
|
||||
|
|
106
cmd/tools/vtest-all.v
Normal file
106
cmd/tools/vtest-all.v
Normal file
|
@ -0,0 +1,106 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
import term
|
||||
import time
|
||||
|
||||
const vexe = os.getenv('VEXE')
|
||||
|
||||
const vroot = os.dir(vexe)
|
||||
|
||||
const args_string = os.args[1..].join(' ')
|
||||
|
||||
const vargs = args_string.all_before('test-all')
|
||||
|
||||
fn main() {
|
||||
commands := get_all_commands()
|
||||
commands.summary()
|
||||
}
|
||||
|
||||
struct Command {
|
||||
mut:
|
||||
line string
|
||||
label string // when set, the label will be printed *before* cmd.line is executed
|
||||
ecode int
|
||||
okmsg string
|
||||
errmsg string
|
||||
}
|
||||
|
||||
fn get_all_commands() []Command {
|
||||
mut res := []Command{}
|
||||
res << Command{
|
||||
line: '$vexe $vargs -progress test-cleancode'
|
||||
okmsg: 'All important .v files are invariant when processed with `v fmt`'
|
||||
}
|
||||
res << Command{
|
||||
line: '$vexe $vargs -progress test-fmt'
|
||||
okmsg: 'All .v files can be processed with `v fmt`. NB: the result may not always be compilable, it just means that `v fmt` does not crash.'
|
||||
}
|
||||
res << Command{
|
||||
line: '$vexe $vargs -progress test-compiler-full'
|
||||
okmsg: 'There are no _test.v file regressions.'
|
||||
}
|
||||
res << Command{
|
||||
line: '$vexe $vargs -progress build-tools'
|
||||
okmsg: 'All tools can be compiled.'
|
||||
}
|
||||
res << Command{
|
||||
line: '$vexe $vargs -progress build-examples'
|
||||
okmsg: 'All examples can be compiled.'
|
||||
}
|
||||
res << Command{
|
||||
line: '$vexe run cmd/tools/check-md.v -hide-warnings -all'
|
||||
label: 'Check ```v ``` code examples and formatting of .MD files...'
|
||||
okmsg: 'All .md files look good.'
|
||||
}
|
||||
res << Command{
|
||||
line: '$vexe install nedpals.args'
|
||||
okmsg: '`v install` works.'
|
||||
}
|
||||
$if macos {
|
||||
res << Command{
|
||||
line: '$vexe -o v.c cmd/v && cc -Werror v.c && rm -rf v.c'
|
||||
label: 'v.c should be buildable with no warnings...'
|
||||
okmsg: 'v.c can be compiled without warnings. This is good :)'
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
fn (mut cmd Command) run() {
|
||||
// Changing the current directory is needed for some of the compiler tests,
|
||||
// vlib/v/tests/local_test.v and vlib/v/tests/repl/repl_test.v
|
||||
os.chdir(vroot)
|
||||
if cmd.label != '' {
|
||||
println(term.header(cmd.label, '*'))
|
||||
}
|
||||
sw := time.new_stopwatch({})
|
||||
cmd.ecode = os.system(cmd.line)
|
||||
spent := sw.elapsed().milliseconds()
|
||||
println(term.yellow('> Running: "$cmd.line" took: $spent ms.'))
|
||||
println('')
|
||||
}
|
||||
|
||||
fn (commands []Command) summary() {
|
||||
sw := time.new_stopwatch({})
|
||||
for mut cmd in commands {
|
||||
cmd.run()
|
||||
}
|
||||
spent := sw.elapsed().milliseconds()
|
||||
oks := commands.filter(it.ecode == 0)
|
||||
fails := commands.filter(it.ecode != 0)
|
||||
println('')
|
||||
println(term.header(term.yellow(term.bold('Summary of `v test-all`:')), '-'))
|
||||
println(term.yellow('Total runtime: $spent ms'))
|
||||
for ocmd in oks {
|
||||
msg := if ocmd.okmsg != '' { ocmd.okmsg } else { ocmd.line }
|
||||
println(term.green('> OK: $msg '))
|
||||
}
|
||||
for fcmd in fails {
|
||||
msg := if fcmd.errmsg != '' { fcmd.errmsg } else { fcmd.line }
|
||||
println(term.red('> Failed: $msg '))
|
||||
}
|
||||
if fails.len > 0 {
|
||||
exit(1)
|
||||
}
|
||||
}
|
|
@ -95,7 +95,7 @@ fn main() {
|
|||
os.chdir(vroot)
|
||||
args := os.args.clone()
|
||||
args_string := args[1..].join(' ')
|
||||
cmd_prefix := args_string.all_before('test-fixed')
|
||||
cmd_prefix := args_string.all_before('test-compiler-full')
|
||||
title := 'testing all fixed tests'
|
||||
all_test_files := os.walk_ext(os.join_path(vroot, 'vlib'), '_test.v')
|
||||
testing.eheader(title)
|
|
@ -1,70 +0,0 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
import testing
|
||||
import benchmark
|
||||
import v.pref
|
||||
|
||||
fn main() {
|
||||
args_string := os.args[1..].join(' ')
|
||||
v_test_compiler(args_string.all_before('test-compiler'))
|
||||
}
|
||||
|
||||
fn v_test_compiler(vargs string) {
|
||||
vexe := pref.vexe_path()
|
||||
parent_dir := os.dir(vexe)
|
||||
testing.vlib_should_be_present(parent_dir)
|
||||
// Changing the current directory is needed for some of the compiler tests,
|
||||
// vlib/v/tests/local_test.v and vlib/v/tests/repl/repl_test.v
|
||||
os.chdir(parent_dir)
|
||||
/*
|
||||
if !os.exists(parent_dir + '/v.v') {
|
||||
eprintln('v.v is missing, it must be next to the V executable')
|
||||
exit(1)
|
||||
}
|
||||
*/
|
||||
// Make sure v.c can be compiled without warnings
|
||||
$if macos {
|
||||
if os.exists('/cmd/v') {
|
||||
os.system('$vexe -o v.c cmd/v')
|
||||
if os.system('cc -Werror v.c') != 0 {
|
||||
eprintln('cc failed to build v.c without warnings')
|
||||
exit(1)
|
||||
}
|
||||
eprintln('v.c can be compiled without warnings. This is good :)')
|
||||
}
|
||||
}
|
||||
building_tools_failed := os.system('"$vexe" build-tools') != 0
|
||||
eprintln('')
|
||||
testing.eheader('Testing all _test.v files...')
|
||||
mut compiler_test_session := testing.new_test_session(vargs)
|
||||
compiler_test_session.files << os.walk_ext(parent_dir, '_test.v')
|
||||
compiler_test_session.test()
|
||||
eprintln(compiler_test_session.benchmark.total_message('running V tests'))
|
||||
eprintln('')
|
||||
building_examples_failed := testing.v_build_failing(vargs, 'examples')
|
||||
eprintln('')
|
||||
building_live_failed := testing.v_build_failing(vargs + '-live', os.join_path('examples',
|
||||
'hot_reload'))
|
||||
eprintln('')
|
||||
//
|
||||
testing.setup_new_vtmp_folder()
|
||||
v_module_install_cmd := '$vexe install nedpals.args'
|
||||
eprintln('')
|
||||
testing.eheader('Installing a v module with: $v_module_install_cmd')
|
||||
mut vmark := benchmark.new_benchmark()
|
||||
ret := os.system(v_module_install_cmd)
|
||||
if ret != 0 {
|
||||
eprintln('failed to run v install')
|
||||
}
|
||||
desired_path := os.join_path(pref.default_module_path, 'nedpals', 'args')
|
||||
if !(os.exists(desired_path) && os.is_dir(desired_path)) {
|
||||
eprintln('v failed to install a test module')
|
||||
}
|
||||
vmark.stop()
|
||||
eprintln('Installing a v module took: ' + vmark.total_duration().str() + 'ms')
|
||||
//
|
||||
if building_tools_failed || compiler_test_session.failed || building_examples_failed || building_live_failed {
|
||||
exit(1)
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ fn main() {
|
|||
args_after := cmdline.options_after(args_to_executable, ['test'])
|
||||
if args_after.join(' ') == 'v' {
|
||||
eprintln('`v test v` has been deprecated.')
|
||||
eprintln('Use `v test-compiler` instead.')
|
||||
eprintln('Use `v test-all` instead.')
|
||||
exit(1)
|
||||
}
|
||||
mut ts := testing.new_test_session(args_before.join(' '))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue