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 */
29 from optparse import OptionParser
34 for line in s.split("\n"):
35 if line.startswith("[") and line.endswith("]"):
39 if not line.startswith("ok"):
41 if line.startswith("ok "):
45 nr,len = int(line[3:i]),int(line[i+1:])
61 def runcmd(cmd,args,wait):
64 fo = os.fdopen(fo, "wb")
65 p = subprocess.Popen([cmd] + args, executable=cmd, stdout=fo, stderr=fo)
68 for i in range(wait*10):
69 if fi in select.select([fi],[],[], 0.01)[0]:
70 output += os.read(fi, 8192)
71 if "[exit]" in output:
79 os.system("killall -9 %s >/dev/null 2>/dev/null" % cmd)
82 if fi in select.select([fi],[],[], 0.01)[0]:
83 output += os.read(fi, 8192)
89 def __init__(self, filename):
91 self.filename2status = marshal.load(open(filename, "rb"))
93 self.filename2status = {}
96 parser = OptionParser()
97 parser.add_option("-d", "--diff", dest="diff", help="Only run tests that failed the last time",action="store_true")
98 (options, args) = parser.parse_args()
99 self.__dict__.update(options.__dict__)
103 self.checknum = int(args[0])
107 return Cache(filename)
109 def save(self, filename):
110 fi = open(filename, "wb")
111 marshal.dump(self.filename2status, fi)
114 def highlight(self, nr, filename):
115 return self.checknum==nr
117 def skip_file(self, nr, filename):
118 if self.checknum>=0 and nr!=self.checknum:
120 if self.diff and self.filename2status[filename]=="ok":
124 def file_status(self, filename, status):
125 self.filename2status[filename] = status
128 def __init__(self, nr, file, run):
132 self.flash_output = None
133 self.flash_error = None
134 self.compile_output = None
135 self.compile_error = None
138 try: os.unlink("abc.swf");
140 ret,output = runcmd("./parser",[self.file],wait=60)
141 self.compile_error = 0
142 self.compile_output = output
144 self.compile_output += "\nExit status %d" % (-ret)
145 self.compile_error = 1
147 if not os.path.isfile("abc.swf"):
148 self.compile_error = 1
153 ret,output = runcmd("flashplayer",["abc.swf"],wait=1)
154 os.system("killall flashplayer")
155 self.flash_output = output
157 if not check(self.flash_output):
163 print self.r(str(self.nr),3)," ",
164 if self.compile_error:
172 if not self.flash_error:
181 def doprintlong(self):
182 print self.nr, self.file
183 print "================================"
184 print "compile:", (self.compile_error and "error" or "ok")
185 print self.compile_output
188 print "================================"
189 print "run:", (self.flash_error and "error" or "ok")
190 print self.flash_output
191 print "================================"
196 return (" "*(l-len(s))) + s
200 return s + (" "*(l-len(s)))
202 class Test(TestBase):
203 def __init__(self, cache, nr, file):
204 TestBase.__init__(self, nr, file, run=1)
205 if self.compile() and self.run():
206 cache.file_status(file, "ok")
208 cache.file_status(file, "error")
210 class ErrTest(TestBase):
211 def __init__(self, cache, nr, file):
212 TestBase.__init__(self, nr, file, run=0)
214 cache.file_status(file, "error")
215 self.compile_error = True
217 cache.file_status(file, "ok")
218 self.compile_error = False
221 def __init__(self, cache, dir):
224 self.errtest = "err" in dir
226 print "-"*40,"tests \""+self.dir+"\"","-"*40
227 for file in sorted(os.listdir(self.dir)):
228 if not file.endswith(".as"):
231 file = os.path.join(self.dir, file)
233 if cache.skip_file(nr, file):
237 test = ErrTest(cache, nr, file)
239 test = Test(cache, nr, file)
241 if not cache.highlight(nr, file):
247 cache = Cache.load(".tests.cache")
251 nr = Suite(cache, "err").run(nr)
252 nr = Suite(cache, "ok").run(nr)
254 cache.save(".tests.cache")