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
|
|
|
|
|
{
|
2016-01-26 22:53:56 +00:00
|
|
|
|
protected readonly TempDirectory TempProjectRoot;
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
protected readonly string MainProject;
|
|
|
|
|
protected readonly string ExpectedOutput;
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
|
|
|
|
public IncrementalTestBase(string testProjectsRoot, string mainProject, string expectedOutput)
|
|
|
|
|
{
|
2016-01-26 22:53:56 +00:00
|
|
|
|
MainProject = mainProject;
|
|
|
|
|
ExpectedOutput = expectedOutput;
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
|
|
|
|
var root = Temp.CreateDirectory();
|
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
TempProjectRoot = root.CopyDirectory(testProjectsRoot);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void TouchSourcesOfProject()
|
|
|
|
|
{
|
2016-01-26 22:53:56 +00:00
|
|
|
|
TouchSourcesOfProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void TouchSourcesOfProject(string projectToTouch)
|
|
|
|
|
{
|
|
|
|
|
foreach (var sourceFile in GetSourceFilesForProject(projectToTouch))
|
|
|
|
|
{
|
|
|
|
|
TouchFile(sourceFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static void TouchFile(string file)
|
|
|
|
|
{
|
|
|
|
|
File.SetLastWriteTimeUtc(file, DateTime.UtcNow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected CommandResult BuildProject(bool forceIncrementalUnsafe = false, bool expectBuildFailure = false)
|
|
|
|
|
{
|
2016-01-26 22:53:56 +00:00
|
|
|
|
var outputDir = GetBinRoot();
|
|
|
|
|
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 00:00:19 +00:00
|
|
|
|
var buildCommand = new BuildCommand(mainProjectFile, output: outputDir, tempOutput: intermediateOutputDir ,forceIncrementalUnsafe : forceIncrementalUnsafe);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
var result = buildCommand.ExecuteWithCapturedOutput();
|
|
|
|
|
|
|
|
|
|
if (!expectBuildFailure)
|
|
|
|
|
{
|
|
|
|
|
result.Should().Pass();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
TestOutputExecutable(outputDir, buildCommand.GetOutputExecutableName(), ExpectedOutput);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.Should().Fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
protected string GetBinRoot()
|
2016-01-14 19:52:54 +00:00
|
|
|
|
{
|
2016-01-26 22:53:56 +00:00
|
|
|
|
return Path.Combine(TempProjectRoot.Path, "bin");
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual string GetProjectDirectory(string projectName)
|
|
|
|
|
{
|
2016-01-26 22:53:56 +00:00
|
|
|
|
return Path.Combine(TempProjectRoot.Path);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2016-01-26 22:53:56 +00:00
|
|
|
|
var executablePath = Path.Combine(GetBinRoot(), "Debug", "dnxcore50");
|
2016-01-21 23:01:21 +00:00
|
|
|
|
|
|
|
|
|
return executablePath;
|
|
|
|
|
}
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|