forked from bamboo/boojay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefresh-tests.boo
executable file
·58 lines (48 loc) · 1.76 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
"""
Finds all test cases under tests/integration and generates runTestCase calls
in IntegrationTest.Generated.boo
First line of test case can specify a nunit attribute to go with it:
* "// ignore reason" for [Ignore("reason")]
* "// category name" for [Category("name")]
"""
import System.IO
import Boo.Lang.PatternMatching
def testCaseName(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(".boo")
++count
writeTestCase(writer, fname)
for subDir in Directory.GetDirectories(baseDir):
writeTestCases(writer, subDir)
print("${count} test cases found in ${baseDir}.")
def writeTestCase(writer as TextWriter, fname as string):
writer.Write("""
${CategoryAttributeFor(fname)}
[Test] def ${testCaseName(fname)}():
runTestCase("${fname.Replace('\\', '/')}")
""")
def CategoryAttributeFor(testFile as string):
"""
If the first line of the test case file starts with // category CategoryName
then return a suitable [CategoryName()] attribute.
"""
match FirstLineOf(testFile):
case /\/\/\s*ignore\s+(?<reason>.*)/:
return "[Ignore(\"${reason[0].Value.Trim()}\")]"
case /\/\/\s*category\s+(?<name>.*)/:
return "[Category(\"${name[0].Value.Trim()}\")]"
otherwise:
return ""
def FirstLineOf(fname as string):
using reader=File.OpenText(fname):
return reader.ReadLine()
using writer = StreamWriter("src/Boojay.Compilation.Tests/IntegrationTest.Generated.boo"):
writer.Write("""
namespace Boojay.Compilation.Tests
import NUnit.Framework
partial class IntegrationTest:
""")
writeTestCases(writer, "tests/integration")