2015-05-30 01:51:37 +00:00
|
|
|
from sys import stdout, exit
|
2015-05-31 15:33:49 +00:00
|
|
|
from os import listdir, remove, name as osname
|
|
|
|
from os.path import splitext, join as joinp
|
2015-05-30 01:51:37 +00:00
|
|
|
import subprocess as sp
|
|
|
|
|
|
|
|
COMPILER = "c++"
|
2015-05-31 15:12:55 +00:00
|
|
|
CXXFLAGS = [
|
|
|
|
"-std=c++11",
|
|
|
|
"-Wall", "-Wextra",
|
|
|
|
"-Wno-missing-braces", # clang false positive
|
|
|
|
"-I."
|
|
|
|
]
|
2015-05-31 15:33:49 +00:00
|
|
|
COLORS = (osname != "nt")
|
2015-05-30 01:51:37 +00:00
|
|
|
|
2015-05-31 15:03:43 +00:00
|
|
|
nsuccess = 0
|
|
|
|
nfailed = 0
|
|
|
|
|
2015-05-31 15:33:49 +00:00
|
|
|
def print_result(modname, fmsg = None):
|
2015-05-31 15:36:39 +00:00
|
|
|
global nsuccess, nfailed
|
2015-05-31 15:33:49 +00:00
|
|
|
if fmsg:
|
|
|
|
if COLORS:
|
|
|
|
print "%s...\t\033[91m\033[1m(%s)\033[0m" % (modname, fmsg)
|
|
|
|
else:
|
|
|
|
print "%s...\t(%s)" % (modname, fmsg)
|
2015-05-31 15:36:39 +00:00
|
|
|
nfailed += 1
|
2015-05-31 15:33:49 +00:00
|
|
|
else:
|
|
|
|
if COLORS:
|
|
|
|
print "%s...\t\033[92m\033[1m(success)\033[0m" % modname
|
|
|
|
else:
|
|
|
|
print "%s...\t(success)" % modname
|
2015-05-31 15:36:39 +00:00
|
|
|
nsuccess += 1
|
2015-05-31 15:33:49 +00:00
|
|
|
|
2015-05-31 15:12:55 +00:00
|
|
|
for fname in listdir("tests"):
|
2015-05-31 14:50:09 +00:00
|
|
|
(modname, modext) = splitext(fname)
|
|
|
|
|
|
|
|
if modext != ".cpp":
|
|
|
|
continue
|
|
|
|
|
2015-05-31 15:33:49 +00:00
|
|
|
srcpath = joinp("tests", fname)
|
|
|
|
exepath = joinp("tests", modname)
|
|
|
|
|
|
|
|
pc = sp.Popen([ COMPILER, srcpath, "-o", exepath ] + CXXFLAGS,
|
|
|
|
stdout = sp.PIPE, stderr = sp.STDOUT)
|
2015-05-31 14:50:09 +00:00
|
|
|
stdout.write(pc.communicate()[0])
|
|
|
|
|
|
|
|
if pc.returncode != 0:
|
2015-05-31 15:33:49 +00:00
|
|
|
print_result(modname, "compile error")
|
2015-05-31 15:03:43 +00:00
|
|
|
continue
|
2015-05-31 14:50:09 +00:00
|
|
|
|
2015-05-31 15:33:49 +00:00
|
|
|
pc = sp.Popen(exepath, stdout = sp.PIPE, stderr = sp.STDOUT)
|
2015-05-31 14:50:09 +00:00
|
|
|
stdout.write(pc.communicate()[0])
|
|
|
|
|
|
|
|
if pc.returncode != 0:
|
2015-05-31 15:33:49 +00:00
|
|
|
remove(exepath)
|
|
|
|
print_result(modname, "runtime error")
|
2015-05-31 15:03:43 +00:00
|
|
|
continue
|
2015-05-31 14:50:09 +00:00
|
|
|
|
2015-05-31 15:33:49 +00:00
|
|
|
remove(exepath)
|
|
|
|
print_result(modname)
|
2015-05-30 01:51:37 +00:00
|
|
|
|
2015-05-31 15:33:49 +00:00
|
|
|
if COLORS:
|
|
|
|
print "\n\033[94m\033[1mtesting done:\033[0m"
|
|
|
|
print "\033[92mSUCCESS\033[0m: \033[1m%d\033[0m" % nsuccess
|
|
|
|
print "\033[91mFAILURE\033[0m: \033[1m%d\033[0m" % nfailed
|
|
|
|
else:
|
|
|
|
print "\ntesting done:"
|
|
|
|
print "SUCCESS: %d" % nsuccess
|
|
|
|
print "FAILURE: %d" % nfailed
|