int main(int argc, char *argv[]) { kbool_t ret = 1; int scriptidx = konoha_ginit(argc, argv); if(builtin_test != NULL) { return konoha_builtintest(builtin_test); } if(test_script != NULL) { return konoha_test(test_script); } konoha_t konoha = konoha_open(); if(preimport != NULL) { konoha_preimport((CTX_t)konoha, preimport); } if(startup_script != NULL) { konoha_startup(konoha, startup_script); } if(scriptidx < argc) { ret = konoha_load(konoha, argv[scriptidx]); } if(ret && interactive_flag) { ret = konoha_shell(konoha); } konoha_close(konoha); MODGC_check_malloced_size(); return ret ? konoha_AssertResult: 1; }
static int konoha_test(CTX, const char *testname) { int ret = 1; //FAILED char script_file[256]; char correct_file[256]; char result_file[256]; PLAT snprintf_i(script_file, 256, "%s", testname); PLAT snprintf_i(correct_file, 256, "%s.proof", script_file); PLAT snprintf_i(result_file, 256, "%s.tested", script_file); FILE *fp = fopen(correct_file, "r"); if (fp == NULL) { fprintf(stdout, "no proof file: %s\n", testname); } stdlog = fopen(result_file, "w"); konoha_load((konoha_t)_ctx, script_file); fprintf(stdlog, "Q.E.D.\n"); // Q.E.D. fclose(stdlog); if(fp != NULL) { FILE *fp2 = fopen(result_file, "r"); ret = check_result(fp, fp2); if(ret == 0) { fprintf(stdout, "[PASS]: %s\n", testname); } else { fprintf(stdout, "[FAIL]: %s\n", testname); konoha_AssertResult = 1; } fclose(fp); fclose(fp2); } return ret; }
static void konoha_startup(CTX, const char *startup_script) { char buf[256]; char *path = getenv("KONOHA_SCRIPTPATH"), *local = ""; if(path == NULL) { path = getenv("KONOHA_HOME"); local = "/script"; } if(path == NULL) { path = getenv("HOME"); local = "/.konoha2/script"; } snprintf(buf, sizeof(buf), "%s%s/%s.k", path, local, startup_script); if(!konoha_load((konoha_t)_ctx, (const char*)buf)) { PLAT exit_i(EXIT_FAILURE); } }
static int konoha_test(const char *testname) { verbose_debug = 0; verbose_sugar = 0; verbose_gc = 0; verbose_code = 0; konoha_t konoha = konoha_open(); if(preimport != NULL) { konoha_preimport((CTX_t)konoha, preimport); } if(startup_script != NULL) { konoha_startup(konoha, startup_script); } int ret = 0;//OK char script_file[256]; char correct_file[256]; char result_file[256]; snprintf(script_file, 256, "%s", testname); snprintf(correct_file, 256, "%s.proof", script_file); snprintf(result_file, 256, "%s.tested", script_file); FILE *fp = fopen(correct_file, "r"); if (fp == NULL) { fprintf(stdout, "no proof file: %s\n", testname); } stdlog = fopen(result_file, "w"); ((struct _klib2*)konoha->lib2)->Kreport = Kreport; ((struct _klib2*)konoha->lib2)->Kreportf = Kreportf; konoha_load(konoha, script_file); fprintf(stdlog, "Q.E.D.\n"); // Q.E.D. fclose(stdlog); if(fp != NULL) { FILE *fp2 = fopen(result_file, "r"); ret = check_result(fp, fp2); if(ret == 0) { fprintf(stdout, "[PASS]: %s\n", testname); } fclose(fp); fclose(fp2); } else { ret = 1; } konoha_close(konoha); return ret; }
static int konoha_parseopt(konoha_t konoha, kplatform_t *plat, int argc, char **argv) { int ret = true, scriptidx = 0; while (1) { int option_index = 0; int c = getopt_long (argc, argv, "icD:I:S:", long_options2, &option_index); if (c == -1) break; /* Detect the end of the options. */ switch (c) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options2[option_index].flag != 0) break; printf ("option %s", long_options2[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 'c': { compileonly_flag = 1; CTX_setCompileOnly(konoha); } break; case 'i': { interactive_flag = 1; CTX_setInteractive(konoha); } break; case 'B': return konoha_builtintest(konoha, optarg); case 'D': konoha_define(konoha, optarg); break; case 'I': konoha_import(konoha, optarg); break; case 'S': konoha_startup(konoha, optarg); break; case 'T': // DUMP_P ("option --test-with `%s'\n", optarg); verbose_debug = 0; verbose_sugar = 0; verbose_gc = 0; verbose_code = 0; plat->dbg_p = NOP_dbg_p; plat->printf_i = TEST_printf; plat->vprintf_i = TEST_vprintf; plat->begin = TEST_begin; plat->end = TEST_end; return konoha_test(konoha, optarg); case '?': /* getopt_long already printed an error message. */ break; default: return 1; } } scriptidx = optind; konoha_commandline(konoha, argc - scriptidx, argv + scriptidx); if(scriptidx < argc) { ret = konoha_load(konoha, argv[scriptidx]); } else { interactive_flag = 1; CTX_setInteractive(konoha); } if(ret && interactive_flag) { konoha_import(konoha, "konoha.i"); ret = konoha_shell(konoha); } return (ret == true) ? 0 : 1; }