Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Basic integration test setup #938

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
<PackageVersion Include="System.Collections.Immutable" Version="6.0.0"/>
<PackageVersion Include="libclang" Version="14.0.0"/>
<PackageVersion Include="libClangSharp" Version="14.0.0-beta1"/>
<PackageVersion Include="Verify.Xunit" Version="16.9.0" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.Symbols.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.Scraper.Tests", "tests\Silk.NET.SilkTouch.Scraper.Tests\Silk.NET.SilkTouch.Scraper.Tests.csproj", "{5329AC43-7177-4953-AFAB-A9FA7B9A4C7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.IntegrationTests", "tests\Silk.NET.SilkTouch.IntegrationTests\Silk.NET.SilkTouch.IntegrationTests.csproj", "{66FE736C-C407-44C3-A94E-4345E22AA95E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -316,6 +318,18 @@ Global
{5329AC43-7177-4953-AFAB-A9FA7B9A4C7C}.Release|x64.Build.0 = Release|Any CPU
{5329AC43-7177-4953-AFAB-A9FA7B9A4C7C}.Release|x86.ActiveCfg = Release|Any CPU
{5329AC43-7177-4953-AFAB-A9FA7B9A4C7C}.Release|x86.Build.0 = Release|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Debug|x64.ActiveCfg = Debug|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Debug|x64.Build.0 = Debug|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Debug|x86.ActiveCfg = Debug|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Debug|x86.Build.0 = Debug|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|Any CPU.Build.0 = Release|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x64.ActiveCfg = Release|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x64.Build.0 = Release|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x86.ActiveCfg = Release|Any CPU
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -346,6 +360,7 @@ Global
{97AF0383-2665-446E-9FBD-218051422B13} = {8238D9F3-E158-4633-8017-B29AA3AD61F7}
{795A93A6-9578-439F-BB08-07B148B1D4CE} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
{5329AC43-7177-4953-AFAB-A9FA7B9A4C7C} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
{66FE736C-C407-44C3-A94E-4345E22AA95E} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

<!-- Workaround for issue https://github.com/microsoft/ClangSharp/issues/129 -->
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="libclang" />
<PackageReference Include="libClangSharp" />
<PackageReference Include="Verify.Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\generators\Silk.NET.SilkTouch.Scraper\Silk.NET.SilkTouch.Scraper.csproj" />
<ProjectReference Include="..\..\src\generators\Silk.NET.SilkTouch.Emitter\Silk.NET.SilkTouch.Emitter.csproj" />
<ProjectReference Include="..\..\src\generators\Silk.NET.SilkTouch.Symbols\Silk.NET.SilkTouch.Symbols.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


/* -------------------------- NEW OUTPUT -------------------------- */

namespace LIBRARY_NAMESPACE
{
[StructLayout(LayoutKind.Explicit)]
public struct Test
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading.Tasks;
using VerifyXunit;
using Xunit;

namespace Silk.NET.SilkTouch.IntegrationTests;

[UsesVerify]
public class StructIntegrationTests
{
[Fact]
public Task Test1()
{
var result = TestHelper.GetCSharpOutputFromCPP(@"
#include <stdint.h>

typedef struct {
int32_t f1;
int32_t f2;
} Test;");
return Verifier.Verify(result);
}
}
43 changes: 43 additions & 0 deletions tests/Silk.NET.SilkTouch.IntegrationTests/TestHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Silk.NET.SilkTouch.Emitter;
using Silk.NET.SilkTouch.Scraper;
using Xunit;

namespace Silk.NET.SilkTouch.IntegrationTests;

public static class TestHelper
{
public static string GetCSharpOutputFromCPP(string cpp)
{
var tempFile = Path.GetTempFileName();

File.WriteAllText(tempFile, "/* THIS IS A GENERATED FILE, PIPED TO CLANG FOR TESTING BY SILK.NET */" + cpp);

var scraper = new ClangScraper();
var xml = scraper.GenerateXML
(tempFile, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>());

Assert.NotNull(xml);

try
{
File.Delete(tempFile);
} catch { /* It's a Temporary File. We dont' care. */}

var symbols = scraper.ScrapeXML(xml!);
var emitter = new CSharpEmitter();
var outputs = symbols.Select(x => emitter.Transform(x));
return outputs.Aggregate
(
"",
(old, node) => old + "\n\n/* -------------------------- NEW OUTPUT -------------------------- */\n\n" +
node.ToFullString()
);
}
}