Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Yang
cs444
Commits
58030445
Commit
58030445
authored
5 years ago
by
Xun Yang
Browse files
Options
Downloads
Patches
Plain Diff
change Test.py
parent
f2377d3f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Test.py
+15
-33
15 additions, 33 deletions
Test.py
TestA5Step0.py
+0
-139
0 additions, 139 deletions
TestA5Step0.py
with
15 additions
and
172 deletions
Test.py
+
15
−
33
View file @
58030445
...
...
@@ -6,7 +6,7 @@ import traceback
from
Scanning
import
scan
from
Parsing
import
parse
from
AstBuilding
import
astBuild
,
buildEnvAndLink
,
disamiguateAndTypeChecking
,
reachabilityChecking
from
AstBuilding
import
astBuild
,
buildEnvAndLink
,
disamiguateAndTypeChecking
,
reachabilityChecking
,
codeGen
import
Weeding
...
...
@@ -19,28 +19,16 @@ def main():
def
allFiles
(
testDir
):
return
[
testDir
+
f
for
f
in
listdir
(
testDir
)
if
isfile
(
join
(
testDir
,
f
))
and
f
.
startswith
(
'
J1
'
)]
def
a1
():
if
len
(
sys
.
argv
)
>
1
:
testFiles
=
[
"
./Tests/
"
+
f
for
f
in
sys
.
argv
[
1
:]]
else
:
# All files in the test directory
testDirectory
=
"
./Tests/
"
testFiles
=
allFiles
(
testDirectory
)
print
(
"
**********************************************************
"
)
run
(
testFiles
)
def
a2Single
():
# test all the single file cases in a2
pass
def
a2Multiple
():
if
len
(
sys
.
argv
)
>
1
:
testCases
=
[
f
for
f
in
sys
.
argv
[
1
:]]
else
:
testCases
=
[
"
./Tests/A5/J1_00_Step0.java
"
]
# All files in the test directory
testDirectory
=
"
./Tests/A4/
"
testCases
=
[
f
.
path
for
f
in
scandir
(
testDirectory
)
if
f
.
is_dir
()]
testCases
+=
[
f
.
path
for
f
in
scandir
(
testDirectory
)
if
not
f
.
is_dir
()]
# testDirectory = "./Tests/A4/"
# testCases = [f.path for f in scandir(testDirectory) if f.is_dir()]
# testCases += [f.path for f in scandir(testDirectory) if not f.is_dir()]
total
=
0
correct
=
0
...
...
@@ -51,12 +39,11 @@ def a2Multiple():
testFiles
=
[
join
(
dp
,
f
)
for
dp
,
dn
,
filenames
in
walk
(
'
stdlib/5.0/java/
'
)
for
f
in
filenames
]
if
'
.java
'
in
c
:
# add this one file
# make sure the test file is the first in the list
testFiles
=
[
c
].
extend
(
testFiles
)
testFiles
=
[
c
]
+
testFiles
# make sure the file containing test is at the front
else
:
# get all files in the folder recursively
testFiles
=
[
join
(
dp
,
f
)
for
dp
,
dn
,
filenames
in
walk
(
c
)
for
f
in
filenames
].
extend
(
testFiles
)
testFiles
=
[
join
(
dp
,
f
)
for
dp
,
dn
,
filenames
in
walk
(
c
)
for
f
in
filenames
]
+
testFiles
ret
=
run
(
testFiles
)
total
+=
1
...
...
@@ -134,22 +121,11 @@ def run(testFiles):
parseTrees
.
append
((
f
,
tree
))
# for (n, t) in parseTrees:
# if n == "./Tests/A4/Je_8_DefiniteAssignment_InitToItself.java":
# print(n)
# print(t)
try
:
ASTs
=
astBuild
(
parseTrees
)
except
Exception
as
e
:
return
"
AST buidling:
"
+
e
.
args
[
0
]
# for (n, t) in ASTs:
# if n == "./Tests/A4/Je_8_DefiniteAssignment_ComplexInitializer.java":
# print(n)
# print("--------------------")
# t.printTree()
# print("\n \n\n \n")
try
:
buildEnvAndLink
(
ASTs
)
except
Exception
as
e
:
...
...
@@ -164,6 +140,12 @@ def run(testFiles):
except
Exception
as
e
:
return
"
reachabilityChecking:
"
+
e
.
args
[
0
]
try
:
codeGen
(
ASTs
)
except
Exception
as
e
:
return
"
codeGen:
"
+
e
.
args
[
0
]
return
""
main
()
This diff is collapsed.
Click to expand it.
TestA5Step0.py
deleted
100644 → 0
+
0
−
139
View file @
f2377d3f
import
sys
import
time
from
os
import
listdir
,
scandir
,
walk
from
os.path
import
isfile
,
join
import
traceback
from
Scanning
import
scan
from
Parsing
import
parse
from
AstBuilding
import
astBuild
,
buildEnvAndLink
,
disamiguateAndTypeChecking
,
reachabilityChecking
,
codeGen
import
Weeding
# run test with python Test.py Tests/A2/J1_3_ImportOnDemand_ProgramDefinedPackage/
def
main
():
a2Multiple
()
def
a2Multiple
():
if
len
(
sys
.
argv
)
>
1
:
testCases
=
[
f
for
f
in
sys
.
argv
[
1
:]]
else
:
testCases
=
[
"
A5Step0Test.java
"
]
total
=
0
correct
=
0
start
=
time
.
time
()
for
c
in
testCases
:
# get all files from stdlib folder
testFiles
=
[
join
(
dp
,
f
)
for
dp
,
dn
,
filenames
in
walk
(
'
stdlib/5.0/java/
'
)
for
f
in
filenames
]
testFiles
=
[
c
]
+
testFiles
# make sure the file containing test is at the front
ret
=
run
(
testFiles
)
total
+=
1
if
ret
==
""
:
if
'
Je_
'
in
c
:
print
(
c
)
print
(
"
JE Passed without error
"
)
print
(
"
**********************************************************
"
)
else
:
correct
+=
1
else
:
if
not
'
Je_
'
in
c
:
print
(
c
)
print
(
ret
)
print
(
"
**********************************************************
"
)
else
:
correct
+=
1
end
=
time
.
time
()
print
(
"
\n
Time Elapsed: {}
"
.
format
(
time
.
strftime
(
'
%H:%M:%S
'
,
time
.
gmtime
(
end
-
start
))))
print
(
"
SCORE: {} / {} -> {:.3g}%
"
.
format
(
correct
,
total
,
(
correct
/
total
)
*
100
))
def
run
(
testFiles
):
parseTrees
=
[]
for
f
in
testFiles
:
if
f
.
split
(
"
/
"
)[
-
1
]
==
"
.DS_Store
"
:
continue
content
=
open
(
f
,
"
r
"
).
read
()
# Scanning
(
tokens
,
error
)
=
scan
(
content
)
# Error in Scanning
if
tokens
is
None
:
if
not
'
Je_
'
in
f
:
print
(
f
)
print
(
"
ERROR in Scanning:
"
+
error
)
print
(
"
**********************************************************
"
)
return
"
ERROR in scanning
"
# s = "All Tokens: "
# for token in tokens:
# if (token.name and token.lex):
# s += '(' + token.name + ',' + token.lex + '), '
# print(s)
# Weeding after scanning
# No weeds if everything is good (weeds = None)
weeds
=
Weeding
.
fileNameCheck
(
tokens
,
f
)
if
weeds
:
print
(
f
)
print
(
"
ERROR in Weeding after Scanning:
"
)
print
(
weeds
)
print
(
"
**********************************************************
"
)
return
"
ERROR in weeding
"
# Parsing
tree
=
None
try
:
(
tree
,
error
)
=
parse
(
tokens
)
except
:
print
(
"
Exception in Parsing
"
)
# Error in Parsing
if
tree
is
None
:
if
not
'
Je_
'
in
f
:
print
(
f
)
print
(
"
ERROR in Parsing:
"
+
error
.
args
[
0
])
# for n in error.args[1]: # the parse tree
# print(n)
print
(
"
**********************************************************
"
)
return
"
ERROR in parsing
"
parseTrees
.
append
((
f
,
tree
))
try
:
ASTs
=
astBuild
(
parseTrees
)
except
Exception
as
e
:
return
"
AST buidling:
"
+
e
.
args
[
0
]
try
:
buildEnvAndLink
(
ASTs
)
except
Exception
as
e
:
return
"
buildEnvAndLink:
"
+
e
.
args
[
0
]
try
:
disamiguateAndTypeChecking
(
ASTs
)
except
Exception
as
e
:
return
"
disamiguateAndTypeChecking:
"
+
e
.
args
[
0
]
try
:
reachabilityChecking
(
ASTs
)
except
Exception
as
e
:
return
"
reachabilityChecking:
"
+
e
.
args
[
0
]
try
:
codeGen
(
ASTs
)
except
Exception
as
e
:
return
"
codeGen:
"
+
e
.
args
[
0
]
return
""
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment