From 2cfbb4cf903c6cf0d50fcf2c6c8bd231fa9e61fe Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 11 Oct 2019 23:46:19 +0200 Subject: [PATCH] :art: Test enum import --- src/lib/import.c | 8 ++------ tests/import/Makefile | 2 +- tests/import/enum_fail.c | 19 +++++++++++++++++++ tests/import/enum_fail2.c | 19 +++++++++++++++++++ tests/sh/import.sh | 2 +- 5 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 tests/import/enum_fail.c create mode 100644 tests/import/enum_fail2.c diff --git a/src/lib/import.c b/src/lib/import.c index af8af4b0..102317c6 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -678,13 +678,9 @@ ANN Type gwi_enum_end(const Gwi gwi) { DL_Enum* d = &gwi->enum_data; const Enum_Def edef = new_enum_def(gwi->gwion->mp, d->base, d->t ? insert_symbol(gwi->gwion->st, d->t) : NULL, loc_cpy(gwi->gwion->mp, gwi->loc)); - if(traverse_enum_def(gwi->gwion->env, edef) < 0) { - if(!edef->t) - free_enum_def(gwi->gwion->mp, edef); - return NULL; - } + const m_bool ret = traverse_enum_def(gwi->gwion->env, edef); import_enum_end(gwi, &edef->values); - const Type t =edef->t; + const Type t = ret > 0 ? edef->t : NULL; free_enum_def(gwi->gwion->mp, edef); return t; } diff --git a/tests/import/Makefile b/tests/import/Makefile index e7f73371..8d0336ba 100644 --- a/tests/import/Makefile +++ b/tests/import/Makefile @@ -4,7 +4,7 @@ CC ?= gcc NAME := ${NAME} SRC = ${NAME}.c OBJ = $(SRC:.c=.o) -CFLAGS = -std=c99 $(../../gwion -k 2>&1 | grep CFLAGS | sed 's/CFLAGS: //') ${INC} ${CICFLAGS} -Wall -Wextra +CFLAGS = -std=c99 $(../../gwion -k 2>&1 | grep CFLAGS | sed 's/CFLAGS: //') ${INC} ${CICFLAGS} -Wall -Wextra -g -Og LDFLAGS = $(../../gwion -k 2>&1 | grep LDFLAGS) # os specific diff --git a/tests/import/enum_fail.c b/tests/import/enum_fail.c new file mode 100644 index 00000000..8071ad43 --- /dev/null +++ b/tests/import/enum_fail.c @@ -0,0 +1,19 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "value.h" +#include "operator.h" +#include "import.h" + +GWION_IMPORT(enum_test) { + GWI_BB(gwi_enum_ini(gwi, "int")) + GWI_BB(gwi_enum_add(gwi, "zero", 0)) + GWI_OB(gwi_enum_end(gwi)) + return GW_OK; +} diff --git a/tests/import/enum_fail2.c b/tests/import/enum_fail2.c new file mode 100644 index 00000000..6f5550b0 --- /dev/null +++ b/tests/import/enum_fail2.c @@ -0,0 +1,19 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "vm.h" +#include "env.h" +#include "type.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "value.h" +#include "operator.h" +#include "import.h" + +GWION_IMPORT(enum_test) { + GWI_BB(gwi_enum_ini(gwi, NULL)) + GWI_BB(gwi_enum_add(gwi, "adc", 0)) + GWI_OB(gwi_enum_end(gwi)) + return GW_OK; +} diff --git a/tests/sh/import.sh b/tests/sh/import.sh index af464767..ab2028c6 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #41 +# [test] #43 n=0 [ "$1" ] && n="$1" -- 2.43.0