Skip to content

Commit 2418d9e

Browse files
authored
Forward merge fixes from master to rc2 (#2581)
* Avoid logging >Task returned false but did not log an error.< (#2557) * Avoid logging >Task returned false but did not log an error.< on test failure * Add VSTEST_BUILD_DEBUG env var * Using namespaces * Invert the switch because it will be still backwards in the final release * Use bitness from process or OS (#2571) * Do not force .NET4.5 in case legacy test settings are provided (#2545) * Do not force .NET4.5 in case legacy test settings are provided * Net core app * Fix runconfig * Default platform
1 parent 70a599d commit 2418d9e

File tree

6 files changed

+76
-29
lines changed

6 files changed

+76
-29
lines changed

src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs

+24
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ namespace Microsoft.TestPlatform.Build.Tasks
55
{
66
using System;
77
using System.Collections.Generic;
8+
using System.Diagnostics;
89
using System.Linq;
10+
using System.Threading;
911
using Microsoft.Build.Framework;
1012
using Microsoft.Build.Utilities;
1113
using Microsoft.TestPlatform.Build.Resources;
@@ -161,6 +163,28 @@ public override bool Execute()
161163
var traceEnabledValue = Environment.GetEnvironmentVariable("VSTEST_BUILD_TRACE");
162164
Tracing.traceEnabled = !string.IsNullOrEmpty(traceEnabledValue) && traceEnabledValue.Equals("1", StringComparison.OrdinalIgnoreCase);
163165

166+
var debugEnabled = Environment.GetEnvironmentVariable("VSTEST_BUILD_DEBUG");
167+
if (!string.IsNullOrEmpty(debugEnabled) && debugEnabled.Equals("1", StringComparison.Ordinal))
168+
{
169+
Console.WriteLine("Waiting for debugger attach...");
170+
171+
var currentProcess = Process.GetCurrentProcess();
172+
Console.WriteLine(string.Format("Process Id: {0}, Name: {1}", currentProcess.Id, currentProcess.ProcessName));
173+
174+
while (!Debugger.IsAttached)
175+
{
176+
Thread.Sleep(1000);
177+
}
178+
179+
Debugger.Break();
180+
}
181+
182+
// Avoid logging "Task returned false but did not log an error." on test failure, because we don't
183+
// write MSBuild error. https://github.com/dotnet/msbuild/blob/51a1071f8871e0c93afbaf1b2ac2c9e59c7b6491/src/Framework/IBuildEngine7.cs#L12
184+
var allowfailureWithoutError = BuildEngine.GetType().GetProperty("AllowFailureWithoutError");
185+
// setting this to false because the switch is implemented backwards and it won't be fixed till next release
186+
allowfailureWithoutError?.SetValue(BuildEngine, false);
187+
164188
vsTestForwardingApp = new VSTestForwardingApp(this.VSTestConsolePath, this.CreateArgument());
165189
if (!string.IsNullOrEmpty(this.VSTestFramework))
166190
{

src/Microsoft.TestPlatform.Utilities/MSTestSettingsUtilities.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ public static class MSTestSettingsUtilities
2525
/// Settings file which need to be imported. The file extension of the settings file will be specified by <paramref name="SettingsFileExtension"/> property.
2626
/// </param>
2727
/// <param name="defaultRunSettings"> Input RunSettings document to which settings file need to be imported. </param>
28-
/// <param name="architecture"> The architecture. </param>
29-
/// <param name="frameworkVersion"> The framework Version. </param>
3028
/// <returns> Updated RunSetting Xml document with imported settings. </returns>
3129
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
3230
Justification = "XmlDocument.XmlResolver is not available in core. Suppress until fxcop issue is fixed.")]
33-
public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSettings, Architecture architecture, FrameworkVersion frameworkVersion)
31+
public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSettings)
3432
{
3533
ValidateArg.NotNull(settingsFile, "settingsFile");
3634
ValidateArg.NotNull(defaultRunSettings, "defaultRunSettings");
@@ -57,14 +55,6 @@ public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSett
5755
var doc = new XmlDocument();
5856
var runConfigurationNode = doc.CreateElement(Constants.RunConfigurationSettingsName);
5957

60-
var targetPlatformNode = doc.CreateElement("TargetPlatform");
61-
targetPlatformNode.InnerXml = architecture.ToString();
62-
runConfigurationNode.AppendChild(targetPlatformNode);
63-
64-
var targetFrameworkVersionNode = doc.CreateElement("TargetFrameworkVersion");
65-
targetFrameworkVersionNode.InnerXml = frameworkVersion.ToString();
66-
runConfigurationNode.AppendChild(targetFrameworkVersionNode);
67-
6858
defaultRunSettings.DocumentElement.PrependChild(defaultRunSettings.ImportNode(runConfigurationNode, true));
6959
}
7060

