Skip to content

Commit

Permalink
added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
helino committed Mar 19, 2011
1 parent a2c0cfe commit 1681ff9
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
78 changes: 78 additions & 0 deletions test/integration/parser/Factorial.syntax
@@ -0,0 +1,78 @@
(Program
(MainClass
(Identifier[ Factorial ]
)
(Identifier[ a ]
)
(Print
(Call[ ComputeFac ]
(NewObject
(Identifier[ Fac ]
)
)
(Identifier[ ComputeFac ]
)
(IntegerLiteral[ 10 ]
)
)
)
)
(ClassDeclSimple
(Identifier[ Fac ]
)
(MethodDecl
(IntegerType
)
(Identifier[ ComputeFac ]
)
(Formal
(IntegerType
)
(Identifier[ num ]
)
)
(VarDecl
(IntegerType
)
(Identifier[ num_aux ]
)
)
(If
(LessThan
(IdentifierExp[ num ]
)
(IntegerLiteral[ 1 ]
)
)
(Assign
(Identifier[ num_aux ]
)
(IntegerLiteral[ 1 ]
)
)
(Assign
(Identifier[ num_aux ]
)
(Times
(IdentifierExp[ num ]
)
(Call[ ComputeFac ]
(This
)
(Identifier[ ComputeFac ]
)
(Minus
(IdentifierExp[ num ]
)
(IntegerLiteral[ 1 ]
)
)
)
)
)
)
(IdentifierExp[ num_aux ]
)
)
)
)
Empty file.
13 changes: 13 additions & 0 deletions test/integration/parser/runner.py
@@ -0,0 +1,13 @@
import os.path
import os

def run(cmd, files):
res = True;
d = os.path.split(os.path.abspath(__file__))[0]
for p in files:
fname = os.path.split(p)[1]
fname = fname.replace('java', 'syntax')
exp = open((d + '/' + fname), 'r').read()
output = os.popen((cmd + ' ' + p)).read()
res = ((output == exp) and res)
return res
18 changes: 18 additions & 0 deletions test/integration/runner.py
@@ -0,0 +1,18 @@
import os
import os.path
import sys
import parser.runner

def run():
d = os.path.split(os.path.abspath(__file__))[0]
d += '/sample_programs/'
samples = [os.path.abspath(d + 'Factorial.java')]
cmd = './build/src/jurov'
res = parser.runner.run(cmd, samples)
if res:
sys.exit(0)
else:
sys.exit(1)

if __name__ == '__main__':
run()
12 changes: 11 additions & 1 deletion wscript
Expand Up @@ -13,6 +13,8 @@ def options(opt):
help = 'Runs all the speficications')
opt.add_option('--valgrind', action = 'store_true', default = False,
help = 'Runs all the specifications in valgrind')
opt.add_option('--integration', action = 'store_true', default = False,
help = 'Runs all the integration tests')

def run_valgrind(bld):
print "Starting to run valgrind"
Expand All @@ -26,14 +28,20 @@ def run_valgrind(bld):
if res != 0:
bld.fatal("Memory leaks detected!")


def run_specs(bld):
print "Starting to run specs"
run_all_specs = '{0}/test/spec/run_all_specs'.format(os.path.abspath(out))
res = bld.exec_command(run_all_specs)
if res != 0:
bld.fatal("The specifications were not fulfilled!")

def run_integration(bld):
print "Starting to run integration tests"
cmd = 'python test/integration/runner.py'
res = bld.exec_command(cmd)
if res != 0:
bld.fatal("The integration tests did not pass!")

def configure(conf):
conf.env.CFLAGS = ['-g', '-Wall', '-Werror', '-ansi', '-pedantic']
conf.env.FLEXFLAGS = ['--header-file=src/lex.yy.h']
Expand All @@ -56,3 +64,5 @@ def build(bld):
bld.add_post_fun(run_specs)
if Options.options.valgrind and bld.env.VALGRIND:
bld.add_post_fun(run_valgrind)
if Options.options.integration:
bld.add_post_fun(run_integration)

0 comments on commit 1681ff9

Please sign in to comment.