Recognize that current framework is .NET 4.5 and allow Net-4.5 to be used with PlatformAttribute

This commit is contained in:
Charlie Poole 2012-10-18 10:03:50 -07:00
Родитель 428994f198
Коммит beb3010d17
2 изменённых файлов: 233 добавлений и 89 удалений

Просмотреть файл

@ -174,6 +174,12 @@ namespace NUnit.Core
} }
} }
} }
else if (major == 4)
{
minor = Type.GetType("System.Reflection.ReflectionContext", false) != null
? 5
: 0;
}
currentFramework = new RuntimeFramework(runtime, new Version(major, minor)); currentFramework = new RuntimeFramework(runtime, new Version(major, minor));
currentFramework.clrVersion = Environment.Version; currentFramework.clrVersion = Environment.Version;
@ -372,7 +378,7 @@ namespace NUnit.Core
/// greater than or equal to the corresponding target components. /// greater than or equal to the corresponding target components.
/// ///
/// The last provision allows tests requiring .NET 2.0 to run under the /// The last provision allows tests requiring .NET 2.0 to run under the
/// 3.0 and 3.5 platforms as well. /// 3.0 and 3.5 platforms and those requiring .NET 4.0 to run under 4.5.
/// </summary> /// </summary>
/// <param name="target">The RuntimeFramework to be matched.</param> /// <param name="target">The RuntimeFramework to be matched.</param>
/// <returns>True on match, otherwise false</returns> /// <returns>True on match, otherwise false</returns>
@ -410,6 +416,8 @@ namespace NUnit.Core
return runtime.ToString(); return runtime.ToString();
else if (runtime == RuntimeType.Any) else if (runtime == RuntimeType.Any)
return "v" + version.ToString(); return "v" + version.ToString();
else if (runtime == RuntimeType.Mono && version.Major == 1)
return "Mono 1.0";
else else
return runtime.ToString() + " " + version.ToString(); return runtime.ToString() + " " + version.ToString();
} }

Просмотреть файл

