fix tests for tcc, extract failing stuff to separate simpler files to ease debugging

* Fix compiling vlib/compiler/tests/fn_test.v with tcc.

* Extract failing tests from fn_test.v so that they are more readable and easier to debug.
pull/2733/head
Delyan Angelov 2019-11-11 16:59:59 +02:00 committed by Alexander Medvednikov
parent e6775913aa
commit de5b4f0497
4 changed files with 47 additions and 35 deletions

View File

@ -57,8 +57,10 @@ CommonCHeaders = '
#define TCCSKIP(x) x
#ifdef __TINYC__
#undef EMPTY_STRUCT_DECLARATION
#undef EMPTY_STRUCT_INITIALIZATION
#define EMPTY_STRUCT_INITIALIZATION
#define EMPTY_STRUCT_DECLARATION char _dummy
#define EMPTY_STRUCT_INITIALIZATION 0
#undef EMPTY_ARRAY_OF_ELEMS
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[n])
#undef TCCSKIP

View File

@ -0,0 +1,23 @@
struct Foo {
}
fn (f Foo) str() string { return 'Foo{}' }
fn process_foo(foo &Foo) {
println('>process_foo, called for ${foo} === ${*foo}')
}
fn get_foo() Foo {
println('>get_foo')
return Foo{}
}
/*
// TODO: Fix this. It 'works' only with tcc, but is not stable.
fn test_ref_fn_arg() {
process_foo(get_foo())
println(3434)
assert true
}
*/
fn test_dummy(){}

View File

@ -0,0 +1,21 @@
/*
// TODO: Fix this.
import time
// using a manual temporary intermediate variable should always work:
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_manual(){
t1 := time.random()
t2 := t1.calc_unix()
println('tmp: $t2')
assert true
}
// v should produce temporary intermediate variables in chained calls:
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_chained(){
res := (time.random().calc_unix())
println('res: $res')
assert true
}
*/
fn test_dummy(){}

View File

@ -21,8 +21,6 @@ multi line comment (3)
multi line comment (2)
*/
import time
type myfn fn (int) string
type myfn2 fn (a int, b int) int
@ -120,35 +118,3 @@ fn high_fn_multi_return(a int, b fn (c []int, d []string) ([]int, []string)) {
fn test_fns() {
// no asserts for now, just test function declarations above
}
struct Foo {
}
fn process_foo(foo &Foo) {
}
fn get_foo() Foo {
return Foo{}
}
// This used to be broken.
fn test_ref_fn_arg() {
// TODO tcc bug
/*
$if !tinyc {
process_foo(get_foo())
println(3434)
assert true
}
*/
/*
res := (time.random().calc_unix())
println(res)
assert true
*/
}