From a25939c040f3cecafbfc82b750e0d344e2a2b1c8 Mon Sep 17 00:00:00 2001 From: Rex <631752+reginaldford@users.noreply.github.com> Date: Sun, 30 Jun 2024 09:53:32 -0400 Subject: [PATCH] cxGet unit tests were fixed to match new cxGet. on failure, we get an error, not false --- src/main/engine/sm_ast_engine.c | 25 ++++++++++++++++--------- test_zone/cx/0.sms | 8 ++++---- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/engine/sm_ast_engine.c b/src/main/engine/sm_ast_engine.c index 0822453a..0d62350e 100644 --- a/src/main/engine/sm_ast_engine.c +++ b/src/main/engine/sm_ast_engine.c @@ -172,8 +172,12 @@ sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *sf) { if (key->my_type == SM_ERR_TYPE) return (sm_object *)key; char *result = getenv(&key->content); - if (!result) - return (sm_object *)sms_false; + if (!result) { + sm_symbol *title = sm_new_symbol("osGetEnvFailed", 14); + sm_string *message = + sm_new_fstring_at(sms_heap, "Failed to get environment variable: %s", &key->content); + return (sm_object *)sm_new_error_from_expr(title, message, sme, NULL); + } return (sm_object *)sm_new_string(strlen(result), result); break; } @@ -251,7 +255,9 @@ sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *sf) { char *path_cstr = &path->content; if (chdir(path_cstr) == 0) return (sm_object *)sms_true; - return (sm_object *)sms_false; + sm_symbol *title = sm_new_symbol("cdFailed", 8); + sm_string *message = sm_new_fstring_at(sms_heap, "Failed to change directory to %s"); + return (sm_object *)sm_new_error_from_expr(title, message, sme, NULL); break; } case SM_DATE_STR_EXPR: { @@ -361,7 +367,7 @@ sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *sf) { sm_object *value = (sm_object *)sm_engine_eval(sm_expr_get_arg(sme, 1), current_cx, sf); // If an error occurred, it is stored in the mapping sm_cx_let(current_cx, sym, value); - return (sm_object *)sms_true; + return value; } case SM_CX_SETPARENT_EXPR: { sm_cx *cx = (sm_cx *)eager_type_check(sme, 0, SM_CX_TYPE, current_cx, sf); @@ -382,9 +388,8 @@ sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *sf) { if (sym->my_type == SM_ERR_TYPE) return (sm_object *)sym; sm_object *value = (sm_object *)sm_engine_eval(sm_expr_get_arg(sme, 2), current_cx, sf); - if (sm_cx_let(cx, sym, value)) - return (sm_object *)sms_true; - return (sm_object *)sms_false; + sm_cx_let(cx, sym, value); + return value; } case SM_CX_GET_EXPR: { sm_cx *cx = (sm_cx *)eager_type_check(sme, 0, SM_CX_TYPE, current_cx, sf); @@ -396,8 +401,10 @@ sm_object *sm_engine_eval(sm_object *input, sm_cx *current_cx, sm_expr *sf) { sm_object *result = sm_cx_get(cx, sym); if (result) return result; - else - return (sm_object *)sms_false; + sm_symbol *title = sm_new_symbol("cxGetFailed", 11); + sm_string *message = + sm_new_fstring_at(sms_heap, "cxGet did not find %s in this context.", &sym->name->content); + return (sm_object *)sm_new_error_from_expr(title, message, sme, NULL); } case SM_CX_HAS_EXPR: { sm_cx *cx = (sm_cx *)eager_type_check(sme, 0, SM_CX_TYPE, current_cx, sf); diff --git a/test_zone/cx/0.sms b/test_zone/cx/0.sms index fc4ceef4..8dd13a9f 100644 --- a/test_zone/cx/0.sms +++ b/test_zone/cx/0.sms @@ -5,7 +5,7 @@ [cxKeys(cx1),[ ex1, ex2 ], "cxKeys"], [cxValues(cx1),[ "info", "info2" ], "cxValues"], [cxGet(cx1,:ex2),"info2", "cxGet"], - [cxGet(cx1,:true),false, "cxGet true should fail"], + [isErr(cxGet(cx1,:true)),true, "cxGet true should fail"], [cxGetFar(cx1,:true),true, "cxGetFar true should succeed"], [cxGetFar(cx1,:PI),3.141592653589793, "cxGetFar PI"], [cxSize(cx1),2, "cxSize is 2"], @@ -13,15 +13,15 @@ [cxSize(cx1),0, "cxSize is 0"], [cxKeys(cx1),[], "cxKeys is []"], [cxValues(cx1),[], "cxValues is []"], - [cxLet(cx1,:a,4),true, "cxLet a 4"], + [cxLet(cx1,:a,4),4, "cxLet a 4"], [cxGet(cx1,:a),4, "cxGet a"], [cxGetFar(cx1,:a),4, "cxGetFar a"], [cxRm(cx1,:a),true, "cxRm a"], - [cxGet(cx1,:a),false, "cxGet a"], + [isErr(cxGet(cx1,:a)),true, "cxGet a should fail"], [cxGetFar(cx1,:a),false, "cxGetFar a"], [cxRm(parent(parent(self)),:false),true, "cxRm False"], [cxGetFar(self,:false),false, "cxGetFar False"], - [cxLet(parent(self),:false,:false),true, "cxLet :false :false"], + [cxLet(parent(self),:false,:false),false, "cxLet :false :false"], [cxGetFar(self,:false),false, "cxLet :false :false"], [cxGetFar(self,:false) is false,true, "Same false instance."] ];