src/vstest.console/Processors/RunSettingsArgumentProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private XmlDocument GetRunSettingsDocument(string runSettingsFile)
199199
else
200200
{
201201
runSettingsDocument = XmlRunSettingsUtilities.CreateDefaultRunSettings();
202-
runSettingsDocument = MSTestSettingsUtilities.Import(runSettingsFile, runSettingsDocument, Architecture.X86, FrameworkVersion.Framework45);
202+
runSettingsDocument = MSTestSettingsUtilities.Import(runSettingsFile, runSettingsDocument);
203203
}
204204

205205
return runSettingsDocument;

src/vstest.console/TestPlatformHelpers/TestRequestManager.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,19 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List<string> sou
451451
|| chosenFramework.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0
452452
|| chosenFramework.Name.IndexOf("net5", StringComparison.OrdinalIgnoreCase) >= 0)
453453
{
454-
defaultArchitecture = Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86;
454+
#if NETCOREAPP
455+
// We are running in vstest.console that is either started via dotnet.exe or via vstest.console.exe .NET Core
456+
// executable. For AnyCPU dlls this should resolve 32-bit SDK when running from 32-bit dotnet process and
457+
// 64-bit SDK when running from 64-bit dotnet process.
458+
defaultArchitecture = Environment.Is64BitProcess ? Architecture.X64 : Architecture.X86;
459+
#else
460+
// We are running in vstest.console.exe that was built against .NET Framework. This console prefers 32-bit
461+
// because it needs to run as 32-bit to be compatible with QTAgent. It runs as 32-bit both under VS and
462+
// in Developer console. Set the default architecture based on the OS architecture, to find 64-bit dotnet SDK
463+
// when running AnyCPU dll on 64-bit system, and 32-bit SDK when running AnyCPU dll on 32-bit OS.
464+
// We want to find 64-bit SDK because it is more likely to be installed.
465+
defaultArchitecture = Environment.Is64BitOperatingSystem ? Architecture.X64 : Architecture.X86;
466+
#endif
455467
}
456468

457469
settingsUpdated |= this.UpdatePlatform(document, navigator, sources, sourcePlatforms, defaultArchitecture, out Architecture chosenPlatform);

test/Microsoft.TestPlatform.Utilities.UnitTests/MSTestSettingsUtilitiesTests.cs

+18-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace Microsoft.TestPlatform.Utilities.Tests
88

99
using Microsoft.VisualStudio.TestPlatform.Utilities;
1010
using Microsoft.VisualStudio.TestTools.UnitTesting;
11-
using VisualStudio.TestPlatform.ObjectModel;
1211
using MSTest.TestFramework.AssertExtensions;
1312

1413
[TestClass]
@@ -49,9 +48,7 @@ public void ImportShouldThrowIfNotLegacySettingsFile()
4948
() =>
5049
MSTestSettingsUtilities.Import(
5150
"C:\\temp\\r.runsettings",
52-
xmlDocument,
53-
Architecture.X86,
54-
FrameworkVersion.Framework45);
51+
xmlDocument);
5552
Assert.That.Throws<XmlException>(action).WithMessage("Unexpected settings file specified.");
5653
}
5754

@@ -66,9 +63,7 @@ public void ImportShouldThrowIfDefaultRunSettingsIsIncorrect()
6663
() =>
6764
MSTestSettingsUtilities.Import(
6865
"C:\\temp\\r.testsettings",
69-
xmlDocument,
70-
Architecture.X86,
71-
FrameworkVersion.Framework45);
66+
xmlDocument);
7267
Assert.That.Throws<XmlException>(action).WithMessage("Could not find 'RunSettings' node.");
7368
}
7469

@@ -80,14 +75,18 @@ public void ImportShouldEmbedTestSettingsInformation()
8075
xmlDocument.LoadXml(defaultRunSettingsXml);
8176
var finalxPath = MSTestSettingsUtilities.Import(
8277
"C:\\temp\\r.testsettings",
83-
xmlDocument,
84-
Architecture.X86,
85-
FrameworkVersion.Framework45);
78+
xmlDocument);
8679

8780
var finalSettingsXml = finalxPath.CreateNavigator().OuterXml;
8881

