2016-01-14 19:52:54 +00: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;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Builder.Tests
|
|
|
|
|
{
|
|
|
|
|
public class IncrementalTestBase : TestBase
|
|
|
|
|
{
|
|
|
|
|
protected readonly TempDirectory _tempProjectRoot;
|
|
|
|
|
|
|
|
|
|
private readonly string _testProjectsRoot;
|
|
|
|
|
protected readonly string _mainProject;
|
|
|
|
|
protected readonly string _expectedOutput;
|
|
|
|
|
|
|
|
|
|
public IncrementalTestBase(string testProjectsRoot, string mainProject, string expectedOutput)
|
|
|
|
|
{
|
|
|
|
|
_testProjectsRoot = testProjectsRoot;
|
|
|
|
|
_mainProject = mainProject;
|
|
|
|
|
_expectedOutput = expectedOutput;
|
|
|
|
|
|
|
|
|
|
var root = Temp.CreateDirectory();
|
|
|
|
|
|
|
|
|
|
_tempProjectRoot = root.CopyDirectory(testProjectsRoot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void TouchSourcesOfProject()
|
|
|
|
|
{
|
|
|
|
|
TouchSourcesOfProject(_mainProject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void TouchSourcesOfProject(string projectToTouch)
|
|
|
|
|
{
|
|
|
|
|
foreach (var sourceFile in GetSourceFilesForProject(projectToTouch))
|
|
|
|
|
{
|
|
|
|
|
TouchFile(sourceFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static void TouchFile(string file)
|
|
|
|
|
{
|
|
|
|
|
File.SetLastWriteTimeUtc(file, DateTime.UtcNow);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 19:04:45 +00:00
|
|
|
|
protected CommandResult BuildProject(bool noIncremental = false, bool expectBuildFailure = false)
|
2016-01-14 19:52:54 +00:00
|
|
|
|
{
|
|
|
|
|
var outputDir = GetBinDirectory();
|
2016-01-21 00:00:19 +00:00
|
|
|
|
var intermediateOutputDir = Path.Combine(Directory.GetParent(outputDir).FullName, "obj", _mainProject);
|
|
|
|
|
var mainProjectFile = GetProjectFile(_mainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
2016-01-21 19:04:45 +00:00
|
|
|
|
var buildCommand = new BuildCommand(mainProjectFile, output: outputDir, tempOutput: intermediateOutputDir ,noIncremental : noIncremental);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
var result = buildCommand.ExecuteWithCapturedOutput();
|
|
|
|
|
|
|
|
|
|
if (!expectBuildFailure)
|
|
|
|
|
{
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
TestOutputExecutable(outputDir, buildCommand.GetOutputExecutableName(), _expectedOutput);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static void AssertProjectSkipped(string skippedProject, CommandResult buildResult)
|
|
|
|
|
{
|
2016-01-26 14:39:13 +00:00
|
|
|
|
Assert.Contains($"Project {skippedProject} (DNXCore,Version=v5.0) was previously compiled. Skipping compilation.", buildResult.StdOut, StringComparison.OrdinalIgnoreCase);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static void AssertProjectCompiled(string rebuiltProject, CommandResult buildResult)
|
|
|
|
|
{
|
2016-01-26 14:39:13 +00:00
|
|
|
|
Assert.Contains($"Project {rebuiltProject} (DNXCore,Version=v5.0) will be compiled", buildResult.StdOut, StringComparison.OrdinalIgnoreCase);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string GetBinDirectory()
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(_tempProjectRoot.Path, "bin");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual string GetProjectDirectory(string projectName)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(_tempProjectRoot.Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string GetProjectFile(string projectName)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(GetProjectDirectory(projectName), "project.json");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetOutputFileForProject(string projectName)
|
|
|
|
|
{
|
2016-01-21 23:01:21 +00:00
|
|
|
|
return Path.Combine(GetCompilationOutputPath(), projectName + ".dll");
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<string> GetSourceFilesForProject(string projectName)
|
|
|
|
|
{
|
|
|
|
|
return Directory.EnumerateFiles(GetProjectDirectory(projectName)).
|
|
|
|
|
Where(f => f.EndsWith(".cs"));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 23:01:21 +00:00
|
|
|
|
protected string GetCompilationOutputPath()
|
|
|
|
|
{
|
|
|
|
|
var executablePath = Path.Combine(GetBinDirectory(), "Debug", "dnxcore50");
|
|
|
|
|
|
|
|
|
|
return executablePath;
|
|
|
|
|
}
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|