Răsfoiți Sursa

Added a bunch of tests for parsing and more

Taddeus Kroes 12 ani în urmă
părinte
comite
201057e27b

+ 0 - 0
test/basic/check_error/duplicate_dimension_name.cvc → test/arrays/check_error/duplicate_dimension_name.cvc


+ 2 - 1
test/basic/check_error/export_extern_fun.cvc

@@ -1,3 +1,4 @@
 extern void f(int a);
-export void f(bool a) { }
+export void f(bool a) {}   // context analysis error
 
+export extern void g() {}  // syntax error

+ 3 - 0
test/basic/check_error/expr_statement.cvc

@@ -0,0 +1,3 @@
+void foo() {
+    1;
+}

+ 2 - 0
test/basic/check_error/global_statement.cvc

@@ -0,0 +1,2 @@
+int a;
+a = 1;

+ 11 - 0
test/basic/check_error/invalid_for_loop_type.cvc

@@ -0,0 +1,11 @@
+void foo() {
+    // These loops should yield syntax errors
+
+    for (float f = 0.0, 10.0) {
+        foo();
+    }
+
+    for (bool b = true, false) {
+        foo();
+    }
+}

+ 3 - 1
test/basic/check_error/invalid_vardec_type.cvc

@@ -1,3 +1,5 @@
+void a;
+
 void foo() {
-    void a;
+    void b;
 }

+ 7 - 0
test/basic/check_success/function_scope.cvc

@@ -0,0 +1,7 @@
+void foo() {
+    bar(glob);  // Uses function and variable that are defined later than foo()
+}
+
+void bar(int a) {}
+
+int glob;

+ 4 - 0
test/basic/check_success/params_funcall.cvc

@@ -0,0 +1,4 @@
+int foo() {
+    foo();
+    return foo() + 1;
+}

+ 0 - 0
test/basic/check_success/parse.cvc → test/basic/check_success/parse_all.cvc


+ 7 - 0
test/basic/check_success/parse_assign.cvc

@@ -0,0 +1,7 @@
+int b;
+
+void foo() {
+    int a;
+    a = 2;
+    b = 1;
+}

+ 10 - 0
test/basic/check_success/parse_do_while.cvc

@@ -0,0 +1,10 @@
+void foo() {
+    do {
+        foo();
+        foo();
+    } while (true);
+
+    do
+        foo();
+    while (false);
+}

+ 3 - 0
test/basic/check_success/parse_expr_parens.cvc

@@ -0,0 +1,3 @@
+int foo() {
+    return 2 * (1 + 2);
+}

+ 12 - 0
test/basic/check_success/parse_for.cvc

@@ -0,0 +1,12 @@
+void foo() {
+    for (int i = 0, 10) {
+        foo();
+        foo();
+    }
+
+    for (int i = 0, 10)
+        foo();
+
+    for (int i = 10, 0, -1)
+        foo();
+}

+ 28 - 0
test/basic/check_success/parse_funbody.cvc

@@ -0,0 +1,28 @@
+void vardec() {
+    int a;
+}
+
+void vardec_stat() {
+    int a;
+    a = 2;
+}
+
+int vardec_ret() {
+    int a;
+    return 2;
+}
+
+int vardec_stat_ret() {
+    int a;
+    a = 2;
+    return a;
+}
+
+int stat_ret() {
+    vardec();
+    return 2;
+}
+
+int ret() {
+    return 2;
+}

+ 3 - 0
test/basic/check_success/parse_funcall.cvc

@@ -0,0 +1,3 @@
+void foo() {
+    foo();
+}

+ 5 - 0
test/basic/check_success/parse_fundec.cvc

@@ -0,0 +1,5 @@
+extern void vfoo();
+extern bool bfoo();
+extern int ifoo();
+extern float ffoo();
+extern int bar(int arg1, float arg2);

+ 6 - 0
test/basic/check_success/parse_fundef.cvc

