Skip to content

Commit 1cfc47c

Browse files
authored
UnitTests: add and use SkipIfGitHubActionsAttribute (#693)
* IsRunningOnGitHubActions * ... * last? * ChatGPT
1 parent 92e5e69 commit 1cfc47c

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ jobs:
66
build:
77
runs-on: windows-2022
88

9+
env:
10+
IsRunningOnGitHubActions: 'true'
11+
912
steps:
1013
- uses: actions/checkout@v2
1114

System.Linq.Dynamic.Core.sln.DotSettings

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UTC/@EntryIndexedValue">UTC</s:String>
55
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WASM/@EntryIndexedValue">WASM</s:String>
66
<s:Boolean x:Key="/Default/UserDictionary/Words/=Formattable/@EntryIndexedValue">True</s:Boolean>
7-
<s:Boolean x:Key="/Default/UserDictionary/Words/=renamer/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
7+
<s:Boolean x:Key="/Default/UserDictionary/Words/=renamer/@EntryIndexedValue">True</s:Boolean>
8+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xunit/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

test/EntityFramework.DynamicLinq.Tests.net452/EntityFramework.DynamicLinq.Tests.net452.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<AssemblyName>EntityFramework.DynamicLinq.Tests.net452</AssemblyName>
1414
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1515
<FileAlignment>512</FileAlignment>
16-
<LangVersion>10</LangVersion>
16+
<LangVersion>10</LangVersion>
1717
<NuGetPackageImportStamp>
1818
</NuGetPackageImportStamp>
1919
</PropertyGroup>
@@ -288,6 +288,9 @@
288288
<Compile Include="..\System.Linq.Dynamic.Core.Tests\QueryableTests.Is,OfType,As,Cast.cs">
289289
<Link>QueryableTests.Is,OfType,As,Cast.cs</Link>
290290
</Compile>
291+
<Compile Include="..\System.Linq.Dynamic.Core.Tests\TestHelpers\DisplayTestMethodNameAttribute.cs">
292+
<Link>TestHelpers\DisplayTestMethodNameAttribute.cs</Link>
293+
</Compile>
291294
<Compile Include="..\System.Linq.Dynamic.Core.Tests\TestHelpers\ExpressionString.cs">
292295
<Link>TestHelpers\ExpressionString.cs</Link>
293296
</Compile>

test/System.Linq.Dynamic.Core.Tests/DynamicClassTest.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using System.Dynamic;
3+
using System.Linq.Dynamic.Core.Tests.TestHelpers;
34
using FluentAssertions;
45
using Newtonsoft.Json;
56
using Xunit;
@@ -156,8 +157,7 @@ public void DynamicClass_GetRuntimeType()
156157
typeOf.ToString().Should().Be("System.Linq.Dynamic.Core.DynamicClass"); // ???
157158
}
158159

159-
// [Fact(Skip = "fails on CI build GitHub Actions")]
160-
[Fact]
160+
[SkipIfGitHubActions]
161161
public void DynamicClassArray()
162162
{
163163
// Arrange
@@ -189,7 +189,7 @@ public void DynamicClassArray()
189189
isValid.Should().BeTrue();
190190
}
191191

192-
[Fact]
192+
[SkipIfGitHubActions]
193193
public void DynamicClassArray_Issue593_Fails()
194194
{
195195
// Arrange
@@ -221,7 +221,7 @@ public void DynamicClassArray_Issue593_Fails()
221221
isValid.Should().BeFalse(); // This should actually be true, but fails. For solution see Issue593_Solution1 and Issue593_Solution2.
222222
}
223223

224-
[Fact]
224+
[SkipIfGitHubActions]
225225
public void DynamicClassArray_Issue593_Solution1()
226226
{
227227
// Arrange
@@ -253,7 +253,7 @@ public void DynamicClassArray_Issue593_Solution1()
253253
isValid.Should().BeTrue();
254254
}
255255

256-
[Fact]
256+
[SkipIfGitHubActions]
257257
public void DynamicClassArray_Issue593_Solution2()
258258
{
259259
// Arrange
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace System.Linq.Dynamic.Core.Tests.TestHelpers
1+
namespace System.Linq.Dynamic.Core.Tests.TestHelpers
82
{
93
public static class ExpressionString
104
{
@@ -17,4 +11,4 @@ public static string NullableConversion(string convertedExpr)
1711
#endif
1812
}
1913
}
20-
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Xunit;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.TestHelpers;
4+
5+
internal class SkipIfGitHubActionsAttribute : FactAttribute
6+
{
7+
public SkipIfGitHubActionsAttribute()
8+
{
9+
if (IsRunningOnGitHubActions())
10+
{
11+
// ReSharper disable once VirtualMemberCallInConstructor
12+
Skip = "This test is skipped on GitHub Actions";
13+
}
14+
}
15+
16+
/// <summary>
17+
/// According to ChatGPT:
18+
///
19+
/// The GITHUB_ACTIONS environment variable is not officially documented by GitHub, but it is mentioned in the GitHub Actions documentation in a few places. Here are some relevant links:
20+
/// [Context and expression syntax for GitHub Actions](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context) - This page lists all the GitHub-specific context variables that are available in a GitHub Actions workflow, including GITHUB_ACTIONS.
21+
/// [Virtual environments for GitHub-hosted runners](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#virtual-environments-for-github-hosted-runners) - This page explains the environment variables that are available on GitHub-hosted runners, including GITHUB_ACTIONS.
22+
/// [Actions virtual environments](https://github.com/actions/virtual-environments#operating-systems) - This page provides more information about the virtual environments used by GitHub Actions, including the operating systems and software versions used on each environment.
23+
/// </summary>
24+
private static bool IsRunningOnGitHubActions()
25+
{
26+
return GetBool("GITHUB_ACTIONS") || GetBool("IsRunningOnGitHubActions");
27+
}
28+
29+
private static bool GetBool(string variable)
30+
{
31+
return bool.TryParse(Environment.GetEnvironmentVariable(variable), out var value) && value;
32+
}
33+
}

0 commit comments

Comments
 (0)