2016-03-14 17:38:36 -07:00
|
|
|
|
// 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
|
|
|
|
|
{
|
2016-05-02 11:32:24 -07:00
|
|
|
|
public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
|
2016-03-14 17:38:36 -07:00
|
|
|
|
{
|
2016-05-02 11:32:24 -07:00
|
|
|
|
var result = BuildTestProject(projectContext, dotnetTestParams, workspace);
|
2016-03-14 17:38:36 -07:00
|
|
|
|
|
|
|
|
|
return result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal abstract int DoRunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams);
|
|
|
|
|
|
2016-05-02 11:32:24 -07:00
|
|
|
|
private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
|
2016-03-14 17:38:36 -07:00
|
|
|
|
{
|
|
|
|
|
if (dotnetTestParams.NoBuild)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 11:32:24 -07:00
|
|
|
|
return DoBuildTestProject(projectContext, dotnetTestParams, workspace);
|
2016-03-14 17:38:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 11:32:24 -07:00
|
|
|
|
private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
|
2016-03-14 17:38:36 -07:00
|
|
|
|
{
|
|
|
|
|
var strings = new List<string>
|
|
|
|
|
{
|
|
|
|
|
$"--configuration",
|
|
|
|
|
dotnetTestParams.Config,
|
|
|
|
|
$"{dotnetTestParams.ProjectPath}"
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-14 15:59:11 -07:00
|
|
|
|
// 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());
|
2016-03-14 17:38:36 -07:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-14 15:59:11 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier))
|
2016-03-14 17:38:36 -07:00
|
|
|
|
{
|
|
|
|
|
strings.Add("--runtime");
|
2016-04-14 15:59:11 -07:00
|
|
|
|
strings.Add(projectContext.RuntimeIdentifier);
|
2016-03-14 17:38:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 11:32:24 -07:00
|
|
|
|
var result = Build.BuildCommand.Run(strings.ToArray(), workspace);
|
2016-03-14 17:38:36 -07:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|