Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mjtest
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
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
ufebl
mjtest
Commits
20db85ed
Commit
20db85ed
authored
Nov 28, 2016
by
Johannes Bechberger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto detect main class in `compile-firm` mode
parent
aba4af12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
18 deletions
+38
-18
mjtest/environment.py
mjtest/environment.py
+3
-2
mjtest/test/exec_tests.py
mjtest/test/exec_tests.py
+18
-14
mjtest/util/utils.py
mjtest/util/utils.py
+17
-2
No files found.
mjtest/environment.py
View file @
20db85ed
...
...
@@ -30,7 +30,8 @@ class TestMode:
exec
=
"exec"
USE_TESTS_OF_OTHER
=
{
ast
:
[
syntax
]
ast
:
[
syntax
],
compile_firm
:
[
exec
]
}
""" All 'success' tests of the n.th mode can used as 'success' tests for the n-1.th mode"""
...
...
@@ -39,7 +40,7 @@ TEST_MODES = [TestMode.lexer, TestMode.syntax, TestMode.ast, TestMode.semantic,
def
get_test_dirname
(
mode
:
str
)
->
str
:
d
=
{
TestMode
.
compile_firm
:
"exec"
#
TestMode.compile_firm: "exec"
}
if
mode
not
in
d
:
return
mode
...
...
mjtest/test/exec_tests.py
View file @
20db85ed
import
hashlib
import
logging
import
os
import
shutil
...
...
@@ -6,6 +7,7 @@ from mjtest.environment import TestMode, Environment
from
mjtest.test.syntax_tests
import
BasicSyntaxTest
from
mjtest.test.tests
import
TestCase
,
BasicDiffTestResult
,
BasicTestResult
from
mjtest.util.shell
import
SigKill
from
mjtest.util.utils
import
get_main_class_name
_LOG
=
logging
.
getLogger
(
"exec_tests"
)
...
...
@@ -25,9 +27,11 @@ class JavaExecTest(BasicSyntaxTest):
if
not
path
.
exists
(
prev_out_dir
):
os
.
mkdir
(
prev_out_dir
)
self
.
_prev_out_file
=
path
.
join
(
prev_out_dir
,
path
.
basename
(
self
.
_expected_output_file
))
self
.
_prev_out_hash_file
=
self
.
_prev_out_file
+
"_hash"
self
.
_has_expected_output_file
=
path
.
exists
(
self
.
_expected_output_file
)
if
not
self
.
_has_expected_output_file
:
if
path
.
exists
(
self
.
_prev_out_file
)
and
self
.
compare_files_by_age
(
file
,
self
.
_prev_out_file
)
==
-
1
:
if
path
.
exists
(
self
.
_prev_out_file
)
and
path
.
exists
(
self
.
_prev_out_hash_file
)
\
and
self
.
_check_hash_sum
(
self
.
preprocessed_file
,
self
.
_prev_out_hash_file
):
self
.
_has_expected_output_file
=
True
self
.
_expected_output_file
=
self
.
_prev_out_file
_LOG
.
info
(
"Reuse old java output file
\"
{}
\"
"
.
format
(
path
.
relpath
(
self
.
_prev_out_file
)))
...
...
@@ -40,6 +44,7 @@ class JavaExecTest(BasicSyntaxTest):
cwd
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
exp_out
=
None
#print(base_filename, get_main_class_name(base_filename + ".java"))
if
not
self
.
_has_expected_output_file
:
_
,
_
,
javac_rtcode
=
\
self
.
env
.
run_command
(
"javac"
,
base_filename
+
".java"
)
...
...
@@ -48,11 +53,14 @@ class JavaExecTest(BasicSyntaxTest):
os
.
chdir
(
cwd
)
raise
InterruptedError
()
exp_out
,
_
,
_
=
\
self
.
env
.
run_command
(
"java"
,
base_filename
)
self
.
env
.
run_command
(
"java"
,
get_main_class_name
(
base_filename
+
".java"
)
)
exp_out
=
exp_out
.
decode
().
strip
()
with
open
(
self
.
_prev_out_file
,
"w"
)
as
f
:
f
.
write
(
exp_out
)
f
.
flush
()
with
open
(
self
.
_prev_out_hash_file
,
"w"
)
as
f
:
f
.
write
(
self
.
_hash_sum_for_file
(
base_filename
+
".java"
))
f
.
flush
()
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
()
...
...
@@ -71,18 +79,14 @@ class JavaExecTest(BasicSyntaxTest):
os
.
chdir
(
cwd
)
raise
def
get_file_time
(
self
,
file
:
str
)
->
float
:
return
max
(
os
.
path
.
getmtime
(
file
),
os
.
path
.
getatime
(
file
))
def
_check_hash_sum
(
self
,
file
:
str
,
hash_sum_file
:
str
)
->
bool
:
old_hash
=
""
with
open
(
hash_sum_file
,
"r"
)
as
f
:
old_hash
=
f
.
readline
().
strip
()
return
self
.
_hash_sum_for_file
(
file
)
==
old_hash
def
compare_files_by_age
(
self
,
file
:
str
,
other_file
:
str
)
->
int
:
"""
:return: -1 == file is older, 0 == almost equal ages, 1 == other file is older
"""
diff
=
self
.
get_file_time
(
file
)
-
self
.
get_file_time
(
other_file
)
if
diff
<
60
:
return
-
1
if
diff
>
-
60
:
return
1
return
0
def
_hash_sum_for_file
(
self
,
file
:
str
)
->
str
:
with
open
(
file
,
"r"
)
as
f
:
return
hashlib
.
sha256
(
f
.
read
().
encode
()).
hexdigest
()
TestCase
.
TEST_CASE_CLASSES
[
TestMode
.
compile_firm
].
append
(
JavaExecTest
)
\ No newline at end of file
mjtest/util/utils.py
View file @
20db85ed
import
logging
from
os
import
path
import
sys
from
typing
import
Tuple
from
typing
import
Tuple
,
Optional
import
re
COLOR_OUTPUT_IF_POSSIBLE
=
False
...
...
@@ -41,4 +42,18 @@ def cprint(text: str, *args, **kwargs):
if
COLOR_OUTPUT_IF_POSSIBLE
:
termcolor
.
cprint
(
text
,
*
args
,
**
kwargs
)
else
:
print
(
text
)
\ No newline at end of file
print
(
text
)
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
match
:
has_public_class
=
True
current_class
=
match
.
group
(
0
)
elif
"String[]"
in
line
and
"main"
in
line
and
"void"
in
line
and
"static"
in
line
and
"public"
in
line
:
return
current_class
return
None
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