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.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 IncrementalTests : IncrementalTestBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public IncrementalTests() : base(
|
2016-01-29 00:16:50 +00:00
|
|
|
|
Path.Combine(AppContext.BaseDirectory, "TestProjects", "TestSimpleIncrementalApp"),
|
2016-01-14 19:52:54 +00:00
|
|
|
|
"TestSimpleIncrementalApp",
|
|
|
|
|
"Hello World!" + Environment.NewLine)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2016-01-21 19:04:45 +00:00
|
|
|
|
public void TestNoIncrementalFlag()
|
2016-01-14 19:52:54 +00:00
|
|
|
|
{
|
|
|
|
|
var buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
2016-01-21 19:04:45 +00:00
|
|
|
|
buildResult = BuildProject(noIncremental: true);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
Assert.Contains("[Forced Unsafe]", buildResult.StdOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestRebuildMissingPdb()
|
|
|
|
|
{
|
|
|
|
|
TestDeleteOutputWithExtension("pdb");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestRebuildMissingDll()
|
|
|
|
|
{
|
|
|
|
|
TestDeleteOutputWithExtension("dll");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestRebuildMissingXml()
|
|
|
|
|
{
|
|
|
|
|
TestDeleteOutputWithExtension("xml");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestNoLockFile()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
var lockFile = Path.Combine(TempProjectRoot.Path, "project.lock.json");
|
2016-01-14 19:52:54 +00:00
|
|
|
|
Assert.True(File.Exists(lockFile));
|
|
|
|
|
|
|
|
|
|
File.Delete(lockFile);
|
|
|
|
|
Assert.False(File.Exists(lockFile));
|
|
|
|
|
|
|
|
|
|
buildResult = BuildProject(expectBuildFailure : true);
|
2016-01-26 14:39:13 +00:00
|
|
|
|
Assert.Contains("does not have a lock file", buildResult.StdOut);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
[Fact]
|
2016-01-14 19:52:54 +00:00
|
|
|
|
public void TestRebuildChangedLockFile()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
var lockFile = Path.Combine(TempProjectRoot.Path, "project.lock.json");
|
2016-01-14 19:52:54 +00:00
|
|
|
|
TouchFile(lockFile);
|
|
|
|
|
|
|
|
|
|
buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
[Fact]
|
2016-01-14 19:52:54 +00:00
|
|
|
|
public void TestRebuildChangedProjectFile()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
|
|
|
|
|
|
|
|
|
TouchFile(GetProjectFile(MainProject));
|
|
|
|
|
|
|
|
|
|
buildResult = BuildProject();
|
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// regression for https://github.com/dotnet/cli/issues/965
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestInputWithSameTimeAsOutputCausesProjectToCompile()
|
|
|
|
|
{
|
|
|
|
|
var buildResult = BuildProject();
|
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
2016-01-26 22:53:56 +00:00
|
|
|
|
var outputTimestamp = SetAllOutputItemsToSameTime();
|
|
|
|
|
|
|
|
|
|
// set an input to have the same last write time as an output item
|
|
|
|
|
// this should trigger recompilation to account for file systems with second timestamp granularity
|
|
|
|
|
// (an input file that changed within the same second as the previous outputs should trigger a rebuild)
|
|
|
|
|
File.SetLastWriteTime(GetProjectFile(MainProject), outputTimestamp);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
|
|
|
|
buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DateTime SetAllOutputItemsToSameTime()
|
|
|
|
|
{
|
|
|
|
|
var now = DateTime.Now;
|
|
|
|
|
foreach (var f in Directory.EnumerateFiles(GetCompilationOutputPath()))
|
|
|
|
|
{
|
|
|
|
|
File.SetLastWriteTime(f, now);
|
|
|
|
|
}
|
|
|
|
|
return now;
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TestDeleteOutputWithExtension(string extension)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
|
2016-01-21 23:01:21 +00:00
|
|
|
|
Reporter.Verbose.WriteLine($"Files in {GetCompilationOutputPath()}");
|
|
|
|
|
foreach (var file in Directory.EnumerateFiles(GetCompilationOutputPath()))
|
2016-01-14 19:52:54 +00:00
|
|
|
|
{
|
|
|
|
|
Reporter.Verbose.Write($"\t {file}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete output files with extensions
|
2016-01-21 23:01:21 +00:00
|
|
|
|
foreach (var outputFile in Directory.EnumerateFiles(GetCompilationOutputPath()).Where(f =>
|
2016-01-14 19:52:54 +00:00
|
|
|
|
{
|
|
|
|
|
var fileName = Path.GetFileName(f);
|
2016-01-26 22:53:56 +00:00
|
|
|
|
return fileName.StartsWith(MainProject, StringComparison.OrdinalIgnoreCase) &&
|
2016-01-14 19:52:54 +00:00
|
|
|
|
fileName.EndsWith(extension, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
Reporter.Output.WriteLine($"Deleted {outputFile}");
|
|
|
|
|
|
|
|
|
|
File.Delete(outputFile);
|
|
|
|
|
Assert.False(File.Exists(outputFile));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// second build; should get rebuilt since we deleted an output item
|
|
|
|
|
buildResult = BuildProject();
|
2016-01-26 22:53:56 +00:00
|
|
|
|
buildResult.Should().HaveCompiledProject(MainProject);
|
2016-01-14 19:52:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|