Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ufebl
mjtest
Commits
3040b097
Commit
3040b097
authored
Nov 30, 2016
by
Johannes Bechberger
Browse files
Fix `compile-firm` mode (error code) bug
parent
7c898e5c
Changes
4
Hide whitespace changes
Inline
Side-by-side
mjtest/test/exec_tests.py
View file @
3040b097
...
...
@@ -56,22 +56,26 @@ class JavaExecTest(BasicSyntaxTest):
if
javac_rtcode
!=
0
:
_LOG
.
error
(
"File
\"
{}
\"
isn't valid Java"
.
format
(
self
.
preprocessed_file
))
test_result
.
incorrect_msg
=
"invalid java code, but output file missing"
test_result
.
error_code
=
javac_rtcode
test_result
.
set_
error_code
(
javac_rtcode
)
test_result
.
add_long_text
(
"Javac error message"
,
err
.
decode
())
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
os
.
chdir
(
cwd
)
return
test_result
main_class
=
get_main_class_name
(
base_filename
+
".java"
)
if
not
main_class
:
_LOG
.
debug
(
"Can't find a main class, using the file name instead"
)
main_class
=
base_filename
exp_out
,
err
,
java_rtcode
=
\
self
.
env
.
run_command
(
"java"
,
get_main_class_name
(
base_filename
+
".java"
))
test_result
.
add_long_text
(
"Java output: "
,
exp_out
.
decode
())
if
javac_rtcode
!=
0
:
test_result
.
incorrect_msg
=
"java runtime error"
test_result
.
error_code
=
java_rtcode
test_result
.
set_
error_code
(
java_rtcode
)
test_result
.
add_long_text
(
"Java error message"
,
err
.
decode
())
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
os
.
chdir
(
cwd
)
return
test_result
exp_out
=
exp_out
.
decode
()
.
strip
()
exp_out
=
exp_out
.
decode
()
with
open
(
self
.
_prev_out_file
,
"w"
)
as
f
:
f
.
write
(
exp_out
)
...
...
@@ -90,7 +94,7 @@ class JavaExecTest(BasicSyntaxTest):
out
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
self
.
MODE
,
base_filename
+
".java"
)
if
rtcode
!=
0
:
test_result
.
incorrect_msg
=
"file can't be compiled"
test_result
.
error_code
=
rtcode
test_result
.
set_
error_code
(
rtcode
)
test_result
.
add_long_text
(
"Error output"
,
err
.
decode
())
test_result
.
add_long_text
(
"Output"
,
out
.
decode
())
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
...
...
@@ -98,7 +102,7 @@ class JavaExecTest(BasicSyntaxTest):
return
test_result
except
SigKill
as
sig
:
test_result
.
incorrect_msg
=
"file can't be compiled: "
+
sig
.
name
test_result
.
error_code
=
sig
.
retcode
test_result
.
set_
error_code
(
sig
.
retcode
)
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
os
.
chdir
(
cwd
)
return
test_result
...
...
@@ -106,31 +110,23 @@ class JavaExecTest(BasicSyntaxTest):
os
.
chdir
(
cwd
)
raise
try
:
out
,
err
,
rtcode
=
self
.
env
.
run_command
(
"./"
+
base_filename
)
if
rtcode
!=
0
:
test_result
.
incorrect_msg
=
"file can't be run"
test_result
.
error_code
=
rtcode
test_result
.
add_long_text
(
"Error output"
,
err
.
decode
())
test_result
.
add_long_text
(
"Output"
,
out
.
decode
())
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
os
.
chdir
(
cwd
)
return
test_result
out
,
err
,
_
=
self
.
env
.
run_command
(
"./"
+
base_filename
)
except
SigKill
as
sig
:
test_result
.
incorrect_msg
=
"binary can't be run: "
+
sig
.
name
test_result
.
error_code
=
sig
.
retcode
test_result
.
incorrect_msg
=
"binary can't be run: "
+
sig
.
name
.
strip
()
test_result
.
set_
error_code
(
sig
.
retcode
)
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
os
.
chdir
(
cwd
)
return
test_result
except
:
os
.
chdir
(
cwd
)
raise
out
=
out
.
decode
()
.
strip
()
out
=
out
.
decode
()
if
self
.
type
==
self
.
MODE
and
self
.
env
.
mode
==
self
.
MODE
:
test_result
.
add_long_text
(
"Output"
,
out
.
decode
()
)
test_result
.
add_long_text
(
"Output"
,
out
)
if
exp_out
.
strip
()
!=
out
.
strip
():
test_result
.
incorrect_msg
=
"incorrect output"
test_result
.
has_succeeded
=
False
test_result
.
add_diff
(
"Output diff [expected <-> actual]"
,
exp_out
,
out
)
test_result
.
add_diff
(
"Output diff [expected <-> actual]"
,
exp_out
,
out
,
with_line_numbers
=
True
)
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
os
.
chdir
(
cwd
)
return
test_result
...
...
@@ -181,7 +177,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
out
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
self
.
MODE
,
base_filename
+
".java"
)
if
rtcode
!=
0
:
test_result
.
incorrect_msg
=
"file can't be compiled"
test_result
.
error_code
=
rtcode
test_result
.
set_
error_code
(
rtcode
)
test_result
.
add_long_text
(
"Error output"
,
err
.
decode
())
test_result
.
add_long_text
(
"Output"
,
out
.
decode
())
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
...
...
@@ -189,8 +185,8 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
return
test_result
out
,
err
,
rtcode
=
self
.
env
.
run_command
(
"./"
+
base_filename
,
timeout
=
timeout
)
if
rtcode
!=
0
:
test_result
.
incorrect_msg
=
"
file
can't be run"
test_result
.
error_code
=
rtcode
test_result
.
incorrect_msg
=
"
binary
can't be run"
test_result
.
set_
error_code
(
rtcode
)
test_result
.
add_long_text
(
"Error output"
,
err
.
decode
())
test_result
.
add_long_text
(
"Output"
,
out
.
decode
())
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
...
...
@@ -217,7 +213,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
return
test_result
else
:
test_result
.
incorrect_msg
=
"binary can't be run: "
+
sig
.
name
test_result
.
error_code
=
sig
.
retcode
test_result
.
set_
error_code
(
sig
.
retcode
)
test_result
.
add_file
(
"Source file"
,
self
.
preprocessed_file
)
os
.
chdir
(
cwd
)
return
test_result
...
...
mjtest/test/tests.py
View file @
3040b097
...
...
@@ -367,6 +367,9 @@ class ExtensibleTestResult(TestResult):
self
.
add_long_text
(
title
,
""
.
join
(
difflib
.
Differ
().
compare
(
first
.
splitlines
(
True
),
second
.
splitlines
(
True
))),
with_line_numbers
=
with_line_numbers
)
def
set_error_code
(
self
,
error_code
:
int
):
self
.
has_succeeded
=
error_code
==
0
self
.
error_code
=
error_code
class
TestResultMessage
:
...
...
mjtest/util/shell.py
View file @
3040b097
...
...
@@ -87,7 +87,7 @@ class _Execute(object):
def
run
(
self
):
if
self
.
timeout
>
0.0
:
_LOG
.
debug
(
"run with timeout %.1f"
%
float
(
self
.
timeout
))
_LOG
.
debug
(
"run with timeout %.1f
: %s
"
%
(
float
(
self
.
timeout
)
,
self
.
cmd
)
)
thread
=
threading
.
Thread
(
target
=
self
.
_run_process
)
thread
.
start
()
thread
.
join
(
float
(
self
.
timeout
))
...
...
mjtest/util/utils.py
View file @
3040b097
...
...
@@ -49,8 +49,8 @@ def get_main_class_name(file: str) -> Optional[str]:
current_class
=
None
with
open
(
file
,
"r"
)
as
f
:
for
line
in
f
:
if
line
.
startswith
(
"class "
):
match
=
re
.
search
(
"[A-Za-z_0-9]+"
,
line
.
replace
(
"class "
,
""
))
if
line
.
startswith
(
"class
"
)
or
line
.
startswith
(
"/*public*/ class
"
):
match
=
re
.
search
(
"[A-Za-z_0-9]+"
,
line
.
replace
(
"class "
,
""
).
replace
(
"/*public*/"
,
""
))
if
match
:
has_public_class
=
True
current_class
=
match
.
group
(
0
)
...
...
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