Quit `mruby -v` immediately if no program is given for Ruby compatibility
MODIFY
mrbgems/mruby-bin-mruby/bintest/mruby.rb
mrbgems/mruby-bin-mruby/bintest/mruby.rb
@@ -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_])
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

MODIFY
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
@@ -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");

Quit `mruby -v` immediately if no program is given for Ruby compatibility