diff options
| author | jiang <30155751@qq.com> | 2014-04-29 16:05:16 +0800 |
|---|---|---|
| committer | jiang <30155751@qq.com> | 2014-04-29 16:05:16 +0800 |
| commit | 2a8905c93b4f67a21e3dbf297c3e93c598831528 (patch) | |
| tree | 6f7491150cfe01700c9863946906203adad0de13 /tests/tests2 | |
| parent | 02e2fe3c260415f4cb1cbcaca9b2403a17f7ff2e (diff) | |
| parent | e20c1eb99e1003c1e59522c136dbb15c52d7cc7c (diff) | |
| download | tinycc-2a8905c93b4f67a21e3dbf297c3e93c598831528.tar.gz tinycc-2a8905c93b4f67a21e3dbf297c3e93c598831528.tar.bz2 | |
So that the generated code, and more short
Diffstat (limited to 'tests/tests2')
31 files changed, 135 insertions, 39 deletions
diff --git a/tests/tests2/03_struct.c b/tests/tests2/03_struct.c index df0d3e7..c5d48c5 100644 --- a/tests/tests2/03_struct.c +++ b/tests/tests2/03_struct.c @@ -6,7 +6,7 @@ struct fred int natasha; }; -void main() +int main() { struct fred bloggs; diff --git a/tests/tests2/30_hanoi.c b/tests/tests2/30_hanoi.c index b1a1181..7c0893b 100644 --- a/tests/tests2/30_hanoi.c +++ b/tests/tests2/30_hanoi.c @@ -68,7 +68,7 @@ void PrintAll() /* Returns the value moved (not used.) */ int Move(int *source, int *dest) { - int i,j; + int i = 0, j = 0; while (i<N && (source[i])==0) i++; while (j<N && (dest[j])==0) j++; diff --git a/tests/tests2/31_args.c b/tests/tests2/31_args.c index 275f8cf..dcafed5 100644 --- a/tests/tests2/31_args.c +++ b/tests/tests2/31_args.c @@ -5,7 +5,7 @@ int main(int argc, char **argv) int Count; printf("hello world %d\n", argc); - for (Count = 0; Count < argc; Count++) + for (Count = 1; Count < argc; Count++) printf("arg %d: %s\n", Count, argv[Count]); return 0; diff --git a/tests/tests2/31_args.expect b/tests/tests2/31_args.expect index c392b67..8c60bfc 100644 --- a/tests/tests2/31_args.expect +++ b/tests/tests2/31_args.expect @@ -1,7 +1,6 @@ hello world 6 -arg 0: 31_args.c -arg 1: - -arg 2: arg1 -arg 3: arg2 -arg 4: arg3 -arg 5: arg4 +arg 1: arg1 +arg 2: arg2 +arg 3: arg3 +arg 4: arg4 +arg 5: arg5 diff --git a/tests/tests2/46_grep.c b/tests/tests2/46_grep.c index 5f52220..3123bc3 100644 --- a/tests/tests2/46_grep.c +++ b/tests/tests2/46_grep.c @@ -15,6 +15,7 @@ * privileges were granted by DECUS. */ #include <stdio.h> +#include <stdlib.h> /* * grep @@ -25,14 +26,13 @@ * See below for more information. */ -#if 0 char *documentation[] = { "grep searches a file for a given pattern. Execute by", " grep [flags] regular_expression file_list\n", - "Flags are single characters preceeded by '-':", + "Flags are single characters preceded by '-':", " -c Only a count of matching lines is printed", " -f Print file name for matching lines switch, see below", - " -n Each line is preceeded by its line number", + " -n Each line is preceded by its line number", " -v Only print non-matching lines\n", "The file_list is a list of files (wildcards are acceptable on RSX modes).", "\nThe file name is normally printed if there is a file given.", @@ -54,10 +54,10 @@ char *patdoc[] = { "':n' \":n\" matches alphanumerics, \": \" matches spaces, tabs, and", "': ' other control characters, such as new-line.", "'*' An expression followed by an asterisk matches zero or more", - " occurrances of that expression: \"fo*\" matches \"f\", \"fo\"", + " occurrences of that expression: \"fo*\" matches \"f\", \"fo\"", " \"foo\", etc.", "'+' An expression followed by a plus sign matches one or more", - " occurrances of that expression: \"fo+\" matches \"fo\", etc.", + " occurrences of that expression: \"fo+\" matches \"fo\", etc.", "'-' An expression followed by a minus sign optionally matches", " the expression.", "'[]' A string enclosed in square brackets matches any character in", @@ -70,7 +70,6 @@ char *patdoc[] = { " [a-z] matches alphabetics, while [z-a] never matches.", "The concatenation of regular expressions is a regular expression.", 0}; -#endif #define LMAX 512 #define PMAX 256 @@ -97,6 +96,10 @@ char *pp, lbuf[LMAX], pbuf[PMAX]; char *cclass(); char *pmatch(); +void store(int); +void error(char *); +void badpat(char *, char *, char *); +int match(void); /*** Display a file name *******************************/ @@ -153,7 +156,7 @@ void compile(char *source) o == STAR || o == PLUS || o == MINUS) - badpat("Illegal occurrance op.", source, s); + badpat("Illegal occurrence op.", source, s); store(ENDPAT); store(ENDPAT); spp = pp; /* Save pattern end */ @@ -300,7 +303,7 @@ void badpat(char *message, char *source, char *stop) /* char *stop; // Pattern end */ { fprintf(stderr, "-GREP-E-%s, pattern is\"%s\"\n", message, source); - fprintf(stderr, "-GREP-E-Stopped at byte %d, '%c'\n", + fprintf(stderr, "-GREP-E-Stopped at byte %ld, '%c'\n", stop-source, stop[-1]); error("?GREP-E-Bad pattern\n"); } @@ -338,7 +341,7 @@ void grep(FILE *fp, char *fn) } /*** Match line (lbuf) with pattern (pbuf) return 1 if match ***/ -void match() +int match() { char *l; /* Line pointer */ @@ -368,7 +371,7 @@ char *pmatch(char *line, char *pattern) p = pattern; while ((op = *p++) != ENDPAT) { if (debug > 1) - printf("byte[%d] = 0%o, '%c', op = 0%o\n", + printf("byte[%ld] = 0%o, '%c', op = 0%o\n", l-line, *l, *l, op); switch(op) { diff --git a/tests/tests2/46_grep.expect b/tests/tests2/46_grep.expect new file mode 100644 index 0000000..e8a6791 --- /dev/null +++ b/tests/tests2/46_grep.expect @@ -0,0 +1,3 @@ +File 46_grep.c: +/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ + diff --git a/tests/tests2/56_btype_excess-1.c b/tests/tests2/56_btype_excess-1.c new file mode 100644 index 0000000..06eabe7 --- /dev/null +++ b/tests/tests2/56_btype_excess-1.c @@ -0,0 +1 @@ +struct A {} int i; diff --git a/tests/tests2/56_btype_excess-1.expect b/tests/tests2/56_btype_excess-1.expect new file mode 100644 index 0000000..4e6d2d7 --- /dev/null +++ b/tests/tests2/56_btype_excess-1.expect @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..ab95c3e --- /dev/null +++ b/tests/tests2/57_btype_excess-2.c @@ -0,0 +1 @@ +char int i; diff --git a/tests/tests2/57_btype_excess-2.expect b/tests/tests2/57_btype_excess-2.expect new file mode 100644 index 0000000..c12ef81 --- /dev/null +++ b/tests/tests2/57_btype_excess-2.expect @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..33f16ee --- /dev/null +++ b/tests/tests2/58_function_redefinition.c @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000..a95a3f0 --- /dev/null +++ b/tests/tests2/58_function_redefinition.expect @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..9fcc12d --- /dev/null +++ b/tests/tests2/59_function_array.c @@ -0,0 +1 @@ +int (*fct)[42](int x); diff --git a/tests/tests2/59_function_array.expect b/tests/tests2/59_function_array.expect new file mode 100644 index 0000000..bf62c6e --- /dev/null +++ b/tests/tests2/59_function_array.expect @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..2601560 --- /dev/null +++ b/tests/tests2/60_enum_redefinition.c @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000..5cb41bc --- /dev/null +++ b/tests/tests2/60_enum_redefinition.expect @@ -0,0 +1 @@ +60_enum_redefinition.c:2: error: struct/union/enum already defined diff --git a/tests/tests2/61_undefined_enum.c b/tests/tests2/61_undefined_enum.c new file mode 100644 index 0000000..bc7c6ea --- /dev/null +++ b/tests/tests2/61_undefined_enum.c @@ -0,0 +1 @@ +enum rgb c = 42; diff --git a/tests/tests2/61_undefined_enum.expect b/tests/tests2/61_undefined_enum.expect new file mode 100644 index 0000000..7ccdeca --- /dev/null +++ b/tests/tests2/61_undefined_enum.expect @@ -0,0 +1 @@ +61_undefined_enum.c:1: error: unknown struct/union/enum diff --git a/tests/tests2/62_enumerator_redefinition.c b/tests/tests2/62_enumerator_redefinition.c new file mode 100644 index 0000000..3da85ae --- /dev/null +++ b/tests/tests2/62_enumerator_redefinition.c @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000..3d0e879 --- /dev/null +++ b/tests/tests2/62_enumerator_redefinition.expect @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000..dd4d8e0 --- /dev/null +++ b/tests/tests2/63_local_enumerator_redefinition.c @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/tests2/63_local_enumerator_redefinition.expect diff --git a/tests/tests2/64_macro_nesting.c b/tests/tests2/64_macro_nesting.c new file mode 100644 index 0000000..44b582f --- /dev/null +++ b/tests/tests2/64_macro_nesting.c @@ -0,0 +1,10 @@ +#define CAT2(a,b) a##b +#define CAT(a,b) CAT2(a,b) +#define AB(x) CAT(x,y) + +int main(void) +{ + int xy = 42; + printf("%d\n", CAT(A,B)(x)); + return 0; +} diff --git a/tests/tests2/64_macro_nesting.expect b/tests/tests2/64_macro_nesting.expect new file mode 100644 index 0000000..d81cc07 --- /dev/null +++ b/tests/tests2/64_macro_nesting.expect @@ -0,0 +1 @@ +42 diff --git a/tests/tests2/65_macro_concat_start.c b/tests/tests2/65_macro_concat_start.c new file mode 100644 index 0000000..d63d67a --- /dev/null +++ b/tests/tests2/65_macro_concat_start.c @@ -0,0 +1,2 @@ +#define paste(A,B) ##A B +paste(x,y) diff --git a/tests/tests2/65_macro_concat_start.expect b/tests/tests2/65_macro_concat_start.expect new file mode 100644 index 0000000..88ed6c5 --- /dev/null +++ b/tests/tests2/65_macro_concat_start.expect @@ -0,0 +1 @@ +65_macro_concat_start.c:1: error: '##' invalid at start of macro diff --git a/tests/tests2/66_macro_concat_end.c b/tests/tests2/66_macro_concat_end.c new file mode 100644 index 0000000..55dcaef --- /dev/null +++ b/tests/tests2/66_macro_concat_end.c @@ -0,0 +1,2 @@ +#define paste(A,B) A B## +paste(x,y) diff --git a/tests/tests2/66_macro_concat_end.expect b/tests/tests2/66_macro_concat_end.expect new file mode 100644 index 0000000..224e5c9 --- /dev/null +++ b/tests/tests2/66_macro_concat_end.expect @@ -0,0 +1 @@ +66_macro_concat_end.c:2: error: '##' invalid at end of macro diff --git a/tests/tests2/67_macro_concat.c b/tests/tests2/67_macro_concat.c new file mode 100644 index 0000000..c580d3a --- /dev/null +++ b/tests/tests2/67_macro_concat.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +#define P(A,B) A ## B ; bob +#define Q(A,B) A ## B+ + +int main(void) +{ + int bob, jim = 21; + bob = P(jim,) *= 2; + printf("jim: %d, bob: %d\n", jim, bob); + jim = 60 Q(+,)3; + printf("jim: %d\n", jim); + return 0; +} diff --git a/tests/tests2/67_macro_concat.expect b/tests/tests2/67_macro_concat.expect new file mode 100644 index 0000000..8386c2d --- /dev/null +++ b/tests/tests2/67_macro_concat.expect @@ -0,0 +1,2 @@ +jim: 21, bob: 42 +jim: 63 diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index 369ed47..c47fe0a 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -1,10 +1,10 @@ TOP = ../.. include $(TOP)/Makefile -VPATH = $(top_srcdir)/tests/tests2 -TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include ifdef CONFIG_WIN32 TCCFLAGS = -B$(top_srcdir)/win32 -I$(top_srcdir)/include -L$(TOP) +else + TCCFLAGS = -B$(TOP) -I$(top_srcdir)/include -lm endif ifeq ($(TARGETOS),Darwin) @@ -46,9 +46,11 @@ TESTS = \ 27_sizeof.test \ 28_strings.test \ 29_array_address.test \ + 30_hanoi.test \ 31_args.test \ 32_led.test \ 33_ternary_op.test \ + 34_array_assignment.test \ 35_sizeof.test \ 36_array_initialisers.test \ 37_sprintf.test \ @@ -60,6 +62,7 @@ TESTS = \ 43_void_param.test \ 44_scoped_declarations.test \ 45_empty_for.test \ + 46_grep.test \ 47_switch_return.test \ 48_nested_break.test \ 49_bracket_evaluation.test \ @@ -67,35 +70,48 @@ TESTS = \ 51_static.test \ 52_unnamed_enum.test \ 54_goto.test \ - 55_lshift_type.test + 55_lshift_type.test \ + 56_btype_excess-1.test \ + 57_btype_excess-2.test \ + 58_function_redefinition.test \ + 59_function_array.test \ + 60_enum_redefinition.test \ + 61_undefined_enum.test \ + 62_enumerator_redefinition.test \ + 63_local_enumerator_redefinition.test \ + 64_macro_nesting.test \ + 65_macro_concat_start.test \ + 66_macro_concat_end.test \ + 67_macro_concat.test -# 30_hanoi.test -- seg fault in the code, gcc as well # 34_array_assignment.test -- array assignment is not in C standard -# 46_grep.test -- does not compile even with gcc + +SKIP = 34_array_assignment.test # some tests do not pass on all platforms, remove them for now ifeq ($(TARGETOS),Darwin) - TESTS := $(filter-out 40_stdio.test,$(TESTS)) + SKIP += 40_stdio.test endif ifdef CONFIG_WIN32 - TESTS := $(filter-out 24_math_library.test 28_strings.test,$(TESTS)) + SKIP += 24_math_library.test # don't have round() + SKIP += 28_strings.test # don't have r/index() / strings.h endif +# Some tests might need arguments +ARGS = +31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 +46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' 46_grep.c + +all test: $(filter-out $(SKIP),$(TESTS)) + %.test: %.c %.expect @echo Test: $*... - @if [ "x`echo $* | grep args`" != "x" ]; \ - then $(TCC) $< -norunsrc -run $(notdir $<) - arg1 arg2 arg3 arg4 >$*.output; \ - else $(TCC) -run $< >$*.output; \ - fi - @if diff -bu $(<:.c=.expect) $*.output ; \ - then rm -f $*.output; \ - else exit 1; \ - fi -all test: $(TESTS) + @$(TCC) -run $< $(ARGS) >$*.output 2>&1 || true + @diff -bu $*.expect $*.output && rm -f $*.output -clean: - rm -vf fred.txt *.output + @($(TCC) $< -o $*.exe && ./$*.exe $(ARGS)) >$*.output2 2>&1 || true + @diff -bu $*.expect $*.output2 && rm -f $*.output2 $*.exe -Makefile: $(top_srcdir)/tests/tests2/Makefile - cp $< $@ +clean: + rm -vf fred.txt *.output* *.exe |
