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_error = 1
137 if not os.path.isfile("abc.swf"):
138 self.compile_error = 1
143 ret,output = runcmd("flashplayer",["abc.swf"],wait=1)
144 os.system("killall flashplayer")
145 self.flash_output = output
147 if not check(self.flash_output):
153 print self.r(str(self.nr),3)," ",
154 if self.compile_error:
162 if not self.flash_error:
171 def doprintlong(self):
172 print self.nr, self.file
173 print "================================"
174 print "compile:", (test.compile_error and "error" or "ok")
175 print test.compile_output
178 print "================================"
179 print "run:", (test.flash_error and "error" or "ok")
180 print test.flash_output
181 print "================================"
186 return (" "*(l-len(s))) + s
190 return s + (" "*(l-len(s)))
192 class Test(TestBase):
193 def __init__(self, cache, nr, file):
194 TestBase.__init__(self, nr, file, run=1)
195 if self.compile() and self.run():
196 cache.file_status(file, "ok")
198 cache.file_status(file, "error")
200 class ErrTest(TestBase):
201 def __init__(self, cache, nr, file):
202 TestBase.__init__(self, nr, file, run=0)
204 cache.file_status(file, "error")
205 self.compile_error = True
207 cache.file_status(file, "ok")
208 self.compile_error = False
211 def __init__(self, cache, dir):
214 self.errtest = "err" in dir
216 print "-"*40,"tests \""+self.dir+"\"","-"*40
217 for file in sorted(os.listdir(self.dir)):
218 if not file.endswith(".as"):
221 file = os.path.join(self.dir, file)
223 if cache.skip_file(nr, file):
227 test = ErrTest(cache, nr, file)
229 test = Test(cache, nr, file)
231 if not cache.highlight(nr, file):
237 cache = Cache.load(".tests.cache")
241 nr = Suite(cache, "err").run(nr)
242 nr = Suite(cache, "ok").run(nr)
244 cache.save(".tests.cache")