Skip to content

Commit 7af782a

Browse files
committed
Fixing tests
1 parent a3dd335 commit 7af782a

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

src/RustAnalyzer.TestAdapter.UnitTests/Cargo/ToolChainServiceTests.GetTestSuiteTestsAsync.hello_library.approved.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"TestExecutionEnvironment": "",
1010
"Profile": "release",
1111
"TestExes": [
12-
"<TestRoot>\\hello_library\\target\\release\\deps\\hello_lib-d9d78f0fcd1af879.exe",
13-
"<TestRoot>\\hello_library\\target\\release\\deps\\int_tests-58f9d629627e8abd.exe"
12+
"<TestRoot>\\hello_library\\target\\release\\deps\\hello_lib-*.exe",
13+
"<TestRoot>\\hello_library\\target\\release\\deps\\int_tests-*.exe"
1414
]
1515
},
16-
"exe": "<TestRoot>\\hello_library\\target\\release\\deps\\hello_lib-d9d78f0fcd1af879.exe",
16+
"exe": "<TestRoot>\\hello_library\\target\\release\\deps\\hello_lib-*.exe",
1717
"tests": [
1818
{
1919
"type": "test",
@@ -159,11 +159,11 @@
159159
"TestExecutionEnvironment": "",
160160
"Profile": "release",
161161
"TestExes": [
162-
"<TestRoot>\\hello_library\\target\\release\\deps\\hello_lib-d9d78f0fcd1af879.exe",
163-
"<TestRoot>\\hello_library\\target\\release\\deps\\int_tests-58f9d629627e8abd.exe"
162+
"<TestRoot>\\hello_library\\target\\release\\deps\\hello_lib-*.exe",
163+
"<TestRoot>\\hello_library\\target\\release\\deps\\int_tests-*.exe"
164164
]
165165
},
166-
"exe": "<TestRoot>\\hello_library\\target\\release\\deps\\int_tests-58f9d629627e8abd.exe",
166+
"exe": "<TestRoot>\\hello_library\\target\\release\\deps\\int_tests-*.exe",
167167
"tests": [
168168
{
169169
"type": "test",

src/RustAnalyzer.TestAdapter.UnitTests/Cargo/ToolChainServiceTests.GetTestSuiteTestsAsync.hello_world.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"TestExecutionEnvironment": "",
1010
"Profile": "release",
1111
"TestExes": [
12-
"<TestRoot>\\hello_world\\target\\release\\deps\\hello_world-d116900458eb29b6.exe"
12+
"<TestRoot>\\hello_world\\target\\release\\deps\\hello_world-*.exe"
1313
]
1414
},
15-
"exe": "<TestRoot>\\hello_world\\target\\release\\deps\\hello_world-d116900458eb29b6.exe",
15+
"exe": "<TestRoot>\\hello_world\\target\\release\\deps\\hello_world-*.exe",
1616
"tests": []
1717
}
1818
]

src/RustAnalyzer.TestAdapter.UnitTests/Cargo/ToolChainServiceTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.IO;
22
using System.Linq;
3+
using System.Text.RegularExpressions;
34
using System.Threading.Tasks;
45
using ApprovalTests;
56
using ApprovalTests.Namers;
@@ -10,6 +11,7 @@
1011
using KS.RustAnalyzer.Tests.Common;
1112
using Newtonsoft.Json;
1213
using Xunit;
14+
using static ApprovalTests.Scrubber.PdfScrubber;
1315

1416
namespace KS.RustAnalyzer.TestAdapter.UnitTests.Cargo;
1517

@@ -113,8 +115,8 @@ public async Task AdditionalBuildArgsTestsAsync(string workspaceRelRoot, string
113115
}
114116

115117
[Theory]
116-
[InlineData(@"hello_world", "hello_world_hello_world.rusttests", "release", new string[] { "hello_world-d116900458eb29b6.exe" })] // No tests.
117-
[InlineData(@"hello_library", "hello_lib_libhello_lib.rusttests", "release", new[] { "hello_lib-d9d78f0fcd1af879.exe", "int_tests-58f9d629627e8abd.exe" })] // Has tests.
118+
[InlineData(@"hello_world", "hello_world_hello_world.rusttests", "release", new string[] { "hello_world-*.exe" })] // No tests.
119+
[InlineData(@"hello_library", "hello_lib_libhello_lib.rusttests", "release", new[] { "hello_lib-*.exe", "int_tests-*.exe" })] // Has tests.
118120
[UseReporter(typeof(RaVsDiffReporter))]
119121
public async Task GetTestSuiteTestsAsync(string workspaceRelRoot, string containerName, string profile, string[] testExes)
120122
{
@@ -129,12 +131,12 @@ public async Task GetTestSuiteTestsAsync(string workspaceRelRoot, string contain
129131
var tc = JsonConvert.DeserializeObject<TestContainer>(await tcPath.ReadAllTextAsync(default));
130132

131133
tc.TestExes.All(e => e.FileExists()).Should().BeTrue();
132-
tc.TestExes.Select(e => e.GetFileName()).Should().BeEquivalentTo(testExes.Select(e => (PathEx)e));
134+
tc.TestExes.Select(e => Regex.Replace(e.GetFileName(), @"\-[\da-f]{16}\.", "-*.", RegexOptions.IgnoreCase)).Should().BeEquivalentTo(testExes);
133135
tc.Profile.Should().Be(profile);
134136
tc.ThisPath.Should().Be(tcPath);
135137
testSuites.Should().HaveCount(testExes.Length);
136138
testSuites.Select(x => x.Container.ThisPath).Should().OnlyContain(x => x == tcPath);
137-
var normalizedStr = testSuites.SerializeAndNormalizeObject();
139+
var normalizedStr = testSuites.OrderBy(x => (string)x.Exe).SerializeAndNormalizeObject();
138140
Approvals.Verify(normalizedStr);
139141
}
140142
}

src/RustAnalyzer.TestAdapter/Common/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static string ReplaceNullWithBar(this string s)
3737
return s?.Replace("\0", "|");
3838
}
3939

40-
public static string RegexReplace(this string @this, string pattern, string replacement)
40+
public static string RegexReplace(this string @this, string pattern, string replacement, RegexOptions options = RegexOptions.None)
4141
{
4242
return Regex.Replace(@this, pattern, replacement);
4343
}

src/TestsCommon/TestHelpers.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.IO;
44
using System.Reflection;
5+
using System.Text.RegularExpressions;
56
using System.Threading.Tasks;
67
using KS.RustAnalyzer.TestAdapter;
78
using KS.RustAnalyzer.TestAdapter.Cargo;
@@ -86,7 +87,8 @@ public static string SerializeAndNormalizeObject(this object @this)
8687
.SerializeObject(Formatting.Indented, new PathExJsonConverter())
8788
.Replace(((string)ThisTestRoot).Replace("\\", "\\\\"), "<TestRoot>", StringComparison.OrdinalIgnoreCase)
8889
.RegexReplace(@" ""(Start|End)Time"": ""(.*)"",", string.Empty)
89-
.RegexReplace(@" ""Duration"": ""00:00:00.2\d{6}"",", @" ""Duration"": ""00:00:00.2000000""")
90+
.RegexReplace(@" ""Duration"": ""00:00:00.[0-2]\d{6}"",", @" ""Duration"": ""00:00:00.2000000""")
91+
.RegexReplace(@"\-[\da-f]{16}\.", "-*.", RegexOptions.IgnoreCase)
9092
.Replace("note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\\n", string.Empty);
9193
}
9294

0 commit comments

Comments
 (0)