@@ -0,0 +1,6 @@
+void  vfoo() {}
+bool  bfoo() { return true; }
+int   ifoo(int arg) { return arg; }
+float ffoo(float arg1, float arg2) { return arg1 + arg2; }
+
+export int exported_fun() { return 1; }

+ 3 - 0
test/basic/check_success/parse_globaldec.cvc

@@ -0,0 +1,3 @@
+extern bool a;
+extern int b;
+extern float c;

+ 15 - 0
test/basic/check_success/parse_globaldef.cvc

@@ -0,0 +1,15 @@
+int a;
+float b;
+bool c;
+
+int d = 321;
+float e = 1.0;
+bool f = false;
+
+export int a2;
+export float b2;
+export bool c2;
+
+export int d2 = 321;
+export float e2 = 1.0;
+export bool f2 = false;

+ 9 - 0
test/basic/check_success/parse_if.cvc

@@ -0,0 +1,9 @@
+void foo() {
+    if (true) {
+        foo();
+        foo();
+    }
+
+    if (false)
+        foo();
+}

+ 21 - 0
test/basic/check_success/parse_if_else.cvc

@@ -0,0 +1,21 @@
+void foo() {
+    if (true) {
+        foo();
+    } else {
+        foo();
+    }
+
+    if (false)
+        foo();
+    else
+        foo();
+
+    // Whitespaces should not matter for your lexer
+    if      (    true   )
+foo();
+
+else     {
+
+
+    foo();
+}}

+ 22 - 0
test/basic/check_success/parse_operators.cvc

@@ -0,0 +1,22 @@
+void foo() {
+    int a;
+    bool b;
+    a = 1 + 2;
+    a = a - 1;
+    a = a * 45;
+    a = a / 9;
+    a = a % 4;
+    b = a < 1;
+    b = a > 2;
+    b = a <= 3;
+    b = a >= 4;
+    b = a == 5;
+    b = a != 6;
+    b = a != 6 && a >= 4;
+    b = a == 6 || a <= 4;
+    a = -a;
+    b = !b;
+
+    a = a - -1;
+    a = ------a;
+}

+ 5 - 0
test/basic/check_success/parse_typecast.cvc

@@ -0,0 +1,5 @@
+void foo() {
+    int i = (int)1.0;
+    float f = (float)1;
+    bool b = (bool)1;
+}

+ 9 - 0
test/basic/check_success/parse_vardec.cvc

@@ -0,0 +1,9 @@
+void foo() {
+    bool b;
+    int i;
+    float f;
+
+    bool b2 = true;
+    int i2 = 1;
+    float f2 = 1.0;
+}

+ 9 - 0
test/basic/check_success/parse_while.cvc

@@ -0,0 +1,9 @@
+void foo() {
+    while (true) {
+        foo();
+        foo();
+    }
+
+    while (true)
+        foo();
+}

+ 8 - 0
test/basic/functional/global_init.cvc

@@ -0,0 +1,8 @@
+extern void printInt(int val);
+
+int a = 10;
+
+export int main() {
+    printInt(a);
+    return 0;
+}

+ 1 - 0
test/basic/functional/global_init.out

@@ -0,0 +1 @@
+10

+ 6 - 2
test/run.bash

@@ -116,7 +116,7 @@ function check_return {
     total_tests=$((total_tests+1))
     printf "%-${ALIGN}s " $file:
 
-    if $CIVCC $CFLAGS $file -o tmp.s > /dev/null 2>&1
+    if $CIVCC $CFLAGS $file -o tmp.s > tmp.out 2>&1
     then
         if [ $expect_failure -eq 1 ]; then
             echo_failed
@@ -129,11 +129,15 @@ function check_return {
             echo_success
         else
             echo_failed
+            echo -------------------------------
+            cat tmp.out
+            echo -------------------------------
+            echo
             failed_tests=$((failed_tests+1))
         fi
     fi
 
-    rm -f tmp.s
+    rm -f tmp.s tmp.out
 }
 
 function run_dir {