]> ocean-lang.org Git - ocean/commitdiff
oceani: add test for duplicate main functions
authorNeilBrown <neil@brown.name>
Wed, 3 Nov 2021 00:57:01 +0000 (11:57 +1100)
committerNeilBrown <neil@brown.name>
Mon, 8 Nov 2021 09:56:36 +0000 (20:56 +1100)
Add a test so the check for duplicate main functions gets exercised.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index 881fee7229e7642869bca66b3cc79c9d808ad63d..7be2d2502b1e99deed67e58830498a7b984404b5 100644 (file)
@@ -824,12 +824,20 @@ various places that `type_err()` are called.
                foo := 4
                print foo, bar
 
+       // trigger duplicate-main error
+       func main()
+               foo := 6
+               print bar, foo
+
 ###### output: type_err_const
        .tmp.code:4:16: error: expected number found string
        .tmp.code:6:8: error: name already declared: bar
        .tmp.code:4:8: info: this is where 'bar' was first declared
        .tmp.code:8:8: error: variable 'foo' redeclared
        .tmp.code:3:8: info: this is where 'foo' was first declared
+       .tmp.code:13:8: error: variable 'foo' redeclared
+       .tmp.code:3:8: info: this is where 'foo' was first declared
+       .tmp.code:13:8: "main" defined a second time
 
 ###### test: type_err_const1
        const
index fd753ce5e0b0d43484fb6959e19cb30c7ee04aab..59b8540122e2f75cd6ee471c3482a8bb8810380d 100644 (file)
@@ -166,6 +166,12 @@ structures can be used.
                {NULL,        0, NULL, 0},
        };
        const char *options = "tpnbs";
+
+       static void pr_err(char *msg)
+       {
+               fprintf(stderr, "%s\n", msg);           // NOTEST
+       }
+
        int main(int argc, char *argv[])
        {
                int fd;
@@ -207,7 +213,7 @@ structures can be used.
                context.file_name = argv[optind];
                len = lseek(fd, 0, 2);
                file = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
-               s = code_extract(file, file+len, NULL);
+               s = code_extract(file, file+len, pr_err);
                if (!s) {
                        fprintf(stderr, "oceani: could not find any code in %s\n",
                                argv[optind]);