Skip to content
Permalink
Browse files
Quit mruby -v immediately if no program is given for Ruby compatibi…
…lity
  • Loading branch information
shuujii committed Nov 30, 2019
1 parent 5eb08a0 commit 49653b81ea978a5f02c4a6ce1ed53eb1cd0dbe7a
Showing 2 changed files with 15 additions and 2 deletions.
@@ -128,6 +128,12 @@ def hoge
assert_mruby("", /\A.*: Cannot open library file: .*\n\z/, false, %w[-r _no_exists_])
end

assert('mruby -v option') do
ver_re = /\Amruby \d+\.\d+\.\d+ \(\d+-\d+-\d+\)\n/
assert_mruby(/#{ver_re}\z/, "", true, %w[-v])
assert_mruby(/#{ver_re}^[^\n]*NODE.*\n:end\n\z/m, "", true, %w[-v -e p(:end)])
end

assert('mruby --verbose option') do
assert_mruby(/\A[^\n]*NODE.*\n:end\n\z/m, "", true, %w[--verbose -e p(:end)])
end
@@ -14,6 +14,7 @@ struct _args {
mrb_bool mrbfile : 1;
mrb_bool check_syntax : 1;
mrb_bool verbose : 1;
mrb_bool version : 1;
mrb_bool debug : 1;
int argc;
char **argv;
@@ -180,7 +181,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
}
}
else if (strcmp(opt, "v") == 0) {
if (!args->verbose) mrb_show_version(mrb);
if (!args->verbose) {
mrb_show_version(mrb);
args->version = TRUE;
}
args->verbose = TRUE;
}
else if (strcmp(opt, "version") == 0) {
@@ -203,7 +207,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)

argc = opts->argc; argv = opts->argv;
if (args->cmdline == NULL) {
if (*argv == NULL) args->rfp = stdin;
if (*argv == NULL) {
if (args->version) exit(EXIT_SUCCESS);
args->rfp = stdin;
}
else {
args->rfp = strcmp(argv[0], "-") == 0 ?
stdin : fopen(argv[0], args->mrbfile ? "rb" : "r");

0 comments on commit 49653b8

Please sign in to comment.