checker: bugfix for `__global ( cpu_get_id fn () u64 ) ... cpu_get_id()`
Support new vlib/v/checker/tests/globals_run/ folder, for .vv files that will be run with `-enable-globals run`, and the results will be compared with their matching `.run.out` files. Add regression tests.pull/10581/head
parent
6890756cd2
commit
19dca026a9
10
TESTS.md
10
TESTS.md
|
@ -80,8 +80,14 @@ Run `vlib` module tests, *including* the compiler tests.
|
||||||
## `v vlib/v/compiler_errors_test.v`
|
## `v vlib/v/compiler_errors_test.v`
|
||||||
|
|
||||||
This runs tests for:
|
This runs tests for:
|
||||||
* `checker/tests/*.vv`
|
* `vlib/v/checker/tests/*.vv`
|
||||||
* `parser/tests/*.vv`
|
* `vlib/v/parser/tests/*.vv`
|
||||||
|
|
||||||
|
### Special folders that compiler_errors_test.v will try to
|
||||||
|
run/compile with specific options:
|
||||||
|
|
||||||
|
vlib/v/checker/tests/globals_run/ - `-enable-globals run`;
|
||||||
|
results stored in `.run.out` files, matching the .vv ones.
|
||||||
|
|
||||||
## `v test-all`
|
## `v test-all`
|
||||||
|
|
||||||
|
|
|
@ -2413,6 +2413,7 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
|
||||||
sym := c.table.get_type_symbol(obj.typ)
|
sym := c.table.get_type_symbol(obj.typ)
|
||||||
if sym.kind == .function {
|
if sym.kind == .function {
|
||||||
found = true
|
found = true
|
||||||
|
func = (sym.info as ast.FnType).func
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:14] voidptr(main.abc) == voidptr(cpu_get_id): true
|
||||||
|
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:15] main.cpu_get_id(): 123
|
||||||
|
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:16] abc(): 123
|
||||||
|
[vlib/v/checker/tests/globals_run/function_stored_in_global.vv:17] abc() == main.cpu_get_id(): true
|
|
@ -0,0 +1,20 @@
|
||||||
|
__global (
|
||||||
|
cpu_get_id fn () u64
|
||||||
|
)
|
||||||
|
fn current() u64 {
|
||||||
|
return cpu_get_id()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn abc() u64 {
|
||||||
|
return 123
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
cpu_get_id = abc
|
||||||
|
dump(voidptr(abc) == voidptr(cpu_get_id))
|
||||||
|
dump(cpu_get_id())
|
||||||
|
dump(abc())
|
||||||
|
dump(abc() == cpu_get_id())
|
||||||
|
assert abc() == cpu_get_id()
|
||||||
|
assert voidptr(abc) == voidptr(cpu_get_id)
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
[vlib/v/checker/tests/globals_run/global_array_indexed_by_global_fn.vv:30] cpu_locals.map(it.x): [123, 456]
|
||||||
|
[vlib/v/checker/tests/globals_run/global_array_indexed_by_global_fn.vv:33] x.x: 123
|
||||||
|
[vlib/v/checker/tests/globals_run/global_array_indexed_by_global_fn.vv:36] y.x: 456
|
|
@ -0,0 +1,40 @@
|
||||||
|
struct Local {
|
||||||
|
x int
|
||||||
|
}
|
||||||
|
|
||||||
|
__global (
|
||||||
|
cpu_locals []&Local
|
||||||
|
)
|
||||||
|
|
||||||
|
__global (
|
||||||
|
cpu_get_id fn () u64
|
||||||
|
cpu_set_id fn (u64)
|
||||||
|
)
|
||||||
|
|
||||||
|
fn abc0() u64 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn abc1() u64 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current() &Local {
|
||||||
|
return cpu_locals[cpu_get_id()]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
cpu_locals = []&Local{}
|
||||||
|
cpu_locals << &Local{123}
|
||||||
|
cpu_locals << &Local{456}
|
||||||
|
dump(cpu_locals.map(it.x))
|
||||||
|
cpu_get_id = abc0
|
||||||
|
x := current()
|
||||||
|
dump(x.x)
|
||||||
|
cpu_get_id = abc1
|
||||||
|
y := current()
|
||||||
|
dump(y.x)
|
||||||
|
assert x != y
|
||||||
|
assert x.x == 123
|
||||||
|
assert y.x == 456
|
||||||
|
}
|
|
@ -57,6 +57,7 @@ fn test_all() {
|
||||||
scanner_dir := 'vlib/v/scanner/tests'
|
scanner_dir := 'vlib/v/scanner/tests'
|
||||||
module_dir := '$checker_dir/modules'
|
module_dir := '$checker_dir/modules'
|
||||||
global_dir := '$checker_dir/globals'
|
global_dir := '$checker_dir/globals'
|
||||||
|
global_run_dir := '$checker_dir/globals_run'
|
||||||
run_dir := '$checker_dir/run'
|
run_dir := '$checker_dir/run'
|
||||||
skip_unused_dir := 'vlib/v/tests/skip_unused'
|
skip_unused_dir := 'vlib/v/tests/skip_unused'
|
||||||
//
|
//
|
||||||
|
@ -64,6 +65,7 @@ fn test_all() {
|
||||||
parser_tests := get_tests_in_dir(parser_dir, false)
|
parser_tests := get_tests_in_dir(parser_dir, false)
|
||||||
scanner_tests := get_tests_in_dir(scanner_dir, false)
|
scanner_tests := get_tests_in_dir(scanner_dir, false)
|
||||||
global_tests := get_tests_in_dir(global_dir, false)
|
global_tests := get_tests_in_dir(global_dir, false)
|
||||||
|
global_run_tests := get_tests_in_dir(global_run_dir, false)
|
||||||
module_tests := get_tests_in_dir(module_dir, true)
|
module_tests := get_tests_in_dir(module_dir, true)
|
||||||
run_tests := get_tests_in_dir(run_dir, false)
|
run_tests := get_tests_in_dir(run_dir, false)
|
||||||
skip_unused_dir_tests := get_tests_in_dir(skip_unused_dir, false)
|
skip_unused_dir_tests := get_tests_in_dir(skip_unused_dir, false)
|
||||||
|
@ -77,6 +79,8 @@ fn test_all() {
|
||||||
tasks.add('', scanner_dir, '-prod', '.out', scanner_tests, false)
|
tasks.add('', scanner_dir, '-prod', '.out', scanner_tests, false)
|
||||||
tasks.add('', checker_dir, '-enable-globals run', '.run.out', ['globals_error.vv'],
|
tasks.add('', checker_dir, '-enable-globals run', '.run.out', ['globals_error.vv'],
|
||||||
false)
|
false)
|
||||||
|
tasks.add('', global_run_dir, '-enable-globals run', '.run.out', global_run_tests,
|
||||||
|
false)
|
||||||
tasks.add('', global_dir, '-enable-globals', '.out', global_tests, false)
|
tasks.add('', global_dir, '-enable-globals', '.out', global_tests, false)
|
||||||
tasks.add('', module_dir, '-prod run', '.out', module_tests, true)
|
tasks.add('', module_dir, '-prod run', '.out', module_tests, true)
|
||||||
tasks.add('', run_dir, 'run', '.run.out', run_tests, false)
|
tasks.add('', run_dir, 'run', '.run.out', run_tests, false)
|
||||||
|
|
Loading…
Reference in New Issue