From de5b4f0497e79b0089ac3506cdbbb81fa158b0c4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 11 Nov 2019 16:59:59 +0200 Subject: [PATCH] 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. --- vlib/compiler/cheaders.v | 4 ++- ..._expecting_ref_but_returning_struct_test.v | 23 +++++++++++++ ...ef_but_returning_struct_time_module_test.v | 21 ++++++++++++ vlib/compiler/tests/fn_test.v | 34 ------------------- 4 files changed, 47 insertions(+), 35 deletions(-) create mode 100644 vlib/compiler/tests/fn_expecting_ref_but_returning_struct_test.v create mode 100644 vlib/compiler/tests/fn_expecting_ref_but_returning_struct_time_module_test.v diff --git a/vlib/compiler/cheaders.v b/vlib/compiler/cheaders.v index 8172c77dd6..e6920c7a0c 100644 --- a/vlib/compiler/cheaders.v +++ b/vlib/compiler/cheaders.v @@ -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 diff --git a/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_test.v b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_test.v new file mode 100644 index 0000000000..9e8d4727d3 --- /dev/null +++ b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_test.v @@ -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(){} diff --git a/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_time_module_test.v b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_time_module_test.v new file mode 100644 index 0000000000..e86957456a --- /dev/null +++ b/vlib/compiler/tests/fn_expecting_ref_but_returning_struct_time_module_test.v @@ -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(){} diff --git a/vlib/compiler/tests/fn_test.v b/vlib/compiler/tests/fn_test.v index d225303fcc..d19b57d528 100644 --- a/vlib/compiler/tests/fn_test.v +++ b/vlib/compiler/tests/fn_test.v @@ -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 - */ - -} -