Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
IPDSnelting
mjtest
Commits
f17b62b1
Commit
f17b62b1
authored
Oct 31, 2016
by
Johannes Bechberger
Browse files
Improve .java test type
parent
fbdfc829
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.mdwn
View file @
f17b62b1
...
...
@@ -39,7 +39,7 @@ Test types for the syntax mode
</tr>
<tr>
<td><code>.java</code>
<td>If <code>javac</code> accepts the syntax
(and semantic)
of the file then the MiniJava compiler
<td>If <code>javac</code> accepts the syntax of the file then the MiniJava compiler
should accept its syntax too.</td>
</tr>
</table>
...
...
mjtest/test/syntax_tests.py
View file @
f17b62b1
...
...
@@ -32,22 +32,28 @@ class JavaCompileTest(BasicSyntaxTest):
"""
FILE_ENDINGS
=
[
".java"
]
SYNTAX_TEST
=
True
def
__init__
(
self
,
env
:
Environment
,
type
:
str
,
file
:
str
):
super
().
__init__
(
env
,
type
,
file
)
tmp_dir
=
self
.
env
.
create_tmpdir
()
_
,
self
.
javac_err
,
self
.
javac_rtcode
=
\
self
.
env
.
run_command
(
"javac"
,
path
.
relpath
(
file
),
"-d"
,
tmp_dir
)
self
.
env
.
run_command
(
"javac"
,
path
.
relpath
(
file
),
"-d"
,
tmp_dir
,
"-verbose"
)
self
.
javac_err
=
self
.
javac_err
.
decode
()
# type: str
shutil
.
rmtree
(
tmp_dir
,
ignore_errors
=
True
)
self
.
_should_succeed
=
self
.
javac_rtcode
==
0
self
.
_should_succeed
=
self
.
_is_file_syntactically_correct
()
if
self
.
SYNTAX_TEST
else
self
.
javac_rtcode
==
0
def
short_name
(
self
)
->
str
:
return
path
.
basename
(
self
.
file
)
def
_is_file_syntactically_correct
(
self
):
return
self
.
javac_rtcode
==
0
or
"META-INF"
in
self
.
javac_err
def
_is_file_semantically_correct
(
self
):
return
self
.
javac_rtcode
==
0
def
run
(
self
)
->
BasicTestResult
:
ret
=
super
().
run
()
ret
.
add_additional_text
(
"javac error output"
,
self
.
javac_err
.
decode
()
)
ret
.
add_additional_text
(
"javac
(verbose)
error output"
,
self
.
javac_err
)
ret
.
add_additional_text_line
(
"javac return code"
,
str
(
self
.
javac_rtcode
))
ret
.
add_additional_text_line
(
"Is syntax correct? "
,
str
(
self
.
_is_file_syntactically_correct
()))
return
ret
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
syntax
].
append
(
JavaCompileTest
)
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