More elaborate test structure

This commit is contained in:
Robin Jadoul 2016-05-29 20:21:43 +02:00
parent 8328fee2e4
commit ced7c7786f
5 changed files with 174 additions and 2 deletions

View File

@ -9,7 +9,12 @@ REGEXES_DATA = [ #TODO
[r"a|b", r"a"],
]
def make_test(regexes, idx):
EXAMPLE_TESTS = { #Mapping from test name to executable and number of available test input files
"keywords" : ("examples/keywords/keywords", 1),
"highlighter": ("examples/SyntaxHighlighter/highlighter", 1),
}
def make_pipeline_test(regexes, idx):
def test(self):
p = subprocess.Popen([os.path.join(args.builddir, "src", "Lexesis-test"), "test_%s" % idx, data_dir], stdin=subprocess.PIPE)
p.communicate(bytes("\n".join(regexes), "utf-8"))
@ -22,6 +27,24 @@ def make_test(regexes, idx):
return test
def make_functional_test(name, prog, idx):
def test(self):
inpath = os.path.join(REFERENCE_DIR, "%s_%s.in" % (name, idx))
infile = open(inpath)
outpath = os.path.join(data_dir, "%s_%s.out" % (name, idx))
outfile = open(outpath, "w")
checkpath = os.path.join(REFERENCE_DIR, "%s_%s.exp" % (name, idx))
p = subprocess.Popen([prog], stdin=infile, stdout=outfile)
p.communicate()
infile.close()
outfile.close()
self.assertTrue(filecmp.cmp(checkpath, outpath), "Testcase %s for example program %s failed" % (idx, name))
return test
class Tests(unittest.TestCase):
pass
@ -38,7 +61,12 @@ if __name__ == "__main__":
os.mkdir(data_dir)
for i, regexes in enumerate(REGEXES_DATA):
t = make_test(regexes, i)
t = make_pipeline_test(regexes, i)
setattr(Tests, "test_%s" % i, t)
for test, (prog, num) in EXAMPLE_TESTS.items():
for i in range(num):
t = make_functional_test(test, os.path.join(args.builddir, prog), i)
setattr(Tests, "test_%s_%s" % (test, i), t)
unittest.main()

61
tests/highlighter_0.exp Normal file
View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="/static/images/logo.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<title>SyntaxHighligter example</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" >
<meta name="author" content="Thomas Avé" >
<script type="text/javascript" src="/static/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.slidertron-1.1.js"></script>
</head>
<body onload="javascript:doStuff()">
<!-- This is a comment -->
<div id="logotextname">Pellentesque lacus neque, rutrum ut ante et, posuere consequat elit.</div>
<div id="logotextfunction" style="letter-spacing:9px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
<a href="/"><img src="/static/images/logo.png" alt="Logo" id="logo"></a>
<nav>
<ul class="nav">
<li class="nav"><a href="/welkom" class="nav" id="linkwelkom">WELKOM</a></li>
<li class="nav"><a href="/werkwijze" class="nav" id="linkwerkwijze">WERKWIJZE</a></li>
<li class="nav"><a href="/praktisch" class="nav" id="linkpraktisch">PRAKTISCH</a></li>
<li class="nav"><a href="/contact" class="nav" id="linkcontact">CONTACT</a></li>
<li class="nav"><a class="nav" id="login" href="javascript:toggle();">LOGIN</a></li>
</ul>
</nav>
<div id="toggleText">
<form action="/login" method="POST">
<div class="login" style="margin-top:25px;">Gebruikersnaam:</div>
<input type="text" name="username" id="username" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<br>
<div class="login" style="margin-top:15px;">Wachtwoord:</div>
<input type="password" name="password" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<input type="hidden" name="submit" value="1">
<input type="submit" value="Login" style="height:0;width:0;background:none;border:none;">
</form>
</div>
<div id="content">
<video id="video" autoplay loop>
<source src="/static/video/root.mp4" type="video/mp4">
<source src="/static/video/root.webm" type="video/webm">
</video>
</div>
<form action="javascript:search();" method="get">
<input type="text" name="query" id="search" size="40" value=" " autocomplete="off">
<input type="submit" value="Search" style="height:0;width:0;background:none;border:none;">
<input type="hidden" name="search" value="1">
</form>
<div id="logindowndiv">
<form action="/login" method="POST">
<div class="login" style="margin-top:25px;">Gebruikersnaam:</div>
<input type="text" name="user" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<br>
<div class="login" style="margin-top:15px;">Wachtwoord:</div>
<input type="password" name="pass" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<input type="hidden" name="sublogin" value="1">
</form>
</div>
</body>
<!-- End of the document -->
</html>


