Skip to content

Commit 7045302

Browse files
authored
Added support for WinUI3 appxrecipe. (#2849)
1 parent e1f8d2a commit 7045302

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscoveryManager.cs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEve
100100
// Validate the sources
101101
foreach (var kvp in discoveryCriteria.AdapterSourceMap)
102102
{
103-
var verifiedSources = GetValidSources(kvp.Value, this.sessionMessageLogger);
103+
var verifiedSources = GetValidSources(kvp.Value, this.sessionMessageLogger, discoveryCriteria.Package);
104104
if (verifiedSources.Any())
105105
{
106106
verifiedExtensionSourceMap.Add(kvp.Key, kvp.Value);
@@ -189,8 +189,9 @@ private void OnReportTestCases(IEnumerable<TestCase> testCases)
189189
/// </summary>
190190
/// <param name="sources"> Paths to source file to look for tests in. </param>
191191
/// <param name="logger">logger</param>
192+
/// <param name="package">package</param>
192193
/// <returns> The list of verified sources. </returns>
193-
internal static IEnumerable<string> GetValidSources(IEnumerable<string> sources, IMessageLogger logger)
194+
internal static IEnumerable<string> GetValidSources(IEnumerable<string> sources, IMessageLogger logger, string package)
194195
{
195196
Debug.Assert(sources != null, "sources");
196197
var verifiedSources = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
@@ -202,10 +203,28 @@ internal static IEnumerable<string> GetValidSources(IEnumerable<string> sources,
202203

203204
if (!File.Exists(src))
204205
{
205-
var errorMessage = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.FileNotFound, src);
206-
logger.SendMessage(TestMessageLevel.Warning, errorMessage);
206+
void SendWarning()
207+
{
208+
var errorMessage = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.FileNotFound, src);
209+
logger.SendMessage(TestMessageLevel.Warning, errorMessage);
210+
}
207211

208-
continue;
212+
if (string.IsNullOrEmpty(package))
213+
{
214+
SendWarning();
215+
216+
continue;
217+
}
218+
219+
// It is also possible that this is a packaged app, so the tests might be inside the package
220+
src = !Path.IsPathRooted(source) ? Path.Combine(Path.GetDirectoryName(package), source) : source;
221+
222+
if (!File.Exists(src))
223+
{
224+
SendWarning();
225+
226+
continue;
227+
}
209228
}
210229

211230
if (!verifiedSources.Add(src))

src/Microsoft.TestPlatform.CrossPlatEngine/Execution/BaseRunTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal abstract class BaseRunTests
4848
private ITestRunEventsHandler testRunEventsHandler;
4949
private ITestEventsPublisher testEventsPublisher;
5050
private ITestRunCache testRunCache;
51-
private string package;
51+
private protected string package;
5252
private IRequestData requestData;
5353

5454
/// <summary>

src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithSources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private Dictionary<Tuple<Uri, string>, IEnumerable<string>> GetExecutorVsSources
150150
// Validate the sources
151151
foreach (var kvp in this.adapterSourceMap)
152152
{
153-
var verifiedSources = DiscoveryManager.GetValidSources(kvp.Value, logger);
153+
var verifiedSources = DiscoveryManager.GetValidSources(kvp.Value, logger, package);
154154
if (verifiedSources.Any())
155155
{
156156
verifiedExtensionSourceMap.Add(kvp.Key, kvp.Value);

test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Discovery/DiscoveryManagerTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,29 @@ public void DiscoverTestsShouldLogIfTheSourceDoesNotExist()
8888
Times.Once);
8989
}
9090

91+
[TestMethod]
92+
public void DiscoverTestsShouldLogIfTheSourceDoesNotExistIfItHasAPackage()
93+
{
94+
var criteria = new DiscoveryCriteria(new List<string> { "imaginary.exe" }, 100, null);
95+
96+
var packageName = "recipe.AppxRecipe";
97+
98+
var fakeDirectory = Directory.GetDirectoryRoot(typeof(DiscoveryManagerTests).GetTypeInfo().Assembly.Location);
99+
100+
criteria.Package = Path.Combine(fakeDirectory, Path.Combine(packageName));
101+
var mockLogger = new Mock<ITestDiscoveryEventsHandler2>();
102+
103+
this.discoveryManager.DiscoverTests(criteria, mockLogger.Object);
104+
105+
var errorMessage = string.Format(CultureInfo.CurrentCulture, "Could not find file {0}.", Path.Combine(fakeDirectory, "imaginary.exe"));
106+
mockLogger.Verify(
107+
l =>
108+
l.HandleLogMessage(
109+
Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Warning,
110+
errorMessage),
111+
Times.Once);
112+
}
113+
91114
[TestMethod]
92115
public void DiscoverTestsShouldLogIfThereAreNoValidSources()
93116
{

0 commit comments

Comments
 (0)