From 1d16646506ff7bc95d501deaee67740b08b218b5 Mon Sep 17 00:00:00 2001 From: Hiroshi Mimaki Date: Wed, 2 May 2018 20:52:02 +0900 Subject: Add `-d` option for `mruby` and `mirb`. --- mrbgems/mruby-bin-mirb/bintest/mirb.rb | 7 +++++++ mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 7 +++++++ mrbgems/mruby-bin-mruby/bintest/mruby.rb | 7 +++++++ mrbgems/mruby-bin-mruby/tools/mruby/mruby.c | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/mrbgems/mruby-bin-mirb/bintest/mirb.rb b/mrbgems/mruby-bin-mirb/bintest/mirb.rb index ed53321bd..a1a0651b4 100644 --- a/mrbgems/mruby-bin-mirb/bintest/mirb.rb +++ b/mrbgems/mruby-bin-mirb/bintest/mirb.rb @@ -10,3 +10,10 @@ assert('regression for #1563') do o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1;b=2;c=3\nb\nc") assert_true o.include?('=> 3') end + +assert('mirb -d option') do + o, s = Open3.capture2('bin/mirb', :stdin_data => "p $DEBUG\n") + assert_true o.include?('=> false') + o, s = Open3.capture2('bin/mirb -d', :stdin_data => "p $DEBUG\n") + assert_true o.include?('=> true') +end diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index a58a72e7d..5ea4df07e 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -54,6 +54,7 @@ #include #include #include +#include #ifdef ENABLE_READLINE @@ -219,6 +220,7 @@ is_code_block_open(struct mrb_parser_state *parser) struct _args { FILE *rfp; mrb_bool verbose : 1; + mrb_bool debug : 1; int argc; char** argv; }; @@ -228,6 +230,7 @@ usage(const char *name) { static const char *const usage_msg[] = { "switches:", + "-d Set $DEBUG to true (same as `mruby -d`)" "-v print version number, then run in verbose mode", "--verbose run in verbose mode", "--version print the version", @@ -254,6 +257,9 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) item = argv[0] + 1; switch (*item++) { + case 'd': + args->debug = TRUE; + break; case 'v': if (!args->verbose) mrb_show_version(mrb); args->verbose = TRUE; @@ -413,6 +419,7 @@ main(int argc, char **argv) } } mrb_define_global_const(mrb, "ARGV", ARGV); + mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug)); #ifdef ENABLE_READLINE history_path = get_history_path(mrb); diff --git a/mrbgems/mruby-bin-mruby/bintest/mruby.rb b/mrbgems/mruby-bin-mruby/bintest/mruby.rb index b6b090185..3f6f3755d 100644 --- a/mrbgems/mruby-bin-mruby/bintest/mruby.rb +++ b/mrbgems/mruby-bin-mruby/bintest/mruby.rb @@ -58,3 +58,10 @@ RUBY assert_equal "NilClass", `#{cmd('mruby')} #{script.path}` assert_equal 0, $?.exitstatus end + +assert('mruby -d option') do + o = `#{cmd('mruby')} -e #{shellquote('p $DEBUG')}>&1` + assert_equal o, "false\n" + o = `#{cmd('mruby')} -d -e #{shellquote('p $DEBUG')}>&1` + assert_equal o, "true\n" +end diff --git a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c index 61d4cde94..0db2c3f37 100644 --- a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +++ b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c @@ -27,6 +27,7 @@ struct _args { mrb_bool mrbfile : 1; mrb_bool check_syntax : 1; mrb_bool verbose : 1; + mrb_bool debug : 1; int argc; char** argv; }; @@ -38,6 +39,7 @@ usage(const char *name) "switches:", "-b load and execute RiteBinary (mrb) file", "-c check syntax only", + "-d Set debugging flags (set $DEBUG to true)" "-e 'command' one line of script", "-v print version number, then run in verbose mode", "--verbose run in verbose mode", @@ -78,6 +80,9 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) case 'c': args->check_syntax = TRUE; break; + case 'd': + args->debug = TRUE; + break; case 'e': if (item[0]) { goto append_cmdline; @@ -199,6 +204,7 @@ main(int argc, char **argv) } } mrb_define_global_const(mrb, "ARGV", ARGV); + mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug)); c = mrbc_context_new(mrb); if (args.verbose) -- cgit v1.2.3 From 0c01afc3c9d3ec95badb6c463288376908bf18d7 Mon Sep 17 00:00:00 2001 From: Hiroshi Mimaki Date: Mon, 7 May 2018 12:23:32 +0900 Subject: Fix CI build errors and warnings. --- mrbgems/mruby-bin-mirb/bintest/mirb.rb | 4 ++-- mrbgems/mruby-bin-mruby/bintest/mruby.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mrbgems/mruby-bin-mirb/bintest/mirb.rb b/mrbgems/mruby-bin-mirb/bintest/mirb.rb index a1a0651b4..f6f8cd869 100644 --- a/mrbgems/mruby-bin-mirb/bintest/mirb.rb +++ b/mrbgems/mruby-bin-mirb/bintest/mirb.rb @@ -12,8 +12,8 @@ assert('regression for #1563') do end assert('mirb -d option') do - o, s = Open3.capture2('bin/mirb', :stdin_data => "p $DEBUG\n") + o, _ = Open3.capture2('bin/mirb', :stdin_data => "p $DEBUG\n") assert_true o.include?('=> false') - o, s = Open3.capture2('bin/mirb -d', :stdin_data => "p $DEBUG\n") + o, _ = Open3.capture2('bin/mirb -d', :stdin_data => "p $DEBUG\n") assert_true o.include?('=> true') end diff --git a/mrbgems/mruby-bin-mruby/bintest/mruby.rb b/mrbgems/mruby-bin-mruby/bintest/mruby.rb index 3f6f3755d..ca11ce2e7 100644 --- a/mrbgems/mruby-bin-mruby/bintest/mruby.rb +++ b/mrbgems/mruby-bin-mruby/bintest/mruby.rb @@ -60,8 +60,8 @@ RUBY end assert('mruby -d option') do - o = `#{cmd('mruby')} -e #{shellquote('p $DEBUG')}>&1` - assert_equal o, "false\n" - o = `#{cmd('mruby')} -d -e #{shellquote('p $DEBUG')}>&1` - assert_equal o, "true\n" + o = `#{cmd('mruby')} -e #{shellquote('p $DEBUG')}` + assert_equal "false\n", o + o = `#{cmd('mruby')} -d -e #{shellquote('p $DEBUG')}` + assert_equal "true\n", o end -- cgit v1.2.3