Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aborting test run when source and target frameworks/architectures are incompatible #1789

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f60b214
ExceptionWhenTargetingDiffFramworksPlat
vagisha-nidhi Oct 9, 2018
0a8e968
Acceptance tests updated
vagisha-nidhi Oct 23, 2018
ce5de2f
Merge branch 'master' of https://github.com/Microsoft/vstest into Tar…
vagisha-nidhi Oct 29, 2018
37fa219
Message change in conflict dlls
vagisha-nidhi Oct 29, 2018
75e2164
Changes in methods
vagisha-nidhi Dec 1, 2018
92fe52c
Merge branch 'master' of https://github.com/Microsoft/vstest into Tar…
vagisha-nidhi Dec 1, 2018
9943636
minor fix in test
vagisha-nidhi Dec 1, 2018
30ebd14
fix in test
vagisha-nidhi Dec 6, 2018
e6230ba
improved error message
vagisha-nidhi Dec 21, 2018
3fa02c1
PR comments
vagisha-nidhi Dec 31, 2018
ce59bb3
fix acceptance test
vagisha-nidhi Jan 2, 2019
d7057e2
Merge branch 'master' of https://github.com/Microsoft/vstest into Tar…
vagisha-nidhi Jan 2, 2019
220c955
Refactoring InferRunSettingsHelper
vagisha-nidhi Jan 14, 2019
c9740ea
Refactor
vagisha-nidhi Jan 14, 2019
e4f233f
Merge branch 'master' into TargetingDifferentFrameworks
vagisha-nidhi Jan 14, 2019
2e66caa
Tests updated
vagisha-nidhi Jan 14, 2019
550b4cc
Merge branch 'TargetingDifferentFrameworks' of https://github.com/vag…
vagisha-nidhi Jan 14, 2019
10bc3f3
Update TestRequestManager.cs
vagisha-nidhi Jan 16, 2019
ed39fbd
Restructured and Added test
vagisha-nidhi Jan 16, 2019
58b3dfa
Merge branch 'TargetingDifferentFrameworks' of https://github.com/vag…
vagisha-nidhi Jan 16, 2019
bc8c120
Update TestRequestManager.cs
vagisha-nidhi Jan 16, 2019
e850846
minor change
vagisha-nidhi Jan 21, 2019
b033b87
Merge branch 'TargetingDifferentFrameworks' of https://github.com/vag…
vagisha-nidhi Jan 21, 2019
3d5b844
minor change
vagisha-nidhi Jan 23, 2019
615fbac
Merge branch 'master' into TargetingDifferentFrameworks
vagisha-nidhi Jan 31, 2019
35ba9e5
Merge branch 'master' of https://github.com/Microsoft/vstest into Tar…
vagisha-nidhi Feb 12, 2019
1ddc150
Merge branch 'master' into TargetingDifferentFrameworks
vagisha-nidhi Feb 12, 2019
6bcc76c
Modified logic in IsFrameworkIncompatible
vagisha-nidhi Feb 12, 2019
7836605
Merge branch 'TargetingDifferentFrameworks' of https://github.com/vag…
vagisha-nidhi Feb 12, 2019
53b609b
Removing unused variable
vagisha-nidhi Feb 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactoring InferRunSettingsHelper
  • Loading branch information
vagisha-nidhi committed Jan 14, 2019
commit 220c95569a7568d7905cb638ab738260729a1fb8
86 changes: 34 additions & 52 deletions src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class InferRunSettingsHelper
private const string LegacyElementsString = "Elements";
private const string DeploymentAttributesString = "DeploymentAttributes";
private const string ExecutionAttributesString = "ExecutionAttributes";
private const string DotNetFrameworkString = ".NETFramework";
private const string DotNetCoreString = ".NETCoreApp";
private static readonly List<string> ExecutionNodesPaths = new List<string> { @"/RunSettings/LegacySettings/Execution/TestTypeSpecific/UnitTestRunConfig/AssemblyResolution", @"/RunSettings/LegacySettings/Execution/Timeouts", @"/RunSettings/LegacySettings/Execution/Hosts" };

/// <summary>
Expand Down Expand Up @@ -608,6 +610,28 @@ public static bool TryGetFrameworkXml(XPathNavigator runSettingsNavigator, out s
return XmlUtilities.IsValidNodeXmlValue(frameworkXml, validator);
}

/// <summary>
/// Returns true if target framework is incompatible with any source framework, that is run needs to be aborted
/// </summary>
public static bool IsFrameworkIncompatible(Framework chosenFramework, IDictionary<String, Framework> sourceFrameworks)
{
bool isFrameworkIncompatible = false;
foreach (var source in sourceFrameworks.Keys)
{
Framework actualFramework = sourceFrameworks[source];
string sourceFrameworkName = actualFramework.Name.Split(',')[0];
string targetFrameworkName = chosenFramework.Name.Split(',')[0];

if (sourceFrameworkName.Equals(DotNetFrameworkString, StringComparison.OrdinalIgnoreCase) && targetFrameworkName.Equals(DotNetCoreString, StringComparison.OrdinalIgnoreCase) ||
sourceFrameworkName.Equals(DotNetCoreString, StringComparison.OrdinalIgnoreCase) && targetFrameworkName.Equals(DotNetFrameworkString, StringComparison.OrdinalIgnoreCase))
{
isFrameworkIncompatible = true;
}
}

return isFrameworkIncompatible;
}

/// <summary>
/// Returns the sources matching the specified platform and framework settings.
/// For incompatible sources, warning is added to incompatibleSettingWarning.
Expand Down Expand Up @@ -648,73 +672,31 @@ public static IEnumerable<String> FilterCompatibleSources(Architecture chosenPla
return compatibleSources;
}

