Skip to content

Commit 03dacfb

Browse files
authored
[generator-Tests] Move lone Tests-Core test to NUnit (#679)
The `make run-test-generator-core` target ran a set of `generator` unit tests, but only on macOS, *not* Windows. Move these tests into the `Integration-Tests` NUnit suite for `generator` so that it runs everywhere.
1 parent e59d37f commit 03dacfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+334
-365
lines changed

Makefile

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ run-all-tests:
4444
r=0; \
4545
$(MAKE) run-tests || r=1 ; \
4646
$(MAKE) run-test-jnimarshal || r=1 ; \
47-
$(MAKE) run-test-generator-core || r=1 ; \
4847
$(MAKE) run-ptests || r=1 ; \
4948
exit $$r;
5049

@@ -165,31 +164,9 @@ run-test-jnimarshal: bin/Test$(CONFIGURATION)/Java.Interop.Export-Tests.dll bin/
165164
$(call run-jnimarshalmethod-gen,"$<")
166165
$(call RUN_TEST,$<)
167166

168-
# $(call GEN_CORE_OUTPUT, outdir, suffix, extra)
169-
define GEN_CORE_OUTPUT
170-
-$(RM) -Rf $(1)
171-
mkdir -p $(1)
172-
$(RUNTIME) bin/Test$(CONFIGURATION)/generator.exe -o $(1) $(3) --api-level=20 tests/generator-Tests/Tests-Core/api$(2).xml \
173-
--enummethods=tests/generator-Tests/Tests-Core/methods$(2).xml \
174-
--enumfields=tests/generator-Tests/Tests-Core/fields$(2).xml \
175-
--enumdir=$(1)
176-
endef
177-
178-
run-test-generator-core: bin/Test$(CONFIGURATION)/generator.exe
179-
$(call GEN_CORE_OUTPUT,bin/Test$(CONFIGURATION)/generator-core)
180-
diff -rup --strip-trailing-cr tests/generator-Tests/Tests-Core/expected bin/Test$(CONFIGURATION)/generator-core
181-
$(call GEN_CORE_OUTPUT,bin/Test$(CONFIGURATION)/generator-core,,--codegen-target=JavaInterop1)
182-
diff -rup --strip-trailing-cr tests/generator-Tests/Tests-Core/expected.ji bin/Test$(CONFIGURATION)/generator-core
183-
$(call GEN_CORE_OUTPUT,bin/Test$(CONFIGURATION)/generator-core,-cp)
184-
diff -rup --strip-trailing-cr tests/generator-Tests/Tests-Core/expected.cp bin/Test$(CONFIGURATION)/generator-core
185-
186167
bin/Test$(CONFIGURATION)/generator.exe: bin/$(CONFIGURATION)/generator.exe
187168
cp $<* `dirname "$@"`
188169

189-
update-test-generator-core:
190-
$(call GEN_CORE_OUTPUT,tests/generator-Tests/Tests-Core/expected)
191-
$(call GEN_CORE_OUTPUT,tests/generator-Tests/Tests-Core/expected.ji,--codegen-target=JavaInterop1)
192-
193170
update-test-generator-nunit:
194171
-$(MAKE) run-tests TESTS=bin/Test$(CONFIGURATION)/generator-Tests.dll
195172
for f in `find tests/generator-Tests/expected -name \*.cs` ; do \

tests/generator-Tests/Integration-Tests/BaseGeneratorTest.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ private byte[] ReadAllBytesIgnoringLineEndings (string path)
119119
}
120120
}
121121

122-
protected void RunAllTargets (string outputRelativePath, string apiDescriptionFile, string expectedRelativePath, string[] additionalSupportPaths = null)
122+
protected void RunAllTargets (string outputRelativePath, string apiDescriptionFile, string expectedRelativePath, string[] additionalSupportPaths = null, string enumFieldsMapFile = null, string enumMethodMapFile = null)
123123
{
124-
Run (CodeGenerationTarget.XamarinAndroid, Path.Combine ("out", outputRelativePath), apiDescriptionFile, Path.Combine ("expected", expectedRelativePath), additionalSupportPaths);
125-
Run (CodeGenerationTarget.JavaInterop1, Path.Combine ("out.ji", outputRelativePath), apiDescriptionFile, Path.Combine ("expected.ji", expectedRelativePath), additionalSupportPaths);
124+
Run (CodeGenerationTarget.XamarinAndroid, Path.Combine ("out", outputRelativePath), apiDescriptionFile, Path.Combine ("expected", expectedRelativePath), additionalSupportPaths, enumFieldsMapFile, enumMethodMapFile);
125+
Run (CodeGenerationTarget.JavaInterop1, Path.Combine ("out.ji", outputRelativePath), apiDescriptionFile, Path.Combine ("expected.ji", expectedRelativePath), additionalSupportPaths, enumFieldsMapFile, enumMethodMapFile);
126126
}
127127

128128
protected string FullPath (string path)
@@ -131,20 +131,37 @@ protected string FullPath (string path)
131131
return Path.Combine (dir, path.Replace ('/', Path.DirectorySeparatorChar));
132132
}
133133

