Skip to content

Commit 511c12a

Browse files
authored
Standard project for unit tests (#15)
* dotnet standard project for unit tests * tests * tests of any serialize
1 parent c3bf815 commit 511c12a

Some content is hidden

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

49 files changed

+395
-110
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@ sysinfo.txt
6161
crashlytics-build.properties
6262

6363
# Rider
64-
/.idea/
64+
/.idea/
65+
66+
!/Standard/**

Assets/Samples/AnySerialize.Samples.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "AnySerialize.Samples",
33
"rootNamespace": "",
44
"references": [
5-
"GUID:3ea4545e70041684b9bbf08dd5c6e257"
5+
"GUID:3ea4545e70041684b9bbf08dd5c6e257",
6+
"GUID:c8a1986dcbf446bd9c54d4528d20455d"
67
],
78
"includePlatforms": [],
89
"excludePlatforms": [],

Assets/Tests/AnyProcessor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "AnyProcessor.Tests",
3+
"rootNamespace": "",
4+
"references": [
5+
"UnityEngine.TestRunner",
6+
"UnityEditor.TestRunner",
7+
"AnyProcessor",
8+
"CecilTests",
9+
"AnyProcessor.CodeGen"
10+
],
11+
"includePlatforms": [],
12+
"excludePlatforms": [],
13+
"allowUnsafeCode": false,
14+
"overrideReferences": true,
15+
"precompiledReferences": [
16+
"nunit.framework.dll",
17+
"Mono.Cecil.dll",
18+
"Mono.Cecil.Mdb.dll",
19+
"Mono.Cecil.Pdb.dll",
20+
"Mono.Cecil.Rocks.dll"
21+
],
22+
"autoReferenced": false,
23+
"defineConstraints": [
24+
"UNITY_INCLUDE_TESTS"
25+
],
26+
"versionDefines": [],
27+
"noEngineReferences": false
28+
}

Assets/Tests/AnyProcessor/AnyProcessor.Tests.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Tests/CecilTestBase.cs renamed to Assets/Tests/AnyProcessor/CecilTestBase.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
3-
using AnyProccesor.Tests;
44
using AnyProcessor.CodeGen;
55
using Mono.Cecil;
66
using NUnit.Framework;
7-
using UnityEngine;
8-
using Assert = UnityEngine.Assertions.Assert;
97
using Object = System.Object;
108

119
namespace AnyProcessor.Tests
@@ -14,19 +12,23 @@ public class CecilTestBase
1412
{
1513
protected AssemblyDefinition _assemblyDefinition;
1614
protected ModuleDefinition _module;
15+
protected virtual IEnumerable<string> _AdditionalLocations => Enumerable.Empty<string>();
1716

1817
[SetUp]
1918
public void SetUp()
2019
{
2120
var assemblyLocation = GetType().Assembly.Location;
2221
_assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyLocation, new ReaderParameters
2322
{
24-
AssemblyResolver = new CodeGen.PostProcessorAssemblyResolver(
23+
AssemblyResolver = new CodeGen.PostProcessorAssemblyResolver(new []
24+
{
2525
GetType().Assembly.Location
2626
, typeof(object).Assembly.Location
2727
, typeof(Object).Assembly.Location
28+
#if UNITY_2020_1_OR_NEWER
2829
, typeof(UnityEngine.Object).Assembly.Location
29-
, typeof(AnotherAssembly).Assembly.Location
30+
#endif
31+
}.Concat(_AdditionalLocations).ToArray()
3032
)
3133
});
3234
_module = _assemblyDefinition.MainModule;
@@ -74,10 +76,28 @@ protected TypeReference ImportReference(Type type)
7476
}
7577
catch (Exception ex)
7678
{
77-
Debug.LogError($"cannot import reference of {type.AssemblyQualifiedName}: {ex}");
79+
LogError($"cannot import reference of {type.AssemblyQualifiedName}: {ex}");
7880
throw;
7981
}
8082
}
83+
84+
protected void Log(string msg)
85+
{
86+
#if UNITY_2020_1_OR_NEWER
87+
UnityEngine.Debug.Log(msg);
88+
#else
89+
Console.Out.WriteLine(msg);
90+
#endif
91+
}
92+
93+
protected void LogError(string error)
94+
{
95+
#if UNITY_2020_1_OR_NEWER
96+
UnityEngine.Debug.LogError(error);
97+
#else
98+
Console.Error.WriteLine(error);
99+
#endif
100+
}
81101

82102
protected TypeDefinition ImportDefinition<T>() => ImportDefinition(typeof(T));
83103
protected TypeDefinition ImportDefinition(Type type) => ImportReference(type).Resolve();
File renamed without changes.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
2-
using UnityEngine.Scripting;
32

4-
namespace AnyProccesor.Tests
3+
namespace AnyProcessor.Tests
54
{
65
public static class NonGeneric
76
{
@@ -45,7 +44,6 @@ public class DoubleObject : IInterface<double>
4544

4645
public static class MultipleGeneric
4746
{
48-
[Preserve]
4947
public interface IInterface<T, U> {}
5048

5149
[Serializable]

0 commit comments

Comments
 (0)