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=1)
141 self.compile_error = 0
142 self.compile_output = output
145 self.compile_output += "\nExit status %d" % (-ret)
146 self.exit_status = -ret
147 self.compile_error = 1
149 if not os.path.isfile("abc.swf"):
150 self.compile_error = 1
155 ret,output = runcmd("flashplayer",["abc.swf"],wait=1)
156 os.system("killall flashplayer")
157 self.flash_output = output
159 if not check(self.flash_output):
165 print self.r(str(self.nr),3)," ",
166 if self.compile_error:
168 if self.exit_status == 11:
177 if not self.flash_error:
186 def doprintlong(self):
187 print self.nr, self.file
188 print "================================"
189 print "compile:", (self.compile_error and "error" or "ok")
190 print self.compile_output
193 print "================================"
194 print "run:", (self.flash_error and "error" or "ok")
195 print self.flash_output
196 print "================================"
201 return (" "*(l-len(s))) + s
205 return s + (" "*(l-len(s)))
207 class Test(TestBase):
208 def __init__(self, cache, nr, file):
209 TestBase.__init__(self, nr, file, run=1)
210 if self.compile() and self.run():
211 cache.file_status(file, "ok")
213 cache.file_status(file, "error")
215 class ErrTest(TestBase):
216 def __init__(self, cache, nr, file):
217 TestBase.__init__(self, nr, file, run=0)
219 cache.file_status(file, "error")
220 self.compile_error = True
222 cache.file_status(file, "ok")
223 self.compile_error = False
226 def __init__(self, cache, dir):
229 self.errtest = "err" in dir
231 print "-"*40,"tests \""+self.dir+"\"","-"*40
232 for file in sorted(os.listdir(self.dir)):
233 if not file.endswith(".as"):
236 file = os.path.join(self.dir, file)
238 if cache.skip_file(nr, file):
242 test = ErrTest(cache, nr, file)
244 test = Test(cache, nr, file)
246 if not cache.highlight(nr, file):
252 cache = Cache.load(".tests.cache")
256 #nr = Suite(cache, "err").run(nr)
257 nr = Suite(cache, "ok").run(nr)
259 cache.save(".tests.cache")