Unverified Commit 25b5b79c authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4847 from shuujii/quit-mruby-v-immediately-if-no-program-is-given

Quit `mruby -v` immediately if no program is given for Ruby compatibility
parents 5eb08a0d 49653b81
...@@ -128,6 +128,12 @@ assert('mruby -r option (file not found)') do ...@@ -128,6 +128,12 @@ assert('mruby -r option (file not found)') do
assert_mruby("", /\A.*: Cannot open library file: .*\n\z/, false, %w[-r _no_exists_]) assert_mruby("", /\A.*: Cannot open library file: .*\n\z/, false, %w[-r _no_exists_])
end 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 --verbose option') do
assert_mruby(/\A[^\n]*NODE.*\n:end\n\z/m, "", true, %w[--verbose -e p(:end)]) assert_mruby(/\A[^\n]*NODE.*\n:end\n\z/m, "", true, %w[--verbose -e p(:end)])
end end
......
...@@ -14,6 +14,7 @@ struct _args { ...@@ -14,6 +14,7 @@ struct _args {
mrb_bool mrbfile : 1; mrb_bool mrbfile : 1;
mrb_bool check_syntax : 1; mrb_bool check_syntax : 1;
mrb_bool verbose : 1; mrb_bool verbose : 1;
mrb_bool version : 1;
mrb_bool debug : 1; mrb_bool debug : 1;
int argc; int argc;
char **argv; char **argv;
...@@ -180,7 +181,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) ...@@ -180,7 +181,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
} }
} }
else if (strcmp(opt, "v") == 0) { 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; args->verbose = TRUE;
} }
else if (strcmp(opt, "version") == 0) { else if (strcmp(opt, "version") == 0) {
...@@ -203,7 +207,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) ...@@ -203,7 +207,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
argc = opts->argc; argv = opts->argv; argc = opts->argc; argv = opts->argv;
if (args->cmdline == NULL) { if (args->cmdline == NULL) {
if (*argv == NULL) args->rfp = stdin; if (*argv == NULL) {
if (args->version) exit(EXIT_SUCCESS);
args->rfp = stdin;
}
else { else {
args->rfp = strcmp(argv[0], "-") == 0 ? args->rfp = strcmp(argv[0], "-") == 0 ?
stdin : fopen(argv[0], args->mrbfile ? "rb" : "r"); stdin : fopen(argv[0], args->mrbfile ? "rb" : "r");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment