dotnet-installer/src/dotnet/commands/dotnet-test/BaseDotnetTestRunner.cs

68 lines
2.3 KiB
C#
Raw Normal View History

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.DotNet.ProjectModel;
namespace Microsoft.DotNet.Tools.Test
{
public abstract class BaseDotnetTestRunner : IDotnetTestRunner
{
public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
{
var result = BuildTestProject(projectContext, dotnetTestParams);
return result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result;
}
internal abstract int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams);
private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
{
if (dotnetTestParams.NoBuild)
{
return 0;
}
return DoBuildTestProject(projectContext, dotnetTestParams);
}
private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams)
{
var strings = new List<string>
{
$"--configuration",
dotnetTestParams.Config,
$"{dotnetTestParams.ProjectPath}"
};
// Build the test specifically for the target framework \ rid of the ProjectContext. This avoids building the project
// for tfms that the user did not request.
strings.Add("--framework");
strings.Add(projectContext.TargetFramework.ToString());
if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath))
{
strings.Add("--build-base-path");
strings.Add(dotnetTestParams.BuildBasePath);
}
if (!string.IsNullOrEmpty(dotnetTestParams.Output))
{
strings.Add("--output");
strings.Add(dotnetTestParams.Output);
}
if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier))
{
strings.Add("--runtime");
strings.Add(projectContext.RuntimeIdentifier);
}
var result = Build.BuildCommand.Run(strings.ToArray());
return result;
}
}
}