checker: fix comptime custom defines usages, add tests
parent
e97d3af4b1
commit
ac6fad6a63
|
@ -3615,7 +3615,9 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
|
||||||
else { return false }
|
else { return false }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.error('unknown \$if value', pos)
|
if cond.name !in c.pref.compile_defines_all {
|
||||||
|
c.error('unknown \$if value', pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
optional compitme define works
|
||||||
|
non optional comptime define works
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/checker/tests/custom_comptime_define_error.vv:6:9: error: unknown $if value
|
||||||
|
4 | println('optional compitme define works')
|
||||||
|
5 | }
|
||||||
|
6 | $if mysymbol {
|
||||||
|
| ~~~~~~~~~~~~
|
||||||
|
7 | // this will produce a checker error when `-d mysymbol` is not given on the CLI
|
||||||
|
8 | println('non optional comptime define works')
|
|
@ -0,0 +1,10 @@
|
||||||
|
fn main() {
|
||||||
|
$if mysymbol? {
|
||||||
|
// this should not produce checker errors, but will print only with `-d mysymbol`
|
||||||
|
println('optional compitme define works')
|
||||||
|
}
|
||||||
|
$if mysymbol {
|
||||||
|
// this will produce a checker error when `-d mysymbol` is not given on the CLI
|
||||||
|
println('non optional comptime define works')
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
start
|
||||||
|
message: verbose message
|
||||||
|
message: debugging system
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
start
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Calls to edebug/1 should be executed only when `-d mydebug` is passed on the CLI
|
||||||
|
// Otherwise they will not be present *at all* in the generated code.
|
||||||
|
[if mydebug]
|
||||||
|
fn edebug(message string) {
|
||||||
|
println('message: $message')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println('start')
|
||||||
|
edebug('verbose message')
|
||||||
|
edebug('debugging system')
|
||||||
|
println('end')
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ const (
|
||||||
skip_files = [
|
skip_files = [
|
||||||
'vlib/v/checker/tests/return_missing_comp_if.vv',
|
'vlib/v/checker/tests/return_missing_comp_if.vv',
|
||||||
'vlib/v/checker/tests/return_missing_comp_if_nested.vv',
|
'vlib/v/checker/tests/return_missing_comp_if_nested.vv',
|
||||||
|
'vlib/v/checker/tests/custom_comptime_define_if_flag.vv',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,36 +34,37 @@ fn test_all() {
|
||||||
vexe := os.getenv('VEXE')
|
vexe := os.getenv('VEXE')
|
||||||
vroot := os.dir(vexe)
|
vroot := os.dir(vexe)
|
||||||
os.chdir(vroot)
|
os.chdir(vroot)
|
||||||
classic_dir := 'vlib/v/checker/tests'
|
checker_dir := 'vlib/v/checker/tests'
|
||||||
classic_tests := get_tests_in_dir(classic_dir, false)
|
|
||||||
global_dir := '$classic_dir/globals'
|
|
||||||
global_tests := get_tests_in_dir(global_dir, false)
|
|
||||||
module_dir := '$classic_dir/modules'
|
|
||||||
module_tests := get_tests_in_dir(module_dir, true)
|
|
||||||
run_dir := '$classic_dir/run'
|
|
||||||
run_tests := get_tests_in_dir(run_dir, false)
|
|
||||||
parser_dir := 'vlib/v/parser/tests'
|
parser_dir := 'vlib/v/parser/tests'
|
||||||
|
module_dir := '$checker_dir/modules'
|
||||||
|
global_dir := '$checker_dir/globals'
|
||||||
|
run_dir := '$checker_dir/run'
|
||||||
|
//
|
||||||
|
checker_tests := get_tests_in_dir(checker_dir, false)
|
||||||
parser_tests := get_tests_in_dir(parser_dir, false)
|
parser_tests := get_tests_in_dir(parser_dir, false)
|
||||||
// -prod so that warns are errors
|
global_tests := get_tests_in_dir(global_dir, false)
|
||||||
|
module_tests := get_tests_in_dir(module_dir, true)
|
||||||
|
run_tests := get_tests_in_dir(run_dir, false)
|
||||||
|
// -prod is used for the parser and checker tests, so that warns are errors
|
||||||
mut tasks := []TaskDescription{}
|
mut tasks := []TaskDescription{}
|
||||||
tasks << new_tasks(vexe, classic_dir, '-prod', '.out', classic_tests, false)
|
tasks.add(vexe, parser_dir, '-prod', '.out', parser_tests, false)
|
||||||
tasks <<
|
tasks.add(vexe, checker_dir, '-prod', '.out', checker_tests, false)
|
||||||
new_tasks(vexe, global_dir, '--enable-globals', '.out', global_tests, false)
|
tasks.add(vexe, checker_dir, '-d mysymbol run', '.mysymbol.run.out', ['custom_comptime_define_error.vv'], false)
|
||||||
tasks <<
|
tasks.add(vexe, checker_dir, '-d mydebug run', '.mydebug.run.out', ['custom_comptime_define_if_flag.vv'], false)
|
||||||
new_tasks(vexe, classic_dir, '--enable-globals run', '.run.out', ['globals_error.vv'], false)
|
tasks.add(vexe, checker_dir, '-d nodebug run', '.nodebug.run.out', ['custom_comptime_define_if_flag.vv'], false)
|
||||||
tasks << new_tasks(vexe, module_dir, '-prod run', '.out', module_tests, true)
|
tasks.add(vexe, checker_dir, '--enable-globals run', '.run.out', ['globals_error.vv'], false)
|
||||||
tasks << new_tasks(vexe, run_dir, 'run', '.run.out', run_tests, false)
|
tasks.add(vexe, global_dir, '--enable-globals', '.out', global_tests, false)
|
||||||
tasks << new_tasks(vexe, parser_dir, '-prod', '.out', parser_tests, false)
|
tasks.add(vexe, module_dir, '-prod run', '.out', module_tests, true)
|
||||||
|
tasks.add(vexe, run_dir, 'run', '.run.out', run_tests, false)
|
||||||
tasks.run()
|
tasks.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_tasks(vexe string, dir string, voptions string, result_extension string, tests []string, is_module bool) []TaskDescription {
|
fn (mut tasks []TaskDescription) add(vexe string, dir string, voptions string, result_extension string, tests []string, is_module bool) {
|
||||||
paths := vtest.filter_vtest_only(tests, {
|
paths := vtest.filter_vtest_only(tests, {
|
||||||
basepath: dir
|
basepath: dir
|
||||||
})
|
})
|
||||||
mut res := []TaskDescription{}
|
|
||||||
for path in paths {
|
for path in paths {
|
||||||
res << TaskDescription{
|
tasks << TaskDescription{
|
||||||
vexe: vexe
|
vexe: vexe
|
||||||
dir: dir
|
dir: dir
|
||||||
voptions: voptions
|
voptions: voptions
|
||||||
|
@ -71,7 +73,11 @@ fn new_tasks(vexe string, dir string, voptions string, result_extension string,
|
||||||
is_module: is_module
|
is_module: is_module
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn bstep_message(mut bench benchmark.Benchmark, label string, msg string, sduration time.Duration) string {
|
||||||
|
return bench.step_message_with_label_and_duration(label, msg, sduration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// process an array of tasks in parallel, using no more than vjobs worker threads
|
// process an array of tasks in parallel, using no more than vjobs worker threads
|
||||||
|
@ -109,15 +115,13 @@ fn (mut tasks []TaskDescription) run() {
|
||||||
bench.step()
|
bench.step()
|
||||||
if task.is_skipped {
|
if task.is_skipped {
|
||||||
bench.skip()
|
bench.skip()
|
||||||
eprintln(bench.step_message_with_label_and_duration(benchmark.b_skip, task.path,
|
eprintln(bstep_message(mut bench, benchmark.b_skip, task.path, task.took))
|
||||||
task.took))
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if task.is_error {
|
if task.is_error {
|
||||||
total_errors++
|
total_errors++
|
||||||
bench.fail()
|
bench.fail()
|
||||||
eprintln(bench.step_message_with_label_and_duration(benchmark.b_fail, task.path,
|
eprintln(bstep_message(mut bench, benchmark.b_fail, task.path, task.took))
|
||||||
task.took))
|
|
||||||
println('============')
|
println('============')
|
||||||
println('expected:')
|
println('expected:')
|
||||||
println(task.expected)
|
println(task.expected)
|
||||||
|
@ -128,8 +132,7 @@ fn (mut tasks []TaskDescription) run() {
|
||||||
diff_content(task.expected, task.found___)
|
diff_content(task.expected, task.found___)
|
||||||
} else {
|
} else {
|
||||||
bench.ok()
|
bench.ok()
|
||||||
eprintln(bench.step_message_with_label_and_duration(benchmark.b_ok, task.path,
|
eprintln(bstep_message(mut bench, benchmark.b_ok, task.path, task.took))
|
||||||
task.took))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bench.stop()
|
bench.stop()
|
||||||
|
|
Loading…
Reference in New Issue