Explorar o código

feat: 修复run_code的错误

SongZihuan %!s(int64=3) %!d(string=hai) anos
pai
achega
2513f78106
Modificáronse 4 ficheiros con 24 adicións e 9 borrados
  1. 1 1
      src/core/core_init.c
  2. 1 1
      src/runtime/aFunlang.c
  3. 20 5
      test/src/run_code.c
  4. 2 2
      test/src/tool_regex.c

+ 1 - 1
src/core/core_init.c

@@ -22,7 +22,7 @@ static void destructCoreExit(void) {
 
 bool aFunCoreInit(aFunCoreInitInfo *info) {
     if (info == NULL) {
-        static aFunCoreInitInfo info_default = {.base_dir="",
+        static aFunCoreInitInfo info_default = {.base_dir=".",
                                                 .pc=log_pc_all,
                                                 .fe=true,
                                                 .se=true,

+ 1 - 1
src/runtime/aFunlang.c

@@ -10,7 +10,7 @@ bool aFunInit(aFunInitInfo *info) {
         return false;
 
     if (info == NULL) {
-        static aFunInitInfo info_default = {.base_dir="",
+        static aFunInitInfo info_default = {.base_dir=".",
                                             .pc=log_pc_all,
                                             .buf=NULL,
                                             .level=log_info};

+ 20 - 5
test/src/run_code.c

@@ -370,12 +370,27 @@ bool infixFunc(char *id, af_Object *obj) {
 }
 
 int main(int argc, char **argv) {
-    bool re = aFunInit(NULL);
+    jmp_buf main_buf;
+    char *base_path = getExedir(*argv, 1);
+    if (base_path == NULL)
+        goto INIT_ERROR;
+
+    if (setjmp(main_buf) == 1)
+        return EXIT_FAILURE;
+
+    aFunInitInfo info = {.base_dir=base_path,
+            .level=log_debug,
+            .buf=&main_buf,
+            .pc=log_pc_all};
+
+    if (!aFunInit(&info)) {
+INIT_ERROR:
+        free(base_path);
+        printf_stderr(0, "aFunlang init error.");
+        return EXIT_FAILURE;
+    } else
+        free(base_path);
 
-    if (!re) {
-        printf("re = %d\n", re);
-        exit(EXIT_FAILURE);
-    }
 
     af_Environment *env = creatAFunEnvironment(0, NULL);
     if(!pushLiteralRegex("data.*", "func", true, env)) {

+ 2 - 2
test/src/tool_regex.c

@@ -3,8 +3,8 @@
 #include "regex.h"
 
 int main() {
-    af_Regex *rg = makeRegex("Hello.*d");
-    int rc1 = matchRegex("HelloWorld", rg);
+    af_Regex *rg = makeRegex("Hello.*d");
+    int rc1 = matchRegex("HelloWorld", rg);
     int rc2 = matchRegex("Nossss", rg);
     freeRegex(rg);
     if (rc1 == 1 && rc2 == 0) {