Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
uceme
mjtest
Commits
fbdfc829
Commit
fbdfc829
authored
Oct 31, 2016
by
Johannes Bechberger
Browse files
Improve .java test type
parent
dfc94ae0
Changes
4
Hide whitespace changes
Inline
Side-by-side
mjtest/environment.py
View file @
fbdfc829
...
...
@@ -79,14 +79,17 @@ class Environment:
if
not
self
.
own_tmp_dir
:
shutil
.
rmtree
(
self
.
tmp_dir
)
def
run_mj_command
(
self
,
*
args
:
Tuple
[
str
])
->
Tuple
[
bytes
,
bytes
,
int
]:
def
run_mj_command
(
self
,
mode
:
str
,
*
args
:
Tuple
[
str
])
->
Tuple
[
bytes
,
bytes
,
int
]:
"""
Execute the MiniJava `run` script with the given arguments.
:param args: arguments for the MiniJava `run` script
:return: (out, err, return code)
"""
cmd
=
[
self
.
mj_run_cmd
]
+
list
(
args
)
mode_flag
=
{
TestMode
.
syntax
:
"--parsetest"
}[
mode
]
cmd
=
[
self
.
mj_run_cmd
,
mode_flag
]
+
list
(
args
)
return
execute
(
cmd
,
timeout
=
self
.
timeout
)
def
run_command
(
self
,
cmd
:
str
,
*
args
:
Tuple
[
str
])
->
Tuple
[
bytes
,
bytes
,
int
]:
...
...
mjtest/test/syntax_tests.py
View file @
fbdfc829
import
shutil
from
mjtest.environment
import
Environment
,
TestMode
from
mjtest.test.tests
import
TestCase
,
TestResult
,
BasicTestResult
from
mjtest.test.tests
import
TestCase
,
BasicTestResult
from
os
import
path
from
mjtest.util.shell
import
execute
class
BasicSyntaxTest
(
TestCase
):
FILE_ENDINGS
=
[
".invalid.mj"
,
".valid.mj"
,
".mj"
]
MODE
=
TestMode
.
syntax
def
__init__
(
self
,
env
:
Environment
,
type
:
str
,
file
:
str
):
super
().
__init__
(
env
,
type
,
file
)
...
...
@@ -19,7 +20,7 @@ class BasicSyntaxTest(TestCase):
return
path
.
basename
(
self
.
file
)[:
-
3
]
def
run
(
self
)
->
BasicTestResult
:
out
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
"--parsetest "
,
self
.
file
)
out
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
self
.
MODE
,
self
.
file
)
return
BasicTestResult
(
self
,
rtcode
,
out
.
decode
(),
err
.
decode
())
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
syntax
].
append
(
BasicSyntaxTest
)
...
...
@@ -36,7 +37,8 @@ class JavaCompileTest(BasicSyntaxTest):
super
().
__init__
(
env
,
type
,
file
)
tmp_dir
=
self
.
env
.
create_tmpdir
()
_
,
self
.
javac_err
,
self
.
javac_rtcode
=
\
self
.
env
.
run_command
(
"javac"
,
file
,
"-d"
,
tmp_dir
)
self
.
env
.
run_command
(
"javac"
,
path
.
relpath
(
file
),
"-d"
,
tmp_dir
)
shutil
.
rmtree
(
tmp_dir
,
ignore_errors
=
True
)
self
.
_should_succeed
=
self
.
javac_rtcode
==
0
def
short_name
(
self
)
->
str
:
...
...
@@ -44,9 +46,8 @@ class JavaCompileTest(BasicSyntaxTest):
def
run
(
self
)
->
BasicTestResult
:
ret
=
super
().
run
()
ret
.
add_additional_text
(
"javac error output"
,
str
(
self
.
javac_err
))
ret
.
add_additional_text
(
"javac error output"
,
self
.
javac_err
.
decode
(
))
ret
.
add_additional_text_line
(
"javac return code"
,
str
(
self
.
javac_rtcode
))
return
ret
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
syntax
].
append
(
JavaCompileTest
)
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
semantic
].
append
(
JavaCompileTest
)
mjtest/test/tests.py
View file @
fbdfc829
...
...
@@ -108,7 +108,7 @@ class TestSuite:
def
_func
(
self
,
test_case
:
'TestCase'
):
ret
=
self
.
_run_test_case
(
test_case
)
if
ret
.
is_correct
():
if
ret
is
not
False
and
ret
.
is_correct
():
return
0
,
[
test_case
]
return
1
,
[]
...
...
mjtest/util/shell.py
View file @
fbdfc829
# source: https://github.com/libfirm/sisyphus
# source: https://github.com/libfirm/sisyphus
, but slightly modified to support Windows
"""
Convenience function
Alternative to subprocess and os.system
"""
import
shlex
import
subprocess
has_resource_module
=
True
try
:
import
resource
import
resource
except
ImportError
:
has_resource_module
=
False
pass
has_resource_module
=
False
pass
import
sys
import
signal
...
...
@@ -75,6 +76,7 @@ class _Execute(object):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
self
.
env
,
shell
=
True
,
**
prexec_args
)
x
=
self
.
proc
.
communicate
()
self
.
out
,
self
.
err
=
x
...
...
@@ -119,9 +121,11 @@ def execute(cmd, env=None, timeout=0, rlimit=None, propagate_sigint=True):
if
not
rlimit
:
rlimit
=
dict
()
if
cmd
is
str
:
cmd
=
filter
(
lambda
x
:
x
,
cmd
.
split
(
' '
))
pass
#cmd = filter(lambda x: x, cmd.split(' '))
else
:
cmd
=
list
(
filter
(
lambda
x
:
x
,
cmd
[
0
].
split
(
' '
)))
+
cmd
[
1
:]
#cmd = shlex.split(cmd[0]) + cmd[1:]
cmd
=
cmd
[
0
]
+
" "
+
" "
.
join
(
shlex
.
quote
(
c
)
for
c
in
cmd
[
1
:])
exc
=
_Execute
(
cmd
,
timeout
,
env
,
rlimit
)
(
out
,
err
,
returncode
)
=
exc
.
run
()
if
returncode
==
-
signal
.
SIGINT
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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