6
import distutils.file_util
10
import nose.plugins.builtin
11
import makeloadertests
13
class JsTest(nose.plugins.Plugin):
14
def options(self, parser, env=os.environ):
15
nose.plugins.Plugin.options(self, parser, env)
16
parser.add_option("--revalidate-logs", action="store_true",
17
dest="revalidate_logs",
19
help="For all tests run, makes their logs "
20
"the expected, or canonical, log file to "
21
"which all future runs of the tests are "
24
def configure(self, options, config):
25
nose.plugins.Plugin.configure(self, options, config)
26
self.revalidate_logs = options.revalidate_logs
28
def wantFile(self, file):
29
basename = os.path.basename(file)
30
ext = os.path.splitext(file)[1]
31
if (basename.startswith("test_") and ext == ".js"):
33
# Oddly enough, if we return 'False' here instead of 'None',
34
# none of the other plugins get a chance to test the file.
37
def loadTestsFromFile(self, filename):
38
return [JsTestCase(filename, self.revalidate_logs)]
40
class JsTestCase(unittest.TestCase):
41
def __init__(self, test, revalidate_logs):
43
self.__revalidate_logs = revalidate_logs
44
unittest.TestCase.__init__(self)
46
def shortDescription(self):
47
return os.path.basename(os.path.splitext(self.__test)[0])
51
dirname = os.path.dirname(test)
52
testname = os.path.splitext(os.path.basename(test))[0]
53
result = subprocess.call(
56
"-f", "../harness/Makefile",
58
stdout = subprocess.PIPE,
59
stderr = subprocess.STDOUT
61
logfile_name = os.path.join(dirname, testname + ".log")
63
self.fail(open(logfile_name, "r").read())
65
expected_logfile_name = logfile_name + ".expected"
66
if self.__revalidate_logs:
67
distutils.file_util.copy_file(logfile_name,
68
expected_logfile_name)
69
if os.path.exists(expected_logfile_name):
70
expected = open(expected_logfile_name, "r").read()
71
actual = open(logfile_name, "r").read()
72
if expected != actual:
73
diff = "Expected results differ from actual results.\n\n"
74
diff += "\n".join(difflib.unified_diff(
75
expected.splitlines(), actual.splitlines(),
76
"expected results", "actual results"
78
diff += ("\n\nIf you believe that these changes are valid "
79
"(i.e., that they don't represent malfunctioning "
80
"code), you may want to re-validate the expected "
81
"results by running the following command:\n\n")
82
diff += "python %s %s --revalidate-logs\n" % (
88
if __name__ == "__main__":
89
makeloadertests.remove_old_loader_tests()
90
makeloadertests.make_loader_tests()
92
sys.argv.append("--with-jstest")
93
nose.main(defaultTest=["scripts",