@ -21,6 +21,7 @@ namespace NUnit.Core.Tests
{ {
RuntimeFramework framework = RuntimeFramework.CurrentFramework; RuntimeFramework framework = RuntimeFramework.CurrentFramework;
Console.WriteLine("Running under {0}", framework.DisplayName);
Assert.That(framework.Runtime, Is.EqualTo(currentRuntime)); Assert.That(framework.Runtime, Is.EqualTo(currentRuntime));
Assert.That(framework.ClrVersion, Is.EqualTo(Environment.Version)); Assert.That(framework.ClrVersion, Is.EqualTo(Environment.Version));
} }
@ -63,7 +64,10 @@ namespace NUnit.Core.Tests
[TestCaseSource("frameworkData")] [TestCaseSource("frameworkData")]
public void CanCreateUsingClrVersion(FrameworkData data) public void CanCreateUsingClrVersion(FrameworkData data)
{ {
// Can't create using CLR version if we expect version 3.0, 3.5 or 4.5
Assume.That(data.frameworkVersion.Major != 3); Assume.That(data.frameworkVersion.Major != 3);
if (data.frameworkVersion.Major == 4)
Assume.That(data.frameworkVersion.Minor != 5);
RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion); RuntimeFramework framework = new RuntimeFramework(data.runtime, data.clrVersion);
Assert.AreEqual(data.runtime, framework.Runtime); Assert.AreEqual(data.runtime, framework.Runtime);
@ -87,90 +91,177 @@ namespace NUnit.Core.Tests
Assert.AreEqual(data.displayName, framework.DisplayName); Assert.AreEqual(data.displayName, framework.DisplayName);
} }
[TestCaseSource("matchData")] [TestCaseSource("AllFrameworks")]
public bool CanMatchRuntimes(RuntimeFramework f1, RuntimeFramework f2) public void AnyFrameworkSupportsItself(RuntimeFramework framework)
{ {
return f1.Supports(f2); Assert.That(framework.Supports(framework));
} }
internal static TestCaseData[] matchData = new TestCaseData[] { [Test]
new TestCaseData( public void Mono11IsSynonymousWithMono10()
new RuntimeFramework(RuntimeType.Net, new Version(3,5)), {
new RuntimeFramework(RuntimeType.Net, new Version(2,0))) RuntimeFramework mono10 = new RuntimeFramework(RuntimeType.Mono, new Version(1, 0));
.Returns(true), RuntimeFramework mono11 = new RuntimeFramework(RuntimeType.Mono, new Version(1, 1));
new TestCaseData(
new RuntimeFramework(RuntimeType.Net, new Version(2,0)), Assert.That(mono11.ToString(), Is.EqualTo("mono-1.0"));
new RuntimeFramework(RuntimeType.Net, new Version(3,5))) Assert.That(mono11.DisplayName, Is.EqualTo("Mono 1.0"));
.Returns(false), Assert.That(mono11.Runtime, Is.EqualTo(RuntimeType.Mono));
new TestCaseData( Assert.That(mono11.FrameworkVersion, Is.EqualTo(new Version(1, 0)));
new RuntimeFramework(RuntimeType.Net, new Version(3,5)),
new RuntimeFramework(RuntimeType.Net, new Version(3,5))) Assert.That(mono11.Supports(mono10));
.Returns(true), Assert.That(mono10.Supports(mono11));
new TestCaseData( }
new RuntimeFramework(RuntimeType.Net, new Version(2,0)),
new RuntimeFramework(RuntimeType.Net, new Version(2,0))) [TestCase("net-1.0.3705")]
.Returns(true), [TestCase("net-1.1.4322")]
new TestCaseData( [TestCase("net-2.0.50727")]
new RuntimeFramework(RuntimeType.Net, new Version(2,0)), [TestCase("net-4.0.30319")]
new RuntimeFramework(RuntimeType.Net, new Version(2,0,50727))) public void WellKnownClrVersions_SupportEquivalentFrameworkVersions(string s)
.Returns(true), {
new TestCaseData( RuntimeFramework f1 = RuntimeFramework.Parse(s);
new RuntimeFramework(RuntimeType.Net, new Version(2,0,50727)), RuntimeFramework f2 = new RuntimeFramework(f1.Runtime, f1.FrameworkVersion);
new RuntimeFramework(RuntimeType.Net, new Version(2,0)))
.Returns(true), Assert.That(f1.Runtime, Is.EqualTo(f2.Runtime));
new TestCaseData( Assert.That(f1.FrameworkVersion, Is.EqualTo(f2.FrameworkVersion));
new RuntimeFramework(RuntimeType.Net, new Version(2,0,50727)), Assert.That(f1.ClrVersion, Is.EqualTo(f2.ClrVersion));
new RuntimeFramework(RuntimeType.Net, new Version(2,0)))
.Returns(true), Assert.That(f1.Supports(f2));
new TestCaseData( Assert.That(f2.Supports(f1));
new RuntimeFramework(RuntimeType.Net, new Version(2,0)), }
new RuntimeFramework(RuntimeType.Mono, new Version(2,0)))
.Returns(false), [TestCaseSource("LowHigh")]
new TestCaseData( public void SameRuntime_HigherVersion_NotSupported(RuntimeFramework f1, RuntimeFramework f2)
new RuntimeFramework(RuntimeType.Net, new Version(2,0)), {
new RuntimeFramework(RuntimeType.Net, new Version(1,1))) Assert.False(f1.Supports(f2));
.Returns(false), }
new TestCaseData(
new RuntimeFramework(RuntimeType.Net, new Version(2,0,50727)), [TestCaseSource("HighLow_SameCLR")]
new RuntimeFramework(RuntimeType.Net, new Version(2,0,40607))) public void SameRuntime_LowerVersion_SameCLR_Supported(RuntimeFramework f1, RuntimeFramework f2)
.Returns(false), {
new TestCaseData( Assert.That(f1.Supports(f2));
new RuntimeFramework(RuntimeType.Mono, new Version(1,1)), // non-existent version but it works }
new RuntimeFramework(RuntimeType.Mono, new Version(1,0)))
.Returns(true), [TestCaseSource("HighLow_DifferentCLR")]
new TestCaseData( public void SameRuntime_LowerVersion_DifferentCLR_NotSupported(RuntimeFramework f1, RuntimeFramework f2)
new RuntimeFramework(RuntimeType.Mono, new Version(2,0)), {
new RuntimeFramework(RuntimeType.Any, new Version(2,0))) Assert.False(f1.Supports(f2));
.Returns(true), }
new TestCaseData(
new RuntimeFramework(RuntimeType.Any, new Version(2,0)), [TestCaseSource("MonoFrameworks")]
new RuntimeFramework(RuntimeType.Mono, new Version(2,0))) public void DifferentRuntimes_NotSupported(RuntimeFramework f1)
.Returns(true), {
new TestCaseData( RuntimeFramework f2 = new RuntimeFramework(RuntimeType.Net, f1.FrameworkVersion);
new RuntimeFramework(RuntimeType.Any, new Version(2,0)),
new RuntimeFramework(RuntimeType.Any, new Version(2,0))) Assert.False(f1.Supports(f2));
.Returns(true), Assert.False(f2.Supports(f1));
new TestCaseData( }
new RuntimeFramework(RuntimeType.Any, new Version(2,0)),
new RuntimeFramework(RuntimeType.Any, new Version(4,0))) [Test]
.Returns(false), public void SameRuntimes_DifferentBuilds_NotSupported()
new TestCaseData( {
new RuntimeFramework(RuntimeType.Net, RuntimeFramework.DefaultVersion), RuntimeFramework f1 = new RuntimeFramework(RuntimeType.Net, new Version(2, 0, 50727));
new RuntimeFramework(RuntimeType.Net, new Version(2,0))) RuntimeFramework f2 = new RuntimeFramework(RuntimeType.Net, new Version(2, 0, 40607));
.Returns(true),
new TestCaseData( Assert.False(f1.Supports(f2));
new RuntimeFramework(RuntimeType.Net, new Version(2,0)), Assert.False(f2.Supports(f1));
new RuntimeFramework(RuntimeType.Net, RuntimeFramework.DefaultVersion)) }
.Returns(true),
new TestCaseData( [TestCaseSource("MicrosoftFrameworks")]
new RuntimeFramework(RuntimeType.Any, RuntimeFramework.DefaultVersion), [TestCaseSource("MonoFrameworks")]
new RuntimeFramework(RuntimeType.Net, new Version(2,0))) public void UnspecifiedRuntime_SameVersion_Supported(RuntimeFramework f1)
.Returns(true), {
new TestCaseData( // NOTE: Mono 1.0 has a 1.1 ClrVersion, so this doesn't work.
new RuntimeFramework(RuntimeType.Net, new Version(2,0)), // Since we're phasing out support for 1.x versions, we
new RuntimeFramework(RuntimeType.Any, RuntimeFramework.DefaultVersion)) // aren't planning to fix this.
.Returns(true) Assume.That(f1.ToString() != "mono-1.0");
};
RuntimeFramework f2 = new RuntimeFramework(RuntimeType.Any, f1.FrameworkVersion);
Assert.That(f1.Supports(f2));
Assert.That(f2.Supports(f1));
}
[TestCaseSource("MicrosoftFrameworks")]
[TestCaseSource("MonoFrameworks")]
public void UnspecifiedVersion_SameRuntime_Supported(RuntimeFramework f1)
{
RuntimeFramework f2 = new RuntimeFramework(f1.Runtime, RuntimeFramework.DefaultVersion);
Assert.That(f1.Supports(f2));
Assert.That(f2.Supports(f1));
}
[TestCaseSource("MicrosoftFrameworks")]
[TestCaseSource("MonoFrameworks")]
public void UnspecifiedRuntimeAndVersion_Supported(RuntimeFramework f1)
{
RuntimeFramework f2 = new RuntimeFramework(RuntimeType.Any, RuntimeFramework.DefaultVersion);
Assert.That(f1.Supports(f2));
Assert.That(f2.Supports(f1));
}
#region TestCaseSources
static TestCaseData[] LowHigh
{
get { return GetFrameworkPairs(false); }
}
static TestCaseData[] HighLow_SameCLR
{
get { return GetFrameworkPairs(true, true, false); }
}
static TestCaseData[] HighLow_DifferentCLR
{
get { return GetFrameworkPairs(true, false, true); }
}
static RuntimeFramework[] AllFrameworks
{
get
{
RuntimeFramework[] frameworks =
new RuntimeFramework[MicrosoftFrameworks.Length + MonoFrameworks.Length + UnspecifiedFrameworks.Length];
int index = 0;
foreach (RuntimeFramework[] array in _frameworkArrays)
foreach (RuntimeFramework framework in array)
frameworks[index++] = framework;
return frameworks;
}
}
static readonly RuntimeFramework[] MicrosoftFrameworks = new RuntimeFramework[] {
new RuntimeFramework(RuntimeType.Net, new Version(1,0)),
new RuntimeFramework(RuntimeType.Net, new Version(1,1)),
new RuntimeFramework(RuntimeType.Net, new Version(2,0)),
new RuntimeFramework(RuntimeType.Net, new Version(3,0)),
new RuntimeFramework(RuntimeType.Net, new Version(3,5)),
new RuntimeFramework(RuntimeType.Net, new Version(4,0)),
new RuntimeFramework(RuntimeType.Net, new Version(4,5))
};
static readonly RuntimeFramework[] MonoFrameworks = new RuntimeFramework[] {
new RuntimeFramework(RuntimeType.Mono, new Version(1,0)),
new RuntimeFramework(RuntimeType.Mono, new Version(2,0)),
new RuntimeFramework(RuntimeType.Mono, new Version(3,0)),
new RuntimeFramework(RuntimeType.Mono, new Version(3,5)),
new RuntimeFramework(RuntimeType.Mono, new Version(4,0)),
new RuntimeFramework(RuntimeType.Mono, new Version(4,5))
};
static readonly RuntimeFramework[] UnspecifiedFrameworks = new RuntimeFramework[] {
new RuntimeFramework(RuntimeType.Any, new Version(1,0)),
new RuntimeFramework(RuntimeType.Any, new Version(1,1)),
new RuntimeFramework(RuntimeType.Any, new Version(2,0)),
new RuntimeFramework(RuntimeType.Any, new Version(3,0)),
new RuntimeFramework(RuntimeType.Any, new Version(3,5)),
new RuntimeFramework(RuntimeType.Any, new Version(4,0)),
new RuntimeFramework(RuntimeType.Any, new Version(4,5))
};
static readonly RuntimeFramework[][] _frameworkArrays =
new RuntimeFramework[][] { MicrosoftFrameworks, MonoFrameworks, UnspecifiedFrameworks };
public struct FrameworkData public struct FrameworkData
{ {
@ -198,29 +289,74 @@ namespace NUnit.Core.Tests
internal FrameworkData[] frameworkData = new FrameworkData[] { internal FrameworkData[] frameworkData = new FrameworkData[] {
new FrameworkData(RuntimeType.Net, new Version(1,0), new Version(1,0,3705), "net-1.0", "Net 1.0"), new FrameworkData(RuntimeType.Net, new Version(1,0), new Version(1,0,3705), "net-1.0", "Net 1.0"),
//new FrameworkData(RuntimeType.Net, new Version(1,0,3705), new Version(1,0,3705), "net-1.0.3705", "Net 1.0.3705"),
//new FrameworkData(RuntimeType.Net, new Version(1,0), new Version(1,0,3705), "net-1.0.3705", "Net 1.0.3705"),
new FrameworkData(RuntimeType.Net, new Version(1,1), new Version(1,1,4322), "net-1.1", "Net 1.1"), new FrameworkData(RuntimeType.Net, new Version(1,1), new Version(1,1,4322), "net-1.1", "Net 1.1"),
//new FrameworkData(RuntimeType.Net, new Version(1,1,4322), new Version(1,1,4322), "net-1.1.4322", "Net 1.1.4322"),
new FrameworkData(RuntimeType.Net, new Version(2,0), new Version(2,0,50727), "net-2.0", "Net 2.0"), new FrameworkData(RuntimeType.Net, new Version(2,0), new Version(2,0,50727), "net-2.0", "Net 2.0"),
//new FrameworkData(RuntimeType.Net, new Version(2,0,40607), new Version(2,0,40607), "net-2.0.40607", "Net 2.0.40607"),
//new FrameworkData(RuntimeType.Net, new Version(2,0,50727), new Version(2,0,50727), "net-2.0.50727", "Net 2.0.50727"),
new FrameworkData(RuntimeType.Net, new Version(3,0), new Version(2,0,50727), "net-3.0", "Net 3.0"), new FrameworkData(RuntimeType.Net, new Version(3,0), new Version(2,0,50727), "net-3.0", "Net 3.0"),
new FrameworkData(RuntimeType.Net, new Version(3,5), new Version(2,0,50727), "net-3.5", "Net 3.5"), new FrameworkData(RuntimeType.Net, new Version(3,5), new Version(2,0,50727), "net-3.5", "Net 3.5"),
new FrameworkData(RuntimeType.Net, new Version(4,0), new Version(4,0,30319), "net-4.0", "Net 4.0"), new FrameworkData(RuntimeType.Net, new Version(4,0), new Version(4,0,30319), "net-4.0", "Net 4.0"),
new FrameworkData(RuntimeType.Net, new Version(4,5), new Version(4,0,30319), "net-4.5", "Net 4.5"),
new FrameworkData(RuntimeType.Net, RuntimeFramework.DefaultVersion, RuntimeFramework.DefaultVersion, "net", "Net"), new FrameworkData(RuntimeType.Net, RuntimeFramework.DefaultVersion, RuntimeFramework.DefaultVersion, "net", "Net"),
new FrameworkData(RuntimeType.Mono, new Version(1,0), new Version(1,1,4322), "mono-1.0", "Mono 1.0"), new FrameworkData(RuntimeType.Mono, new Version(1,0), new Version(1,1,4322), "mono-1.0", "Mono 1.0"),
new FrameworkData(RuntimeType.Mono, new Version(2,0), new Version(2,0,50727), "mono-2.0", "Mono 2.0"), new FrameworkData(RuntimeType.Mono, new Version(2,0), new Version(2,0,50727), "mono-2.0", "Mono 2.0"),
//new FrameworkData(RuntimeType.Mono, new Version(2,0,50727), new Version(2,0,50727), "mono-2.0.50727", "Mono 2.0.50727"),
new FrameworkData(RuntimeType.Mono, new Version(3,5), new Version(2,0,50727), "mono-3.5", "Mono 3.5"), new FrameworkData(RuntimeType.Mono, new Version(3,5), new Version(2,0,50727), "mono-3.5", "Mono 3.5"),
new FrameworkData(RuntimeType.Mono, new Version(4,0), new Version(4,0,30319), "mono-4.0", "Mono 4.0"), new FrameworkData(RuntimeType.Mono, new Version(4,0), new Version(4,0,30319), "mono-4.0", "Mono 4.0"),
new FrameworkData(RuntimeType.Mono, RuntimeFramework.DefaultVersion, RuntimeFramework.DefaultVersion, "mono", "Mono"), new FrameworkData(RuntimeType.Mono, RuntimeFramework.DefaultVersion, RuntimeFramework.DefaultVersion, "mono", "Mono"),
new FrameworkData(RuntimeType.Any, new Version(1,1), new Version(1,1,4322), "v1.1", "v1.1"), new FrameworkData(RuntimeType.Any, new Version(1,1), new Version(1,1,4322), "v1.1", "v1.1"),
new FrameworkData(RuntimeType.Any, new Version(2,0), new Version(2,0,50727), "v2.0", "v2.0"), new FrameworkData(RuntimeType.Any, new Version(2,0), new Version(2,0,50727), "v2.0", "v2.0"),
//new FrameworkData(RuntimeType.Any, new Version(2,0,50727), new Version(2,0,50727), "v2.0.50727", "v2.0.50727"),
new FrameworkData(RuntimeType.Any, new Version(3,5), new Version(2,0,50727), "v3.5", "v3.5"), new FrameworkData(RuntimeType.Any, new Version(3,5), new Version(2,0,50727), "v3.5", "v3.5"),
new FrameworkData(RuntimeType.Any, new Version(4,0), new Version(4,0,30319), "v4.0", "v4.0"), new FrameworkData(RuntimeType.Any, new Version(4,0), new Version(4,0,30319), "v4.0", "v4.0"),
new FrameworkData(RuntimeType.Any, RuntimeFramework.DefaultVersion, RuntimeFramework.DefaultVersion, "any", "Any") new FrameworkData(RuntimeType.Any, RuntimeFramework.DefaultVersion, RuntimeFramework.DefaultVersion, "any", "Any")
}; };
#endregion
#region Helper Methods
static TestCaseData[] GetFrameworkPairs(bool highToLow)
{
return GetFrameworkPairs(highToLow, true, true);
}
static TestCaseData[] GetFrameworkPairs(bool highToLow, bool sameCLR, bool differentCLR)
{
int fullCount = PairCount(MicrosoftFrameworks) + PairCount(MonoFrameworks) + PairCount(UnspecifiedFrameworks);
int count = 0;
if (sameCLR && differentCLR)
count = fullCount;
else if (sameCLR)
count = 12;
else if (differentCLR)
count = fullCount - 12;
TestCaseData[] cases = new TestCaseData[count];
int index = 0;
foreach (RuntimeFramework[] farray in _frameworkArrays)
for (int i = 0; i < farray.Length - 1; i++)
for (int j = i + 1; j < farray.Length; j++)
{
RuntimeFramework f1 = farray[i];
RuntimeFramework f2 = farray[j];
if (sameCLR && f1.ClrVersion == f2.ClrVersion || differentCLR && f1.ClrVersion != f2.ClrVersion)
cases[index++] = highToLow
? new TestCaseData(f2, f1)
: new TestCaseData(f1, f2);
}
return cases;
}
static int PairCount(RuntimeFramework[] array)
{
return array.Length * (array.Length - 1) / 2;
}
private RuntimeFramework Framework(string representation)
{
return RuntimeFramework.Parse(representation);
}
#endregion
} }
} }