Skip to content

Commit

Permalink
rz-test: add -y option to accept all (rizinorg#4772)
Browse files Browse the repository at this point in the history
* Add rz-test '-y' option to accept all
* Add '-y' into the help text
  • Loading branch information
imbillow authored and well-mannered-goat committed Dec 24, 2024
1 parent d9a5a42 commit e3f82b7
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion binrz/rz-test/rz-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static void interact(RzTestState *state);
static bool interact_fix(RzTestResultInfo *result, RzPVector /*<RzTestResultInfo *>*/ *fixup_results);
static void interact_break(RzTestResultInfo *result, RzPVector /*<RzTestResultInfo *>*/ *fixup_results);
static void interact_commands(RzTestResultInfo *result, RzPVector /*<RzTestResultInfo *>*/ *fixup_results);
static void accept_all(RzTestState *state);

static int help(bool verbose) {
printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET);
Expand All @@ -71,6 +72,7 @@ static int help(bool verbose) {
"-q", "", "Quiet mode",
"-V", "", "Be verbose",
"-i", "", "Interactive mode",
"-y", "", "Accept all interactive changes",
"-n", "", "Do nothing (don't run any test, just load/parse them)",
"-L", "", "Log mode (better printing for CI, logfiles, etc.)",
"-F", "[dir]", "Run fuzz tests (open and default analysis) on all files in the given dir",
Expand Down Expand Up @@ -176,6 +178,7 @@ int rz_test_main(int argc, const char **argv) {
bool nothing = false;
bool quiet = false;
bool interactive = false;
bool accept = false;
char *rizin_cmd = NULL;
char *rz_asm_cmd = NULL;
char *json_test_file = NULL;
Expand Down Expand Up @@ -209,7 +212,7 @@ int rz_test_main(int argc, const char **argv) {
#endif

RzGetopt opt;
rz_getopt_init(&opt, argc, (const char **)argv, "hqvj:r:m:f:C:LnVt:F:io:e:s:x:");
rz_getopt_init(&opt, argc, (const char **)argv, "hqvj:r:m:f:C:LnVt:F:io:e:s:x:y");

int c;
while ((c = rz_getopt_next(&opt)) != -1) {
Expand All @@ -236,6 +239,9 @@ int rz_test_main(int argc, const char **argv) {
case 'i':
interactive = true;
break;
case 'y':
accept = true;
break;
case 'L':
log_mode = true;
break;
Expand Down Expand Up @@ -561,6 +567,10 @@ int rz_test_main(int argc, const char **argv) {
interact(&state);
}

if (accept) {
accept_all(&state);
}

if (expect_succ > 0 && expect_succ != state.ok_count) {
ret = 1;
}
Expand Down Expand Up @@ -1050,6 +1060,40 @@ static void interact(RzTestState *state) {
rz_pvector_clear(&failed_results);
}

static void accept_all(RzTestState *state) {
void **it;
RzPVector failed_results;
rz_pvector_init(&failed_results, NULL);
rz_pvector_foreach (&state->results, it) {
RzTestResultInfo *result = *it;
if (result->result == RZ_TEST_RESULT_FAILED) {
rz_pvector_push(&failed_results, result);
}
}
if (rz_pvector_empty(&failed_results)) {
goto beach;
}

#if __WINDOWS__
(void)SetConsoleOutputCP(65001); // UTF-8
#endif

rz_pvector_foreach (&failed_results, it) {
RzTestResultInfo *result = *it;
if (result->test->type != RZ_TEST_TYPE_CMD && result->test->type != RZ_TEST_TYPE_ASM) {
continue;
}
if (!interact_fix(result, &failed_results)) {
char *name = rz_test_test_name(result->test);
printf("This test %s has failed too hard to be fixed.\n", name ? name : "");
free(name);
}
}

beach:
rz_pvector_clear(&failed_results);
}

static char *format_cmd_kv(const char *key, const char *val) {
RzStrBuf buf;
rz_strbuf_init(&buf);
Expand Down

0 comments on commit e3f82b7

Please sign in to comment.