3 # Copyright (C) 2007 Apple Inc. All rights reserved.
4 # Copyright (C) 2010 Mozilla Foundation
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 from __future__
import with_statement
32 suites
= ["kraken-1.1"]
34 def get_tests_path(path
):
35 prefix
= sys
.argv
[1] if len(sys
.argv
) > 1 else '.'
36 return os
.path
.join(prefix
, path
)
38 def get_hosted_path(path
):
39 prefix
= sys
.argv
[2] if len(sys
.argv
) > 2 else '.'
40 return os
.path
.join(prefix
, "hosted", path
)
42 def readTemplate(path
):
43 with
open(path
, 'r') as f
:
46 template
= readTemplate(get_tests_path("resources/TEMPLATE.html"))
47 driverTemplate
= readTemplate(get_tests_path("resources/driver-TEMPLATE.html"))
48 resultsTemplate
= readTemplate(get_tests_path("resources/results-TEMPLATE.html"))
50 def testListForSuite(suite
):
52 with
open(get_tests_path("tests/%s/LIST" % suite
), "r") as f
:
53 for line
in f
.readlines():
54 tests
.append(line
.strip())
57 def categoriesFromTests(tests
):
60 categories
.add(test
[:test
.find("-")])
61 categories
= list(categories
)
65 def escapeTestContent(test
,suite
):
66 with
open(get_tests_path("tests/" + suite
+ "/" + test
+ ".js")) as f
:
69 output
= output
.replace("@NAME@", test
)
70 output
= output
.replace("@SCRIPT@", script
)
71 dataPath
= get_tests_path("tests/" + suite
+ "/" + test
+ "-data.js")
72 if (os
.path
.exists(dataPath
)):
73 with
open(dataPath
) as f
:
75 output
= output
.replace("@DATASCRIPT@", datascript
)
77 output
= output
.replace("\\", "\\\\")
78 output
= output
.replace('"', '\\"')
79 output
= output
.replace("\n", "\\n\\\n")
82 def testContentsFromTests(suite
, tests
):
85 testContents
.append(escapeTestContent(test
, suite
))
88 def writeTemplate(suite
, template
, fileName
):
89 output
= template
.replace("@SUITE@", suite
)
90 with
open(get_hosted_path(suite
+ "/" + fileName
), "w") as f
:
94 suiteDir
= get_hosted_path(suite
)
95 if not os
.path
.exists(suiteDir
):
97 tests
= testListForSuite(suite
)
98 categories
= categoriesFromTests(tests
)
99 testContents
= testContentsFromTests(suite
, tests
)
100 writeTemplate(suite
, driverTemplate
, "driver.html")
101 writeTemplate(suite
, resultsTemplate
, "results.html")
103 prefix
= "var tests = [ " + ", ".join(['"%s"' % s
for s
in tests
]) + " ];\n"
104 prefix
+= "var categories = [ " + ", ".join(['"%s"' % s
for s
in categories
]) + " ];\n"
105 with
open(get_hosted_path(suite
+ "/test-prefix.js"), "w") as f
:
108 contents
= "var testContents = [ " + ", ".join(['"%s"' % s
for s
in testContents
]) + " ];\n"
109 with
open(get_hosted_path(suite
+ "/test-contents.js"), "w") as f
:
112 shutil
.copyfile(get_tests_path("resources/analyze-results.js"),
113 get_hosted_path("analyze-results.js"))
114 shutil
.copyfile(get_tests_path("resources/compare-results.js"),
115 get_hosted_path("compare-results.js"))
116 shutil
.copyfile(get_tests_path("hosted/json2.js"),
117 get_hosted_path("json2.js"))
118 shutil
.copyfile(get_tests_path("hosted/kraken.css"),
119 get_hosted_path("kraken.css"))