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
cf697240
Unverified
Commit
cf697240
authored
Jun 29, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jun 29, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4540 from dearblue/assert-nesting
Nested `assert` for mrbtest
parents
ff5ec824
a215292b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
128 additions
and
45 deletions
+128
-45
mrbgems/mruby-bin-mruby/bintest/mruby.rb
mrbgems/mruby-bin-mruby/bintest/mruby.rb
+5
-3
mrbgems/mruby-complex/test/complex.rb
mrbgems/mruby-complex/test/complex.rb
+4
-2
mrbgems/mruby-io/test/io.rb
mrbgems/mruby-io/test/io.rb
+21
-19
mrbgems/mruby-pack/test/pack.rb
mrbgems/mruby-pack/test/pack.rb
+4
-2
mrbgems/mruby-rational/test/rational.rb
mrbgems/mruby-rational/test/rational.rb
+12
-8
test/assert.rb
test/assert.rb
+82
-11
No files found.
mrbgems/mruby-bin-mruby/bintest/mruby.rb
View file @
cf697240
...
...
@@ -3,9 +3,11 @@ require 'open3'
def
assert_mruby
(
exp_out
,
exp_err
,
exp_success
,
args
)
out
,
err
,
stat
=
Open3
.
capture3
(
cmd
(
"mruby"
),
*
args
)
assert
do
assert_operator
(
exp_out
,
:===
,
out
,
"standard output"
)
assert_operator
(
exp_err
,
:===
,
err
,
"standard error"
)
assert_equal
(
exp_success
,
stat
.
success?
,
"exit success?"
)
end
end
assert
(
'regression for #1564'
)
do
...
...
mrbgems/mruby-complex/test/complex.rb
View file @
cf697240
def
assert_complex
(
real
,
exp
)
assert
do
assert_float
real
.
real
,
exp
.
real
assert_float
real
.
imaginary
,
exp
.
imaginary
end
end
assert
'Complex'
do
...
...
mrbgems/mruby-io/test/io.rb
View file @
cf697240
...
...
@@ -4,7 +4,8 @@
MRubyIOTestUtil
.
io_test_setup
$cr
,
$crlf
,
$cmd
=
MRubyIOTestUtil
.
win?
?
[
1
,
"
\r\n
"
,
"cmd /c "
]
:
[
0
,
"
\n
"
,
""
]
assert_io_open
=
->
(
meth
)
do
def
assert_io_open
(
meth
)
assert
do
fd
=
IO
.
sysopen
(
$mrbtest_io_rfname
)
assert_equal
Fixnum
,
fd
.
class
io1
=
IO
.
__send__
(
meth
,
fd
)
...
...
@@ -23,6 +24,7 @@ assert_io_open = ->(meth) do
end
end
io2
.
close
unless
meth
==
:open
end
end
assert
(
'IO.class'
,
'15.2.20'
)
do
...
...
@@ -38,7 +40,7 @@ assert('IO.ancestors', '15.2.20.3') do
end
assert
(
'IO.open'
,
'15.2.20.4.1'
)
do
assert_io_open
.
(
:open
)
assert_io_open
(
:open
)
end
assert
(
'IO#close'
,
'15.2.20.5.1'
)
do
...
...
@@ -224,11 +226,11 @@ assert('IO#dup for writable') do
end
assert
(
'IO.for_fd'
)
do
assert_io_open
.
(
:for_fd
)
assert_io_open
(
:for_fd
)
end
assert
(
'IO.new'
)
do
assert_io_open
.
(
:new
)
assert_io_open
(
:new
)
end
assert
(
'IO gc check'
)
do
...
...
mrbgems/mruby-pack/test/pack.rb
View file @
cf697240
...
...
@@ -2,8 +2,10 @@ PACK_IS_LITTLE_ENDIAN = "\x01\00".unpack('S')[0] == 0x01
def
assert_pack
tmpl
,
packed
,
unpacked
t
=
tmpl
.
inspect
assert
do
assert_equal
packed
,
unpacked
.
pack
(
tmpl
),
"
#{
unpacked
.
inspect
}
.pack(
#{
t
}
)"
assert_equal
unpacked
,
packed
.
unpack
(
tmpl
),
"
#{
packed
.
inspect
}
.unpack(
#{
t
}
)"
end
end
# pack & unpack 'm' (base64)
...
...
mrbgems/mruby-rational/test/rational.rb
View file @
cf697240
...
...
@@ -23,11 +23,14 @@ class ComplexLikeNumeric < UserDefinedNumeric
end
def
assert_rational
(
exp
,
real
)
assert
do
assert_float
exp
.
numerator
,
real
.
numerator
assert_float
exp
.
denominator
,
real
.
denominator
end
end
def
assert_equal_rational
(
exp
,
o1
,
o2
)
assert
do
if
exp
assert_operator
(
o1
,
:==
,
o2
)
assert_not_operator
(
o1
,
:
!=
,
o2
)
...
...
@@ -35,6 +38,7 @@ def assert_equal_rational(exp, o1, o2)
assert_not_operator
(
o1
,
:==
,
o2
)
assert_operator
(
o1
,
:
!=
,
o2
)
end
end
end
def
assert_cmp
(
exp
,
o1
,
o2
)
...
...
test/assert.rb
View file @
cf697240
...
...
@@ -15,6 +15,36 @@ unless RUBY_ENGINE == "mruby"
end
end
class
Array
def
_assertion_join
join
(
"-"
)
end
end
class
String
def
_assertion_indent
(
indent
)
indent
=
indent
.
to_s
off
=
0
str
=
self
while
nl
=
index
(
"
\n
"
,
off
)
nl
+=
1
nl
+=
1
while
slice
(
nl
)
==
"
\n
"
break
if
nl
>=
size
str
=
indent
.
dup
if
off
==
0
str
+=
slice
(
off
,
nl
-
off
)
+
indent
off
=
nl
end
if
off
==
0
str
=
indent
+
self
else
str
+=
slice
(
off
..-
1
)
end
str
end
end
##
# Create the assertion in a readable way
def
assertion_string
(
err
,
str
,
iso
=
nil
,
e
=
nil
,
bt
=
nil
)
...
...
@@ -22,14 +52,14 @@ def assertion_string(err, str, iso=nil, e=nil, bt=nil)
msg
+=
" [
#{
iso
}
]"
if
iso
&&
!
iso
.
empty?
msg
+=
" =>
#{
e
}
"
if
e
&&
!
e
.
to_s
.
empty?
msg
+=
" (
#{
GEMNAME
==
'mruby-test'
?
'core'
:
"mrbgems:
#{
GEMNAME
}
"
}
)"
if
$mrbtest_assert
&&
$mrbtest_assert
.
size
>
0
if
$mrbtest_assert
$mrbtest_assert
.
each
do
|
idx
,
assert_msg
,
diff
|
msg
+=
"
\n
- Assertion[
#{
idx
}
]"
msg
+=
"
#{
assert_msg
}
."
if
assert_msg
&&
!
assert_msg
.
empty?
msg
+=
"
\n
#{
diff
}
"
if
diff
&&
!
diff
.
empty?
end
end
msg
+=
"
\n
backtrace:
\n
\t
#{
bt
.
join
(
"
\n\t
"
)
}
"
if
bt
msg
+=
"
\n
backtrace:
\n
#{
bt
.
join
(
"
\n
"
)
}
"
if
bt
msg
end
...
...
@@ -44,13 +74,35 @@ end
def
assert
(
str
=
'Assertion failed'
,
iso
=
''
)
t_print
(
str
,
(
iso
!=
''
?
" [
#{
iso
}
]"
:
''
),
' : '
)
if
$mrbtest_verbose
begin
$mrbtest_child_noassert
||=
[
0
]
$mrbtest_child_noassert
<<
0
parent_asserts
=
$asserts
$asserts
=
[]
parent_mrbtest_assert
=
$mrbtest_assert
$mrbtest_assert
=
[]
$mrbtest_assert_idx
=
0
if
$mrbtest_assert_idx
&&
!
$mrbtest_assert_idx
.
empty?
$mrbtest_assert_idx
[
-
1
]
+=
1
$mrbtest_assert_idx
<<
0
else
$mrbtest_assert_idx
=
[
0
]
class
<<
$mrbtest_assert_idx
alias
to_s
_assertion_join
end
end
yield
if
(
$mrbtest_assert
.
size
>
0
)
if
$mrbtest_assert
.
size
>
0
if
$mrbtest_assert
.
size
==
$mrbtest_child_noassert
[
-
1
]
$asserts
.
push
(
assertion_string
(
'Info: '
,
str
,
iso
))
$mrbtest_child_noassert
[
-
2
]
+=
1
$ok_test
+=
1
t_print
(
'.'
)
else
$asserts
.
push
(
assertion_string
(
'Fail: '
,
str
,
iso
))
$ko_test
+=
1
t_print
(
'F'
)
end
else
$ok_test
+=
1
t_print
(
'.'
)
...
...
@@ -58,6 +110,7 @@ def assert(str = 'Assertion failed', iso = '')
rescue
MRubyTestSkip
=>
e
$asserts
.
push
(
assertion_string
(
'Skip: '
,
str
,
iso
,
e
))
$skip_test
+=
1
$mrbtest_child_noassert
[
-
2
]
+=
1
t_print
(
'?'
)
rescue
Exception
=>
e
bt
=
e
.
backtrace
if
$mrbtest_verbose
...
...
@@ -65,7 +118,25 @@ def assert(str = 'Assertion failed', iso = '')
$kill_test
+=
1
t_print
(
'X'
)
ensure
$mrbtest_assert
=
nil
if
$mrbtest_assert_idx
.
size
>
1
$asserts
.
each
do
|
mesg
|
idx
=
$mrbtest_assert_idx
[
0
..-
2
].
_assertion_join
mesg
=
mesg
.
_assertion_indent
(
" "
)
# Give `mesg` as a `diff` argument to avoid adding extra periods.
parent_mrbtest_assert
<<
[
idx
,
nil
,
mesg
]
end
else
parent_asserts
.
concat
$asserts
end
$asserts
=
parent_asserts
$mrbtest_assert
=
parent_mrbtest_assert
$mrbtest_assert_idx
.
pop
$mrbtest_assert_idx
=
nil
if
$mrbtest_assert_idx
.
empty?
$mrbtest_child_noassert
.
pop
nil
end
t_print
(
"
\n
"
)
if
$mrbtest_verbose
end
...
...
@@ -76,11 +147,11 @@ def assertion_diff(exp, act)
end
def
assert_true
(
obj
,
msg
=
nil
,
diff
=
nil
)
if
$mrbtest_assert
$mrbtest_assert_idx
+=
1
if
$mrbtest_assert
_idx
&&
$mrbtest_assert_idx
.
size
>
0
$mrbtest_assert_idx
[
-
1
]
+=
1
unless
obj
==
true
diff
||=
" Expected
#{
obj
.
inspect
}
to be true."
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
,
msg
,
diff
])
$mrbtest_assert
.
push
([
$mrbtest_assert_idx
.
to_s
,
msg
,
diff
])
end
end
obj
...
...
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