Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
IPDSnelting
mjtest
Commits
ef323b5c
Commit
ef323b5c
authored
Dec 11, 2018
by
Johannes Bechberger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Really fix unicode code bugs
parent
cf00a6a5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
20 deletions
+20
-20
mjtest/test/ast_tests.py
mjtest/test/ast_tests.py
+1
-1
mjtest/test/exec_tests.py
mjtest/test/exec_tests.py
+8
-8
mjtest/test/tests.py
mjtest/test/tests.py
+7
-7
mjtest/util/utils.py
mjtest/util/utils.py
+1
-1
preproc/preproc/preprocessor.py
preproc/preproc/preprocessor.py
+3
-3
No files found.
mjtest/test/ast_tests.py
View file @
ef323b5c
...
@@ -58,7 +58,7 @@ class ASTPrettyPrintTest(BasicSyntaxTest):
...
@@ -58,7 +58,7 @@ class ASTPrettyPrintTest(BasicSyntaxTest):
def
_pretty_print
(
self
,
input_file
:
str
,
output_file
:
str
)
->
Tuple
[
int
,
str
,
str
]:
def
_pretty_print
(
self
,
input_file
:
str
,
output_file
:
str
)
->
Tuple
[
int
,
str
,
str
]:
out
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
TestMode
.
ast
,
input_file
)
out
,
err
,
rtcode
=
self
.
env
.
run_mj_command
(
TestMode
.
ast
,
input_file
)
with
open
(
output_file
,
"wb"
)
as
f
:
with
open
(
output_file
,
"wb"
,
errors
=
"backslashreplace"
)
as
f
:
f
.
write
(
out
)
f
.
write
(
out
)
f
.
flush
()
f
.
flush
()
return
rtcode
,
decode
(
out
),
decode
(
err
)
return
rtcode
,
decode
(
out
),
decode
(
err
)
...
...
mjtest/test/exec_tests.py
View file @
ef323b5c
...
@@ -66,10 +66,10 @@ class JavaExecTest(BasicSyntaxTest):
...
@@ -66,10 +66,10 @@ class JavaExecTest(BasicSyntaxTest):
if
self
.
_has_input_file
:
if
self
.
_has_input_file
:
if
self
.
_has_character_input
:
if
self
.
_has_character_input
:
with
open
(
self
.
_input_file
,
"r"
)
as
f
:
with
open
(
self
.
_input_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
input_str
=
f
.
read
()
input_str
=
f
.
read
()
else
:
else
:
with
open
(
self
.
_input_file
,
"r"
)
as
f
:
with
open
(
self
.
_input_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
chars
=
bytearray
(
'ascii'
,
'ignore'
)
# type: bytearray
chars
=
bytearray
(
'ascii'
,
'ignore'
)
# type: bytearray
for
line
in
f
.
readlines
():
for
line
in
f
.
readlines
():
for
part
in
line
.
split
(
" "
):
for
part
in
line
.
split
(
" "
):
...
@@ -108,15 +108,15 @@ class JavaExecTest(BasicSyntaxTest):
...
@@ -108,15 +108,15 @@ class JavaExecTest(BasicSyntaxTest):
return
test_result
return
test_result
exp_out
=
decode
(
exp_out
)
exp_out
=
decode
(
exp_out
)
with
open
(
self
.
_prev_out_file
,
"w"
)
as
f
:
with
open
(
self
.
_prev_out_file
,
"w"
,
errors
=
"backslashreplace"
)
as
f
:
f
.
write
(
exp_out
)
f
.
write
(
exp_out
)
f
.
flush
()
f
.
flush
()
with
open
(
self
.
_prev_out_hash_file
,
"w"
)
as
f
:
with
open
(
self
.
_prev_out_hash_file
,
"w"
,
errors
=
"backslashreplace"
)
as
f
:
f
.
write
(
self
.
_hash_sum_for_file
(
base_filename
+
".java"
))
f
.
write
(
self
.
_hash_sum_for_file
(
base_filename
+
".java"
))
f
.
flush
()
f
.
flush
()
if
self
.
_has_expected_output_file
and
self
.
type
==
self
.
MODE
and
self
.
env
.
mode
==
self
.
MODE
\
if
self
.
_has_expected_output_file
and
self
.
type
==
self
.
MODE
and
self
.
env
.
mode
==
self
.
MODE
\
and
not
self
.
_only_compile
:
and
not
self
.
_only_compile
:
with
open
(
self
.
_expected_output_file
,
"r"
)
as
f
:
with
open
(
self
.
_expected_output_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
exp_out
=
f
.
read
()
exp_out
=
f
.
read
()
try
:
try
:
out
,
err
,
rtcode
=
None
,
None
,
None
out
,
err
,
rtcode
=
None
,
None
,
None
...
@@ -194,7 +194,7 @@ class JavaExecTest(BasicSyntaxTest):
...
@@ -194,7 +194,7 @@ class JavaExecTest(BasicSyntaxTest):
def
_check_hash_sum
(
self
,
file
:
str
,
hash_sum_file
:
str
)
->
bool
:
def
_check_hash_sum
(
self
,
file
:
str
,
hash_sum_file
:
str
)
->
bool
:
old_hash
=
""
old_hash
=
""
with
open
(
hash_sum_file
,
"r"
)
as
f
:
with
open
(
hash_sum_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
try
:
try
:
old_hash
=
f
.
readline
().
strip
()
old_hash
=
f
.
readline
().
strip
()
except
UnicodeDecodeError
:
except
UnicodeDecodeError
:
...
@@ -203,7 +203,7 @@ class JavaExecTest(BasicSyntaxTest):
...
@@ -203,7 +203,7 @@ class JavaExecTest(BasicSyntaxTest):
@
classmethod
@
classmethod
def
_hash_sum_for_file
(
self
,
file
:
str
)
->
str
:
def
_hash_sum_for_file
(
self
,
file
:
str
)
->
str
:
with
open
(
file
,
"r"
)
as
f
:
with
open
(
file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
return
hashlib
.
sha256
(
f
.
read
().
encode
()).
hexdigest
()
return
hashlib
.
sha256
(
f
.
read
().
encode
()).
hexdigest
()
@
classmethod
@
classmethod
...
@@ -294,7 +294,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
...
@@ -294,7 +294,7 @@ class JavaInfiniteLoopTest(BasicSyntaxTest):
if
self
.
_has_output_file
:
if
self
.
_has_output_file
:
out
=
decode
(
out
).
strip
()
out
=
decode
(
out
).
strip
()
exp_out
=
""
exp_out
=
""
with
open
(
self
.
_output_file
,
"r"
)
as
f
:
with
open
(
self
.
_output_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
exp_out
=
f
.
read
().
strip
()
exp_out
=
f
.
read
().
strip
()
test_result
.
add_long_text
(
"Expected output start"
,
exp_out
)
test_result
.
add_long_text
(
"Expected output start"
,
exp_out
)
if
not
out
.
startswith
(
exp_out
):
if
not
out
.
startswith
(
exp_out
):
...
...
mjtest/test/tests.py
View file @
ef323b5c
...
@@ -50,7 +50,7 @@ class TestSuite:
...
@@ -50,7 +50,7 @@ class TestSuite:
correct_test_cases
=
set
()
correct_test_cases
=
set
()
log_file
=
self
.
_log_file_for_type
(
mode
)
log_file
=
self
.
_log_file_for_type
(
mode
)
if
exists
(
log_file
):
if
exists
(
log_file
):
with
open
(
log_file
)
as
f
:
with
open
(
log_file
,
errors
=
"backslashreplace"
)
as
f
:
correct_test_cases
=
set
()
correct_test_cases
=
set
()
for
t
in
f
.
readlines
():
for
t
in
f
.
readlines
():
t
=
t
.
strip
()
t
=
t
.
strip
()
...
@@ -223,7 +223,7 @@ class TestSuite:
...
@@ -223,7 +223,7 @@ class TestSuite:
os
.
mkdir
(
os
.
path
.
dirname
(
log_file
))
os
.
mkdir
(
os
.
path
.
dirname
(
log_file
))
except
IOError
:
except
IOError
:
pass
pass
with
open
(
log_file
,
"w"
)
as
f
:
with
open
(
log_file
,
"w"
,
errors
=
"backslashreplace"
)
as
f
:
f
.
write
(
"
\n
"
.
join
(
self
.
correct_test_cases
[
mode
]))
f
.
write
(
"
\n
"
.
join
(
self
.
correct_test_cases
[
mode
]))
except
IOError
as
e
:
except
IOError
as
e
:
_LOG
.
exception
(
"Caught i/o error while storing {}"
.
format
(
log_file
))
_LOG
.
exception
(
"Caught i/o error while storing {}"
.
format
(
log_file
))
...
@@ -314,7 +314,7 @@ class TestResult:
...
@@ -314,7 +314,7 @@ class TestResult:
def
store_at
(
self
,
file
:
str
):
def
store_at
(
self
,
file
:
str
):
os
.
makedirs
(
os
.
path
.
dirname
(
file
),
exist_ok
=
True
)
os
.
makedirs
(
os
.
path
.
dirname
(
file
),
exist_ok
=
True
)
with
open
(
file
,
"w"
)
as
f
:
with
open
(
file
,
"w"
,
errors
=
"backslashreplace"
)
as
f
:
print
(
self
.
long_message
(),
file
=
f
)
print
(
self
.
long_message
(),
file
=
f
)
def
short_message
(
self
)
->
str
:
def
short_message
(
self
)
->
str
:
...
@@ -348,8 +348,8 @@ class ExtensibleTestResult(TestResult):
...
@@ -348,8 +348,8 @@ class ExtensibleTestResult(TestResult):
self
.
messages
.
append
(
TestResultMessage
(
title
,
content
,
multiline
=
False
,
with_line_numbers
=
False
))
self
.
messages
.
append
(
TestResultMessage
(
title
,
content
,
multiline
=
False
,
with_line_numbers
=
False
))
def
add_file
(
self
,
title
:
str
,
file_name
:
str
,
with_line_numbers
:
bool
=
True
):
def
add_file
(
self
,
title
:
str
,
file_name
:
str
,
with_line_numbers
:
bool
=
True
):
with
open
(
file_name
,
"r"
)
as
f
:
with
open
(
file_name
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
file_content
=
os
.
linesep
.
join
([
line
.
rstrip
()
for
line
in
f
])
file_content
=
os
.
linesep
.
join
([
line
.
rstrip
()
for
line
in
f
.
read
()
])
self
.
add_long_text
(
title
,
file_content
,
with_line_numbers
)
self
.
add_long_text
(
title
,
file_content
,
with_line_numbers
)
def
succeeded
(
self
):
def
succeeded
(
self
):
...
@@ -461,7 +461,7 @@ class BasicTestResult(TestResult):
...
@@ -461,7 +461,7 @@ class BasicTestResult(TestResult):
def
long_message
(
self
)
->
str
:
def
long_message
(
self
)
->
str
:
file_content
=
[]
file_content
=
[]
with
open
(
self
.
test_case
.
preprocessed_file
,
"r"
)
as
f
:
with
open
(
self
.
test_case
.
preprocessed_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
file_content
=
[
line
.
rstrip
()
for
line
in
f
]
file_content
=
[
line
.
rstrip
()
for
line
in
f
]
others
=
[]
others
=
[]
for
title
,
content
,
long_text
in
self
.
other_texts
:
for
title
,
content
,
long_text
in
self
.
other_texts
:
...
@@ -563,7 +563,7 @@ class DiffTest(TestCase):
...
@@ -563,7 +563,7 @@ class DiffTest(TestCase):
exp_out
=
""
exp_out
=
""
if
rtcode
==
0
and
self
.
should_succeed
():
if
rtcode
==
0
and
self
.
should_succeed
():
if
self
.
_has_expected_output_file
and
self
.
type
==
self
.
MODE
and
self
.
env
.
mode
==
self
.
MODE
:
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
:
with
open
(
self
.
_expected_output_file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
exp_out
=
f
.
read
()
exp_out
=
f
.
read
()
#else:
#else:
# _LOG.error("Expected output file for test case {}:{} is missing.".format(self.MODE, self.short_name()))
# _LOG.error("Expected output file for test case {}:{} is missing.".format(self.MODE, self.short_name()))
...
...
mjtest/util/utils.py
View file @
ef323b5c
...
@@ -47,7 +47,7 @@ def cprint(text: str, *args, **kwargs):
...
@@ -47,7 +47,7 @@ def cprint(text: str, *args, **kwargs):
def
get_main_class_name
(
file
:
str
)
->
Optional
[
str
]:
def
get_main_class_name
(
file
:
str
)
->
Optional
[
str
]:
current_class
=
None
current_class
=
None
with
open
(
file
,
"r"
)
as
f
:
with
open
(
file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
for
line
in
f
:
for
line
in
f
:
if
line
.
startswith
(
"class "
)
or
line
.
startswith
(
"/*public*/ class "
):
if
line
.
startswith
(
"class "
)
or
line
.
startswith
(
"/*public*/ class "
):
match
=
re
.
search
(
"[A-Za-z_0-9]+"
,
line
.
replace
(
"class "
,
""
).
replace
(
"/*public*/"
,
""
))
match
=
re
.
search
(
"[A-Za-z_0-9]+"
,
line
.
replace
(
"class "
,
""
).
replace
(
"/*public*/"
,
""
))
...
...
preproc/preproc/preprocessor.py
View file @
ef323b5c
...
@@ -48,7 +48,7 @@ class PreProcessor:
...
@@ -48,7 +48,7 @@ class PreProcessor:
def
add_commented
(
line
:
str
):
def
add_commented
(
line
:
str
):
middle_lines
.
append
(
"/*{}*/"
.
format
(
line
))
middle_lines
.
append
(
"/*{}*/"
.
format
(
line
))
with
open
(
file
,
"r"
)
as
f
:
with
open
(
file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
for
line
in
f
:
for
line
in
f
:
line
=
line
.
rstrip
()
line
=
line
.
rstrip
()
if
self
.
_import_regexp
.
match
(
line
):
if
self
.
_import_regexp
.
match
(
line
):
...
@@ -108,7 +108,7 @@ class PreProcessor:
...
@@ -108,7 +108,7 @@ class PreProcessor:
print
()
print
()
print
(
text
)
print
(
text
)
else
:
else
:
with
open
(
self
.
dst_file
,
"w"
)
as
f
:
with
open
(
self
.
dst_file
,
"w"
,
errors
=
"backslashreplace"
)
as
f
:
for
text
in
reversed
(
self
.
imported_strs
):
for
text
in
reversed
(
self
.
imported_strs
):
f
.
write
(
text
)
f
.
write
(
text
)
f
.
write
(
"
\n\n
"
)
f
.
write
(
"
\n\n
"
)
...
@@ -122,7 +122,7 @@ def is_importable_file(file: str) -> bool:
...
@@ -122,7 +122,7 @@ def is_importable_file(file: str) -> bool:
has_package
=
False
has_package
=
False
has_public_class
=
False
has_public_class
=
False
has_main_method
=
False
has_main_method
=
False
with
open
(
file
,
"r"
)
as
f
:
with
open
(
file
,
"r"
,
errors
=
"backslashreplace"
)
as
f
:
for
line
in
f
:
for
line
in
f
:
if
line
.
startswith
(
"package "
):
if
line
.
startswith
(
"package "
):
has_package
=
True
has_package
=
True
...
...
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