Merge pull request #4031 from dotnet/piotrpMSFT/remove_dotnet-build.tests

remove dotnet-build.tests
This commit is contained in:
Piotr Puszkiewicz 2016-08-10 15:52:51 -04:00 committed by GitHub
commit 66dd155160
19 changed files with 1 additions and 1753 deletions

View file

@ -53,7 +53,7 @@ For E2E and functional tests, they all depend on the binaries located under `art
1. `cd src\dotnet\`
2. `dotnet build`
3. `cp bin\debug\netstandardapp1.5\dotnet.dll artifacts\rid\stage2`
4. `cd ..\..\test\dotnet-build.Tests`
4. `cd ..\..\test\dotnet.Tests`
5. `dotnet test`
##Adding a Command

View file

@ -32,8 +32,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProjects", "TestProject
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet", "src\dotnet\dotnet.xproj", "{60CF7E6C-D6C8-439D-B7B7-D8A27E29BE2C}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-build.Tests", "test\dotnet-build.Tests\dotnet-build.Tests.xproj", "{833FFEE1-7EED-4F51-8DFD-946D48833333}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-compile.Tests", "test\dotnet-compile.Tests\dotnet-compile.Tests.xproj", "{833FFEE1-7EED-4F51-8DFD-946D48893D6E}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-publish.Tests", "test\dotnet-publish.Tests\dotnet-publish.Tests.xproj", "{386D412C-003C-47B1-8258-0E35865CB7C4}"
@ -302,22 +300,6 @@ Global
{60CF7E6C-D6C8-439D-B7B7-D8A27E29BE2C}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{60CF7E6C-D6C8-439D-B7B7-D8A27E29BE2C}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{60CF7E6C-D6C8-439D-B7B7-D8A27E29BE2C}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Debug|Any CPU.Build.0 = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Debug|x64.ActiveCfg = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Debug|x64.Build.0 = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Release|Any CPU.ActiveCfg = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Release|Any CPU.Build.0 = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Release|x64.ActiveCfg = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.Release|x64.Build.0 = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48833333}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48893D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48893D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{833FFEE1-7EED-4F51-8DFD-946D48893D6E}.Debug|x64.ActiveCfg = Debug|Any CPU
@ -956,7 +938,6 @@ Global
{65741CB1-8AEE-4C66-8198-10A7EA0E4258} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{713CBFBB-5392-438D-B766-A9A585EF1BB8} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{60CF7E6C-D6C8-439D-B7B7-D8A27E29BE2C} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{833FFEE1-7EED-4F51-8DFD-946D48833333} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{833FFEE1-7EED-4F51-8DFD-946D48893D6E} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{386D412C-003C-47B1-8258-0E35865CB7C4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{D521DD9F-0614-4929-93B4-D8FA5682C174} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}

View file

@ -1,55 +0,0 @@
using System.IO;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class BuildInvalidArgumentsTests : TestBase
{
[Fact]
public void ErrorOccursWhenBuildingPortableProjectToSpecificOutputPathWithoutSpecifyingFramework()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests")
.WithLockFiles();
var result = new BuildCommand(
projectPath: Path.Combine(testInstance.TestRoot, "PortableApp"),
output: Path.Combine(testInstance.TestRoot, "out"))
.ExecuteWithCapturedOutput();
result.Should().Fail();
result.Should().HaveStdErrContaining("When the '--output' option is provided, the '--framework' option must also be provided.");
}
[Fact]
public void ErrorOccursWhenBuildingPortableProjectAndSpecifyingFrameworkThatProjectDoesNotSupport()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests")
.WithLockFiles();
var result = new BuildCommand(
projectPath: Path.Combine(testInstance.TestRoot, "PortableApp"),
output: Path.Combine(testInstance.TestRoot, "out"),
framework: "sl40")
.ExecuteWithCapturedOutput();
result.Should().Fail();
result.Should().HaveStdErrMatching("Project '.*?' does not support framework: Silverlight,Version=v4\\.0\\.");
}
[Fact]
public void ErrorOccursWhenBuildingStandaloneProjectToSpecificOutputPathWithoutSpecifyingFramework()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests")
.WithLockFiles();
var result = new BuildCommand(
projectPath: Path.Combine(testInstance.TestRoot, "StandaloneApp"),
output: Path.Combine(testInstance.TestRoot, "out"))
.ExecuteWithCapturedOutput();
result.Should().Fail();
result.Should().HaveStdErrContaining("When the '--output' option is provided, the '--framework' option must also be provided.");
}
}
}

View file

@ -1,387 +0,0 @@
// 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 System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Newtonsoft.Json.Linq;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class BuildOutputTests : TestBase
{
private string _testProjectsRoot;
private string _runtime;
private DirectoryInfo _rootDirInfo;
private DirectoryInfo _testAppDirDirInfo;
private DirectoryInfo _testLibDirInfo;
private readonly string[] _runtimeFiles =
{
"TestApp" + FileNameSuffixes.DotNet.DynamicLib,
"TestApp" + FileNameSuffixes.DotNet.ProgramDatabase,
"TestApp" + FileNameSuffixes.CurrentPlatform.Exe,
"TestApp" + FileNameSuffixes.DepsJson,
"TestApp" + FileNameSuffixes.RuntimeConfigJson,
"TestLibrary" + FileNameSuffixes.DotNet.DynamicLib,
"TestLibrary" + FileNameSuffixes.DotNet.ProgramDatabase
};
private readonly string[] _runtimeExcludeFiles =
{
"TestLibrary" + FileNameSuffixes.RuntimeConfigJson,
"TestLibrary" + FileNameSuffixes.RuntimeConfigDevJson
};
private readonly string[] _appCompileFiles =
{
"TestApp" + FileNameSuffixes.DotNet.DynamicLib,
"TestApp" + FileNameSuffixes.DotNet.ProgramDatabase
};
private readonly string[] _libCompileFiles =
{
"TestLibrary" + FileNameSuffixes.DotNet.DynamicLib,
"TestLibrary" + FileNameSuffixes.DotNet.ProgramDatabase
};
private readonly string[] _libCompileExcludeFiles =
{
"TestLibrary" + FileNameSuffixes.RuntimeConfigJson,
"TestLibrary" + FileNameSuffixes.RuntimeConfigDevJson
};
private void GetProjectInfo(string testRoot)
{
_testProjectsRoot = testRoot;
_rootDirInfo = new DirectoryInfo(_testProjectsRoot);
_testAppDirDirInfo = new DirectoryInfo(Path.Combine(_testProjectsRoot, "TestApp"));
_testLibDirInfo = new DirectoryInfo(Path.Combine(_testProjectsRoot, "TestLibrary"));
var contexts = ProjectContext.CreateContextForEachFramework(
_testAppDirDirInfo.FullName,
null,
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
_runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
}
private string FormatPath(string input, string framework, string runtime)
{
return input.Replace("{fw}", framework).Replace("{rid}", runtime);
}
[Theory]
// global.json exists
[InlineData("1", true, null, null, "TestLibrary/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}/{rid}")]
[InlineData("2", true, "out", null, "TestLibrary/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}", "out")]
[InlineData("3", true, null, "build", "build/TestLibrary/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}/{rid}")]
[InlineData("4", true, "out", "build", "build/TestLibrary/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}", "out")]
//no global.json
//[InlineData(false, null, null, "TestLibrary/bin/debug/{fw}", "TestApp/bin/debug/{fw}", "TestApp/bin/debug/{fw}/{rid}")]
//[InlineData(false, "out", null, "TestLibrary/bin/debug/{fw}", "TestApp/bin/debug/{fw}", "out")]
//[InlineData(false, null, "build", "build/TestLibrary/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}/{rid}")]
//[InlineData(false, "out", "build", "build/TestLibrary/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}", "out")]
public void AppDefaultPaths(string testIdentifer, bool global, string outputValue, string baseValue, string expectedLibCompile, string expectedAppCompile, string expectedAppRuntime)
{
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifer)
.WithLockFiles();
GetProjectInfo(testInstance.TestRoot);
new BuildCommand(GetProjectPath(_testAppDirDirInfo),
output: outputValue != null ? Path.Combine(_testProjectsRoot, outputValue) : string.Empty,
buildBasePath: baseValue != null ? Path.Combine(_testProjectsRoot, baseValue) : string.Empty,
framework: DefaultFramework)
.ExecuteWithCapturedOutput().Should().Pass();
var libdebug = _rootDirInfo.Sub(FormatPath(expectedLibCompile, DefaultLibraryFramework, _runtime));
var appdebug = _rootDirInfo.Sub(FormatPath(expectedAppCompile, DefaultFramework, _runtime));
var appruntime = _rootDirInfo.Sub(FormatPath(expectedAppRuntime, DefaultFramework, _runtime));
libdebug.Should().Exist()
.And.HaveFiles(_libCompileFiles)
.And.NotHaveFiles(_libCompileExcludeFiles);
appdebug.Should().Exist().And.HaveFiles(_appCompileFiles);
appruntime.Should().Exist()
.And.HaveFiles(_runtimeFiles)
.And.NotHaveFiles(_runtimeExcludeFiles);
}
[Theory]
[InlineData("1", true, null, null, "TestLibrary/bin/Debug/{fw}", "TestLibrary/bin/Debug/{fw}/{rid}")]
[InlineData("2", true, "out", null, "TestLibrary/bin/Debug/{fw}", "out")]
[InlineData("3", true, null, "build", "build/TestLibrary/bin/Debug/{fw}", "build/TestLibrary/bin/Debug/{fw}/{rid}")]
[InlineData("4", true, "out", "build", "build/TestLibrary/bin/Debug/{fw}", "out")]
public void LibDefaultPaths(string testIdentifer, bool global, string outputValue, string baseValue, string expectedLibCompile, string expectedLibOutput)
{
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifer)
.WithLockFiles();
GetProjectInfo(testInstance.TestRoot);
new BuildCommand(GetProjectPath(_testLibDirInfo),
output: outputValue != null ? Path.Combine(_testProjectsRoot, outputValue) : string.Empty,
buildBasePath: baseValue != null ? Path.Combine(_testProjectsRoot, baseValue) : string.Empty,
framework: DefaultLibraryFramework)
.ExecuteWithCapturedOutput().Should().Pass();
var libdebug = _rootDirInfo.Sub(FormatPath(expectedLibCompile, DefaultLibraryFramework, _runtime));
libdebug.Should().Exist()
.And.HaveFiles(_libCompileFiles)
.And.NotHaveFiles(_libCompileExcludeFiles);
}
[Fact]
public void SettingVersionInEnvironment_ShouldStampAssemblyInfoInOutputAssembly()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithConfiguration")
.WithLockFiles();
var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: DefaultLibraryFramework);
cmd.Environment["DOTNET_BUILD_VERSION"] = "85";
cmd.Environment["DOTNET_ASSEMBLY_FILE_VERSION"] = "345";
cmd.ExecuteWithCapturedOutput().Should().Pass();
var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultLibraryFramework, "TestLibraryWithConfiguration.dll");
var informationalVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyInformationalVersionAttribute");
var fileVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyFileVersionAttribute");
informationalVersion.Should().NotBeNull();
informationalVersion.Should().BeEquivalentTo("1.0.0-85");
fileVersion.Should().NotBeNull();
fileVersion.Should().BeEquivalentTo("1.0.0.345");
}
[Fact]
public void SettingVersionSuffixFlag_ShouldStampAssemblyInfoInOutputAssembly()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithConfiguration")
.WithLockFiles();
var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: DefaultLibraryFramework, versionSuffix: "85");
cmd.ExecuteWithCapturedOutput().Should().Pass();
var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultLibraryFramework, "TestLibraryWithConfiguration.dll");
var informationalVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyInformationalVersionAttribute");
informationalVersion.Should().NotBeNull();
informationalVersion.Should().BeEquivalentTo("1.0.0-85");
}
[Fact]
public void BuildGlobbingMakesAllRunnable()
{
var testInstance = TestAssetsManager.CreateTestInstance("AppWithAppDependency")
.WithLockFiles();
var cmd = new BuildCommand(string.Format("*{0}project.json", Path.DirectorySeparatorChar), skipLoadProject: true)
.WithWorkingDirectory(testInstance.TestRoot)
.Execute()
.Should()
.Pass();
foreach (var project in new [] { "TestApp1", "TestApp2" })
{
new DirectoryInfo(Path.Combine(testInstance.TestRoot, project, "bin", "Debug", DefaultFramework))
.Should().HaveFile($"{project}.deps.json");
}
}
[Theory]
// [InlineData("net20", false, true)]
// [InlineData("net40", true, true)]
// [InlineData("net461", true, true)]
[InlineData("netstandard1.5", true, false)]
public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly)
{
var framework = NuGetFramework.Parse(frameworkName);
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithMultipleFrameworks")
.WithLockFiles();
var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: framework.GetShortFolderName());
if (windowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// on non-windows platforms, desktop frameworks will not build
cmd.ExecuteWithCapturedOutput().Should().Fail();
}
else
{
cmd.ExecuteWithCapturedOutput().Should().Pass();
var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", framework.GetShortFolderName(), "TestLibraryWithMultipleFrameworks.dll");
var targetFramework = PeReaderUtils.GetAssemblyAttributeValue(output, "TargetFrameworkAttribute");
if (shouldHaveTargetFrameworkAttribute)
{
targetFramework.Should().NotBeNull();
targetFramework.Should().BeEquivalentTo(framework.DotNetFrameworkName);
}
else
{
targetFramework.Should().BeNull();
}
}
}
[Fact]
public void UnresolvedReferenceCausesBuildToFailAndNotProduceOutput()
{
var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithUnresolvedDependency")
.WithLockFiles();
var restoreResult = new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }
.ExecuteWithCapturedOutput()
.Should().Fail();
new DirectoryInfo(testInstance.TestRoot)
.Should().HaveFile("project.lock.json");
var buildCmd = new BuildCommand(testInstance.TestRoot);
var buildResult = buildCmd.ExecuteWithCapturedOutput();
buildResult.Should().Fail();
buildResult.StdErr.Should().Contain("The dependency ThisIsNotARealDependencyAndIfSomeoneGoesAndAddsAProjectWithThisNameIWillFindThemAndPunishThem could not be resolved.");
var outputDir = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0"));
outputDir.GetFiles().Length.Should().Be(0);
}
[Fact]
public void PackageReferenceWithResourcesTest()
{
var testInstance = TestAssetsManager.CreateTestInstance("ResourcesTests")
.WithLockFiles();
var projectRoot = Path.Combine(testInstance.TestRoot, "TestApp");
var cmd = new BuildCommand(projectRoot);
var result = cmd.Execute();
result.Should().Pass();
var outputDir = new DirectoryInfo(Path.Combine(projectRoot, "bin", "Debug", "netcoreapp1.0"));
outputDir.Should().HaveFile("TestLibraryWithResources.dll");
outputDir.Sub("fr").Should().HaveFile("TestLibraryWithResources.resources.dll");
var depsJson = JObject.Parse(File.ReadAllText(Path.Combine(outputDir.FullName, $"{Path.GetFileNameWithoutExtension(cmd.GetOutputExecutableName())}.deps.json")));
foreach (var library in new[] { Tuple.Create("Microsoft.Data.OData", "5.6.4"), Tuple.Create("TestLibraryWithResources", "1.0.0") })
{
var resources = depsJson
["targets"]
[".NETCoreApp,Version=v1.0"]
[library.Item1.ToLowerInvariant() + "/" + library.Item2.ToLowerInvariant()]
["resources"];
resources.Should().NotBeNull();
foreach (var item in resources.Children<JProperty>())
{
var locale = item.Value["locale"];
locale.Should().NotBeNull();
item.Name.Should().EndWith($"{locale}/{library.Item1}.resources.dll");
}
}
}
[Fact]
public void ResourceTest()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary")
.WithLockFiles();
GetProjectInfo(testInstance.TestRoot);
var names = new[]
{
"uk-UA",
"en",
"en-US"
};
foreach (var folder in new[] { _testAppDirDirInfo, _testLibDirInfo })
{
foreach (var name in names)
{
var resourceFile = Path.Combine(folder.FullName, $"Resource.{name}.resx");
File.WriteAllText(resourceFile, "<root></root>");
}
}
new BuildCommand(GetProjectPath(_testAppDirDirInfo), framework: DefaultFramework)
.ExecuteWithCapturedOutput().Should().Pass();
var libdebug = _testLibDirInfo.Sub("bin/Debug").Sub(DefaultLibraryFramework);
var appdebug = _testAppDirDirInfo.Sub("bin/Debug").Sub(DefaultFramework);
var appruntime = appdebug.Sub(_runtime);
foreach (var name in names)
{
libdebug.Sub(name).Should().Exist().And.HaveFile("TestLibrary.resources.dll");
appdebug.Sub(name).Should().Exist().And.HaveFile("TestApp.resources.dll");
appruntime.Sub(name).Should().Exist().And.HaveFiles(new[] { "TestLibrary.resources.dll", "TestApp.resources.dll" });
}
}
[Fact]
private void StandaloneApp_WithoutCoreClrDll_Fails()
{
// Convert a Portable App to Standalone to simulate the customer scenario
var testInstance = TestAssetsManager.CreateTestInstance("DependencyChangeTest")
.WithLockFiles();
// Convert the portable test project to standalone by removing "type": "platform" and adding rids
var originalTestProject = Path.Combine(testInstance.TestRoot, "PortableApp_Standalone", "project.json");
var modifiedTestProject = Path.Combine(testInstance.TestRoot, "PortableApp_Standalone", "project.json.modified");
// Simulate a user editting the project.json
File.Delete(originalTestProject);
File.Copy(modifiedTestProject, originalTestProject);
var buildResult = new BuildCommand(originalTestProject, framework: DefaultFramework)
.ExecuteWithCapturedOutput();
buildResult.Should().Fail();
buildResult.StdErr.Should().Contain("Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes");
buildResult.StdErr.Should().Contain("The project has not been restored or restore failed - run `dotnet restore`");
}
[Fact]
private void App_WithSelfReferencingDependency_FailsBuild()
{
var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithSelfReferencingDependency")
.WithLockFiles();
var restoreResult = new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.ExecuteWithCapturedOutput();
restoreResult.Should().Fail();
restoreResult.StdOut.Should().Contain("error: Cycle detected");
}
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
{
// copy all the files to temp dir
foreach (var file in Directory.EnumerateFiles(projectDir))
{
tempDir.CopyFile(file);
}
}
private string GetProjectPath(DirectoryInfo projectDir)
{
return Path.Combine(projectDir.FullName, "project.json");
}
}
}

View file

@ -1,99 +0,0 @@
using System.IO;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using Microsoft.DotNet.TestFramework;
using Newtonsoft.Json.Linq;
using FluentAssertions;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class BuildPortableTests : TestBase
{
[Fact]
public void BuildingAPortableProjectProducesDepsJsonFile()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests").WithLockFiles();
var netcoreAppOutput = Build(testInstance);
netcoreAppOutput.Should().Exist().And.HaveFile("PortableApp.deps.json");
}
[Fact]
public void BuildingAPortableProjectProducesADllFile()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests").WithLockFiles();
var netcoreAppOutput = Build(testInstance);
netcoreAppOutput.Should().Exist().And.HaveFile("PortableApp.dll");
}
[Fact]
public void BuildingAPortableProjectProducesAPdbFile()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests").WithLockFiles();
var netcoreAppOutput = Build(testInstance);
netcoreAppOutput.Should().Exist().And.HaveFile("PortableApp.pdb");
}
[Fact]
public void BuildingAPortableProjectProducesARuntimeConfigJsonFile()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests").WithLockFiles();
var netcoreAppOutput = Build(testInstance);
netcoreAppOutput.Should().Exist().And.HaveFile("PortableApp.runtimeconfig.json");
}
[Fact]
public void RuntimeOptionsGetsCopiedToRuntimeConfigJsonForAPortableApp()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests")
.WithLockFiles();
var netcoreAppOutput = Build(testInstance);
var runtimeConfigJsonPath = Path.Combine(netcoreAppOutput.FullName, "PortableApp.runtimeconfig.json");
using (var stream = new FileStream(runtimeConfigJsonPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var reader = new StreamReader(stream);
var rawProject = JObject.Parse(reader.ReadToEnd());
var runtimeOptions = rawProject["runtimeOptions"];
runtimeOptions["somethingString"].Value<string>().Should().Be("anything");
runtimeOptions["somethingBoolean"].Value<bool>().Should().BeTrue();
runtimeOptions["someArray"].ToObject<string[]>().Should().Contain("one", "two");
runtimeOptions["someObject"].Value<JObject>()["someProperty"].Value<string>().Should().Be("someValue");
}
}
[Fact]
public void BuildingAPortableProjectProducesARuntimeConfigDevJsonFile()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests").WithLockFiles();
var netcoreAppOutput = Build(testInstance);
netcoreAppOutput.Should().Exist().And.HaveFile("PortableApp.runtimeconfig.dev.json");
}
private DirectoryInfo Build(TestInstance testInstance)
{
var result = new BuildCommand(
projectPath: Path.Combine(testInstance.TestRoot, "PortableApp"))
.ExecuteWithCapturedOutput();
result.Should().Pass();
var outputBase = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "PortableApp", "bin", "Debug"));
return outputBase.Sub("netcoreapp1.0");
}
}
}

View file

@ -1,187 +0,0 @@
// 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 FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class ProjectToProjectDependenciesIncrementalTest : IncrementalTestBase
{
private readonly string[] _projects = new[] { "L0", "L11", "L12", "L21", "L22" };
private readonly string _appProject = "L0";
private string MainProjectExe
{
get
{
return MainProject + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "");
}
}
public ProjectToProjectDependenciesIncrementalTest()
{
MainProject = "L0";
ExpectedOutput = "L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine;
}
[Theory]
[InlineData("1", "L0", new[] { "L0" })]
[InlineData("2", "L11", new[] { "L0", "L11" })]
[InlineData("3", "L12", new[] { "L0", "L11", "L12" })]
[InlineData("4", "L22", new[] { "L0", "L11", "L12", "L22" })]
[InlineData("5", "L21", new[] { "L0", "L11", "L21" })]
public void TestIncrementalBuildOfDependencyGraph(string testIdentifer, string projectToTouch, string[] expectedRebuiltProjects)
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies", identifier: testIdentifer)
.WithLockFiles()
.WithBuildArtifacts();
TestProjectRoot = testInstance.TestRoot;
// second build; nothing changed; no project required compilation
var result2 = BuildProject();
AssertRebuilt(result2, Array.Empty<string>());
//modify the source code of a project
TouchSourcesOfProject(projectToTouch);
// third build; all projects on the paths from touched project to root project need to be rebuilt
var result3 = BuildProject();
AssertRebuilt(result3, expectedRebuiltProjects);
}
[Fact]
public void TestNoDependencyFlag()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies")
.WithLockFiles()
.WithBuildArtifacts();
TestProjectRoot = testInstance.TestRoot;
var dependencies = new[] { "L11", "L12", "L21", "L22" };
// modify the source code of a leaf dependency
TouchSourcesOfProject("L22");
// second build with no dependencies and no incremental; only the root rebuilds
var result2 = BuildProject(noDependencies: true, noIncremental: true);
result2.Should().HaveStdOutMatching("Compiling.*L0.*");
AssertResultDoesNotContainStrings(result2, dependencies);
// third build with no dependencies but incremental; nothing rebuilds
var result3 = BuildProject(noDependencies: true);
result3.Should().HaveSkippedProjectCompilation("L0", _appFrameworkFullName);
AssertResultDoesNotContainStrings(result3, dependencies);
}
[Fact]
public void TestNoDependenciesDependencyRebuild()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies")
.WithLockFiles()
.WithBuildArtifacts();
TestProjectRoot = testInstance.TestRoot;
// modify the source code of a leaf dependency
TouchSourcesOfProject("L11");
// second build with no dependencies, rebuilding leaf
var result2 = new BuildCommand(GetProjectDirectory("L11"), noDependencies: true, framework: DefaultLibraryFramework).ExecuteWithCapturedOutput();
result2.Should().HaveStdOutMatching("Compiling.*L11.*");
// third build with no dependencies but incremental; root project should rebuild
var result3 = BuildProject(noDependencies: true);
result3.Should().HaveCompiledProject("L0", _appFrameworkFullName);
}
private static void AssertResultDoesNotContainStrings(CommandResult commandResult, string[] strings)
{
foreach (var s in strings)
{
commandResult.StdOut.Should().NotContain(s);
}
}
// compute A - B
private T[] SetDifference<T>(T[] A, T[] B)
{
var setA = new HashSet<T>(A);
setA.ExceptWith(B);
return setA.ToArray();
}
private void AssertRebuilt(CommandResult buildResult, string[] expectedRebuilt)
{
foreach (var rebuiltProject in expectedRebuilt)
{
string frameworkFullName = null;
if (TestProjectIsApp(rebuiltProject))
{
buildResult
.Should()
.HaveCompiledProject(rebuiltProject, frameworkFullName: _appFrameworkFullName);
}
else
{
buildResult
.Should()
.HaveCompiledProject(rebuiltProject, _libraryFrameworkFullName);
}
}
foreach (var skippedProject in SetDifference(_projects, expectedRebuilt))
{
if (TestProjectIsApp(skippedProject))
{
buildResult.Should().HaveSkippedProjectCompilation(skippedProject, _appFrameworkFullName);
}
else
{
buildResult.Should().HaveSkippedProjectCompilation(skippedProject, _libraryFrameworkFullName);
}
}
}
private bool TestProjectIsApp(string testproject)
{
return testproject.Equals(_appProject, StringComparison.OrdinalIgnoreCase);
}
protected override string GetProjectDirectory(string projectName)
{
return Path.Combine(TestProjectRoot, "src", projectName);
}
protected override string GetOutputDir()
{
return "";
}
protected override string GetOutputExePath()
{
var outputExe = Directory.GetFiles(TestProjectRoot, MainProjectExe, SearchOption.AllDirectories)
.FirstOrDefault();
if (string.IsNullOrEmpty(outputExe))
{
throw new FileNotFoundException($"Unable to find {outputExe} in {TestProjectRoot} or its subdirectories");
}
return Path.GetDirectoryName(outputExe);
}
}
}

View file

@ -1,87 +0,0 @@
// 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.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Newtonsoft.Json.Linq;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class BuildStandAloneTests : TestBase
{
[Fact]
public void BuildingAStandAloneProjectProducesARuntimeConfigDevJsonFile()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests")
.WithLockFiles();
var netstandardappOutput = Build(testInstance);
netstandardappOutput.Should().Exist().And.HaveFile("StandaloneApp.runtimeconfig.dev.json");
}
[Fact]
public void BuildingAStandAloneProjectProducesARuntimeConfigJsonFile()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests")
.WithLockFiles();
var netstandardappOutput = Build(testInstance);
netstandardappOutput.Should().Exist().And.HaveFile("StandaloneApp.runtimeconfig.json");
}
[Fact]
public void RuntimeOptionsGetsCopiedToRuntimeConfigJsonForAStandaloneApp()
{
var testInstance = TestAssetsManager.CreateTestInstance("PortableTests")
.WithLockFiles();
var netstandardappOutput = Build(testInstance);
var runtimeConfigJsonPath = Path.Combine(netstandardappOutput.FullName, "StandaloneApp.runtimeconfig.json");
using (var stream = new FileStream(runtimeConfigJsonPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
var reader = new StreamReader(stream);
var rawProject = JObject.Parse(reader.ReadToEnd());
var runtimeOptions = rawProject["runtimeOptions"];
runtimeOptions["somethingString"].Value<string>().Should().Be("anything");
runtimeOptions["somethingBoolean"].Value<bool>().Should().BeTrue();
runtimeOptions["someArray"].ToObject<string[]>().Should().Contain("one", "two");
runtimeOptions["someObject"].Value<JObject>()["someProperty"].Value<string>().Should().Be("someValue");
}
}
public DirectoryInfo Build(TestInstance testInstance)
{
var projectPath = Path.Combine(testInstance.TestRoot, "StandaloneApp");
var result = new BuildCommand(
projectPath: projectPath)
.ExecuteWithCapturedOutput();
var contexts = ProjectContext.CreateContextForEachFramework(
projectPath,
null,
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
var runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
result.Should().Pass();
var outputBase = new DirectoryInfo(
Path.Combine(testInstance.TestRoot, "StandaloneApp", "bin", "Debug", "netcoreapp1.0"));
return outputBase.Sub(runtime);
}
}
}

View file

@ -1,27 +0,0 @@
// 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 FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class BuildWarningsTests : TestBase
{
[Fact]
public void HavingDeprecatedProjectFileProducesWarning()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile").WithLockFiles();
new BuildCommand(testInstance.TestRoot)
.ExecuteWithCapturedOutput()
.Should()
.Pass()
.And
.HaveStdErrContaining("DOTNET1015: The 'compilationOptions' option is deprecated. Use 'buildOptions' instead.")
.And
.HaveStdErrContaining("DOTNET1015: The 'packInclude' option is deprecated. Use 'files' in 'packOptions' instead.");
}
}
}

View file

@ -1,119 +0,0 @@
// 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 FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class GivenDotnetBuildBuildsProjects : TestBase
{
[Fact]
public void It_builds_projects_with_Unicode_in_path()
{
var testInstance = TestAssetsManager
.CreateTestInstance("TestAppWithUnicodéPath")
.WithLockFiles();
var testProjectDirectory = testInstance.TestRoot;
var buildCommand = new BuildCommand("");
buildCommand.WorkingDirectory = testProjectDirectory;
buildCommand.ExecuteWithCapturedOutput()
.Should()
.Pass();
}
[Fact]
public void It_builds_projects_with_Unicode_in_path_project_path_passed()
{
var testInstance = TestAssetsManager
.CreateTestInstance("TestAppWithUnicodéPath")
.WithLockFiles();
var testProject = Path.Combine(testInstance.TestRoot, "project.json");
new BuildCommand(testProject)
.ExecuteWithCapturedOutput()
.Should()
.Pass();
}
[Fact]
public void It_builds_projects_with_ruleset_relative_path()
{
var testInstance = TestAssetsManager
.CreateTestInstance("TestRuleSet")
.WithLockFiles();
new BuildCommand(Path.Combine("TestLibraryWithRuleSet", "project.json"), skipLoadProject: true)
.WithWorkingDirectory(testInstance.TestRoot)
.ExecuteWithCapturedOutput()
.Should()
.Pass()
.And
.HaveStdErrContaining("CA1001")
.And
.HaveStdErrContaining("CA2213")
.And
.NotHaveStdErrContaining("CA1018"); // this violation is hidden in the ruleset
}
[Fact]
public void It_builds_projects_with_a_local_project_json_path()
{
var testInstance = TestAssetsManager
.CreateTestInstance("TestAppSimple")
.WithLockFiles();
new BuildCommand("project.json")
.WithWorkingDirectory(testInstance.TestRoot)
.ExecuteWithCapturedOutput()
.Should()
.Pass();
}
[Fact]
public void It_builds_projects_with_xmlDoc_and_spaces_in_the_path()
{
var testInstance = TestAssetsManager
.CreateTestInstance("TestLibraryWithXmlDoc", identifier: "With Space")
.WithLockFiles();
testInstance.TestRoot.Should().Contain(" ");
var output = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "output"));
new BuildCommand("", output: output.FullName, framework: DefaultLibraryFramework)
.WithWorkingDirectory(testInstance.TestRoot)
.ExecuteWithCapturedOutput()
.Should()
.Pass();
output.Should().HaveFiles(new[]
{
"TestLibraryWithXmlDoc.dll",
"TestLibraryWithXmlDoc.xml"
});
}
[WindowsOnlyFact]
public void It_builds_projects_targeting_net46_and_Roslyn()
{
var testInstance = TestAssetsManager
.CreateTestInstance("AppWithNet46AndRoslyn")
.WithLockFiles();
var testProject = Path.Combine(testInstance.TestRoot, "project.json");
new BuildCommand(testProject)
.Execute()
.Should()
.Pass();
}
}
}

View file

@ -1,138 +0,0 @@
// 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;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestBase : TestBase
{
protected readonly string _libraryFrameworkFullName = ".NETStandard,Version=v1.5";
protected readonly string _appFrameworkFullName = ".NETCoreApp,Version=v1.0";
protected virtual string MainProject
{
get; set;
}
protected virtual string ExpectedOutput
{
get; set;
}
protected virtual string TestProjectRoot
{
get; set;
}
protected IncrementalTestBase()
{
}
public IncrementalTestBase(string testProjectsRoot, string mainProject, string expectedOutput)
{
MainProject = mainProject;
ExpectedOutput = expectedOutput;
TestProjectRoot = 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);
}
protected CommandResult BuildProject(bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false)
{
var mainProjectFile = GetProjectFile(MainProject);
return BuildProject(mainProjectFile, noDependencies, noIncremental, expectBuildFailure);
}
protected CommandResult BuildProject(string projectFile, bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false)
{
var buildCommand = new BuildCommand(projectFile, output: GetOutputDir(), framework: "netcoreapp1.0", noIncremental: noIncremental, noDependencies : noDependencies);
var result = buildCommand.ExecuteWithCapturedOutput();
if (!expectBuildFailure)
{
result.Should().Pass();
TestOutputExecutable(GetOutputExePath(), buildCommand.GetOutputExecutableName(), ExpectedOutput);
}
else
{
result.Should().Fail();
}
return result;
}
protected virtual string GetOutputExePath()
{
return GetBinRoot();
}
protected virtual string GetOutputDir()
{
return GetBinRoot();
}
protected string GetBinRoot()
{
return Path.Combine(TestProjectRoot, "bin");
}
protected virtual string GetProjectDirectory(string projectName)
{
return Path.Combine(TestProjectRoot);
}
protected string GetProjectFile(string projectName)
{
return Path.Combine(GetProjectDirectory(projectName), "project.json");
}
private string GetOutputFileForProject(string projectName)
{
return Path.Combine(GetCompilationOutputPath(), projectName + ".dll");
}
private IEnumerable<string> GetSourceFilesForProject(string projectName)
{
return Directory.EnumerateFiles(GetProjectDirectory(projectName)).
Where(f => f.EndsWith(".cs"));
}
protected string GetCompilationOutputPath()
{
var executablePath = Path.Combine(GetBinRoot(), "Debug", "netcoreapp1.0");
return executablePath;
}
protected string GetIntermediaryOutputPath()
{
var executablePath = Path.Combine(TestProjectRoot, "obj", "Debug", "netcoreapp1.0");
return executablePath;
}
}
}

View file

@ -1,267 +0,0 @@
// 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 FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using Microsoft.DotNet.TestFramework;
using System.Diagnostics;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTests : IncrementalTestBase
{
public IncrementalTests()
{
MainProject = "TestSimpleIncrementalApp";
ExpectedOutput = "Hello World!" + Environment.NewLine;
}
private TestInstance _testInstance;
private void CreateTestInstance()
{
_testInstance = TestAssetsManager.CreateTestInstance("TestSimpleIncrementalApp")
.WithLockFiles();
TestProjectRoot = _testInstance.TestRoot;
}
[Fact]
public void TestNoIncrementalFlag()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
buildResult = BuildProject(noIncremental: true);
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
Assert.Contains("[Forced Unsafe]", buildResult.StdOut);
}
[Fact]
public void TestRebuildMissingPdb()
{
CreateTestInstance();
TestDeleteOutputWithExtension("pdb");
}
[Fact]
public void TestRebuildMissingDll()
{
CreateTestInstance();
TestDeleteOutputWithExtension("dll");
}
[Fact]
public void TestRebuildMissingXml()
{
CreateTestInstance();
TestDeleteOutputWithExtension("xml");
}
[Fact]
public void TestNoLockFile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
var lockFile = Path.Combine(TestProjectRoot, "project.lock.json");
Assert.True(File.Exists(lockFile));
File.Delete(lockFile);
Assert.False(File.Exists(lockFile));
buildResult = BuildProject(expectBuildFailure: true);
Assert.Contains("does not have a lock file", buildResult.StdErr);
Assert.Contains("dotnet restore", buildResult.StdErr);
}
[Fact]
public void TestModifiedVersionFile()
{
CreateTestInstance();
BuildProject().Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
// change version file
var versionFile = Path.Combine(GetIntermediaryOutputPath(), ".SDKVersion");
File.Exists(versionFile).Should().BeTrue();
File.AppendAllText(versionFile, "text");
// assert rebuilt
BuildProject().Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
}
[Fact]
public void TestNoVersionFile()
{
CreateTestInstance();
BuildProject().Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
// delete version file
var versionFile = Path.Combine(GetIntermediaryOutputPath(), ".SDKVersion");
File.Exists(versionFile).Should().BeTrue();
File.Delete(versionFile);
File.Exists(versionFile).Should().BeFalse();
// assert build skipped due to no version file
BuildProject().Should().HaveSkippedProjectCompilation(MainProject, _appFrameworkFullName);
// the version file should have been regenerated during the build, even if compilation got skipped
File.Exists(versionFile).Should().BeTrue();
}
[Fact]
public void TestRebuildDeletedSource()
{
CreateTestInstance();
BuildProject().Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
var sourceFile = Path.Combine(GetProjectDirectory(MainProject), "Program2.cs");
File.Delete(sourceFile);
Assert.False(File.Exists(sourceFile));
// second build; should get rebuilt since we deleted a source file
BuildProject().Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
// third build; incremental cache should have been regenerated and project skipped
BuildProject().Should().HaveSkippedProjectCompilation(MainProject, _appFrameworkFullName);
}
[Fact]
public void TestRebuildRenamedSource()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
var sourceFile = Path.Combine(GetProjectDirectory(MainProject), "Program2.cs");
var destinationFile = Path.Combine(Path.GetDirectoryName(sourceFile), "ProgramNew.cs");
File.Move(sourceFile, destinationFile);
Assert.False(File.Exists(sourceFile));
Assert.True(File.Exists(destinationFile));
// second build; should get rebuilt since we renamed a source file
buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
// third build; incremental cache should have been regenerated and project skipped
BuildProject().Should().HaveSkippedProjectCompilation(MainProject, _appFrameworkFullName);
}
[Fact]
public void TestRebuildDeletedSourceAfterCliChanged()
{
CreateTestInstance();
BuildProject().Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
// change version file
var versionFile = Path.Combine(GetIntermediaryOutputPath(), ".SDKVersion");
File.Exists(versionFile).Should().BeTrue();
File.AppendAllText(versionFile, "text");
// delete a source file
var sourceFile = Path.Combine(GetProjectDirectory(MainProject), "Program2.cs");
File.Delete(sourceFile);
Assert.False(File.Exists(sourceFile));
// should get rebuilt since we changed version file and deleted source file
BuildProject().Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
// third build; incremental cache should have been regenerated and project skipped
BuildProject().Should().HaveSkippedProjectCompilation(MainProject, _appFrameworkFullName);
}
[Fact]
public void TestRebuildChangedLockFile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
var lockFile = Path.Combine(TestProjectRoot, "project.lock.json");
TouchFile(lockFile);
buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
}
[Fact]
public void TestRebuildChangedProjectFile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
TouchFile(GetProjectFile(MainProject));
buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
}
// regression for https://github.com/dotnet/cli/issues/965
[Fact]
public void TestInputWithSameTimeAsOutputCausesProjectToCompile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
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);
buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
}
private DateTime SetAllOutputItemsToSameTime()
{
var now = DateTime.Now;
foreach (var f in Directory.EnumerateFiles(GetCompilationOutputPath()))
{
File.SetLastWriteTime(f, now);
}
return now;
}
private void TestDeleteOutputWithExtension(string extension)
{
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
Reporter.Verbose.WriteLine($"Files in {GetBinRoot()}");
foreach (var file in Directory.EnumerateFiles(GetBinRoot()))
{
Reporter.Verbose.Write($"\t {file}");
}
// delete output files with extensions
foreach (var outputFile in Directory.EnumerateFiles(GetBinRoot()).Where(f =>
{
var fileName = Path.GetFileName(f);
return fileName.StartsWith(MainProject, StringComparison.OrdinalIgnoreCase) &&
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();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
}
}
}

View file

@ -1,36 +0,0 @@
// 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 Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestsOnCultureSpecificResource : IncrementalTestBase
{
public IncrementalTestsOnCultureSpecificResource()
{
MainProject = "TestProjectWithCultureSpecificResource";
ExpectedOutput = "Hello World!" + Environment.NewLine + "Bonjour!" + Environment.NewLine;
}
// Sridhar-MS - temporarily disable the test and investigate why it is failing in CI machine.
// [Fact]
public void TestRebuildSkipsCompilationOnNonCultureResource()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithCultureSpecificResource")
.WithLockFiles();
TestProjectRoot = testInstance.TestRoot;
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
buildResult = BuildProject();
buildResult.Should().HaveSkippedProjectCompilation(MainProject, _appFrameworkFullName);
}
}
}

View file

@ -1,34 +0,0 @@
// 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 Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestsOnResources : IncrementalTestBase
{
public IncrementalTestsOnResources()
{
MainProject = "TestProjectWithResource";
ExpectedOutput = "Hello World!" + Environment.NewLine;
}
[Fact]
public void TestRebuildSkipsCompilationOnNonCultureResource()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithResource")
.WithLockFiles();
TestProjectRoot = testInstance.TestRoot;
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
buildResult = BuildProject();
buildResult.Should().HaveSkippedProjectCompilation(MainProject, _appFrameworkFullName);
}
}
}

View file

@ -1,48 +0,0 @@
// 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 Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestsTransitiveRuntime : IncrementalTestBase
{
private const string TestLibraryWithAppDependency = "TestLibraryWithAppDependency";
private const string LibraryProject = "TestLibrary";
private const string AppProject = "TestApp";
public IncrementalTestsTransitiveRuntime()
{
MainProject = "TestLibrary2";
ExpectedOutput = "This string came from the test library!" + Environment.NewLine;
}
[Fact]
public void TestSkipsRebuildWithTransitiveExeDependency()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithTransitiveAppDependency")
.WithLockFiles();
TestProjectRoot = testInstance.TestRoot;
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject, _appFrameworkFullName);
buildResult.Should().HaveCompiledProject(TestLibraryWithAppDependency, _appFrameworkFullName);
buildResult.Should().HaveCompiledProject(AppProject, _appFrameworkFullName);
buildResult.Should().HaveCompiledProject(LibraryProject, _appFrameworkFullName);
buildResult = BuildProject();
buildResult.Should().HaveSkippedProjectCompilation(MainProject, _appFrameworkFullName);
buildResult.Should().HaveSkippedProjectCompilation(TestLibraryWithAppDependency, _appFrameworkFullName);
buildResult.Should().HaveSkippedProjectCompilation(AppProject, _appFrameworkFullName);
buildResult.Should().HaveSkippedProjectCompilation(LibraryProject, _appFrameworkFullName);
}
protected override string GetProjectDirectory(string projectName)
{
return Path.Combine(TestProjectRoot, projectName);
}
}
}

View file

@ -1,29 +0,0 @@
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestsVersionSuffix : IncrementalTestBase
{
[Fact]
public void TestRebuildWhenVersionSuffixChanged()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestSimpleIncrementalApp")
.WithLockFiles();
// Build with Version Suffix 1
var command = new BuildCommand(testInstance.TestRoot, versionSuffix: "1");
var result = command.ExecuteWithCapturedOutput();
// Verify the result
result.Should().HaveCompiledProject("TestSimpleIncrementalApp", ".NETCoreApp,Version=v1.0");
// Build with Version Suffix 2
command = new BuildCommand(testInstance.TestRoot, versionSuffix: "2");
result = command.ExecuteWithCapturedOutput();
// Verify the result
result.Should().HaveCompiledProject("TestSimpleIncrementalApp", ".NETCoreApp,Version=v1.0");
}
}
}

View file

@ -1,135 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using FluentAssertions;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class ProjectNameArgumentTests : TestBase
{
private TestInstance _testInstance;
[Fact]
public void TestProjectDirectoryPath()
{
Test(new[] { Path.Combine("src", "L21") }, new[] { "L21" });
}
[Fact]
public void TestProjectFile()
{
Test(new[] { Path.Combine("src", "L21", "project.json") }, new[] { "L21" });
}
[Fact]
public void TestMultipleProjectDirectories()
{
Test(new[]
{
Path.Combine("src", "L21"),
Path.Combine("src", "L11")
},
new[] { "L21", "L11" });
}
[Fact]
public void TestMultipleProjectFiles()
{
Test(new[]
{
Path.Combine("src", "L21", "project.json"),
Path.Combine("src", "L11", "project.json"),
},
new[] { "L21", "L11" });
}
[Fact]
public void TestGlobbing()
{
Test(new[]
{
Path.Combine("src", "**", "project.json")
},
new[] { "L21", "L11", "L12" });
}
[Fact]
public void TestMultipleGlobbing()
{
Test(new[]
{
Path.Combine("src", "L1*", "project.json"),
Path.Combine("src", "L2*", "project.json")
},
new[] { "L11", "L12", "L21", "L22" });
}
[Fact]
public void TestFailsWhenNoGlobbingNoMatch()
{
Test(new[]
{
Path.Combine("src", "L33*", "project.json")
},
null);
}
[Fact]
public void TestFailsFileDoedNotExist()
{
Test(new[]
{
Path.Combine("src", "L33", "project.json")
},
null);
}
[Fact]
public void TestFindsProjectJsonInCurrentDirectoryWithNoArguments()
{
Test(new string[] { }, new[] { "L21" }, workingDirectory: Path.Combine("src", "L21"));
}
[Fact]
public void TestFailsIfNoProjectJsonInCurrentDirectoryWithNoArguments()
{
Test(new string[] { }, null, workingDirectory: "src");
}
private void Test(IEnumerable<string> inputs, IEnumerable<string> expectedProjects, string workingDirectory = null, [CallerMemberName] string testName = null)
{
var instance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies", testName)
.WithLockFiles()
.WithBuildArtifacts();
string args = string.Join(" ", inputs);
workingDirectory = workingDirectory != null
? Path.Combine(instance.TestRoot, workingDirectory)
: instance.TestRoot;
var result = new TestCommand("dotnet")
{
WorkingDirectory = Path.Combine(workingDirectory)
}.ExecuteWithCapturedOutput("--verbose build --no-dependencies " + args);
if (expectedProjects != null)
{
result.Should().Pass();
foreach (var expectedProject in expectedProjects)
{
result.Should().HaveSkippedProjectCompilation(expectedProject, NuGetFramework.Parse("netstandard1.5").DotNetFrameworkName);
}
}
else
{
result.Should().Fail();
}
}
}
}

View file

@ -1,36 +0,0 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using FluentAssertions;
using Xunit;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class WrappedProjectTests: TestBase
{
[Fact]
public void WrappedProjectFilesResolvedCorrectly()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithWrapperProjectDependency")
.WithBuildArtifacts()
.WithLockFiles();
var root = testInstance.TestRoot;
// run compile
var outputDir = Path.Combine(root, "bin");
var testProject = ProjectUtils.GetProjectJson(root, "TestApp");
var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
var result = buildCommand.ExecuteWithCapturedOutput();
result.Should().Pass();
new DirectoryInfo(outputDir).Should()
.HaveFiles(new [] { "TestLibrary.dll", "TestLibrary.pdb" });
}
}
}

View file

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>833ffee1-7eed-4f51-8dfd-946d48833333</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Tools.Builder.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -1,28 +0,0 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"System.Runtime.Serialization.Primitives": "4.1.1",
"Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project"
},
"Microsoft.DotNet.Cli.Utils": {
"target": "project"
},
"Newtonsoft.Json": "9.0.1",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-192208-24"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
}