Codebase list mruby / fc24744
Merge pull request #4017 from mimaki/mruby-d-option Add `-d` option for `mruby` and `mirb`. Yukihiro "Matz" Matsumoto authored 6 years ago GitHub committed 6 years ago
4 changed file(s) with 27 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
99 o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1;b=2;c=3\nb\nc")
1010 assert_true o.include?('=> 3')
1111 end
12
13 assert('mirb -d option') do
14 o, _ = Open3.capture2('bin/mirb', :stdin_data => "p $DEBUG\n")
15 assert_true o.include?('=> false')
16 o, _ = Open3.capture2('bin/mirb -d', :stdin_data => "p $DEBUG\n")
17 assert_true o.include?('=> true')
18 end
5353 #include <mruby/proc.h>
5454 #include <mruby/compile.h>
5555 #include <mruby/string.h>
56 #include <mruby/variable.h>
5657
5758 #ifdef ENABLE_READLINE
5859
218219 struct _args {
219220 FILE *rfp;
220221 mrb_bool verbose : 1;
222 mrb_bool debug : 1;
221223 int argc;
222224 char** argv;
223225 };
227229 {
228230 static const char *const usage_msg[] = {
229231 "switches:",
232 "-d Set $DEBUG to true (same as `mruby -d`)"
230233 "-v print version number, then run in verbose mode",
231234 "--verbose run in verbose mode",
232235 "--version print the version",
253256
254257 item = argv[0] + 1;
255258 switch (*item++) {
259 case 'd':
260 args->debug = TRUE;
261 break;
256262 case 'v':
257263 if (!args->verbose) mrb_show_version(mrb);
258264 args->verbose = TRUE;
412418 }
413419 }
414420 mrb_define_global_const(mrb, "ARGV", ARGV);
421 mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug));
415422
416423 #ifdef ENABLE_READLINE
417424 history_path = get_history_path(mrb);
5757 assert_equal "NilClass", `#{cmd('mruby')} #{script.path}`
5858 assert_equal 0, $?.exitstatus
5959 end
60
61 assert('mruby -d option') do
62 o = `#{cmd('mruby')} -e #{shellquote('p $DEBUG')}`
63 assert_equal "false\n", o
64 o = `#{cmd('mruby')} -d -e #{shellquote('p $DEBUG')}`
65 assert_equal "true\n", o
66 end
2626 mrb_bool mrbfile : 1;
2727 mrb_bool check_syntax : 1;
2828 mrb_bool verbose : 1;
29 mrb_bool debug : 1;
2930 int argc;
3031 char** argv;
3132 };
3738 "switches:",
3839 "-b load and execute RiteBinary (mrb) file",
3940 "-c check syntax only",
41 "-d Set debugging flags (set $DEBUG to true)"
4042 "-e 'command' one line of script",
4143 "-v print version number, then run in verbose mode",
4244 "--verbose run in verbose mode",
7779 case 'c':
7880 args->check_syntax = TRUE;
7981 break;
82 case 'd':
83 args->debug = TRUE;
84 break;
8085 case 'e':
8186 if (item[0]) {
8287 goto append_cmdline;
198203 }
199204 }
200205 mrb_define_global_const(mrb, "ARGV", ARGV);
206 mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug));
201207
202208 c = mrbc_context_new(mrb);
203209 if (args.verbose)