From 0954b256ee7faf76a5cb5ef4342b48ab4477b5e6 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 31 May 2015 17:10:27 +0100 Subject: [PATCH] cleaner color handling --- run_tests.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/run_tests.py b/run_tests.py index f50ac45..44ed109 100644 --- a/run_tests.py +++ b/run_tests.py @@ -3,6 +3,8 @@ from os import listdir, remove, name as osname from os.path import splitext, join as joinp import subprocess as sp +# configuration - you can modify this + COMPILER = "c++" CXXFLAGS = [ "-std=c++11", @@ -12,22 +14,29 @@ CXXFLAGS = [ ] COLORS = (osname != "nt") +# don't modify past these lines + nsuccess = 0 nfailed = 0 +if COLORS: + colors = { + "red": "\033[91m", + "green": "\033[92m", + "blue": "\033[94m", + "bold": "\033[1m", + "end": "\033[0m" + } +else: + colors = { "red": "", "green": "", "blue": "", "bold": "", "end": "" } + def print_result(modname, fmsg = None): global nsuccess, nfailed if fmsg: - if COLORS: - print "%s...\t\033[91m\033[1m(%s)\033[0m" % (modname, fmsg) - else: - print "%s...\t(%s)" % (modname, fmsg) + print modname + ("...\t%(red)s%(bold)s(" + fmsg + ")%(end)s") % colors nfailed += 1 else: - if COLORS: - print "%s...\t\033[92m\033[1m(success)\033[0m" % modname - else: - print "%s...\t(success)" % modname + print modname + "...\t%(green)s%(bold)s(success)%(end)s" % colors nsuccess += 1 for fname in listdir("tests"): @@ -58,11 +67,6 @@ for fname in listdir("tests"): remove(exepath) print_result(modname) -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 \ No newline at end of file +print "\n%(blue)s%(bold)stesting done:%(end)s" % colors +print "%(green)sSUCCESS: " % colors + str(nsuccess) + colors["end"] +print "%(red)sFAILURE: " % colors + str(nfailed) + colors["end"] \ No newline at end of file