Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions tests/common/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
case "publish":
case "restore":
case "run":
case "test":
var args = new List<string> ();
args.Add (verb);
args.Add (project);
Expand Down Expand Up @@ -288,11 +289,15 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
Console.WriteLine ($"Binlog: {binlogPath}");

// Work around https://github.com/dotnet/msbuild/issues/8845
args.Add ("/v:diag");
args.Add ("/consoleloggerparameters:Verbosity=Quiet");
// vb does not have preview lang, so we force it to latest
if (project.EndsWith (".vbproj", StringComparison.OrdinalIgnoreCase))
args.Add ("/p:LangVersion=latest");
// Skip these for 'dotnet test' because they leak through '-- ' in
// RunArguments and get passed to the test runner as app arguments.
if (verb != "test") {
args.Add ("/v:diag");
args.Add ("/consoleloggerparameters:Verbosity=Quiet");
// vb does not have preview lang, so we force it to latest
if (project.EndsWith (".vbproj", StringComparison.OrdinalIgnoreCase))
args.Add ("/p:LangVersion=latest");
}
// End workaround

if (msbuildParallelism.HasValue) {
Expand Down
49 changes: 49 additions & 0 deletions tests/dotnet/UnitTests/DotNetTestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Xamarin.Tests;

#nullable enable

namespace Xamarin.Tests {
[TestFixture]
public class DotNetTestTest : TestBaseClass {
[Test]
[TestCase (ApplePlatform.iOS, "iostest")]
[TestCase (ApplePlatform.TVOS, "tvostest")]
// macOS and Mac Catalyst don't use mlaunch (they use 'open' via Desktop.targets),
// so MTP support requires a different approach for these platforms.
// [TestCase (ApplePlatform.MacCatalyst, "maccatalysttest")]
// [TestCase (ApplePlatform.MacOSX, "macostest")]
public void DotNetTest (ApplePlatform platform, string template)
{
Configuration.IgnoreIfIgnoredPlatform (platform);

var tmpDir = Cache.CreateTemporaryDirectory ();
var outputDir = Path.Combine (tmpDir, template);
DotNet.AssertNew (outputDir, template);
var proj = Path.Combine (outputDir, $"{template}.csproj");

// Replace generated tests with a single passing test
var testFile = Path.Combine (outputDir, "Test1.cs");
File.WriteAllText (testFile, $@"namespace {template};

[TestClass]
public sealed class Test1 {{
[TestMethod]
public void TestMethod1 ()
{{
}}
}}
");

var properties = GetDefaultProperties ();

// Mobile platforms use mlaunch to run the app in the simulator.
// Override MlaunchPath if set via the environment variable.
var mlaunchPath = Environment.GetEnvironmentVariable ("MLAUNCH_PATH");
if (!string.IsNullOrEmpty (mlaunchPath)) {
properties ["MlaunchPath"] = mlaunchPath;
}

DotNet.Execute ("test", proj, properties);
}
}
}
Loading