-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Make Tests Great Again #3231
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
Merged
Merged
Make Tests Great Again #3231
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7e15231
Set RuntimeIdentifier based on OS architecture
christophwille c940cbc
Add TestsAssemblyOutput, keep existing behavior of output assembly lo…
christophwille 17a6197
Add TestsAssemblyTempPath to enable the ability to redirect to a cent…
christophwille ae338a0
Early return if DecompilerTests.config.json doesn't exist (saves time…
christophwille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
75 changes: 75 additions & 0 deletions
75
ICSharpCode.Decompiler.Tests/Helpers/TestsAssemblyOutput.cs
This file contains hidden or 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,75 @@ | ||
| // Copyright (c) 2024 Christoph Wille | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
| // software and associated documentation files (the "Software"), to deal in the Software | ||
| // without restriction, including without limitation the rights to use, copy, modify, merge, | ||
| // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
| // to whom the Software is furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in all copies or | ||
| // substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
| // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
| // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
| // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| // DEALINGS IN THE SOFTWARE. | ||
|
|
||
|
|
||
| using System; | ||
| using System.IO; | ||
|
|
||
| using Microsoft.Extensions.Configuration; | ||
|
|
||
| namespace ICSharpCode.Decompiler.Tests.Helpers | ||
| { | ||
| /// <summary> | ||
| /// Centralizes all file-path generation for compilation output (assemblies) | ||
| /// | ||
| /// DecompilerTests.config.json file format: | ||
| /// { | ||
| /// "TestsAssemblyTempPath": "d:\\test\\" | ||
| /// } | ||
| /// </summary> | ||
| internal static class TestsAssemblyOutput | ||
| { | ||
| static string? TestsAssemblyTempPath = null; | ||
|
|
||
| private static bool UseCustomPath => !string.IsNullOrWhiteSpace(TestsAssemblyTempPath); | ||
|
|
||
| static TestsAssemblyOutput() | ||
| { | ||
| if (!File.Exists("DecompilerTests.config.json")) | ||
| return; | ||
|
|
||
| var builder = new ConfigurationBuilder() | ||
| .AddJsonFile("DecompilerTests.config.json", optional: true, reloadOnChange: false); | ||
|
|
||
| IConfigurationRoot configuration = builder.Build(); | ||
| var pathRedirectIfAny = configuration["TestsAssemblyTempPath"]; | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(pathRedirectIfAny)) | ||
| { | ||
| TestsAssemblyTempPath = pathRedirectIfAny; | ||
| } | ||
| } | ||
|
|
||
| public static string GetFilePath(string testCasePath, string testName, string computedExtension) | ||
| { | ||
| if (!UseCustomPath) | ||
| return Path.Combine(testCasePath, testName) + computedExtension; | ||
|
|
||
| // As we are using the TestsAssemblyTempPath flat, we need to make sure that duplicated test names don't create file name clashes | ||
| return Path.Combine(TestsAssemblyTempPath, testName) + Guid.NewGuid().ToString() + computedExtension; | ||
| } | ||
|
|
||
| public static string GetTempFileName() | ||
| { | ||
| if (!UseCustomPath) | ||
| return Path.GetTempFileName(); | ||
|
|
||
| return Path.Combine(TestsAssemblyTempPath, Path.GetRandomFileName()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <IsWindowsX64 Condition="$([MSBuild]::IsOsPlatform('Windows')) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == X64">true</IsWindowsX64> | ||
| <IsWindowsARM64 Condition="$([MSBuild]::IsOsPlatform('Windows')) And $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) == ARM64">true</IsWindowsARM64> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0-windows</TargetFramework> | ||
| <RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
| <RuntimeIdentifier Condition="$(IsWindowsX64) == true">win-x64</RuntimeIdentifier> | ||
| <RuntimeIdentifier Condition="$(IsWindowsARM64) == true">win-arm64</RuntimeIdentifier> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| <StartupObject>AutoGeneratedProgram</StartupObject> | ||
|
|
||
|
|
@@ -43,14 +50,16 @@ | |
| <ItemGroup> | ||
| <PackageReference Include="DiffLib" /> | ||
| <PackageReference Include="CliWrap" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration" /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two new nuget deps for reading a JSON file?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for reading it like a proper settings file. The intent was to be able to later extend it if necessary. |
||
| <PackageReference Include="Microsoft.Extensions.Configuration.Json" /> | ||
| <PackageReference Include="NuGet.Protocol" /> | ||
| <PackageReference Include="System.Collections.Immutable" /> | ||
| <PackageReference Include="System.Reflection.Metadata" /> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp" /> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" /> | ||
| <PackageReference Include="Microsoft.DiaSymReader.Converter.Xml" /> | ||
| <PackageReference Include="Microsoft.DiaSymReader" /> | ||
| <PackageReference Include="Microsoft.DiaSymReader.Native" /> | ||
| <PackageReference Include="Microsoft.DiaSymReader" /> | ||
| <PackageReference Include="Microsoft.DiaSymReader.Native" /> | ||
| <PackageReference Include="NUnit3TestAdapter" /> | ||
| <PackageReference Include="coverlet.collector"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
|
|
@@ -114,6 +123,7 @@ | |
| <ItemGroup> | ||
| <Compile Include="DisassemblerPrettyTestRunner.cs" /> | ||
| <Compile Include="Helpers\RoslynToolset.cs" /> | ||
| <Compile Include="Helpers\TestsAssemblyOutput.cs" /> | ||
| <Compile Include="Output\InsertParenthesesVisitorTests.cs" /> | ||
| <Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" /> | ||
| <Compile Include="TestAssemblyResolver.cs" /> | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply make this part of the Tester class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not really partial about the location, it kind of felt like easier not polluting Tester with another concern that is config-driven.