Skip to content

Commit 6fd5cbf

Browse files
committed
Testing Project
Automatic Versioning
1 parent 3f23d1d commit 6fd5cbf

10 files changed

Lines changed: 321 additions & 5 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<ProjectGuid>{53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}</ProjectGuid>
6+
<OutputType>Library</OutputType>
7+
<AppDesignerFolder>Properties</AppDesignerFolder>
8+
<RootNamespace>Concealment.Tests</RootNamespace>
9+
<AssemblyName>Concealment.Tests</AssemblyName>
10+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
11+
<FileAlignment>512</FileAlignment>
12+
<TargetFrameworkProfile />
13+
<NuGetPackageImportStamp>
14+
</NuGetPackageImportStamp>
15+
<NoWarn>1591,0649</NoWarn>
16+
</PropertyGroup>
17+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
18+
<DebugSymbols>true</DebugSymbols>
19+
<OutputPath>$(SolutionDir)\bin-test\x64\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<DebugType>full</DebugType>
22+
<PlatformTarget>x64</PlatformTarget>
23+
<ErrorReport>prompt</ErrorReport>
24+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
25+
</PropertyGroup>
26+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
27+
<OutputPath>$(SolutionDir)\bin-test\x64\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<Optimize>true</Optimize>
30+
<DebugType>pdbonly</DebugType>
31+
<PlatformTarget>x64</PlatformTarget>
32+
<ErrorReport>prompt</ErrorReport>
33+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
34+
<DocumentationFile>$(SolutionDir)\bin-test\x64\Release\Concealment.Tests.xml</DocumentationFile>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
38+
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="Microsoft.CSharp" />
46+
<Reference Include="System.Data" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xml" />
49+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
50+
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
51+
</Reference>
52+
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
53+
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
54+
</Reference>
55+
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
56+
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
57+
</Reference>
58+
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
59+
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
60+
</Reference>
61+
<Reference Include="Torch">
62+
<HintPath>$(SolutionDir)\TorchBinaries\Torch.dll</HintPath>
63+
<Private>True</Private>
64+
</Reference>
65+
<Reference Include="Torch.API">
66+
<HintPath>$(SolutionDir)\TorchBinaries\Torch.API.dll</HintPath>
67+
<Private>True</Private>
68+
</Reference>
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Compile Include="..\Versioning\AssemblyVersion.cs">
72+
<Link>Properties\AssemblyVersion.cs</Link>
73+
</Compile>
74+
<Compile Include="Properties\AssemblyInfo.cs" />
75+
<Compile Include="ReflectionTestManager.cs" />
76+
<Compile Include="TestUtils.cs" />
77+
<Compile Include="TorchReflectionTest.cs" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<ProjectReference Include="..\Concealment\Concealment.csproj">
81+
<Project>{E5C0184B-7DC4-43D8-872E-2F71162748AA}</Project>
82+
<Name>Concealment</Name>
83+
<Private>True</Private>
84+
</ProjectReference>
85+
</ItemGroup>
86+
<ItemGroup>
87+
<None Include="packages.config" />
88+
</ItemGroup>
89+
<ItemGroup>
90+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
91+
</ItemGroup>
92+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
[assembly: AssemblyTitle("Torch Tests")]
5+
[assembly: AssemblyDescription("")]
6+
[assembly: AssemblyCompany("")]
7+
[assembly: AssemblyProduct("Torch")]
8+
[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
9+
[assembly: AssemblyTrademark("")]
10+
[assembly: AssemblyCulture("")]
11+
[assembly: ComVisible(false)]
12+
13+
#if DEBUG
14+
[assembly: AssemblyConfiguration("Debug")]
15+
#else
16+
[assembly: AssemblyConfiguration("Release")]
17+
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using Torch.Utils;
5+
6+
namespace Torch.Tests
7+
{
8+
public class ReflectionTestManager
9+
{
10+
#region FieldProvider
11+
public struct FieldRef
12+
{
13+
public FieldInfo Field;
14+
15+
public FieldRef(FieldInfo f)
16+
{
17+
Field = f;
18+
}
19+
20+
public override string ToString()
21+
{
22+
if (Field == null)
23+
return "Ignored";
24+
return Field.DeclaringType?.FullName + "." + Field.Name;
25+
}
26+
}
27+
28+
private readonly HashSet<object[]> _getters = new HashSet<object[]>();
29+
private readonly HashSet<object[]> _setters = new HashSet<object[]>();
30+
private readonly HashSet<object[]> _invokers = new HashSet<object[]>();
31+
32+
public ReflectionTestManager()
33+
{
34+
_getters.Add(new object[] { new FieldRef(null) });
35+
_setters.Add(new object[] { new FieldRef(null) });
36+
_invokers.Add(new object[] { new FieldRef(null) });
37+
}
38+
39+
public ReflectionTestManager Init(Assembly asm)
40+
{
41+
foreach (Type type in asm.GetTypes())
42+
Init(type);
43+
return this;
44+
}
45+
46+
public ReflectionTestManager Init(Type type)
47+
{
48+
foreach (FieldInfo field in type.GetFields(BindingFlags.Static |
49+
BindingFlags.Instance |
50+
BindingFlags.Public |
51+
BindingFlags.NonPublic))
52+
{
53+
if (field.GetCustomAttribute<ReflectedMethodAttribute>() != null)
54+
_invokers.Add(new object[] { new FieldRef(field) });
55+
if (field.GetCustomAttribute<ReflectedGetterAttribute>() != null)
56+
_getters.Add(new object[] { new FieldRef(field) });
57+
if (field.GetCustomAttribute<ReflectedSetterAttribute>() != null)
58+
_setters.Add(new object[] { new FieldRef(field) });
59+
}
60+
return this;
61+
}
62+
63+
public IEnumerable<object[]> Getters => _getters;
64+
65+
public IEnumerable<object[]> Setters => _setters;
66+
67+
public IEnumerable<object[]> Invokers => _invokers;
68+
69+
#endregion
70+
71+
}
72+
}

Concealment.Tests/TestUtils.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Torch.Utils;
8+
9+
namespace Torch.Tests
10+
{
11+
public sealed class TestUtils
12+
{
13+
public static void Init()
14+
{
15+
if (_torchResolver == null)
16+
_torchResolver = new TorchAssemblyResolver(GetGameBinaries());
17+
}
18+
19+
private static string GetGameBinaries()
20+
{
21+
string dir = Environment.CurrentDirectory;
22+
while (!string.IsNullOrWhiteSpace(dir))
23+
{
24+
string gameBin = Path.Combine(dir, "GameBinaries");
25+
if (Directory.Exists(gameBin))
26+
return gameBin;
27+
28+
dir = Path.GetDirectoryName(dir);
29+
}
30+
throw new Exception("GetGameBinaries failed to find a folder named GameBinaries in the directory tree");
31+
}
32+
33+
private static TorchAssemblyResolver _torchResolver;
34+
}
35+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
using Torch.Tests;
9+
using Torch.Utils;
10+
using Xunit;
11+
12+
namespace Concealment.Tests
13+
{
14+
public class TorchReflectionTest
15+
{
16+
static TorchReflectionTest()
17+
{
18+
TestUtils.Init();
19+
}
20+
21+
private static ReflectionTestManager _manager;
22+
23+
private static ReflectionTestManager Manager()
24+
{
25+
TestUtils.Init();
26+
if (_manager != null)
27+
return _manager;
28+
return _manager = new ReflectionTestManager().Init(typeof(ConcealmentPlugin).Assembly);
29+
}
30+
31+
public static IEnumerable<object[]> Getters => Manager().Getters;
32+
33+
public static IEnumerable<object[]> Setters => Manager().Setters;
34+
35+
public static IEnumerable<object[]> Invokers => Manager().Invokers;
36+
37+
#region Binding
38+
[Theory]
39+
[MemberData(nameof(Getters))]
40+
public void TestBindingGetter(ReflectionTestManager.FieldRef field)
41+
{
42+
if (field.Field == null)
43+
return;
44+
Assert.True(ReflectedManager.Process(field.Field));
45+
if (field.Field.IsStatic)
46+
Assert.NotNull(field.Field.GetValue(null));
47+
}
48+
49+
[Theory]
50+
[MemberData(nameof(Setters))]
51+
public void TestBindingSetter(ReflectionTestManager.FieldRef field)
52+
{
53+
if (field.Field == null)
54+
return;
55+
Assert.True(ReflectedManager.Process(field.Field));
56+
if (field.Field.IsStatic)
57+
Assert.NotNull(field.Field.GetValue(null));
58+
}
59+
60+
[Theory]
61+
[MemberData(nameof(Invokers))]
62+
public void TestBindingInvoker(ReflectionTestManager.FieldRef field)
63+
{
64+
if (field.Field == null)
65+
return;
66+
Assert.True(ReflectedManager.Process(field.Field));
67+
if (field.Field.IsStatic)
68+
Assert.NotNull(field.Field.GetValue(null));
69+
}
70+
#endregion
71+
}
72+
}

Concealment.Tests/packages.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
4+
<package id="NLog" version="4.4.12" targetFramework="net461" />
5+
<package id="xunit" version="2.2.0" targetFramework="net461" />
6+
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
7+
<package id="xunit.assert" version="2.2.0" targetFramework="net461" />
8+
<package id="xunit.core" version="2.2.0" targetFramework="net461" />
9+
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net461" />
10+
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net461" />
11+
<package id="xunit.runner.console" version="2.2.0" targetFramework="net461" developmentDependency="true" />
12+
</packages>

Concealment.sln

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26730.8
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment/Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment\Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Versioning", "Versioning", "{57BAE926-D9EB-40F2-AC36-007A1E2ED296}"
9+
ProjectSection(SolutionItems) = preProject
10+
Versioning\AssemblyVersion.cs = Versioning\AssemblyVersion.cs
11+
EndProjectSection
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment.Tests", "Concealment.Tests\Concealment.Tests.csproj", "{53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}"
714
EndProject
815
Global
916
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +22,10 @@ Global
1522
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Debug|x64.Build.0 = Debug|x64
1623
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.ActiveCfg = Release|x64
1724
{E5C0184B-7DC4-43D8-872E-2F71162748AA}.Release|x64.Build.0 = Release|x64
25+
{53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Debug|x64.ActiveCfg = Debug|x64
26+
{53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Debug|x64.Build.0 = Debug|x64
27+
{53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Release|x64.ActiveCfg = Release|x64
28+
{53EFDFD0-9BCA-4E67-ABB2-628715E3F74B}.Release|x64.Build.0 = Release|x64
1829
EndGlobalSection
1930
GlobalSection(SolutionProperties) = preSolution
2031
HideSolutionNode = FALSE

Concealment/Concealment.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
<Reference Include="WindowsBase" />
142142
</ItemGroup>
143143
<ItemGroup>
144+
<Compile Include="..\Versioning\AssemblyVersion.cs">
145+
<Link>Properties\AssemblyVersion.cs</Link>
146+
</Compile>
144147
<Compile Include="Commands.cs" />
145148
<Compile Include="ConcealGroup.cs" />
146149
<Compile Include="ConcealmentControl.xaml.cs">

Concealment/ConcealmentPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
namespace Concealment
3333
{
34-
[Plugin("Concealment", "1.2.1", "17f44521-b77a-4e85-810f-ee73311cf75d")]
34+
[Plugin("Concealment", typeof(ConcealmentPlugin), "17f44521-b77a-4e85-810f-ee73311cf75d")]
3535
public sealed class ConcealmentPlugin : TorchPluginBase, IWpfPlugin
3636
{
3737
public Persistent<Settings> Settings { get; private set; }

Jenkinsfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def test_with_torch(branch)
1010

1111
stage('Build + Torch ' + branch) {
1212
currentBuild.description = bat(returnStdout: true, script: '@powershell -File Versioning/version.ps1').trim()
13-
bat "\"${tool 'MSBuild'}msbuild\" Essentials.sln /p:Configuration=Release /p:Platform=x64 /t:Clean"
13+
bat "\"${tool 'MSBuild'}msbuild\" Concealment.sln /p:Configuration=Release /p:Platform=x64 /t:Clean"
1414
bat "\"${tool 'MSBuild'}msbuild\" Concealment.sln /p:Configuration=Release /p:Platform=x64"
1515
}
1616

17-
/*
17+
1818
stage('Test + Torch ' + branch) {
1919
bat 'IF NOT EXIST reports MKDIR reports'
2020
bat "\"packages/xunit.runner.console.2.2.0/tools/xunit.console.exe\" \"bin-test/x64/Release/Concealment.Tests.dll\" -parallel none -xml \"reports/Concealment.Tests.xml\""
@@ -32,7 +32,7 @@ def test_with_torch(branch)
3232
]]
3333
])
3434
}
35-
*/
35+
3636
return true
3737
} catch (e) {
3838
return false
@@ -42,6 +42,7 @@ def test_with_torch(branch)
4242
node {
4343
stage('Checkout') {
4444
checkout scm
45+
bat 'git pull --tags'
4546
}
4647

4748
stage('Acquire SE') {

0 commit comments

Comments
 (0)