Skip to content

Commit c55479c

Browse files
committed
- Clean test containers before build
- Require discovery before exection (which is the VS' behavior) - Preparing for multiple Exes in TestContainer - Adding exe name as namespace for Test explorer - Test discover stability fixes for running multiple test cases - Running exact test cases discovered
1 parent 3c88696 commit c55479c

23 files changed

Lines changed: 158 additions & 136 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"AdditionalTestExecutionArguments": "",
1010
"TestExecutionEnvironment": "",
1111
"Profile": "dev",
12-
"TestExe": "<not_yet_generated>"
12+
"TestExes": []
1313
}
1414
}
1515
]

src/RustAnalyzer.TestAdapter.UnitTests/Cargo/ToolChainServiceTests.BuildTestsAsync.hello_workspace.approved.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"AdditionalTestExecutionArguments": "",
1010
"TestExecutionEnvironment": "",
1111
"Profile": "dev",
12-
"TestExe": "<not_yet_generated>"
12+
"TestExes": []
1313
}
1414
},
1515
{
@@ -22,7 +22,7 @@
2222
"AdditionalTestExecutionArguments": "",
2323
"TestExecutionEnvironment": "",
2424
"Profile": "dev",
25-
"TestExe": "<not_yet_generated>"
25+
"TestExes": []
2626
}
2727
},
2828
{
@@ -35,7 +35,7 @@
3535
"AdditionalTestExecutionArguments": "",
3636
"TestExecutionEnvironment": "",
3737
"Profile": "dev",
38-
"TestExe": "<not_yet_generated>"
38+
"TestExes": []
3939
}
4040
}
4141
]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"AdditionalTestExecutionArguments": "",
1010
"TestExecutionEnvironment": "",
1111
"Profile": "dev",
12-
"TestExe": "<not_yet_generated>"
12+
"TestExes": []
1313
}
1414
}
1515
]

