diff --git a/vlib/v/checker/tests/custom_comptime_define_if_debug.cg.run.out b/vlib/v/checker/tests/custom_comptime_define_if_debug.cg.run.out new file mode 100644 index 0000000000..b8cdbbaf4b --- /dev/null +++ b/vlib/v/checker/tests/custom_comptime_define_if_debug.cg.run.out @@ -0,0 +1,3 @@ +main with debug +foo, x: 123 +done diff --git a/vlib/v/checker/tests/custom_comptime_define_if_debug.debug.bar.run.out b/vlib/v/checker/tests/custom_comptime_define_if_debug.debug.bar.run.out new file mode 100644 index 0000000000..702459bc72 --- /dev/null +++ b/vlib/v/checker/tests/custom_comptime_define_if_debug.debug.bar.run.out @@ -0,0 +1,3 @@ +foo, x: 123 +bar, x: 456 +done diff --git a/vlib/v/checker/tests/custom_comptime_define_if_debug.debug.run.out b/vlib/v/checker/tests/custom_comptime_define_if_debug.debug.run.out new file mode 100644 index 0000000000..8cdd40138e --- /dev/null +++ b/vlib/v/checker/tests/custom_comptime_define_if_debug.debug.run.out @@ -0,0 +1,2 @@ +foo, x: 123 +done diff --git a/vlib/v/checker/tests/custom_comptime_define_if_debug.g.run.out b/vlib/v/checker/tests/custom_comptime_define_if_debug.g.run.out new file mode 100644 index 0000000000..b8cdbbaf4b --- /dev/null +++ b/vlib/v/checker/tests/custom_comptime_define_if_debug.g.run.out @@ -0,0 +1,3 @@ +main with debug +foo, x: 123 +done diff --git a/vlib/v/checker/tests/custom_comptime_define_if_debug.out b/vlib/v/checker/tests/custom_comptime_define_if_debug.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vlib/v/checker/tests/custom_comptime_define_if_debug.run.out b/vlib/v/checker/tests/custom_comptime_define_if_debug.run.out new file mode 100644 index 0000000000..19f86f493a --- /dev/null +++ b/vlib/v/checker/tests/custom_comptime_define_if_debug.run.out @@ -0,0 +1 @@ +done diff --git a/vlib/v/checker/tests/custom_comptime_define_if_debug.vv b/vlib/v/checker/tests/custom_comptime_define_if_debug.vv new file mode 100644 index 0000000000..87476ba3ed --- /dev/null +++ b/vlib/v/checker/tests/custom_comptime_define_if_debug.vv @@ -0,0 +1,18 @@ +[if debug] +fn foo(x int) { + println('foo, x: $x') +} + +[if bar] +fn bar(x int) { + println('bar, x: $x') +} + +fn main() { + $if debug { + println('main with debug') + } + foo(123) // will not be called if `-d debug` is not passed + bar(456) // will not be called if `-d bar` is not passed + println('done') +} diff --git a/vlib/v/compiler_errors_test.v b/vlib/v/compiler_errors_test.v index 071719085c..bfb8e56480 100644 --- a/vlib/v/compiler_errors_test.v +++ b/vlib/v/compiler_errors_test.v @@ -8,7 +8,7 @@ import runtime import benchmark const skip_files = [ - 'vlib/v/checker/tests/custom_comptime_define_if_flag.vv', + 'non_existing.vv' /* minimize commit diff churn, do not remove */, ] const skip_on_ubuntu_musl = [ @@ -74,12 +74,6 @@ fn test_all() { tasks.add('', parser_dir, '-prod', '.out', parser_tests, false) tasks.add('', checker_dir, '-prod', '.out', checker_tests, false) tasks.add('', scanner_dir, '-prod', '.out', scanner_tests, false) - tasks.add('', checker_dir, '-d mysymbol run', '.mysymbol.run.out', ['custom_comptime_define_error.vv'], - false) - tasks.add('', checker_dir, '-d mydebug run', '.mydebug.run.out', ['custom_comptime_define_if_flag.vv'], - false) - tasks.add('', checker_dir, '-d nodebug run', '.nodebug.run.out', ['custom_comptime_define_if_flag.vv'], - false) tasks.add('', checker_dir, '--enable-globals run', '.run.out', ['globals_error.vv'], false) tasks.add('', global_dir, '--enable-globals', '.out', global_tests, false) @@ -118,6 +112,25 @@ fn test_all() { '.var_invalid.run.out', ['using_comptime_env.vv'], false) cte_tasks.run() } + mut ct_tasks := Tasks{ + vexe: vexe + parallel_jobs: 1 + label: 'comptime define tests' + } + ct_tasks.add_checked_run('-d mysymbol run', '.mysymbol.run.out', ['custom_comptime_define_error.vv']) + ct_tasks.add_checked_run('-d mydebug run', '.mydebug.run.out', ['custom_comptime_define_if_flag.vv']) + ct_tasks.add_checked_run('-d nodebug run', '.nodebug.run.out', ['custom_comptime_define_if_flag.vv']) + ct_tasks.add_checked_run('run', '.run.out', ['custom_comptime_define_if_debug.vv']) + ct_tasks.add_checked_run('-g run', '.g.run.out', ['custom_comptime_define_if_debug.vv']) + ct_tasks.add_checked_run('-cg run', '.cg.run.out', ['custom_comptime_define_if_debug.vv']) + ct_tasks.add_checked_run('-d debug run', '.debug.run.out', ['custom_comptime_define_if_debug.vv']) + ct_tasks.add_checked_run('-d debug -d bar run', '.debug.bar.run.out', ['custom_comptime_define_if_debug.vv']) + ct_tasks.run() +} + +fn (mut tasks Tasks) add_checked_run(voptions string, result_extension string, tests []string) { + checker_dir := 'vlib/v/checker/tests' + tasks.add('', checker_dir, voptions, result_extension, tests, false) } fn (mut tasks Tasks) add(custom_vexe string, dir string, voptions string, result_extension string, tests []string, is_module bool) {