Skip to content

Commit

Permalink
rz-test: Refactor call to rz_regex_full_match_str()
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy committed Dec 10, 2024
1 parent 3fae9c0 commit c9f00d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion binrz/rz-test/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,14 @@ RZ_API RzSubprocessOutput *rz_test_run_cmd_test(RzTestRunConfig *config, RzCmdTe
return out;
}

RZ_API RZ_OWN RzStrBuf *rz_test_regex_full_match_str(RZ_NONNULL const char *pattern, RZ_NONNULL const char *text) {
return rz_regex_full_match_str(pattern, text, RZ_REGEX_ZERO_TERMINATED, RZ_REGEX_EXTENDED, RZ_REGEX_DEFAULT,
"\n");
}

RZ_API bool rz_test_cmp_cmd_output(const char *output, const char *expect, const char *regexp) {
if (regexp) {
RzStrBuf *match_str = rz_regex_full_match_str(regexp, output, RZ_REGEX_ZERO_TERMINATED, RZ_REGEX_EXTENDED, RZ_REGEX_DEFAULT, "\n");
RzStrBuf *match_str = rz_test_regex_full_match_str(regexp, output);
bool equal = false;
ut32 expect_len = strlen(expect);
if (expect_len > 0 && expect[expect_len - 1] == '\n') {
Expand Down
5 changes: 2 additions & 3 deletions binrz/rz-test/rz-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ static void print_diff(const char *actual, const char *expected, const char *reg
const char *output = actual;

if (regexp) {
RzStrBuf *match_str = rz_regex_full_match_str(regexp, actual, RZ_REGEX_ZERO_TERMINATED, RZ_REGEX_EXTENDED, RZ_REGEX_DEFAULT, "\n");
RzStrBuf *match_str = rz_test_regex_full_match_str(regexp, actual);
output = rz_strbuf_drain(match_str);
}

Expand Down Expand Up @@ -1237,8 +1237,7 @@ static void replace_cmd_kv_file(const char *path, ut64 line_begin, ut64 line_end
}

static char *get_matched_str(const char *regexp, const char *str) {
RzStrBuf *match_str = rz_regex_full_match_str(regexp, str, RZ_REGEX_ZERO_TERMINATED, RZ_REGEX_EXTENDED,
RZ_REGEX_DEFAULT, "\n");
RzStrBuf *match_str = rz_test_regex_full_match_str(regexp, str);
int len = rz_strbuf_length(match_str);
if (len && rz_strbuf_get(match_str)[len - 1] != '\n') { // empty matches are not changed
rz_strbuf_append(match_str, "\n");
Expand Down
1 change: 1 addition & 0 deletions binrz/rz-test/rz_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ RZ_API RzSubprocessOutput *rz_test_run_cmd_test(RzTestRunConfig *config, RzCmdTe
RZ_API bool rz_test_check_cmd_test(RzSubprocessOutput *out, RzCmdTest *test);
RZ_API bool rz_test_cmp_cmd_output(const char *output, const char *expect, const char *regexp);
RZ_API bool rz_test_check_jq_available(void);
RZ_API RZ_OWN RzStrBuf *rz_test_regex_full_match_str(RZ_NONNULL const char *pattern, RZ_NONNULL const char *text);
RZ_API RzSubprocessOutput *rz_test_run_json_test(RzTestRunConfig *config, RzJsonTest *test, RzTestCmdRunner runner, void *user);
RZ_API bool rz_test_check_json_test(RzSubprocessOutput *out, RzJsonTest *test);
RZ_API RzAsmTestOutput *rz_test_run_asm_test(RzTestRunConfig *config, RzAsmTest *test);
Expand Down

0 comments on commit c9f00d1

Please sign in to comment.