Small fix in `mruby-bin-mruby`
Modify some error messages for consistency.
Add test for codegen error.
Use regular expression for error message matching in test.
MODIFY
mrbgems/mruby-bin-mruby/bintest/mruby.rb
mrbgems/mruby-bin-mruby/bintest/mruby.rb
require 'tempfile'
require 'open3'
-assert_mruby = ->(exp_out_pattern, exp_err_pattern, exp_success, args) do
+assert_mruby = ->(exp_out, exp_err, exp_success, args) do
out, err, stat = Open3.capture3(cmd("mruby"), *args)
- assert_match(exp_out_pattern, out, "standard output")
- assert_match(exp_err_pattern, err, "standard error")
+ assert_operator(exp_out, :===, out, "standard output")
+ assert_operator(exp_err, :===, err, "standard error")
assert_equal(exp_success, stat.success?, "exit success?")
end
assert('regression for #1564') do
- assert_mruby.("", "-e:1:2: syntax error, *", false, %w[-e <<])
- assert_mruby.("", "-e:1:3: syntax error, *", false, %w[-e <<-])
+ assert_mruby.("", /\A-e:1:2: syntax error, .*\n\z/, false, %w[-e <<])
+ assert_mruby.("", /\A-e:1:3: syntax error, .*\n\z/, false, %w[-e <<-])
end
assert('regression for #1572') do
@@ -74,7 +74,7 @@ end
assert('mruby -c option') do
assert_mruby.("Syntax OK\n", "", true, ["-c", "-e", "p 1"])
- assert_mruby.("", "-e:1:7: syntax error, *", false, ["-c", "-e", "p 1; 1."])
+ assert_mruby.("", /\A-e:1:7: syntax error, .*\n\z/, false, ["-c", "-e", "p 1; 1."])
end
assert('mruby -d option') do
@@ -85,11 +85,11 @@ assert('mruby -d option') do
end
assert('mruby -e option (no code specified)') do
- assert_mruby.("", "* No code specified for -e\n", false, %w[-e])
+ assert_mruby.("", /\A.*: No code specified for -e\n\z/, false, %w[-e])
end
assert('mruby -h option') do
- assert_mruby.("Usage: *mruby*", "", true, %w[-h])
+ assert_mruby.(/\AUsage: #{Regexp.escape cmd("mruby")} .*/m, "", true, %w[-h])
end
assert('mruby -r option') do
@@ -116,25 +116,30 @@ EOS
end
assert('mruby -r option (no library specified)') do
- assert_mruby.("", "*: No library specified for -r\n", false, %w[-r])
+ assert_mruby.("", /\A.*: No library specified for -r\n\z/, false, %w[-r])
end
assert('mruby -r option (file not found)') do
- assert_mruby.("", "*: Cannot open library file: *", false, %w[-r _no_exists_])
+ assert_mruby.("", /\A.*: Cannot open library file: .*\n\z/, false, %w[-r _no_exists_])
end
assert('mruby invalid short option') do
- assert_mruby.("", "*: invalid option -1 *", false, %w[-1])
+ assert_mruby.("", /\A.*: invalid option -1 .*\n\z/, false, %w[-1])
end
assert('mruby invalid long option') do
- assert_mruby.("", "*: invalid option --longopt *", false, %w[--longopt])
+ assert_mruby.("", /\A.*: invalid option --longopt .*\n\z/, false, %w[--longopt])
end
assert('unhandled exception') do
- assert_mruby.("", "* EXCEPTION!*", false, %w[-e raise("EXCEPTION!")])
+ assert_mruby.("", /\bEXCEPTION\b.*\n\z/, false, %w[-e raise("EXCEPTION")])
end
assert('program file not found') do
- assert_mruby.("", "*: Cannot open program file*", false, %w[_no_exists_])
+ assert_mruby.("", /\A.*: Cannot open program file: .*\n\z/, false, %w[_no_exists_])
+end
+
+assert('codegen error') do
+ code = "def f(#{(1..100).map{|n| "a#{n}"} * ","}); end"
+ assert_mruby.("", /\Acodegen error:.*\n\z/, false, ["-e", code])
end

MODIFY
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
@@ -158,7 +158,7 @@ append_cmdline:
else {
args->rfp = fopen(argv[0], args->mrbfile ? "rb" : "r");
if (args->rfp == NULL) {
- fprintf(stderr, "%s: Cannot open program file. (%s)\n", *origargv, *argv);
+ fprintf(stderr, "%s: Cannot open program file: %s\n", *origargv, *argv);
return EXIT_FAILURE;
}
args->fname = TRUE;
@@ -285,7 +285,7 @@ main(int argc, char **argv)
n = EXIT_FAILURE;
}
else if (args.check_syntax) {
- printf("Syntax OK\n");
+ puts("Syntax OK");
}
}
cleanup(mrb, &args);

Small fix in `mruby-bin-mruby`

- Modify some error messages for consistency.
- Add test for codegen error.
- Use regular expression for error message matching in test.