134-
protected void Run (CodeGenerationTarget target, string outputPath, string apiDescriptionFile, string expectedPath, string[] additionalSupportPaths = null)
134+
protected void Run (CodeGenerationTarget target, string outputPath, string apiDescriptionFile, string expectedPath, string[] additionalSupportPaths = null, string enumFieldsMapFile = null, string enumMethodMapFile = null)
135135
{
136136
Cleanup (outputPath);
137137

138138
Options.CodeGenerationTarget = target;
139139
Options.ApiDescriptionFile = FullPath (apiDescriptionFile);
140140
Options.ManagedCallableWrapperSourceOutputDirectory = FullPath (outputPath);
141141

142+
if (!string.IsNullOrWhiteSpace (enumFieldsMapFile))
143+
Options.EnumFieldsMapFile = FullPath (enumFieldsMapFile);
144+
145+
if (!string.IsNullOrWhiteSpace (enumMethodMapFile))
146+
Options.EnumMethodsMapFile = FullPath (enumMethodMapFile);
147+
148+
var adjuster_output = Path.Combine (Path.GetTempPath (), "generator-tests");
149+
Directory.CreateDirectory (adjuster_output);
150+
151+
// Put this in a temp folder so it doesn't end up in "expected", which breaks the compare.
152+
Options.ApiXmlAdjusterOutput = Path.Combine (adjuster_output, Path.GetFileName (apiDescriptionFile) + ".adjusted");
153+
142154
if (additionalSupportPaths != null) {
143155
AdditionalSourceDirectories.AddRange (additionalSupportPaths.Select (p => FullPath (p)));
144156
}
145157

146158
Execute ();
147159

160+
// Try to clean up after ourselves.
161+
try {
162+
Directory.Delete (adjuster_output, true);
163+
} catch { }
164+
148165
CompareOutputs (expectedPath, outputPath);
149166
}
150167
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using NUnit.Framework;
3+
4+
namespace generatortests
5+
{
6+
[TestFixture]
7+
public class Core_ClassParse : BaseGeneratorTest
8+
{
9+
[Test]
10+
public void GeneratedOK ()
11+
{
12+
AllowWarnings = true;
13+
14+
RunAllTargets (
15+
outputRelativePath: "Core_ClassParse",
16+
apiDescriptionFile: "expected/Core_ClassParse/api.xml",
17+
expectedRelativePath: "Core_ClassParse");
18+
}
19+
}
20+
}
21+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using NUnit.Framework;
3+
4+
namespace generatortests
5+
{
6+
[TestFixture]
7+
public class Core_Jar2Xml : BaseGeneratorTest
8+
{
9+
[Test]
10+
public void GeneratedOK ()
11+
{
12+
AllowWarnings = true;
13+
14+
RunAllTargets (
15+
outputRelativePath: "Core_Jar2Xml",
16+
apiDescriptionFile: "expected/Core_Jar2Xml/api.xml",
17+
expectedRelativePath: "Core_Jar2Xml",
18+
enumFieldsMapFile: "expected/Core_Jar2Xml/fields.xml",
19+
enumMethodMapFile: "expected/Core_Jar2Xml/methods.xml"
20+
);
21+
}
22+
}
23+
}
24+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace Android.Text {
4+
5+
public enum SpanTypes {
6+
None = 0
7+
}
8+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
3+
namespace Java.Interop {
4+
5+
public static class EventHelper {
6+
7+
public static void AddEventHandler<TInterface, TImplementor> (
8+
ref WeakReference implementor,
9+
Func<TImplementor> creator,
10+
Action<TInterface> setListener,
11+
Action<TImplementor> add)
12+
where TImplementor : Java.Lang.Object, TInterface
13+
{
14+
TImplementor impl = null;
15+
if (implementor == null || (impl = (TImplementor) implementor.Target) == null) {
16+
impl = creator ();
17+
implementor = new WeakReference (impl, true);
18+
setListener (impl);
19+
}
20+
add (impl);
21+
}
22+
23+
public static void RemoveEventHandler<TInterface, TImplementor> (
24+
ref WeakReference implementor,
25+
Func<TImplementor, bool> empty,
26+
Action<TInterface> unsetListener,
27+
Action<TImplementor> remove)
28+
where TImplementor : Java.Lang.Object, TInterface
29+
{
30+
TImplementor impl = null;
31+
if (implementor == null || (impl = (TImplementor) implementor.Target) == null)
32+
return;
33+
remove (impl);
34+
if (empty (impl)) {
35+
unsetListener (impl);
36+
impl = null;
37+
implementor.Target = null;
38+
implementor = null;
39+
}
40+
}
41+
}
42+
}
43+

tests/generator-Tests/Tests-Core/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/generator-Tests/Tests-Core/expected.cp/GeneratedFiles.projitems

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/generator-Tests/Tests-Core/expected.cp/Java.Interop.__TypeRegistrations.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/generator-Tests/Tests-Core/expected.cp/__NamespaceMapping__.cs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)