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
70ac960b
Commit
70ac960b
authored
Nov 27, 2016
by
Johannes Bechberger
Browse files
Start implementing the `--compile-firm` mode
parent
eb0f021b
Changes
2
Hide whitespace changes
Inline
Side-by-side
mjtest/environment.py
View file @
70ac960b
...
...
@@ -23,6 +23,8 @@ class TestMode:
semantic
=
"semantic"
comile_firm
=
"compile-firm"
exec
=
"exec"
USE_TESTS_OF_OTHER
=
{
...
...
@@ -30,7 +32,7 @@ class TestMode:
}
""" All 'success' tests of the n.th mode can used as 'success' tests for the n-1.th mode"""
TEST_MODES
=
[
TestMode
.
lexer
,
TestMode
.
syntax
,
TestMode
.
ast
,
TestMode
.
semantic
,
TestMode
.
exec
]
TEST_MODES
=
[
TestMode
.
lexer
,
TestMode
.
syntax
,
TestMode
.
ast
,
TestMode
.
semantic
,
TestMode
.
comile_firm
,
TestMode
.
exec
]
class
Environment
:
...
...
@@ -118,7 +120,8 @@ class Environment:
TestMode
.
lexer
:
"--lextest"
,
TestMode
.
syntax
:
"--parsetest"
,
TestMode
.
ast
:
"--print-ast"
,
TestMode
.
semantic
:
"--check"
TestMode
.
semantic
:
"--check"
,
TestMode
.
comile_firm
:
"--compile-firm"
}[
mode
]
cmd
=
[
self
.
mj_run_cmd
,
mode_flag
]
+
list
(
args
)
return
execute
(
cmd
,
timeout
=
self
.
timeout
)
...
...
mjtest/test/exec_tests.py
0 → 100644
View file @
70ac960b
import
logging
import
os
import
shutil
from
os
import
path
import
sys
from
mjtest.environment
import
TestMode
,
Environment
from
mjtest.test.syntax_tests
import
BasicSyntaxTest
from
mjtest.test.tests
import
TestCase
,
BasicDiffTestResult
,
BasicTestResult
_LOG
=
logging
.
getLogger
(
"exec_tests"
)
class
JavaExecTest
(
BasicSyntaxTest
):
"""
The MiniJava compiler should behave the same as javac
"""
FILE_ENDINGS
=
[
".java"
]
OUTPUT_FILE_ENDING
=
".out"
MODE
=
TestMode
.
comile_firm
def
__init__
(
self
,
env
:
Environment
,
type
:
str
,
file
:
str
,
preprocessed_file
:
str
):
super
().
__init__
(
env
,
type
,
file
,
preprocessed_file
)
self
.
_expected_output_file
=
file
+
self
.
OUTPUT_FILE_ENDING
self
.
_has_expected_output_file
=
path
.
exists
(
self
.
_expected_output_file
)
self
.
_should_succeed
=
True
def
run
(
self
)
->
BasicDiffTestResult
:
base_filename
=
path
.
basename
(
self
.
file
).
split
(
"."
)[
0
]
tmp_dir
=
self
.
env
.
create_tmpdir
()
shutil
.
copy
(
self
.
preprocessed_file
,
path
.
join
(
tmp_dir
,
base_filename
+
".java"
))
cwd
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
exp_out
=
None
if
not
self
.
_has_expected_output_file
:
_
,
_
,
javac_rtcode
=
\
self
.
env
.
run_command
(
"javac"
,
base_filename
+
".java"
)
if
javac_rtcode
!=
0
:
_LOG
.
error
(
"File
\"
{}
\"
isn't valid Java"
.
format
(
self
.
preprocessed_file
))
raise
InterruptedError
()
exp_out
,
_
,
_
=
\
self
.
env
.
run_command
(
"java"
,
base_filename
)
if
self
.
_has_expected_output_file
and
self
.
type
==
self
.
MODE
and
self
.
env
.
mode
==
self
.
MODE
:
with
open
(
self
.
_expected_output_file
,
"r"
)
as
f
:
exp_out
=
f
.
read
()
_
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
self
.
MODE
,
base_filename
+
".java"
)
out
,
_
,
_
=
self
.
env
.
run_command
(
base_filename
)
os
.
chdir
(
cwd
)
if
self
.
type
==
self
.
MODE
and
self
.
env
.
mode
==
self
.
MODE
:
return
BasicDiffTestResult
(
self
,
rtcode
,
out
.
decode
(),
err
.
decode
(),
exp_out
)
return
BasicTestResult
(
self
,
rtcode
,
out
.
decode
(),
err
.
decode
())
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
comile_firm
].
append
(
JavaExecTest
)
\ No newline at end of file
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