60
tests/highlighter_0.in Normal file
View File

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="/static/images/logo.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<title>SyntaxHighligter example</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" >
<meta name="author" content="Thomas Avé" >
<script type="text/javascript" src="/static/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.slidertron-1.1.js"></script>
</head>
<body onload="javascript:doStuff()">
<!-- This is a comment -->
<div id="logotextname">Pellentesque lacus neque, rutrum ut ante et, posuere consequat elit.</div>
<div id="logotextfunction" style="letter-spacing:9px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
<a href="/"><img src="/static/images/logo.png" alt="Logo" id="logo"></a>
<nav>
<ul class="nav">
<li class="nav"><a href="/welkom" class="nav" id="linkwelkom">WELKOM</a></li>
<li class="nav"><a href="/werkwijze" class="nav" id="linkwerkwijze">WERKWIJZE</a></li>
<li class="nav"><a href="/praktisch" class="nav" id="linkpraktisch">PRAKTISCH</a></li>
<li class="nav"><a href="/contact" class="nav" id="linkcontact">CONTACT</a></li>
<li class="nav"><a class="nav" id="login" href="javascript:toggle();">LOGIN</a></li>
</ul>
</nav>
<div id="toggleText">
<form action="/login" method="POST">
<div class="login" style="margin-top:25px;">Gebruikersnaam:</div>
<input type="text" name="username" id="username" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<br>
<div class="login" style="margin-top:15px;">Wachtwoord:</div>
<input type="password" name="password" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<input type="hidden" name="submit" value="1">
<input type="submit" value="Login" style="height:0;width:0;background:none;border:none;">
</form>
</div>
<div id="content">
<video id="video" autoplay loop>
<source src="/static/video/root.mp4" type="video/mp4">
<source src="/static/video/root.webm" type="video/webm">
</video>
</div>
<form action="javascript:search();" method="get">
<input type="text" name="query" id="search" size="40" value=" " autocomplete="off">
<input type="submit" value="Search" style="height:0;width:0;background:none;border:none;">
<input type="hidden" name="search" value="1">
</form>
<div id="logindowndiv">
<form action="/login" method="POST">
<div class="login" style="margin-top:25px;">Gebruikersnaam:</div>
<input type="text" name="user" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<br>
<div class="login" style="margin-top:15px;">Wachtwoord:</div>
<input type="password" name="pass" class="login" style="width:80%;border:1px solid rgba(120, 120, 120, 0.7);border-radius:5px;height:18px;">
<input type="hidden" name="sublogin" value="1">
</form>
</div>
</body>
<!-- End of the document -->
</html>

12
tests/keywords_0.exp Normal file
View File

@ -0,0 +1,12 @@
MODULE: "Module"
MODULE: "module"
IDENT: "MODULE"
IDENT: "END"
END: "end"
END: "End"
IF: "if"
IDENT: "IF"
IF: "If"
IDENT: "something"
IDENT: "random"
DONE

11
tests/keywords_0.in Normal file
View File

@ -0,0 +1,11 @@
Module
module
MODULE
END
end
End
if
IF
If
something random