/// <summary>
/// Returns true if target framework is incompatible with any source framework, that is run needs to be aborted
/// </summary>
public static bool IsFrameworkIncompatible(Framework chosenFramework, IDictionary<String, Framework> sourceFrameworks)
{
bool isSettingIncompatible = false;
foreach (var source in sourceFrameworks.Keys)
{
Framework actualFramework = sourceFrameworks[source];
string sourceFrameworkName = actualFramework.Name.Split(',')[0];
string targetFrameworkName = chosenFramework.Name.Split(',')[0];

if (sourceFrameworkName.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase) && targetFrameworkName.Equals(".NETCoreApp", StringComparison.OrdinalIgnoreCase) ||
sourceFrameworkName.Equals(".NETCoreApp", StringComparison.OrdinalIgnoreCase) && targetFrameworkName.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase))
{
isSettingIncompatible = true;
}
}

return isSettingIncompatible;
}

/// <summary>
/// Returns true if source settings are incompatible with target settings.
/// Returns true if either source Platform is incompatible with target platform or source FrameworkVersion is incompatible with target FrameworkVersion.
/// </summary>
private static bool IsSettingIncompatible(Architecture sourcePlatform,
Architecture targetPlatform,
Framework sourceFramework,
Framework targetFramework)
{
var res = IsPlatformIncompatible(sourcePlatform, targetPlatform) || IsFrameworkIncompatible(sourceFramework, targetFramework);
return res;
}
bool isFrameworkSettingIncompatible = false;
bool isPlatformSettingIncompatible = false;


/// <summary>
/// Returns true if source Platform is incompatible with target platform.
/// </summary>
private static bool IsPlatformIncompatible(Architecture sourcePlatform, Architecture targetPlatform)
{
if (sourcePlatform == Architecture.Default ||
sourcePlatform == Architecture.AnyCPU)
sourcePlatform == Architecture.AnyCPU)
{
return false;
isPlatformSettingIncompatible = false;
}

return sourcePlatform != targetPlatform;
}

/// <summary>
/// Returns true if source FrameworkVersion is incompatible with target FrameworkVersion.
/// </summary>
private static bool IsFrameworkIncompatible(Framework sourceFramework, Framework targetFramework)
{
string sourceFrameworkName = sourceFramework.Name.Split(',')[0];
string targetFrameworkName = targetFramework.Name.Split(',')[0];

bool isFrameworkIncompatible = false;

if (sourceFrameworkName.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase) && targetFrameworkName.Equals(".NETCoreApp", StringComparison.OrdinalIgnoreCase) ||
sourceFrameworkName.Equals(".NETCoreApp", StringComparison.OrdinalIgnoreCase) && targetFrameworkName.Equals(".NETFramework", StringComparison.OrdinalIgnoreCase))
else
{
isFrameworkIncompatible = true;
isPlatformSettingIncompatible = sourcePlatform != targetPlatform ? true : false;
}

var isFrameworkVersionIncompatible = !sourceFramework.Name.Equals(targetFramework.Name, StringComparison.OrdinalIgnoreCase);
return isFrameworkIncompatible || isFrameworkVersionIncompatible;
isFrameworkSettingIncompatible = !sourceFramework.Name.Equals(targetFramework.Name, StringComparison.OrdinalIgnoreCase);

return isPlatformSettingIncompatible || isFrameworkSettingIncompatible;
}
}
}
4 changes: 2 additions & 2 deletions src/vstest.console/CommandLine/InferHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal InferHelper(IAssemblyMetadataProvider assemblyMetadataProvider)
/// <summary>
/// Determines Architecture from sources and returns true if source architectures are incompatible
/// </summary>
public bool TryGetCompatibleArchitecture(List<string> sources, IDictionary<string, Architecture> sourcePlatforms, out Architecture inferredArchitecture)
public bool TryGetAutoDetectCompatibleArchitecture(List<string> sources, IDictionary<string, Architecture> sourcePlatforms, out Architecture inferredArchitecture)
{
inferredArchitecture = Constants.DefaultPlatform;
bool isArchitectureIncompatible = false;
Expand Down Expand Up @@ -93,7 +93,7 @@ public bool TryGetCompatibleArchitecture(List<string> sources, IDictionary<strin
/// <summary>
/// Determines Framework from sources and returns true if source frameworks are incompatible
/// </summary>
public bool TryGetCompatibleFramework(List<string> sources, IDictionary<string, Framework> sourceFrameworkVersions, out Framework inferredFramework)
public bool TryGetAutoDetectCompatibleFramework(List<string> sources, IDictionary<string, Framework> sourceFrameworkVersions, out Framework inferredFramework)
{
inferredFramework = Framework.DefaultFramework;
bool isFrameworkIncompatible = false;
Expand Down
4 changes: 2 additions & 2 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, List<string> sou

var navigator = document.CreateNavigator();

var isFrameworkIncompatible = inferHelper.TryGetCompatibleFramework(sources, sourceFrameworks, out var inferredFramework);
var isFrameworkIncompatible = inferHelper.TryGetAutoDetectCompatibleFramework(sources, sourceFrameworks, out var inferredFramework);
Framework chosenFramework;
var isPlatformIncompatible = inferHelper.TryGetCompatibleArchitecture(sources, sourcePlatforms, out var inferredPlatform);
var isPlatformIncompatible = inferHelper.TryGetAutoDetectCompatibleArchitecture(sources, sourcePlatforms, out var inferredPlatform);
Architecture chosenPlatform;

if (isFrameworkIncompatible || isPlatformIncompatible)
Expand Down
Loading