8982
var expectedSettingsXml =
90-
"<RunSettings>\r\n <MSTest>\r\n <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n <ForcedLegacyMode>true</ForcedLegacyMode>\r\n </MSTest>\r\n <RunConfiguration></RunConfiguration>\r\n</RunSettings>";
83+
"<RunSettings>\r\n" +
84+
" <MSTest>\r\n" +
85+
" <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n" +
86+
" <ForcedLegacyMode>true</ForcedLegacyMode>\r\n" +
87+
" </MSTest>\r\n" +
88+
" <RunConfiguration></RunConfiguration>\r\n" +
89+
"</RunSettings>";
9190

9291
Assert.AreEqual(expectedSettingsXml, finalSettingsXml);
9392
}
@@ -100,14 +99,18 @@ public void ImportShouldEmbedTestSettingsAndDefaultRunConfigurationInformation()
10099
xmlDocument.LoadXml(defaultRunSettingsXml);
101100
var finalxPath = MSTestSettingsUtilities.Import(
102101
"C:\\temp\\r.testsettings",
103-
xmlDocument,
104-
Architecture.X86,
105-
FrameworkVersion.Framework45);
102+
xmlDocument);
106103

107104
var finalSettingsXml = finalxPath.CreateNavigator().OuterXml;
108105

109106
var expectedSettingsXml =
110-
"<RunSettings>\r\n <RunConfiguration>\r\n <TargetPlatform>X86</TargetPlatform>\r\n <TargetFrameworkVersion>Framework45</TargetFrameworkVersion>\r\n </RunConfiguration>\r\n <MSTest>\r\n <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n <ForcedLegacyMode>true</ForcedLegacyMode>\r\n </MSTest>\r\n</RunSettings>";
107+
"<RunSettings>\r\n" +
108+
" <RunConfiguration />\r\n" +
109+
" <MSTest>\r\n" +
110+
" <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n" +
111+
" <ForcedLegacyMode>true</ForcedLegacyMode>\r\n" +
112+
" </MSTest>\r\n" +
113+
"</RunSettings>";
111114

112115
Assert.AreEqual(expectedSettingsXml, finalSettingsXml);
113116
}

test/vstest.console.UnitTests/Processors/RunSettingsArgumentProcessorTests.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,27 @@ public void InitializeShouldSetActiveRunSettingsForTestSettingsFiles()
235235
// Act.
236236
executor.Initialize(fileName);
237237

238+
238239
// Assert.
239240
Assert.IsNotNull(this.settingsProvider.ActiveRunSettings);
240-
StringAssert.Contains(this.settingsProvider.ActiveRunSettings.SettingsXml, $"<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<RunSettings>\r\n <RunConfiguration>\r\n <TargetPlatform>{Constants.DefaultPlatform}</TargetPlatform>\r\n <TargetFrameworkVersion>{Framework.FromString(FrameworkVersion.Framework45.ToString()).Name}</TargetFrameworkVersion>\r\n <ResultsDirectory>{Constants.DefaultResultsDirectory}</ResultsDirectory>\r\n </RunConfiguration>\r\n <MSTest>\r\n <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n <ForcedLegacyMode>true</ForcedLegacyMode>\r\n </MSTest>\r\n <DataCollectionRunSettings>\r\n <DataCollectors />\r\n </DataCollectionRunSettings>\r\n</RunSettings>");
241+
242+
var expected =
243+
$"<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
244+
$"<RunSettings>\r\n" +
245+
$" <RunConfiguration>\r\n" +
246+
$" <ResultsDirectory>{Constants.DefaultResultsDirectory}</ResultsDirectory>\r\n" +
247+
$" <TargetPlatform>{Constants.DefaultPlatform}</TargetPlatform>\r\n" +
248+
$" <TargetFrameworkVersion>{Framework.DefaultFramework.Name}</TargetFrameworkVersion>\r\n" +
249+
$" </RunConfiguration>\r\n" +
250+
$" <MSTest>\r\n" +
251+
$" <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n" +
252+
$" <ForcedLegacyMode>true</ForcedLegacyMode>\r\n" +
253+
$" </MSTest>\r\n" +
254+
$" <DataCollectionRunSettings>\r\n" +
255+
$" <DataCollectors />\r\n" +
256+
$" </DataCollectionRunSettings>\r\n" +
257+
$"</RunSettings>";
258+
StringAssert.Contains(this.settingsProvider.ActiveRunSettings.SettingsXml, expected);
241259
}
242260

243261

0 commit comments

Comments
 (0)