aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorgrischka <grischka>2017-07-20 22:21:27 +0200
committergrischka <grischka>2017-07-20 22:21:27 +0200
commit0cc24d0e8487eaf53bb2849fef7e438a8e8fc94d (patch)
treeba77f5e03cb8944f995b103abb668e37a9dceef2 /tests
parentba2b25e4ead7f0037d548289e517b31d29242880 (diff)
downloadtinycc-0cc24d0e8487eaf53bb2849fef7e438a8e8fc94d.tar.gz
tinycc-0cc24d0e8487eaf53bb2849fef7e438a8e8fc94d.tar.bz2
tcc -dt -run ... : simpler is better
* -dt now with lowercase t * test snippets now separated by real preprocessor statements which is valid C also for other compilers #if defined test_xxx < test snippet x > #elif defined test_yyy < test snippet y > #elif ... #endif * simpler implementation, behaves like -run if no 'test_...' macros are seen, works with -E too * for demonstration I combined some of the small tests for errors and warnings (56..63,74) in "60_errors_and_warnings.c" Also: * libtcc.c: put tcc_preprocess() and tcc_assemble() under the setjmp clause to let them return to caller after errors. This is for -dt -E. * tccgen.c: - get rid of save/restore_parse_state(), macro_ptr is saved by begin_macro anyway, now line_num too. - use expr_eq for parsing _Generic's controlling_type - set nocode_wanted with const_wanted. too, This is to keep VT_JMP on vtop when parsing preprocessor expressions. * tccpp.c: tcc -E: suppress trailing whitespace from lines with comments (that -E removes) such as NO_GOTPLT_ENTRY,\t /* never generate ... */
Diffstat (limited to 'tests')
-rw-r--r--tests/tests2/56_btype_excess-1.c1
-rw-r--r--tests/tests2/56_btype_excess-1.expect1
-rw-r--r--tests/tests2/57_btype_excess-2.c1
-rw-r--r--tests/tests2/57_btype_excess-2.expect1
-rw-r--r--tests/tests2/58_function_redefinition.c9
-rw-r--r--tests/tests2/58_function_redefinition.expect1
-rw-r--r--tests/tests2/59_function_array.c1
-rw-r--r--tests/tests2/59_function_array.expect1
-rw-r--r--tests/tests2/60_enum_redefinition.c4
-rw-r--r--tests/tests2/60_enum_redefinition.expect1
-rw-r--r--tests/tests2/60_errors_and_warnings.c51
-rw-r--r--tests/tests2/60_errors_and_warnings.expect28
-rw-r--r--tests/tests2/61_undefined_enum.c1
-rw-r--r--tests/tests2/61_undefined_enum.expect1
-rw-r--r--tests/tests2/62_enumerator_redefinition.c4
-rw-r--r--tests/tests2/62_enumerator_redefinition.expect1
-rw-r--r--tests/tests2/63_local_enumerator_redefinition.c14
-rw-r--r--tests/tests2/63_local_enumerator_redefinition.expect0
-rw-r--r--tests/tests2/74_nocode_wanted.c1
-rw-r--r--tests/tests2/74_nocode_wanted.expect1
-rw-r--r--tests/tests2/96_nodata_wanted.c46
-rw-r--r--tests/tests2/96_nodata_wanted.expect26
-rw-r--r--tests/tests2/Makefile11
23 files changed, 120 insertions, 86 deletions
diff --git a/tests/tests2/56_btype_excess-1.c b/tests/tests2/56_btype_excess-1.c
deleted file mode 100644
index 06eabe7..0000000
--- a/tests/tests2/56_btype_excess-1.c
+++ /dev/null
@@ -1 +0,0 @@
-struct A {} int i;
diff --git a/tests/tests2/56_btype_excess-1.expect b/tests/tests2/56_btype_excess-1.expect
deleted file mode 100644
index 4e6d2d7..0000000
--- a/tests/tests2/56_btype_excess-1.expect
+++ /dev/null
@@ -1 +0,0 @@
-56_btype_excess-1.c:1: error: too many basic types
diff --git a/tests/tests2/57_btype_excess-2.c b/tests/tests2/57_btype_excess-2.c
deleted file mode 100644
index ab95c3e..0000000
--- a/tests/tests2/57_btype_excess-2.c
+++ /dev/null
@@ -1 +0,0 @@
-char int i;
diff --git a/tests/tests2/57_btype_excess-2.expect b/tests/tests2/57_btype_excess-2.expect
deleted file mode 100644
index c12ef81..0000000
--- a/tests/tests2/57_btype_excess-2.expect
+++ /dev/null
@@ -1 +0,0 @@
-57_btype_excess-2.c:1: error: too many basic types
diff --git a/tests/tests2/58_function_redefinition.c b/tests/tests2/58_function_redefinition.c
deleted file mode 100644
index 33f16ee..0000000
--- a/tests/tests2/58_function_redefinition.c
+++ /dev/null
@@ -1,9 +0,0 @@
-int f(void)
-{
- return 0;
-}
-
-int f(void)
-{
- return 1;
-}
diff --git a/tests/tests2/58_function_redefinition.expect b/tests/tests2/58_function_redefinition.expect
deleted file mode 100644
index a95a3f0..0000000
--- a/tests/tests2/58_function_redefinition.expect
+++ /dev/null
@@ -1 +0,0 @@
-58_function_redefinition.c:7: error: redefinition of 'f'
diff --git a/tests/tests2/59_function_array.c b/tests/tests2/59_function_array.c
deleted file mode 100644
index 9fcc12d..0000000
--- a/tests/tests2/59_function_array.c
+++ /dev/null
@@ -1 +0,0 @@
-int (*fct)[42](int x);
diff --git a/tests/tests2/59_function_array.expect b/tests/tests2/59_function_array.expect
deleted file mode 100644
index bf62c6e..0000000
--- a/tests/tests2/59_function_array.expect
+++ /dev/null
@@ -1 +0,0 @@
-59_function_array.c:1: error: declaration of an array of functions
diff --git a/tests/tests2/60_enum_redefinition.c b/tests/tests2/60_enum_redefinition.c
deleted file mode 100644
index 2601560..0000000
--- a/tests/tests2/60_enum_redefinition.c
+++ /dev/null
@@ -1,4 +0,0 @@
-enum color {RED, GREEN, BLUE};
-enum color {R, G, B};
-
-enum color c;
diff --git a/tests/tests2/60_enum_redefinition.expect b/tests/tests2/60_enum_redefinition.expect
deleted file mode 100644
index 5cb41bc..0000000
--- a/tests/tests2/60_enum_redefinition.expect
+++ /dev/null
@@ -1 +0,0 @@
-60_enum_redefinition.c:2: error: struct/union/enum already defined
diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c
new file mode 100644
index 0000000..0028caf
--- /dev/null
+++ b/tests/tests2/60_errors_and_warnings.c
@@ -0,0 +1,51 @@
+#if defined test_56_btype_excess_1
+struct A {} int i;
+
+#elif defined test_57_btype_excess_2
+char int i;
+
+#elif defined test_58_function_redefinition
+int f(void) { return 0; }
+int f(void) { return 1; }
+
+#elif defined test_global_redefinition
+int xxx = 1;
+int xxx;
+int xxx = 2;
+
+#elif defined test_59_function_array
+int (*fct)[42](int x);
+
+#elif defined test_60_enum_redefinition
+enum color { RED, GREEN, BLUE };
+enum color { R, G, B };
+enum color c;
+
+#elif defined test_62_enumerator_redefinition
+enum color { RED, GREEN, BLUE };
+enum rgb { RED, G, B};
+enum color c = RED;
+
+#elif defined test_63_local_enumerator_redefinition
+enum {
+ FOO,
+ BAR
+};
+
+int main(void)
+{
+ enum {
+ FOO = 2,
+ BAR
+ };
+
+ return BAR - FOO;
+}
+
+#elif defined test_61_undefined_enum
+enum rgb3 c = 42;
+
+#elif defined test_74_non_const_init
+int i = i++;
+
+#endif
diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect
new file mode 100644
index 0000000..ed6a690
--- /dev/null
+++ b/tests/tests2/60_errors_and_warnings.expect
@@ -0,0 +1,28 @@
+[test_56_btype_excess_1]
+60_errors_and_warnings.c:2: error: too many basic types
+
+[test_57_btype_excess_2]
+60_errors_and_warnings.c:5: error: too many basic types
+
+[test_58_function_redefinition]
+60_errors_and_warnings.c:9: error: redefinition of 'f'
+
+[test_global_redefinition]
+60_errors_and_warnings.c:14: error: redefinition of 'xxx'
+
+[test_59_function_array]
+60_errors_and_warnings.c:17: error: declaration of an array of functions
+
+[test_60_enum_redefinition]
+60_errors_and_warnings.c:21: error: struct/union/enum already defined
+
+[test_62_enumerator_redefinition]
+60_errors_and_warnings.c:26: error: redefinition of enumerator 'RED'
+
+[test_63_local_enumerator_redefinition]
+
+[test_61_undefined_enum]
+60_errors_and_warnings.c:46: error: unknown type size
+
+[test_74_non_const_init]
+60_errors_and_warnings.c:49: error: initializer element is not constant
diff --git a/tests/tests2/61_undefined_enum.c b/tests/tests2/61_undefined_enum.c
deleted file mode 100644
index bc7c6ea..0000000
--- a/tests/tests2/61_undefined_enum.c
+++ /dev/null
@@ -1 +0,0 @@
-enum rgb c = 42;
diff --git a/tests/tests2/61_undefined_enum.expect b/tests/tests2/61_undefined_enum.expect
deleted file mode 100644
index eb8b774..0000000
--- a/tests/tests2/61_undefined_enum.expect
+++ /dev/null
@@ -1 +0,0 @@
-61_undefined_enum.c:1: error: unknown type size
diff --git a/tests/tests2/62_enumerator_redefinition.c b/tests/tests2/62_enumerator_redefinition.c
deleted file mode 100644
index 3da85ae..0000000
--- a/tests/tests2/62_enumerator_redefinition.c
+++ /dev/null
@@ -1,4 +0,0 @@
-enum color {RED, GREEN, BLUE};
-enum rgb {RED, G, B};
-
-enum color c = RED;
diff --git a/tests/tests2/62_enumerator_redefinition.expect b/tests/tests2/62_enumerator_redefinition.expect
deleted file mode 100644
index 3d0e879..0000000
--- a/tests/tests2/62_enumerator_redefinition.expect
+++ /dev/null
@@ -1 +0,0 @@
-62_enumerator_redefinition.c:2: error: redefinition of enumerator 'RED'
diff --git a/tests/tests2/63_local_enumerator_redefinition.c b/tests/tests2/63_local_enumerator_redefinition.c
deleted file mode 100644
index dd4d8e0..0000000
--- a/tests/tests2/63_local_enumerator_redefinition.c
+++ /dev/null
@@ -1,14 +0,0 @@
-enum {
- FOO,
- BAR
-};
-
-int main(void)
-{
- enum {
- FOO = 2,
- BAR
- };
-
- return BAR - FOO;
-}
diff --git a/tests/tests2/63_local_enumerator_redefinition.expect b/tests/tests2/63_local_enumerator_redefinition.expect
deleted file mode 100644
index e69de29..0000000
--- a/tests/tests2/63_local_enumerator_redefinition.expect
+++ /dev/null
diff --git a/tests/tests2/74_nocode_wanted.c b/tests/tests2/74_nocode_wanted.c
deleted file mode 100644
index e824d02..0000000
--- a/tests/tests2/74_nocode_wanted.c
+++ /dev/null
@@ -1 +0,0 @@
-int i = i++;
diff --git a/tests/tests2/74_nocode_wanted.expect b/tests/tests2/74_nocode_wanted.expect
deleted file mode 100644
index f060ef4..0000000
--- a/tests/tests2/74_nocode_wanted.expect
+++ /dev/null
@@ -1 +0,0 @@
-74_nocode_wanted.c:1: error: initializer element is not constant
diff --git a/tests/tests2/96_nodata_wanted.c b/tests/tests2/96_nodata_wanted.c
index 6f7f3c2..1f022c9 100644
--- a/tests/tests2/96_nodata_wanted.c
+++ b/tests/tests2/96_nodata_wanted.c
@@ -1,36 +1,35 @@
/*****************************************************************************/
/* test 'nodata_wanted' data output suppression */
-/*-* test 1: initializer not computable 1 */
+#if defined test_static_data_error
void foo() {
if (1) {
- static short w = (int)&foo; /* error */
+ static short w = (int)&foo; /* initializer not computable */
}
}
-/*-* test 2: initializer not computable 2 */
+#elif defined test_static_nodata_error
void foo() {
if (0) {
- static short w = (int)&foo; /* error */
+ static short w = (int)&foo; /* initializer not computable */
}
}
-/*-* test 3: initializer not computable 3 */
+#elif defined test_global_data_error
void foo();
-static short w = (int)&foo; /* error */
+static short w = (int)&foo; /* initializer not computable */
-/*-* test 4: 2 cast warnings */
+#elif defined test_local_data_noerror
void foo() {
- short w = &foo; /* no error */
+ short w = &foo; /* 2 cast warnings */
}
-/*-* test 5; nodata_wanted test */
+#elif defined test_data_suppression
#include <stdio.h>
-#define DATA_LBL(s) \
- __asm__(".global d"#s",t"#s"\n.data\nd"#s":\n.text\nt"#s":\n"); \
- extern char d##s[],t##s[];
+#define ASMLABELS(s) \
+ __asm__(".global d"#s",t"#s"\n.data\nd"#s":\n.text\nt"#s":\n")
#define PROG \
static void *p = (void*)&main;\
@@ -47,28 +46,29 @@ void foo() {
int main()
{
+ extern char ds1[],ts1[];
+ extern char ds2[],ts2[];
+ extern char de1[],te1[];
+ extern char de2[],te2[];
+
printf("suppression off\n");
- DATA_LBL(s1);
if (1) {
+ ASMLABELS(s1);
PROG
+ ASMLABELS(e1);
}
- DATA_LBL(e1);
printf(" data length is %s\n", de1 - ds1 ? "not 0":"0");
- //printf(" text length is %s\n", te1 - ts1 ? "not 0":"0");
+ printf(" text length is %s\n", te1 - ts1 ? "not 0":"0");
printf("suppression on\n");
- DATA_LBL(s2);
if (0) {
+ ASMLABELS(s2);
PROG
+ ASMLABELS(e2);
}
- DATA_LBL(e2);
printf(" data length is %x\n", de2 - ds2);
- //printf(" text length is %X\n", te2 - ts2);
+ printf(" text length is %X\n", te2 - ts2);
return 0;
}
-/*-* test 6: some test */
-int main()
-{
- return 34;
-}
+#endif
diff --git a/tests/tests2/96_nodata_wanted.expect b/tests/tests2/96_nodata_wanted.expect
index 0db4ba2..9fd35ca 100644
--- a/tests/tests2/96_nodata_wanted.expect
+++ b/tests/tests2/96_nodata_wanted.expect
@@ -1,24 +1,22 @@
-/*-* test 1: initializer not computable 1 */
-test 1:3: error: initializer element is not computable at load time
+[test_static_data_error]
+96_nodata_wanted.c:7: error: initializer element is not computable at load time
-/*-* test 2: initializer not computable 2 */
-test 2:3: error: initializer element is not computable at load time
+[test_static_nodata_error]
+96_nodata_wanted.c:14: error: initializer element is not computable at load time
-/*-* test 3: initializer not computable 3 */
-test 3:2: error: initializer element is not computable at load time
+[test_global_data_error]
+96_nodata_wanted.c:20: error: initializer element is not computable at load time
-/*-* test 4: 2 cast warnings */
-test 4:2: warning: assignment makes integer from pointer without a cast
-test 4:2: warning: nonportable conversion from pointer to char/short
+[test_local_data_noerror]
+96_nodata_wanted.c:25: warning: assignment makes integer from pointer without a cast
+96_nodata_wanted.c:25: warning: nonportable conversion from pointer to char/short
-/*-* test 5; nodata_wanted test */
+[test_data_suppression]
suppression off
static data: 8 - 8.0 - 8.0 - main - static string
static bitfields: 333 44 555555 6 7
data length is not 0
+ text length is not 0
suppression on
data length is 0
-returns 0
-
-/*-* test 6: some test */
-returns 34
+ text length is 0
diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile
index 832aa49..4dd1591 100644
--- a/tests/tests2/Makefile
+++ b/tests/tests2/Makefile
@@ -20,7 +20,7 @@ endif
ifeq (,$(filter i386 x86_64,$(ARCH)))
SKIP += 85_asm-outside-function.test
endif
-ifeq (-$(findstring gcc,$(CC)-)-,--)
+ifeq (-$(findstring gcc,$(CC))-,--)
SKIP += $(patsubst %.expect,%.test,$(GEN-ALWAYS))
endif
ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-)
@@ -40,8 +40,9 @@ NORUN =
FLAGS =
76_dollars_in_identifiers.test : FLAGS += -fdollars-in-identifiers
-# run the source file cut into snippets
-96_nodata_wanted.test : FLAGS = -dT
+# These tests run several snippets from the same file one by one
+60_errors_and_warnings.test : FLAGS += -dt
+96_nodata_wanted.test : FLAGS += -dt
# Always generate certain .expects (don't put these in the GIT),
GEN-ALWAYS =
@@ -90,8 +91,8 @@ F2 = $1 UPDATE="$(patsubst %.test,%.expect,$1)"
@$(call GEN,$(SRC)/$*.c) $(FILTER) >$@ 2>&1
@rm -f *.exe *.obj *.pdb
-# using TCC for .expect if -dT in FLAGS
-GEN = $(if $(findstring -dT,$(FLAGS)),$(GEN-TCC),$(GEN-CC))
+# using TCC for .expect if -dt in FLAGS
+GEN = $(if $(filter -dt,$(FLAGS)),$(GEN-TCC),$(GEN-CC))
GEN-CC = $(CC) -w -std=gnu99 $(FLAGS) $1 -o a.exe && ./a.exe $(ARGS)
GEN-TCC = $(TCC) $(FLAGS) -run $1 $(ARGS)
GEN-MSC = $(MS-CC) $1 && ./$(basename $@).exe