forked from bamboo/unityscript
-
Notifications
You must be signed in to change notification settings - Fork 2
/
refresh-tests.boo
executable file
·153 lines (112 loc) · 3.94 KB
/
refresh-tests.boo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env booi
"""
Generates test fixtures from files under tests/
"""
import System
import System.IO
//def MapPath(path):
// return Path.Combine(Project.BaseDirectory, path)
def GetTestCaseName(fname as string):
return Path.GetFileNameWithoutExtension(fname).Replace("-", "_")
def WriteTestCases(writer as TextWriter, baseDir as string):
count = 0
for fname in Directory.GetFiles(baseDir):
continue unless fname.EndsWith(".js")
++count
ignoreAttribute = IgnoreAttributeFor(fname)
writer.Write("""
[Test]${ignoreAttribute}
def ${GetTestCaseName(fname)}():
RunTestCase("${fname.Replace('\\', '/')}")
""")
print("${count} test cases found in ${baseDir}.")
def IgnoreAttributeFor(testFile as string):
"""
If the first line of the test case file starts with // ignore
then return a suitable [Ignore()] attribute.
"""
m = /\/\/\s*ignore\s+(.*)/.Match(FirstLineOf(testFile))
if not m.Success: return string.Empty
reason = m.Groups[1].Value.Trim()
return """[Ignore("${reason}")]"""
def FirstLineOf(fname as string):
using reader=File.OpenText(fname):
return reader.ReadLine()
def GenerateTestFixture(srcDir as string, targetFile as string, header as string):
contents = GenerateTestFixtureSource(srcDir, header)
if ShouldReplaceContent(targetFile, contents):
WriteAllText(targetFile, contents)
def ShouldReplaceContent(fname as string, contents as string):
if not File.Exists(fname): return true
return ns(ReadAllText(fname)) != ns(contents)
def ReadAllText(fname as string):
using reader=File.OpenText(fname):
return reader.ReadToEnd()
def WriteAllText(fname as string, contents as string):
using writer=StreamWriter(fname):
writer.Write(contents)
def ns(s as string):
"""
Normalize string.
"""
return s.Trim().Replace("\r\n", Environment.NewLine)
def GenerateTestFixtureSource(srcDir as string, header as string):
writer=StringWriter()
writer.Write(header)
WriteTestCases(writer, srcDir)
return writer.ToString()
GenerateTestFixture("tests/parser", "src/UnityScript.Tests/ParserTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
partial class ParserTestFixture:
""")
GenerateTestFixture("tests/semantics", "src/UnityScript.Tests/SemanticsTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
[TestFixture]
class SemanticsTestFixture(AbstractSemanticsTestFixture):
""")
GenerateTestFixture("tests/integration", "src/UnityScript.Tests/IntegrationTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
[TestFixture]
class IntegrationTestFixture(AbstractIntegrationTestFixture):
""")
GenerateTestFixture("tests/pragma", "src/UnityScript.Tests/PragmaTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
[TestFixture]
class PragmaTestFixture(AbstractIntegrationTestFixture):
""")
GenerateTestFixture("tests/generics", "src/UnityScript.Tests/GenericsTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
[TestFixture]
class GenericsTestFixture(AbstractIntegrationTestFixture):
""")
GenerateTestFixture("tests/eval", "src/UnityScript.Tests/EvalTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
[TestFixture]
class EvalTestFixture(AbstractIntegrationTestFixture):
""")
GenerateTestFixture("tests/expando", "src/UnityScript.Tests/ExpandoTestFixture.boo", """
namespace UnityScript.Tests
import NUnit.Framework
[TestFixture]
class ExpandoTestFixture(AbstractIntegrationTestFixture):
override def CreateCompiler():
compiler = super()
compiler.Parameters.Expando = true
return compiler
""")
GenerateTestFixture("tests/error-messages", "src/UnityScript.Tests/ErrorMessagesTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
partial class ErrorMessagesTestFixture:
""")
GenerateTestFixture("tests/stacktrace", "src/UnityScript.Tests/StackTraceTestFixture.Generated.boo", """
namespace UnityScript.Tests
import NUnit.Framework
partial class StackTraceTestFixture:
""")