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
9 | 9 |
o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1;b=2;c=3\nb\nc")
|
10 | 10 |
assert_true o.include?('=> 3')
|
11 | 11 |
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
|
53 | 53 |
#include <mruby/proc.h>
|
54 | 54 |
#include <mruby/compile.h>
|
55 | 55 |
#include <mruby/string.h>
|
|
56 |
#include <mruby/variable.h>
|
56 | 57 |
|
57 | 58 |
#ifdef ENABLE_READLINE
|
58 | 59 |
|
|
218 | 219 |
struct _args {
|
219 | 220 |
FILE *rfp;
|
220 | 221 |
mrb_bool verbose : 1;
|
|
222 |
mrb_bool debug : 1;
|
221 | 223 |
int argc;
|
222 | 224 |
char** argv;
|
223 | 225 |
};
|
|
227 | 229 |
{
|
228 | 230 |
static const char *const usage_msg[] = {
|
229 | 231 |
"switches:",
|
|
232 |
"-d Set $DEBUG to true (same as `mruby -d`)"
|
230 | 233 |
"-v print version number, then run in verbose mode",
|
231 | 234 |
"--verbose run in verbose mode",
|
232 | 235 |
"--version print the version",
|
|
253 | 256 |
|
254 | 257 |
item = argv[0] + 1;
|
255 | 258 |
switch (*item++) {
|
|
259 |
case 'd':
|
|
260 |
args->debug = TRUE;
|
|
261 |
break;
|
256 | 262 |
case 'v':
|
257 | 263 |
if (!args->verbose) mrb_show_version(mrb);
|
258 | 264 |
args->verbose = TRUE;
|
|
412 | 418 |
}
|
413 | 419 |
}
|
414 | 420 |
mrb_define_global_const(mrb, "ARGV", ARGV);
|
|
421 |
mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug));
|
415 | 422 |
|
416 | 423 |
#ifdef ENABLE_READLINE
|
417 | 424 |
history_path = get_history_path(mrb);
|
57 | 57 |
assert_equal "NilClass", `#{cmd('mruby')} #{script.path}`
|
58 | 58 |
assert_equal 0, $?.exitstatus
|
59 | 59 |
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
|
26 | 26 |
mrb_bool mrbfile : 1;
|
27 | 27 |
mrb_bool check_syntax : 1;
|
28 | 28 |
mrb_bool verbose : 1;
|
|
29 |
mrb_bool debug : 1;
|
29 | 30 |
int argc;
|
30 | 31 |
char** argv;
|
31 | 32 |
};
|
|
37 | 38 |
"switches:",
|
38 | 39 |
"-b load and execute RiteBinary (mrb) file",
|
39 | 40 |
"-c check syntax only",
|
|
41 |
"-d Set debugging flags (set $DEBUG to true)"
|
40 | 42 |
"-e 'command' one line of script",
|
41 | 43 |
"-v print version number, then run in verbose mode",
|
42 | 44 |
"--verbose run in verbose mode",
|
|
77 | 79 |
case 'c':
|
78 | 80 |
args->check_syntax = TRUE;
|
79 | 81 |
break;
|
|
82 |
case 'd':
|
|
83 |
args->debug = TRUE;
|
|
84 |
break;
|
80 | 85 |
case 'e':
|
81 | 86 |
if (item[0]) {
|
82 | 87 |
goto append_cmdline;
|
|
198 | 203 |
}
|
199 | 204 |
}
|
200 | 205 |
mrb_define_global_const(mrb, "ARGV", ARGV);
|
|
206 |
mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug));
|
201 | 207 |
|
202 | 208 |
c = mrbc_context_new(mrb);
|
203 | 209 |
if (args.verbose)
|