From a9bda54b1bc0057164d630e180cb24596d524023 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 5 Nov 2020 16:01:24 +0100 Subject: [PATCH] :white_check_mark: Thorough plug testing --- src/arg.c | 9 +-------- src/import/import_internals.c | 2 ++ src/plug.c | 4 ---- tests/driver/non_driver.c | 14 ++++++++++++++ tests/error/require_fail.gw | 4 ++++ tests/module/get_module.c | 5 +++-- tests/module/get_module.gw | 2 ++ tests/plug/coverage.gw | 2 ++ tests/plug/deps.c | 18 ++++++++++++++++++ tests/plug/deps.gw | 3 +++ tests/plug/test.log | 1 - tests/sh/import.sh | 11 +++++++---- tests/sh/opt.sh | 16 +++++++++++----- tests/struct/struct_template.gw | 4 ++-- 14 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 tests/driver/non_driver.c create mode 100644 tests/error/require_fail.gw create mode 100644 tests/module/get_module.gw create mode 100644 tests/plug/deps.c create mode 100644 tests/plug/deps.gw delete mode 100644 tests/plug/test.log diff --git a/src/arg.c b/src/arg.c index 495c4577..be2c1e95 100644 --- a/src/arg.c +++ b/src/arg.c @@ -78,14 +78,7 @@ ANN2(1) static void module_arg(const Map map, m_str str) { *val = '\0'; ++val; } - const m_str key = str; - for(m_uint i = 0; i < map_size(map); ++i) { - if(!strcmp(key, (m_str)VKEY(map, i))) { - free((m_str)VKEY(map, i)); - break; - } - } - map_set(map, (vtype)key, (vtype)val); + map_set(map, (vtype)str, (vtype)val); } ANN m_bool _arg_parse(const Gwion gwion, Arg* arg) { diff --git a/src/import/import_internals.c b/src/import/import_internals.c index 8ddc53b0..56292c20 100644 --- a/src/import/import_internals.c +++ b/src/import/import_internals.c @@ -34,6 +34,8 @@ ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { OperCK oper = {}; struct Gwi_ gwi = { .gwion=gwion, .loc=&loc, .oper=&oper }; const m_bool ret = f(&gwi); + if(ret < 0) + gwi_reset(&gwi); gwion->env->name = name; return ret; } diff --git a/src/plug.c b/src/plug.c index b7694be1..4104cf20 100644 --- a/src/plug.c +++ b/src/plug.c @@ -46,7 +46,6 @@ struct PlugHandle { typedef struct Plug_ { void *dl; void *self; - int mod; int imp; } *Plug; @@ -131,9 +130,6 @@ ANN void set_module(const struct Gwion_ *gwion, const m_str name, void *const pt for(m_uint j = 0; j < map_size(map); ++j) { if(!strcmp(name, (m_str)VKEY(map, j))) { Plug plug = (Plug)VVAL(map, j); - if(plug->mod) - return; - plug->mod = 1; plug->self = ptr; return; } diff --git a/tests/driver/non_driver.c b/tests/driver/non_driver.c new file mode 100644 index 00000000..2c020b3b --- /dev/null +++ b/tests/driver/non_driver.c @@ -0,0 +1,14 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "gwion.h" +#include "operator.h" +#include "object.h" +#include "instr.h" +#include "import.h" + +GWION_IMPORT(end_class) { + (void)gwi; + return GW_OK; +} diff --git a/tests/error/require_fail.gw b/tests/error/require_fail.gw new file mode 100644 index 00000000..01646ae7 --- /dev/null +++ b/tests/error/require_fail.gw @@ -0,0 +1,4 @@ +#require NonExisting + +var ftbl f; +<<< var SinOsc s >>>; diff --git a/tests/module/get_module.c b/tests/module/get_module.c index 6387d775..3a27ad05 100644 --- a/tests/module/get_module.c +++ b/tests/module/get_module.c @@ -15,7 +15,7 @@ GWMODINI(get_module) { puts(__func__); - return (void*)2; + return NULL; } GWMODEND(get_module) { @@ -23,7 +23,8 @@ GWMODEND(get_module) { } GWION_IMPORT(dummy_module) { - CHECK_OB(get_module(gwi->gwion, "dummy_module")) + set_module(gwi->gwion, "get_module", (void*)1); + CHECK_OB(get_module(gwi->gwion, "get_module")) puts("test passed"); get_module(gwi->gwion, "non_existant_module"); return GW_OK; diff --git a/tests/module/get_module.gw b/tests/module/get_module.gw new file mode 100644 index 00000000..ef38782f --- /dev/null +++ b/tests/module/get_module.gw @@ -0,0 +1,2 @@ +#require get_module +<<< __file__ >>>; diff --git a/tests/plug/coverage.gw b/tests/plug/coverage.gw index e0d54055..973b0434 100644 --- a/tests/plug/coverage.gw +++ b/tests/plug/coverage.gw @@ -1,4 +1,6 @@ #require coverage +#require coverage + <<< var float f >>>; var Coverage c; c.s_i; diff --git a/tests/plug/deps.c b/tests/plug/deps.c new file mode 100644 index 00000000..7f57c641 --- /dev/null +++ b/tests/plug/deps.c @@ -0,0 +1,18 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "object.h" +#include "instr.h" +#include "gwion.h" +#include "operator.h" +#include "import.h" +#include "gwi.h" + +GWION_IMPORT(deps) { + (void)gwi; + return GW_OK; +} + +static const m_str deps[] = { "array", NULL }; +GWDEPEND { return deps; } diff --git a/tests/plug/deps.gw b/tests/plug/deps.gw new file mode 100644 index 00000000..eda35760 --- /dev/null +++ b/tests/plug/deps.gw @@ -0,0 +1,3 @@ +#require deps + +<<< __file__ >>>; diff --git a/tests/plug/test.log b/tests/plug/test.log deleted file mode 100644 index 87ce6cd6..00000000 --- a/tests/plug/test.log +++ /dev/null @@ -1 +0,0 @@ -op_already_imported.gw diff --git a/tests/sh/import.sh b/tests/sh/import.sh index b102ec59..96a20e0d 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #75 +# [test] #78 n=0 [ "$1" ] && n="$1" @@ -16,7 +16,6 @@ test_plugin() { export PRG="../../gwion" export SUPP="../../scripts/supp" make -# we might have a test file for all now if [ -f "$NAME.gw" ] then GWOPT+="-p." test_gw "$NAME.gw" "$n" else GWOPT+="-p." test_gw "no_file" "$n" @@ -41,13 +40,17 @@ pushd tests/plug || exit for test_file in *.c do test_plugin "$(basename "$test_file" .c)" done +PRG="../../gwion" make NAME="array" +test_plugin "deps" "$n" +make NAME="array" clean popd + pushd tests/driver || exit for test_file in *.c do NAME="$(basename "$test_file" .c)" - GWOPT+="-d $NAME" test_plugin "$(basename "$test_file" .c)" + DRIVER="$NAME=some_arg" test_plugin "$(basename "$test_file" .c)" done popd || exit @@ -55,7 +58,7 @@ pushd tests/module || exit for test_file in *.c do NAME="$(basename "$test_file" .c)" - GWOPT+="-m $NAME" test_plugin "$NAME" + MODULE="$NAME=some_arg" test_plugin "$NAME" done popd || exit diff --git a/tests/sh/opt.sh b/tests/sh/opt.sh index 796fc58e..f3f42e08 100644 --- a/tests/sh/opt.sh +++ b/tests/sh/opt.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #20 +# [test] #21 n=0 [ "$1" ] && n="$1" @@ -50,13 +50,15 @@ run "$n" "arg is a directory" "-p src" "file" # config n=$((n+1)) -RC=tmp_gwionrc -cat << EOF >> "$RC" +RC=./tmp_gwionrc +cat << EOF > "$RC" -p. -l0 EOF -run "$n" "config" "-c $RC" "file" -rm "$RC" +run "$n" "config" "-c$RC" "file" +./gwion -c ./tmp_gwionrc +#GWOPT="-c ./$RC" run "$n" "config" "" "file" +#rm "$RC" # loop n=$((n+1)) @@ -78,6 +80,10 @@ run "$n" "no pass" "-g nopass" "file" n=$((n+1)) run "$n" "option needs argument" "-p" "file" +# option needs argument +n=$((n+1)) +echo "<<< __file__ >>>;" | run "$n" "stdin" "-" "file" + # invalid global type n=$((n+1)) run "$n" "invalid global type" "examples/complex/invalid_type0.gw examples/complex/invalid_type1.gw" "file" diff --git a/tests/struct/struct_template.gw b/tests/struct/struct_template.gw index c9291cc2..a0b14b71 100644 --- a/tests/struct/struct_template.gw +++ b/tests/struct/struct_template.gw @@ -3,8 +3,8 @@ struct S:[A] { var A a1; } -var D:[int] si; -var D:[float] sf; +var S:[int] si; +var S:[float] sf; <<< si.a0 >>>; <<< sf.a0 >>>; -- 2.43.0