Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
25b8ae96
Commit
25b8ae96
authored
May 08, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1239 from bovi/fallback-print
[TestEnv] Fallback print method
parents
8e456308
72f78316
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
23 deletions
+58
-23
test/assert.rb
test/assert.rb
+27
-23
test/driver.c
test/driver.c
+31
-0
No files found.
test/assert.rb
View file @
25b8ae96
...
...
@@ -4,6 +4,20 @@ $kill_test = 0
$asserts
=
[]
$test_start
=
Time
.
now
if
Object
.
const_defined?
(
:Time
)
# Implementation of print due to the reason that there might be no print
def
t_print
(
*
args
)
i
=
0
len
=
args
.
size
while
i
<
len
begin
__printstr__
args
[
i
].
to_s
rescue
NoMethodError
__t_printstr__
args
[
i
].
to_s
end
i
+=
1
end
end
##
# Create the assertion in a readable way
def
assertion_string
(
err
,
str
,
iso
=
nil
,
e
=
nil
)
...
...
@@ -28,31 +42,31 @@ end
# which will be tested by this
# assertion
def
assert
(
str
=
'Assertion failed'
,
iso
=
''
)
print
(
str
,
(
iso
!=
''
?
" [
#{
iso
}
]"
:
''
),
' : '
)
if
$mrbtest_verbose
t_
print
(
str
,
(
iso
!=
''
?
" [
#{
iso
}
]"
:
''
),
' : '
)
if
$mrbtest_verbose
begin
$mrbtest_assert
=
[]
$mrbtest_assert_idx
=
0
if
(
!
yield
||
$mrbtest_assert
.
size
>
0
)
$asserts
.
push
(
assertion_string
(
'Fail: '
,
str
,
iso
,
nil
))
$ko_test
+=
1
print
(
'F'
)
t_
print
(
'F'
)
else
$ok_test
+=
1
print
(
'.'
)
t_
print
(
'.'
)
end
rescue
Exception
=>
e
if
e
.
class
.
to_s
==
'MRubyTestSkip'
$asserts
.
push
"Skip:
#{
str
}
#{
iso
}
#{
e
.
cause
}
"
print
(
'?'
)
t_
print
(
'?'
)
else
$asserts
.
push
(
assertion_string
(
'Error: '
,
str
,
iso
,
e
))
$kill_test
+=
1
print
(
'X'
)
t_
print
(
'X'
)
end
ensure
$mrbtest_assert
=
nil
end
print
(
"
\n
"
)
if
$mrbtest_verbose
t_
print
(
"
\n
"
)
if
$mrbtest_verbose
end
def
assertion_diff
(
exp
,
act
)
...
...
@@ -125,31 +139,21 @@ end
# Report the test result and print all assertions
# which were reported broken.
def
report
()
print
"
\n
"
t_print
(
"
\n
"
)
$asserts
.
each
do
|
msg
|
puts
msg
end
$total_test
=
$ok_test
.
+
(
$ko_test
)
print
(
'Total: '
)
print
(
$total_test
)
print
(
"
\n
"
)
print
(
' OK: '
)
print
(
$ok_test
)
print
(
"
\n
"
)
print
(
' KO: '
)
print
(
$ko_test
)
print
(
"
\n
"
)
print
(
'Crash: '
)
print
(
$kill_test
)
print
(
"
\n
"
)
t_print
(
"Total:
#{
$total_test
}
\n
"
)
t_print
(
" OK:
#{
$ok_test
}
\n
"
)
t_print
(
" KO:
#{
$ko_test
}
\n
"
)
t_print
(
"Crash:
#{
$kill_test
}
\n
"
)
if
Object
.
const_defined?
(
:Time
)
print
(
' Time: '
)
print
(
Time
.
now
-
$test_start
)
print
(
" seconds
\n
"
)
t_print
(
" Time:
#{
Time
.
now
-
$test_start
}
seconds
\n
"
)
end
end
...
...
test/driver.c
View file @
25b8ae96
...
...
@@ -14,6 +14,7 @@
#include <mruby/proc.h>
#include <mruby/data.h>
#include <mruby/compile.h>
#include <mruby/string.h>
#include <mruby/variable.h>
void
...
...
@@ -59,10 +60,37 @@ eval_test(mrb_state *mrb)
return
EXIT_SUCCESS
;
}
static
void
t_printstr
(
mrb_state
*
mrb
,
mrb_value
obj
)
{
struct
RString
*
str
;
char
*
s
;
int
len
;
if
(
mrb_string_p
(
obj
))
{
str
=
mrb_str_ptr
(
obj
);
s
=
str
->
ptr
;
len
=
str
->
len
;
fwrite
(
s
,
len
,
1
,
stdout
);
}
}
mrb_value
mrb_t_printstr
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
argv
;
mrb_get_args
(
mrb
,
"o"
,
&
argv
);
t_printstr
(
mrb
,
argv
);
return
argv
;
}
int
main
(
int
argc
,
char
**
argv
)
{
mrb_state
*
mrb
;
struct
RClass
*
krn
;
int
ret
;
print_hint
();
...
...
@@ -79,6 +107,9 @@ main(int argc, char **argv)
mrb_gv_set
(
mrb
,
mrb_intern
(
mrb
,
"$mrbtest_verbose"
),
mrb_true_value
());
}
krn
=
mrb
->
kernel_module
;
mrb_define_method
(
mrb
,
krn
,
"__t_printstr__"
,
mrb_t_printstr
,
MRB_ARGS_REQ
(
1
));
mrb_init_mrbtest
(
mrb
);
ret
=
eval_test
(
mrb
);
mrb_close
(
mrb
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment