-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
188 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,4 +351,6 @@ MigrationBackup/ | |
|
||
.idea/ | ||
|
||
.DS_Store | ||
.DS_Store | ||
|
||
*.received.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Contributor Guide | ||
================= | ||
|
||
Prerequisites | ||
------------- | ||
.NET SDK 7.0 is required to build and run the project. | ||
|
||
Building | ||
-------- | ||
To build the project, execute the following shell command: | ||
```console | ||
$ cd src && dotnet build | ||
``` | ||
|
||
Tests | ||
----- | ||
To run the tests, execute the following shell command: | ||
```console | ||
$ cd src && dotnet test | ||
``` | ||
|
||
If you made changes and want to update the test data, run the following shell command (PowerShell Core is required): | ||
```console | ||
$ pwsh ./scripts/Approve-TestResults.ps1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
param ( | ||
$SolutionRoot = "$PSScriptRoot/.." | ||
) | ||
|
||
Set-StrictMode -Version Latest | ||
$ErrorActionPreference = 'Stop' | ||
|
||
if (-Not $PSScriptRoot) { | ||
Write-Error "\`$PSScriptRoot variable isn't set. Do you run this code as a script? Please, follow instructions at https://github.com/ForNeVeR/Cesium/blob/main/docs/tests.md" | ||
} | ||
else { | ||
Get-ChildItem -Recurse $SolutionRoot -Filter "*.received.txt" | ForEach-Object { | ||
$receivedTestResult = $_.FullName | ||
$approvedTestResult = $receivedTestResult.Replace('.received.txt', '.verified.txt') | ||
Move-Item -Force -LiteralPath $receivedTestResult $approvedTestResult | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Text; | ||
using Medallion.Shell; | ||
using Mono.Cecil; | ||
|
||
namespace JetBrains.Refasmer.Tests; | ||
|
||
public class IntegrationTests | ||
{ | ||
[TestCase("RefasmerTestAssembly.PublicClassWithPrivateFields")] | ||
[TestCase("RefasmerTestAssembly.PublicStructWithPrivateFields")] | ||
[TestCase("RefasmerTestAssembly.UnsafeClassWithFunctionPointer")] | ||
public async Task CheckRefasmedType(string typeName) | ||
{ | ||
var assemblyPath = await BuildTestAssembly(); | ||
var resultAssembly = RefasmTestAssembly(assemblyPath); | ||
await VerifyTypeContent(resultAssembly, typeName); | ||
} | ||
|
||
private static async Task<string> BuildTestAssembly() | ||
{ | ||
var root = FindSourceRoot(); | ||
var testProject = Path.Combine(root, "src/RefasmerTestAssembly/RefasmerTestAssembly.csproj"); | ||
Console.WriteLine($"Building project {testProject}…"); | ||
var result = await Command.Run("dotnet", "build", testProject, "--configuration", "Release").Task; | ||
|
||
Assert.That( | ||
result.ExitCode, | ||
Is.EqualTo(0), | ||
$"Failed to build test assembly, exit code {result.ExitCode}. StdOut:\n{result.StandardOutput}\nStdErr: {result.StandardError}"); | ||
|
||
return Path.Combine(root, "src/RefasmerTestAssembly/bin/Release/net6.0/RefasmerTestAssembly.dll"); | ||
} | ||
|
||
private static string FindSourceRoot() | ||
{ | ||
var current = Directory.GetCurrentDirectory(); | ||
while (current != null) | ||
{ | ||
if (File.Exists(Path.Combine(current, "README.md"))) | ||
return current; | ||
current = Path.GetDirectoryName(current); | ||
} | ||
throw new Exception("Cannot find source root."); | ||
} | ||
|
||
private static string RefasmTestAssembly(string assemblyPath) | ||
{ | ||
var tempLocation = Path.GetTempFileName(); | ||
var exitCode = Program.Main(new[] { $"-v", $"--output={tempLocation}", assemblyPath }); | ||
Assert.That(exitCode, Is.EqualTo(0)); | ||
|
||
return tempLocation; | ||
} | ||
|
||
private static Task VerifyTypeContent(string assemblyPath, string typeName) | ||
{ | ||
var assembly = AssemblyDefinition.ReadAssembly(assemblyPath); | ||
var type = assembly.MainModule.GetType(typeName); | ||
var printout = new StringBuilder(); | ||
Printer.PrintType(type, printout); | ||
|
||
var verifySettings = new VerifySettings(); | ||
verifySettings.DisableDiff(); | ||
verifySettings.UseDirectory("data"); | ||
verifySettings.UseParameters(typeName); | ||
return Verify(printout, verifySettings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Text; | ||
using Mono.Cecil; | ||
|
||
namespace JetBrains.Refasmer.Tests; | ||
|
||
public static class Printer | ||
{ | ||
public static void PrintType(TypeDefinition type, StringBuilder printout) | ||
{ | ||
printout.AppendLine($"type: {type.FullName}"); | ||
if (type.HasFields) | ||
{ | ||
printout.AppendLine("fields:"); | ||
foreach (var field in type.Fields) | ||
{ | ||
printout.AppendLine($"- {field.Name}: {field.FieldType}"); | ||
} | ||
} | ||
|
||
if (type.HasMethods) | ||
{ | ||
printout.AppendLine("methods:"); | ||
foreach (var method in type.Methods) | ||
{ | ||
printout.Append($"- {method.Name}("); | ||
var parameters = method.Parameters; | ||
for (var i = 0; i < parameters.Count; i++) | ||
{ | ||
printout.Append($"{parameters[i].ParameterType} {parameters[i].Name}"); | ||
if (i < parameters.Count - 1) | ||
{ | ||
printout.Append(", "); | ||
} | ||
} | ||
|
||
printout.AppendLine($"): {method.ReturnType}:"); | ||
foreach (var instruction in method.Body.Instructions) | ||
{ | ||
printout.AppendLine($" - {instruction}"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...CheckRefasmedType_typeName=RefasmerTestAssembly.PublicClassWithPrivateFields.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type: RefasmerTestAssembly.PublicClassWithPrivateFields | ||
fields: | ||
- PublicInt: System.Int32 | ||
methods: | ||
- .ctor(): System.Void: |
5 changes: 5 additions & 0 deletions
5
...heckRefasmedType_typeName=RefasmerTestAssembly.PublicStructWithPrivateFields.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type: RefasmerTestAssembly.PublicStructWithPrivateFields | ||
fields: | ||
- PrivateInt: System.Int32 | ||
- PrivateInt2: System.Int32 | ||
- PublicInt: System.Int32 |
4 changes: 4 additions & 0 deletions
4
...eckRefasmedType_typeName=RefasmerTestAssembly.UnsafeClassWithFunctionPointer.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type: RefasmerTestAssembly.UnsafeClassWithFunctionPointer | ||
methods: | ||
- MethodWithFunctionPointer(method System.Void *() functionPointer): System.Void: | ||
- .ctor(): System.Void: |