Skip to content

Commit

Permalink
fix/improve tests, also accept but warn of = in set command
Browse files Browse the repository at this point in the history
  • Loading branch information
YSaxon committed May 9, 2024
1 parent 1e075a0 commit d6e0ae3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,24 @@ set_tests_properties(repl_test_globals_after_libclose PROPERTIES PASS_REGULAR_EX
set_tests_properties(repl_test_globals_after_libclose PROPERTIES PASS_REGULAR_EXPRESSION "Function returned: 2")
set_tests_properties(repl_test_globals_after_libclose PROPERTIES PASS_REGULAR_EXPRESSION "Function returned: 1")

add_test(NAME repl_test_var_ac_ending_with_0x0
add_test(NAME repl_test_var_ac_with_0x0
COMMAND cliffi --repltest
set charbuffer = -ac h,e,l,l,o," ",w,o,r,l,d,0x0 \n
set charbuffer -ac a,b,0x0,c,d,0x0 \n
print charbuffer \n
)
set_tests_properties(repl_test_var_ac_ending_with_0x0 PROPERTIES PASS_REGULAR_EXPRESSION "charbuffer = \"hello world\\x00")
set_tests_properties(repl_test_var_ac_with_0x0 PROPERTIES PASS_REGULAR_EXPRESSION "charbuffer = ab\\\\x00cd\\\\x00") # \\\\ escapes a single backslash

add_test(NAME repl_test_accidentally_including_equals_in_set
COMMAND cliffi --repltest
set var1 = 3 \n
)
set_tests_properties(repl_test_accidentally_including_equals_in_set PROPERTIES PASS_REGULAR_EXPRESSION "int var1 = 3")

add_test(NAME repl_test_char_array_with_space
COMMAND cliffi --repltest
set charbuffer -ac a,b,\" \",d,e \n
)
set_tests_properties(repl_test_char_array_with_space PROPERTIES PASS_REGULAR_EXPRESSION "charbuffer = ab de")

add_test(NAME repl_test_variable_simple #
COMMAND cliffi --repltest
Expand Down
13 changes: 12 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "shims.h"

const char* NAME = "cliffi";
const char* VERSION = "v1.10.14";
const char* VERSION = "v1.10.15";
const char* BASIC_USAGE_STRING = "<library> <return_typeflag> <function_name> [[-typeflag] <arg>.. [ ... <varargs>..] ]\n";

sigjmp_buf jmpBuffer;
Expand Down Expand Up @@ -461,6 +461,14 @@ char** cliffi_completion(const char* text, int state) {
// from there we would really need to apply the parser to see if we are in a typeflag or an argument etc, and go from there
}

void discard_equals_but_warn_if_present(char*** argv, int* argc) {
if (*argc > 0 && strcmp((*argv)[0], "=") == 0){
fprintf(stderr, "Warning: '=' sign is not necessary when explicitly specifying the command and will be ignored.\n");
(*argv)++;
(*argc)--;
}
}

void parseSetVariable(char* varCommand) {
int argc;
char** argv;
Expand All @@ -473,6 +481,7 @@ void parseSetVariable(char* varCommand) {
char* varName = argv[0]; // first argument is the variable name
int value_args = argc - 1; // all but the first argument
char** value_argv = argv + 1; // starts after the first argument
discard_equals_but_warn_if_present(&value_argv, &value_args);
parseSetVariableWithNameAndValue(varName, value_args, value_argv);
}

Expand All @@ -488,6 +497,7 @@ void parseStoreToMemory(char* memCommand) {
char* address = argv[0]; // first argument is the address
int value_args = argc - 1; // all but the first argument
char** value_argv = argv + 1; // starts after the first argument
discard_equals_but_warn_if_present(&value_argv, &value_args);
parseStoreToMemoryWithAddressAndValue(address, value_args, value_argv);
}

Expand Down Expand Up @@ -519,6 +529,7 @@ void parseLoadMemoryToVar(char* loadCommand) {
char* address = argv[argc - 1]; // last argument is the address
int type_args = argc - 2; // all but the first and last argument
char** type_argv = argv + 1; // starts after the first argument
discard_equals_but_warn_if_present(&type_argv, &type_args);
ArgInfo* arg = parseLoadMemoryToArgWithType(address, type_args, type_argv);
printVariableWithArgInfo(varName, arg);
setVar(varName, arg);
Expand Down

0 comments on commit d6e0ae3

Please sign in to comment.