Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
3f21e819
Commit
3f21e819
authored
Sep 18, 2014
by
Pietro Abate
Browse files
better file globbing for unit tests
parent
d2bffea6
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test.list
View file @
3f21e819
...
...
@@ -9,4 +9,10 @@
Name: misc
Group: misc
Input: misc/*.cd
Exclude: misc/bugs_prod.cd misc/html2latex.cd misc/eval_concat.cd misc/list.cd misc/xhtml-categ.cd
Cmd: cduce -c --verbose -I misc
Name: stdlib
Group: stdlib
Input: stdlib/list/*.cd
Cmd: ../cduce -c --verbose -I stdlib/list
tests/test.py
View file @
3f21e819
...
...
@@ -68,6 +68,7 @@ def test_application(self,expected_file,cmd,diff):
output_file
=
"tmp/%s.cdi"
%
uid
output
=
open
(
output_file
,
'w'
)
print
' '
.
join
(
cmd
)
p
=
Popen
(
cmd
,
stdout
=
output
)
p
.
communicate
()
d
=
diff
(
expected_file
,
output_file
)
...
...
@@ -75,6 +76,41 @@ def test_application(self,expected_file,cmd,diff):
os
.
remove
(
output_file
)
self
.
assertTrue
(
d
)
def
maketest
(
test
)
:
name
=
test
[
'Name'
]
comment
=
test
[
'Comment'
]
if
'Comment'
in
test
else
None
expected
=
test
[
'Expected'
]
if
'Expected'
in
test
else
None
exclude
=
map
(
lambda
s
:
set
(
glob
.
glob
(
s
)),
test
[
'Exclude'
].
split
(
' '
))
if
'Exclude'
in
test
else
[
set
()]
inputfiles
=
set
(
glob
.
glob
(
test
[
'Input'
]))
-
set
.
union
(
*
exclude
)
cmd
=
test
[
'Cmd'
].
split
(
' '
)
difftype
=
diff_text
if
expected
is
not
None
:
if
os
.
path
.
isfile
(
expected
)
and
(
len
(
inputfiles
)
==
1
)
:
expected
=
expected
else
:
if
os
.
path
.
isdir
(
expected
)
and
len
(
inputfiles
)
>
1
:
expected
=
"%s"
%
(
expected
)
else
:
print
"1"
exit
(
-
1
)
else
:
if
len
(
inputfiles
)
==
1
:
expected
=
"_tests/%si"
%
infile
else
:
expected
=
"_tests"
expected
=
expected
l
=
[]
print
inputfiles
for
infile
in
inputfiles
:
cmdline
=
cmd
+
[
infile
]
expectedfile
=
"%s/%si"
%
(
expected
,
infile
)
t
=
CDuceTests
(
name
,
comment
,
expectedfile
,
cmdline
,
infile
)
l
.
append
(
t
)
return
l
def
suite
(
f
,
runtest
,
rungroup
):
suite
=
unittest
.
TestSuite
()
groups
=
Set
()
...
...
@@ -85,13 +121,16 @@ def suite(f,runtest,rungroup):
s
=
dict
(
stanza
)
groups
.
add
(
s
[
'Group'
])
if
(
len
(
runtest
)
==
0
and
len
(
rungroup
)
==
0
)
:
suite
.
addTest
(
CDuceTests
(
s
))
for
t
in
maketest
(
s
)
:
suite
.
addTest
(
t
)
elif
s
[
'Name'
]
in
runtest
:
testFound
=
True
suite
.
addTest
(
CDuceTests
(
s
))
for
t
in
maketest
(
s
)
:
suite
.
addTest
(
t
)
elif
len
(
rungroup
)
>
0
and
s
[
'Group'
]
in
rungroup
:
groupFound
=
True
suite
.
addTest
(
CDuceTests
(
s
))
for
t
in
maketest
(
s
)
:
suite
.
addTest
(
t
)
if
len
(
runtest
)
!=
0
and
testFound
==
False
:
print
"Test(s) [%s] Not found"
%
(
','
.
join
(
str
(
p
)
for
p
in
runtest
))
print
"Tests available [%s]"
%
(
','
.
join
(
str
(
p
)
for
p
in
tests
))
...
...
@@ -102,30 +141,13 @@ def suite(f,runtest,rungroup):
return
suite
class
CDuceTests
(
unittest
.
TestCase
):
def
__init__
(
self
,
test
):
def
__init__
(
self
,
name
,
comment
,
expected
,
cmd
,
infile
):
super
(
CDuceTests
,
self
).
__init__
()
self
.
name
=
test
[
'Name'
]
self
.
comment
=
test
[
'Comment'
]
if
'Comment'
in
test
else
None
self
.
expected
=
test
[
'Expected'
]
if
'Expected'
in
test
else
None
self
.
inputfiles
=
glob
.
glob
(
test
[
'Input'
])
self
.
cmd
=
test
[
'Cmd'
].
split
(
' '
)
self
.
difftype
=
diff_text
if
self
.
expected
is
not
None
:
if
os
.
path
.
isfile
(
self
.
expected
)
and
(
len
(
self
.
inputfiles
)
==
1
)
:
expected
=
self
.
expected
else
:
if
os
.
path
.
isdir
(
self
.
expected
)
and
len
(
self
.
inputfiles
)
>
1
:
expected
=
"%s"
%
(
self
.
expected
)
else
:
print
"1"
exit
(
-
1
)
else
:
if
len
(
self
.
inputfiles
)
==
1
:
expected
=
"_tests/%si"
%
infile
else
:
expected
=
"_tests"
self
.
name
=
name
self
.
comment
=
comment
self
.
expected
=
expected
self
.
cmd
=
cmd
self
.
difftype
=
diff_text
def
shortDescription
(
self
):
if
self
.
comment
:
...
...
@@ -134,12 +156,7 @@ class CDuceTests(unittest.TestCase):
return
"Test = %s"
%
self
.
name
+
"
\n
"
+
(
"Cmd = "
)
+
" "
.
join
(
self
.
cmd
)
+
"
\n
Expected file = %s"
%
self
.
expected
+
"
\n
"
def
runTest
(
self
):
for
infile
in
self
.
inputfiles
:
cmd
=
self
.
cmd
+
[
infile
]
expected
=
"%s/%si"
%
(
self
.
expected
,
infile
)
print
cmd
print
expected
test_application
(
self
,
expected
,
cmd
,
self
.
difftype
)
test_application
(
self
,
self
.
expected
,
self
.
cmd
,
self
.
difftype
)
def
main
():
global
verbose
...
...
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