X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fas3%2Fruntests.py;h=cc24f8f24a04670e9ea3970f70d98fc5e2b01ed6;hb=938c420724d7780bcd4754febc87e47d0d9a3b55;hp=75975bbf430b30d1c0772080b26e5e3651ad032e;hpb=62204b16ee0d3d7f0876471668a68b9382d332bb;p=swftools.git diff --git a/lib/as3/runtests.py b/lib/as3/runtests.py index 75975bb..cc24f8f 100644 --- a/lib/as3/runtests.py +++ b/lib/as3/runtests.py @@ -55,7 +55,7 @@ def check(s): return 0 not in row return 0 -def runcmd(cmd,args,output,wait): +def runcmd(cmd,args,wait): #fo = open(tempfile, "wb") fo= os.tmpfile() p = subprocess.Popen([cmd] + args, executable=cmd, stdout=fo, stderr=fo) @@ -74,22 +74,20 @@ def runcmd(cmd,args,output,wait): fo.close() return ret,output -class Test: - def __init__(self, nr, file): +class TestBase: + def __init__(self, nr, file, run): self.nr = nr + self.dorun = run self.file = file self.flash_output = None self.flash_error = None self.compile_output = None self.compile_error = None - self.compile() - if not self.compile_error: - self.run() def compile(self): try: os.unlink("abc.swf"); except: pass - ret,output = runcmd("./parser",[self.file],"/tmp/abctest.txt",wait=60) + ret,output = runcmd("./parser",[self.file],wait=60) self.compile_error = 0 self.compile_output = output if ret: @@ -98,7 +96,7 @@ class Test: self.compile_error = 1 def run(self): - ret,output = runcmd("flashplayer",["abc.swf"],"/tmp/abctest.txt",wait=1) + ret,output = runcmd("flashplayer",["abc.swf"],wait=1) os.system("killall flashplayer") self.flash_output = output @@ -106,50 +104,86 @@ class Test: self.flash_error = 1 def doprint(self): - def r(s,l): - if(len(s)>=l): - return s - return (" "*(l-len(s))) + s - def l(s,l): - if(len(s)>=l): - return s - return s + (" "*(l-len(s))) - - print r(str(self.nr),3)," ", + print self.r(str(self.nr),3)," ", if self.compile_error: - print "err"," - ", + if self.dorun: + print "err"," - ", + else: + print "err"," ", else: print "ok ", - if not self.flash_error: - print "ok ", + if self.dorun: + if not self.flash_error: + print "ok ", + else: + print "err", else: - print "err", + print " ", print " ", - print file + print self.file def doprintlong(self): print self.nr, self.file print "================================" + print "compile:", (test.compile_error and "error" or "ok") print test.compile_output + if not self.dorun: + return print "================================" + print "run:", (test.flash_error and "error" or "ok") print test.flash_output print "================================" + def r(self,s,l): + if(len(s)>=l): + return s + return (" "*(l-len(s))) + s + def l(self,s,l): + if(len(s)>=l): + return s + return s + (" "*(l-len(s))) + +class Test(TestBase): + def __init__(self, nr, file): + TestBase.__init__(self, nr, file, run=1) + self.compile() + if not self.compile_error: + self.run() + +class ErrTest(TestBase): + def __init__(self, nr, file): + TestBase.__init__(self, nr, file, run=0) + self.compile() + self.compile_error = not self.compile_error + +class Suite: + def __init__(self, dir): + self.dir = dir + self.errtest = "err" in dir + def run(self, nr): + print "-"*40,"tests \""+self.dir+"\"","-"*40 + for file in sorted(os.listdir(self.dir)): + if not file.endswith(".as"): + continue + nr = nr + 1 + file = os.path.join(self.dir, file) + if checknum>=0 and nr!=checknum: + continue + if self.errtest: + test = ErrTest(nr,file) + else: + test = Test(nr,file) + if checknum!=nr: + test.doprint() + else: + test.doprintlong() + return nr + checknum=-1 if len(sys.argv)>1: checknum = int(sys.argv[1]) -for nr,file in sorted(enumerate(os.listdir("ok"))): - if not file.endswith(".as"): - continue - file = os.path.join("ok", file) - if checknum>=0 and nr!=checknum: - continue - test = Test(nr,file) - - if checknum!=nr: - test.doprint() - else: - test.doprintlong() - +nr = 0 +nr = Suite("err").run(nr) +nr = Suite("ok").run(nr)