src/RustAnalyzer.TestAdapter.UnitTests/Cargo/ToolChainServiceTests.BuildTestsAsync.workspace_mixed.approved.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"AdditionalTestExecutionArguments": "",
1010
"TestExecutionEnvironment": "",
1111
"Profile": "dev",
12-
"TestExe": "<not_yet_generated>"
12+
"TestExes": []
1313
}
1414
},
1515
{
@@ -22,7 +22,7 @@
2222
"AdditionalTestExecutionArguments": "",
2323
"TestExecutionEnvironment": "",
2424
"Profile": "dev",
25-
"TestExe": "<not_yet_generated>"
25+
"TestExes": []
2626
}
2727
},
2828
{
@@ -35,7 +35,7 @@
3535
"AdditionalTestExecutionArguments": "",
3636
"TestExecutionEnvironment": "",
3737
"Profile": "dev",
38-
"TestExe": "<not_yet_generated>"
38+
"TestExes": []
3939
}
4040
},
4141
{
@@ -48,7 +48,7 @@
4848
"AdditionalTestExecutionArguments": "",
4949
"TestExecutionEnvironment": "",
5050
"Profile": "dev",
51-
"TestExe": "<not_yet_generated>"
51+
"TestExes": []
5252
}
5353
}
5454
]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"container": "<TestRoot>\\hello_library\\target\\release\\hello_lib_libhello_lib.rusttests",
2+
"source": "<TestRoot>\\hello_library\\target\\release\\hello_lib_libhello_lib.rusttests",
3+
"exe": "<TestRoot>\\hello_library\\target\\release\\deps\\hello_lib-d9d78f0fcd1af879.exe",
34
"tests": [
45
{
56
"type": "test",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2-
"container": "<TestRoot>\\hello_world\\target\\release\\hello_world_hello_world.rusttests",
2+
"source": "<TestRoot>\\hello_world\\target\\release\\hello_world_hello_world.rusttests",
3+
"exe": "<TestRoot>\\hello_world\\target\\release\\deps\\hello_world-d116900458eb29b6.exe",
34
"tests": []
45
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ public async Task BuildTestsAsync(string workspaceRelRoot, string profile)
8989
var workspacePath = TestHelpers.ThisTestRoot + (PathEx)workspaceRelRoot;
9090
var manifestPath = workspacePath + Constants.ManifestFileName2;
9191
var targetPath = (workspacePath + (PathEx)@"target").MakeProfilePath(profile);
92-
targetPath.CleanTestContainers();
9392

9493
var success = await _tcs.DoBuildAsync(workspacePath, manifestPath, profile);
9594

9695
success.Should().BeTrue();
97-
var tasks = Directory.EnumerateFiles(targetPath, TestHelpers.TestContainersSearchPattern)
96+
var tasks = Directory.EnumerateFiles(targetPath, Constants.TestContainersSearchPattern)
9897
.Select(async f => (path: (PathEx)f, container: JsonConvert.DeserializeObject<TestContainer>(await ((PathEx)f).ReadAllTextAsync(default))));
9998
var tcs = await Task.WhenAll(tasks);
10099
var normalizedStr = tcs.SerializeAndNormalizeObject();
@@ -124,17 +123,16 @@ public async Task GetTestSuiteTestsAsync(string workspaceRelRoot, string contain
124123
var manifestPath = workspacePath + Constants.ManifestFileName2;
125124
var targetPath = (workspacePath + (PathEx)@"target").MakeProfilePath(profile);
126125
var tcPath = targetPath + (PathEx)containerName;
127-
targetPath.CleanTestContainers();
128126

129127
await _tcs.DoBuildAsync(workspacePath, manifestPath, profile);
130128
var testSuite = await _tcs.GetTestSuiteInfoAsync(tcPath, profile, default);
131129
var tc = JsonConvert.DeserializeObject<TestContainer>(await tcPath.ReadAllTextAsync(default));
132130

133-
tc.TestExe.FileExists().Should().BeTrue();
134-
tc.TestExe.GetExtension().Should().Be((PathEx)".exe");
131+
tc.TestExes[0].FileExists().Should().BeTrue();
132+
tc.TestExes[0].GetExtension().Should().Be((PathEx)".exe");
135133
tc.Profile.Should().Be(profile);
136134
tc.ThisPath.Should().Be(tcPath);
137-
testSuite.Container.Should().Be(tcPath);
135+
testSuite.Source.Should().Be(tcPath);
138136
var normalizedStr = testSuite.SerializeAndNormalizeObject();
139137
Approvals.Verify(normalizedStr);
140138
}

src/RustAnalyzer.TestAdapter.UnitTests/TestDiscovererTests.AdditionalBuildArgsTestsAsync.bin_with_example.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"Id": "3c9d5449-c265-52a4-8227-4c3045207429",
4-
"FullyQualifiedName": "tests.test_requires_foo",
3+
"Id": "990c634c-378f-43d8-1890-4fa94820013b",
4+
"FullyQualifiedName": "hello_world.tests.test_requires_foo",
55
"DisplayName": "test_requires_foo",
66
"ExecutorUri": "executor://RustTestExecutor/v1",
77
"Source": "<TestRoot>\\bin_with_example\\target\\debug\\hello_world_hello_world.rusttests",

src/RustAnalyzer.TestAdapter.UnitTests/TestDiscovererTests.DiscoverTestsTestsAsync.hello_library.approved.txt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"Id": "9cdd003c-30d9-0b2e-7a1f-6ff5883001b3",
4-
"FullyQualifiedName": "tests.fibonacci_test.case_1",
3+
"Id": "6782c2f7-da7d-1106-e05f-badd5b7660e8",
4+
"FullyQualifiedName": "hello_lib.tests.fibonacci_test.case_1",
55
"DisplayName": "case_1",
66
"ExecutorUri": "executor://RustTestExecutor/v1",
77
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -10,8 +10,8 @@
1010
"Properties": []
1111
},
1212
{
13-
"Id": "be520c15-de75-8385-7805-3f45967d2e25",
14-
"FullyQualifiedName": "tests.fibonacci_test.case_2",
13+
"Id": "2a4db758-57e7-6f77-aafc-942b108f6e2f",
14+
"FullyQualifiedName": "hello_lib.tests.fibonacci_test.case_2",
1515
"DisplayName": "case_2",
1616
"ExecutorUri": "executor://RustTestExecutor/v1",
1717
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -20,8 +20,8 @@
2020
"Properties": []
2121
},
2222
{
23-
"Id": "d4c0ed85-7658-8909-f7c5-c7969544bfa2",
24-
"FullyQualifiedName": "tests.fibonacci_test.case_3",
23+
"Id": "d78bc0e1-7d95-caff-4ad7-a3f039bb4bcc",
24+
"FullyQualifiedName": "hello_lib.tests.fibonacci_test.case_3",
2525
"DisplayName": "case_3",
2626
"ExecutorUri": "executor://RustTestExecutor/v1",
2727
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -30,8 +30,8 @@
3030
"Properties": []
3131
},
3232
{
33-
"Id": "9d2fbab2-5a6a-bfae-6dfb-49f2b2f8eeb3",
34-
"FullyQualifiedName": "tests.it_works",
33+
"Id": "76730596-697e-fd43-cf41-d4c3e5549e99",
34+
"FullyQualifiedName": "hello_lib.tests.it_works",
3535
"DisplayName": "it_works",
3636
"ExecutorUri": "executor://RustTestExecutor/v1",
3737
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -40,8 +40,8 @@
4040
"Properties": []
4141
},
4242
{
43-
"Id": "794e5b7c-add1-83c5-37ea-e4158a439e05",
44-
"FullyQualifiedName": "tests.it_works245_ignored",
43+
"Id": "de0ea079-0e84-c1e8-3dcf-f97ea1311648",
44+
"FullyQualifiedName": "hello_lib.tests.it_works245_ignored",
4545
"DisplayName": "it_works245_ignored",
4646
"ExecutorUri": "executor://RustTestExecutor/v1",
4747
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -50,8 +50,8 @@
5050
"Properties": []
5151
},
5252
{
53-
"Id": "45f11fdd-c68c-e4ce-c89f-6373c6846704",
54-
"FullyQualifiedName": "tests.long_running_test",
53+
"Id": "40bf974a-b1ba-ae40-cb77-25554d0f1899",
54+
"FullyQualifiedName": "hello_lib.tests.long_running_test",
5555
"DisplayName": "long_running_test",
5656
"ExecutorUri": "executor://RustTestExecutor/v1",
5757
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -60,8 +60,8 @@
6060
"Properties": []
6161
},
6262
{
63-
"Id": "513d6fec-4dfa-140a-4e41-8cea20164157",
64-
"FullyQualifiedName": "tests.multiplication_tests.when_both_operands_are_negative",
63+
"Id": "4d549d49-dd0d-f98e-78b0-7b8169955641",
64+
"FullyQualifiedName": "hello_lib.tests.multiplication_tests.when_both_operands_are_negative",
6565
"DisplayName": "when_both_operands_are_negative",
6666
"ExecutorUri": "executor://RustTestExecutor/v1",
6767
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -70,8 +70,8 @@
7070
"Properties": []
7171
},
7272
{
73-
"Id": "7252ac24-86aa-ad90-9abf-5f14d4702319",
74-
"FullyQualifiedName": "tests.multiplication_tests.when_both_operands_are_positive",
73+
"Id": "c6b68734-9a99-3571-c3fe-b18c48181838",
74+
"FullyQualifiedName": "hello_lib.tests.multiplication_tests.when_both_operands_are_positive",
7575
"DisplayName": "when_both_operands_are_positive",
7676
"ExecutorUri": "executor://RustTestExecutor/v1",
7777
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -80,8 +80,8 @@
8080
"Properties": []
8181
},
8282
{
83-
"Id": "d5f95417-2284-8c80-5c2a-6ba057ad0b95",
84-
"FullyQualifiedName": "tests.multiplication_tests.when_operands_are_swapped",
83+
"Id": "6a346c0c-ab11-91b9-7ecf-e0f2fc023470",
84+
"FullyQualifiedName": "hello_lib.tests.multiplication_tests.when_operands_are_swapped",
8585
"DisplayName": "when_operands_are_swapped",
8686
"ExecutorUri": "executor://RustTestExecutor/v1",
8787
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -90,8 +90,8 @@
9090
"Properties": []
9191
},
9292
{
93-
"Id": "42ba209f-75a0-2107-2b27-a52756b8439c",
94-
"FullyQualifiedName": "tests.mytest",
93+
"Id": "70a9d62a-e708-e050-b463-6803c6408f01",
94+
"FullyQualifiedName": "hello_lib.tests.mytest",
9595
"DisplayName": "mytest",
9696
"ExecutorUri": "executor://RustTestExecutor/v1",
9797
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -100,8 +100,8 @@
100100
"Properties": []
101101
},
102102
{
103-
"Id": "6ecf7022-b9df-b85f-668b-a145eb01a5f0",
104-
"FullyQualifiedName": "tests.should_fail",
103+
"Id": "12be2792-6f7a-d121-9cc5-86e8221677d1",
104+
"FullyQualifiedName": "hello_lib.tests.should_fail",
105105
"DisplayName": "should_fail",
106106
"ExecutorUri": "executor://RustTestExecutor/v1",
107107
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",
@@ -110,8 +110,8 @@
110110
"Properties": []
111111
},
112112
{
113-
"Id": "ce619d2c-ff75-4bc5-b42c-f40eeaee2f82",
114-
"FullyQualifiedName": "tests.should_success",
113+
"Id": "1929472f-5da4-283e-d2d6-9dc3ff336be3",
114+
"FullyQualifiedName": "hello_lib.tests.should_success",
115115
"DisplayName": "should_success",
116116
"ExecutorUri": "executor://RustTestExecutor/v1",
117117
"Source": "<TestRoot>\\hello_library\\target\\debug\\hello_lib_libhello_lib.rusttests",

src/RustAnalyzer.TestAdapter.UnitTests/TestDiscovererTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ public async Task DiscoverTestsTestsAsync(string workspaceRelRoot, string contai
2626
NamerFactory.AdditionalInformation = workspaceRelRoot.ReplaceInvalidChars();
2727
var tps = workspaceRelRoot.GetTestPaths(profile);
2828
var tcPath = tps.TargetPath + (PathEx)containerName;
29-
tps.TargetPath.CleanTestContainers();
3029

3130
await _tcs.DoBuildAsync(tps.WorkspacePath, tps.ManifestPath, profile);
3231
var sink = new SpyTestCaseDiscoverySink();
33-
new TestDiscoverer().DiscoverTests(new[] { (string)tcPath }, Mock.Of<IDiscoveryContext>(), Mock.Of<IMessageLogger>(), sink);
32+
new TestDiscoverer().DiscoverTests(tcPath, Mock.Of<IDiscoveryContext>(), Mock.Of<IMessageLogger>(), sink);
3433

3534
var normalizedStr = sink.TestCases
3635
.OrderBy(x => x.FullyQualifiedName).ThenBy(x => x.LineNumber)
@@ -46,11 +45,10 @@ public async Task AdditionalBuildArgsTestsAsync(string workspaceRelRoot, string
4645
NamerFactory.AdditionalInformation = workspaceRelRoot.ReplaceInvalidChars();
4746
var tps = workspaceRelRoot.GetTestPaths(profile);
4847
var tcPath = tps.TargetPath + (PathEx)containerName;
49-
tps.TargetPath.CleanTestContainers();
5048

5149
await _tcs.DoBuildAsync(tps.WorkspacePath, tps.ManifestPath, profile, additionalBuildArgs: @"--config ""build.rustflags = '--cfg foo'""", additionalTestDiscoveryArguments: "--config\0build.rustflags = '--cfg foo'\0\0");
5250
var sink = new SpyTestCaseDiscoverySink();
53-
new TestDiscoverer().DiscoverTests(new[] { (string)tcPath }, Mock.Of<IDiscoveryContext>(), Mock.Of<IMessageLogger>(), sink);
51+
new TestDiscoverer().DiscoverTests(tcPath, Mock.Of<IDiscoveryContext>(), Mock.Of<IMessageLogger>(), sink);
5452

5553
var normalizedStr = sink.TestCases
5654
.OrderBy(x => x.FullyQualifiedName).ThenBy(x => x.LineNumber)

0 commit comments

Comments
 (0)