5 # Run compiler unit tests
7 # Copyright (c) 2008/2009 Matthias Kramm <kramm@quiss.org>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
29 from optparse import OptionParser
34 CMD_ARGS=["-o","abc.swf"]
39 for line in s.split("\n"):
40 if line.startswith("[") and line.endswith("]"):
44 if not line.startswith("ok"):
46 if line.startswith("ok "):
51 nr,len = int(line[3:i]),int(line[i+1:])
69 def runcmd(cmd,args,wait):
72 fo = os.fdopen(fo, "wb")
73 p = subprocess.Popen([cmd] + args, executable=cmd, stdout=fo, stderr=fo)
76 for i in range(wait*10):
77 if fi in select.select([fi],[],[], 0.01)[0]:
78 output += os.read(fi, 8192)
79 if "[exit]" in output:
89 os.system("killall -9 %s >/dev/null 2>/dev/null" % cmd)
92 if fi in select.select([fi],[],[], 0.01)[0]:
93 output += os.read(fi, 8192)
99 def __init__(self, filename):
100 self.filename = filename
101 self.filename_milestone = filename+"_milestone"
103 self.filename2status = marshal.load(open(self.filename, "rb"))
105 self.filename2status = {}
107 self.milestone = marshal.load(open(self.filename_milestone, "rb"))
111 def parse_args(self):
112 parser = OptionParser()
113 parser.add_option("-d", "--diff", dest="diff", help="Only run tests that failed the last time",action="store_true")
114 parser.add_option("-a", "--all", dest="all", help="Run all tests (also tests expected to fail)",action="store_true")
115 parser.add_option("-t", "--tag", dest="tag", help="Mark the current pass/fail statistic as milestone",action="store_true")
116 (options, args) = parser.parse_args()
118 if args and args[0]=="add":
121 self.milestone[args[1]] = "ok"
122 self.filename2status = self.milestone
126 self.__dict__.update(options.__dict__)
130 self.runtime = 5 # allow more time if we're tagging this state
136 self.checknum = int(args[0])
138 self.checkfile = args[0]
142 return Cache(filename)
145 fi = open(self.filename, "wb")
146 marshal.dump(self.filename2status, fi)
150 fi = open(self.filename_milestone, "wb")
151 marshal.dump(self.filename2status, fi)
154 def highlight(self, nr, filename):
155 if self.checkfile and filename==self.checkfile:
157 return self.checknum==nr
159 def skip_file(self, nr, filename):
160 if self.checknum>=0 and nr!=self.checknum:
162 if self.checkfile and filename!=self.checkfile:
164 if not self.all and self.milestone.get(filename,"new")!="ok":
166 if self.diff and self.filename2status(filename,"new")=="ok":
170 def file_status(self, filename, status):
171 self.filename2status[filename] = status
174 def __init__(self, cache, nr, file, run):
179 self.flash_output = None
180 self.flash_error = None
181 self.compile_output = None
182 self.compile_error = None
185 try: os.unlink("abc.swf");
187 ret,output = runcmd(CMD,CMD_ARGS+[self.file],wait=cache.runtime)
188 self.compile_error = 0
189 self.compile_output = output
192 self.compile_output += "\nExit status %d" % (-ret)
193 self.exit_status = -ret
194 self.compile_error = 1
196 if not os.path.isfile("abc.swf"):
197 self.compile_error = 1
202 ret,output = runcmd("flashplayer",["abc.swf"],wait=cache.runtime)
203 os.system("killall flashplayer")
204 self.flash_output = output
206 if not check(self.flash_output):
212 print self.r(str(self.nr),3)," ",
213 if self.compile_error:
215 if self.exit_status == 11:
224 if not self.flash_error:
233 def doprintlong(self):
234 print self.nr, self.file
235 print "================================"
236 print "compile:", (self.compile_error and "error" or "ok")
237 print self.compile_output
240 print "================================"
241 print "run:", (self.flash_error and "error" or "ok")
242 print self.flash_output
243 print "================================"
248 return (" "*(l-len(s))) + s
252 return s + (" "*(l-len(s)))
254 class Test(TestBase):
255 def __init__(self, cache, nr, file):
256 TestBase.__init__(self, cache, nr, file, run=1)
257 if self.compile() and self.run():
258 cache.file_status(file, "ok")
260 cache.file_status(file, "error")
262 class ErrTest(TestBase):
263 def __init__(self, cache, nr, file):
264 TestBase.__init__(self, cache, nr, file, run=0)
266 cache.file_status(file, "error")
267 self.compile_error = True
269 cache.file_status(file, "ok")
270 self.compile_error = False
273 def __init__(self, cache, dir):
276 self.errtest = "err" in dir
278 print "-"*40,"tests \""+self.dir+"\"","-"*40
279 for file in sorted(os.listdir(self.dir)):
280 if not file.endswith(".as"):
283 file = os.path.join(self.dir, file)
285 if cache.skip_file(nr, file):
289 test = ErrTest(cache, nr, file)
291 test = Test(cache, nr, file)
293 if not cache.highlight(nr, file):
299 cache = Cache.load(".tests.cache")
303 nr = Suite(cache, "err").run(nr)
304 nr = Suite(cache, "ok").run(nr)