Browse files

refactor test driver

  • Loading branch information...
1 parent 332565e commit 8846f75ecccf701009fb191207b64ef996544ad8 @matz matz committed May 18, 2012
Showing with 17 additions and 12 deletions.
  1. +13 −12 test/driver.c
  2. +4 −0 test/init_mrbtest.c
View
25 test/driver.c
@@ -27,29 +27,30 @@ int
main(void)
{
struct mrb_parser_state *parser;
- mrb_state *mrb_interpreter;
- mrb_value mrb_return_value;
+ mrb_state *mrb;
+ mrb_value return_value;
int byte_code;
+ const char *prog = "report()";
print_hint();
/* new interpreter instance */
- mrb_interpreter = mrb_open();
- mrb_init_mrbtest(mrb_interpreter);
- parser = mrb_parse_nstring_ext(mrb_interpreter, "report()", strlen("report()"));
+ mrb = mrb_open();
+ mrb_init_mrbtest(mrb);
+ parser = mrb_parse_nstring(mrb, prog, strlen(prog));
/* generate bytecode */
- byte_code = mrb_generate_code(mrb_interpreter, parser->tree);
+ byte_code = mrb_generate_code(mrb, parser->tree);
/* evaluate the bytecode */
- mrb_return_value = mrb_run(mrb_interpreter,
+ return_value = mrb_run(mrb,
/* pass a proc for evaulation */
- mrb_proc_new(mrb_interpreter, mrb_interpreter->irep[byte_code]),
- mrb_top_self(mrb_interpreter));
+ mrb_proc_new(mrb, mrb->irep[byte_code]),
+ mrb_top_self(mrb));
/* did an exception occur? */
- if (mrb_interpreter->exc) {
- mrb_p(mrb_interpreter, mrb_return_value);
- mrb_interpreter->exc = 0;
+ if (mrb->exc) {
+ mrb_p(mrb, return_value);
+ mrb->exc = 0;
}
else {
/* no */
View
4 test/init_mrbtest.c
@@ -12,5 +12,9 @@ mrb_init_mrbtest(mrb_state *mrb)
int n = mrb_read_irep(mrb, mrbtest_irep);
mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
+ if (mrb->exc) {
+ mrb_p(mrb, mrb_obj_value(mrb->exc));
+ exit(0);
+ }
}

0 comments on commit 8846f75

Please sign in to comment.