Skip to content

Commit 9b69f14

Browse files
committed
Move GeneratorTestFixture type to its own file.
1 parent f474a73 commit 9b69f14

File tree

2 files changed

+89
-82
lines changed

2 files changed

+89
-82
lines changed

src/Generator.Tests/GeneratorTest.cs

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4-
using System.Text.RegularExpressions;
54
using CppSharp.AST;
65
using CppSharp.Generators;
7-
using NUnit.Framework;
86

97
namespace CppSharp.Utils
108
{
@@ -107,84 +105,4 @@ static string GetOutputDirectory()
107105
}
108106
#endregion
109107
}
110-
111-
/// <summary>
112-
/// The main NUnit fixture base class for a generator-based tests project.
113-
/// Provides support for a text-based test system that looks for lines
114-
/// in the native test declarations that match a certain pattern, which
115-
/// are used for certain kinds of tests that cannot be done with just
116-
/// C# code and using the generated wrappers.
117-
/// </summary>
118-
[TestFixture]
119-
public abstract class GeneratorTestFixture
120-
{
121-
readonly string assemblyName;
122-
123-
protected GeneratorTestFixture()
124-
{
125-
var location = Assembly.GetCallingAssembly().Location;
126-
assemblyName = Path.GetFileNameWithoutExtension(location);
127-
}
128-
129-
static bool GetGeneratorKindFromLang(string lang, out GeneratorKind kind)
130-
{
131-
kind = GeneratorKind.CSharp;
132-
133-
switch(lang)
134-
{
135-
case "CSharp":
136-
case "C#":
137-
kind = GeneratorKind.CSharp;
138-
return true;
139-
case "CLI":
140-
kind = GeneratorKind.CLI;
141-
return true;
142-
}
143-
144-
return false;
145-
}
146-
147-
[Test]
148-
public void CheckDirectives()
149-
{
150-
var name = assemblyName.Substring(0, assemblyName.IndexOf('.'));
151-
var kind = assemblyName.Substring(assemblyName.LastIndexOf('.') + 1);
152-
GeneratorKind testKind;
153-
if (!GetGeneratorKindFromLang(kind, out testKind))
154-
throw new NotSupportedException("Unknown language generator");
155-
156-
var path = Path.GetFullPath(GeneratorTest.GetTestsDirectory(name));
157-
158-
foreach (var header in Directory.EnumerateFiles(path, "*.h"))
159-
{
160-
var headerText = File.ReadAllText(header);
161-
162-
// Parse the header looking for suitable lines to test.
163-
foreach (var line in File.ReadAllLines(header))
164-
{
165-
var match = Regex.Match(line, @"^\s*///*\s*(\S+)\s*:\s*(.*)");
166-
if (!match.Success)
167-
continue;
168-
169-
var matchLang = match.Groups[1].Value;
170-
GeneratorKind matchKind;
171-
if (!GetGeneratorKindFromLang(matchLang.ToUpper(), out matchKind))
172-
continue;
173-
174-
if (matchKind != testKind)
175-
continue;
176-
177-
var matchText = match.Groups[2].Value;
178-
if (string.IsNullOrWhiteSpace(matchText))
179-
continue;
180-
181-
var matchIndex = headerText.IndexOf(matchText, StringComparison.Ordinal);
182-
Assert.IsTrue(matchIndex != -1,
183-
string.Format("Could not match '{0}' in file '{1}'",
184-
matchText, header));
185-
}
186-
}
187-
188-
}
189-
}
190108
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using System.Text.RegularExpressions;
5+
using CppSharp.Generators;
6+
using NUnit.Framework;
7+
8+
namespace CppSharp.Utils
9+
{
10+
/// <summary>
11+
/// The main NUnit fixture base class for a generator-based tests project.
12+
/// Provides support for a text-based test system that looks for lines
13+
/// in the native test declarations that match a certain pattern, which
14+
/// are used for certain kinds of tests that cannot be done with just
15+
/// C# code and using the generated wrappers.
16+
/// </summary>
17+
[TestFixture]
18+
public abstract class GeneratorTestFixture
19+
{
20+
readonly string assemblyName;
21+
22+
protected GeneratorTestFixture()
23+
{
24+
var location = Assembly.GetCallingAssembly().Location;
25+
assemblyName = Path.GetFileNameWithoutExtension(location);
26+
}
27+
28+
static bool GetGeneratorKindFromLang(string lang, out GeneratorKind kind)
29+
{
30+
kind = GeneratorKind.CSharp;
31+
32+
switch(lang)
33+
{
34+
case "CSharp":
35+
case "C#":
36+
kind = GeneratorKind.CSharp;
37+
return true;
38+
case "CLI":
39+
kind = GeneratorKind.CLI;
40+
return true;
41+
}
42+
43+
return false;
44+
}
45+
46+
[Test]
47+
public void CheckDirectives()
48+
{
49+
var name = assemblyName.Substring(0, assemblyName.IndexOf('.'));
50+
var kind = assemblyName.Substring(assemblyName.LastIndexOf('.') + 1);
51+
GeneratorKind testKind;
52+
if (!GetGeneratorKindFromLang(kind, out testKind))
53+
throw new NotSupportedException("Unknown language generator");
54+
55+
var path = Path.GetFullPath(GeneratorTest.GetTestsDirectory(name));
56+
57+
foreach (var header in Directory.EnumerateFiles(path, "*.h"))
58+
{
59+
var headerText = File.ReadAllText(header);
60+
61+
// Parse the header looking for suitable lines to test.
62+
foreach (var line in File.ReadAllLines(header))
63+
{
64+
var match = Regex.Match(line, @"^\s*///*\s*(\S+)\s*:\s*(.*)");
65+
if (!match.Success)
66+
continue;
67+
68+
var matchLang = match.Groups[1].Value;
69+
GeneratorKind matchKind;
70+
if (!GetGeneratorKindFromLang(matchLang.ToUpper(), out matchKind))
71+
continue;
72+
73+
if (matchKind != testKind)
74+
continue;
75+
76+
var matchText = match.Groups[2].Value;
77+
if (string.IsNullOrWhiteSpace(matchText))
78+
continue;
79+
80+
var matchIndex = headerText.IndexOf(matchText, StringComparison.Ordinal);
81+
Assert.IsTrue(matchIndex != -1,
82+
string.Format("Could not match '{0}' in file '{1}'",
83+
matchText, header));
84+
}
85+
}
86+
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)