5 # Run compiler unit tests
7 # Copyright (c) 2008 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 */
28 from optparse import OptionParser
33 for line in s.split("\n"):
34 if line.startswith("[") and line.endswith("]"):
38 if not line.startswith("ok"):
40 if line.startswith("ok "):
44 nr,len = int(line[3:i]),int(line[i+1:])
60 def runcmd(cmd,args,wait):
61 #fo = open(tempfile, "wb")
63 p = subprocess.Popen([cmd] + args, executable=cmd, stdout=fo, stderr=fo)
65 for i in range(wait*10):
72 os.system("killall -9 "+cmd)
80 def __init__(self, filename):
82 self.filename2status = marshal.load(open(filename, "rb"))
84 self.filename2status = {}
87 parser = OptionParser()
88 parser.add_option("-d", "--diff", dest="diff", help="Only run tests that failed the last time",action="store_true")
89 (options, args) = parser.parse_args()
90 self.__dict__.update(options.__dict__)
94 self.checknum = int(args[0])
98 return Cache(filename)
100 def save(self, filename):
101 fi = open(filename, "wb")
102 marshal.dump(self.filename2status, fi)
105 def highlight(self, nr, filename):
106 return self.checknum==nr
108 def skip_file(self, nr, filename):
109 if self.checknum>=0 and nr!=self.checknum:
111 if self.diff and self.filename2status[filename]=="ok":
115 def file_status(self, filename, status):
116 self.filename2status[filename] = status
119 def __init__(self, nr, file, run):
123 self.flash_output = None
124 self.flash_error = None
125 self.compile_output = None
126 self.compile_error = None
129 try: os.unlink("abc.swf");
131 ret,output = runcmd("./parser",[self.file],wait=60)
132 self.compile_error = 0
133 self.compile_output = output
135 self.compile_output += "\nExit status %d" % (-ret)
136 self.compile_error = 1
138 if not os.path.isfile("abc.swf"):
139 self.compile_error = 1
144 ret,output = runcmd("flashplayer",["abc.swf"],wait=1)
145 os.system("killall flashplayer")
146 self.flash_output = output
148 if not check(self.flash_output):
154 print self.r(str(self.nr),3)," ",
155 if self.compile_error:
163 if not self.flash_error:
172 def doprintlong(self):
173 print self.nr, self.file
174 print "================================"
175 print "compile:", (self.compile_error and "error" or "ok")
176 print self.compile_output
179 print "================================"
180 print "run:", (self.flash_error and "error" or "ok")
181 print self.flash_output
182 print "================================"
187 return (" "*(l-len(s))) + s
191 return s + (" "*(l-len(s)))
193 class Test(TestBase):
194 def __init__(self, cache, nr, file):
195 TestBase.__init__(self, nr, file, run=1)
196 if self.compile() and self.run():
197 cache.file_status(file, "ok")
199 cache.file_status(file, "error")
201 class ErrTest(TestBase):
202 def __init__(self, cache, nr, file):
203 TestBase.__init__(self, nr, file, run=0)
205 cache.file_status(file, "error")
206 self.compile_error = True
208 cache.file_status(file, "ok")
209 self.compile_error = False
212 def __init__(self, cache, dir):
215 self.errtest = "err" in dir
217 print "-"*40,"tests \""+self.dir+"\"","-"*40
218 for file in sorted(os.listdir(self.dir)):
219 if not file.endswith(".as"):
222 file = os.path.join(self.dir, file)
224 if cache.skip_file(nr, file):
228 test = ErrTest(cache, nr, file)
230 test = Test(cache, nr, file)
232 if not cache.highlight(nr, file):
238 cache = Cache.load(".tests.cache")
242 nr = Suite(cache, "err").run(nr)
243 nr = Suite(cache, "ok").run(nr)
245 cache.save(".tests.cache")