Ejemplo n.º 1
0
        public void TestDotnetIncrementalBuild()
        {
            // first build
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: NetCoreAppTfm);
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput);

            var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false);
            var latestWriteTimeFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(
                binariesOutputDirectory);

            // second build; should get skipped (incremental because no inputs changed)
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput);

            var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(
                binariesOutputDirectory);
            Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeUtcSecondBuild);

            TouchSourceFileInDirectory(TestDirectory);

            // third build; should get compiled because the source file got touched
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput);

            var latestWriteTimeUtcThirdBuild = GetLastWriteTimeUtcOfDirectoryFiles(
                binariesOutputDirectory);
            Assert.NotEqual(latestWriteTimeUtcSecondBuild, latestWriteTimeUtcThirdBuild);
        }
        private void Setup([CallerMemberName] string callingMethod = "")
        {
            var testInstance = TestAssetsManager.CreateTestInstance(Path.Combine("ProjectsWithTests", "MultipleFrameworkProject"), callingMethod);

            _projectFilePath = Path.Combine(testInstance.TestRoot, "project.json");
            var contexts = ProjectContext.CreateContextForEachFramework(
                _projectFilePath,
                null,
                RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());

            // Restore the project again in the destination to resolve projects
            // Since the lock file has project relative paths in it, those will be broken
            // unless we re-restore
            new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute().Should().Pass();

            _netCoreAppOutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0");
            var buildCommand = new BuildCommand(_projectFilePath);
            var result = buildCommand.Execute($"-f netcoreapp1.0 -o {_netCoreAppOutputPath}");

            result.Should().Pass();

            if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
            {
                var rid = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers().First();
                _net451OutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "net451", rid);
                result = buildCommand.Execute($"-f net451 -r {rid} -o {_net451OutputPath}");
                result.Should().Pass();
            }
        }
Ejemplo n.º 3
0
        public void TestDotnetBuild()
        {
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: DefaultFramework);

            buildCommand.Execute().Should().Pass();

            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
        }
Ejemplo n.º 4
0
        public void TestDotnetBuild()
        {
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory);

            buildCommand.Execute().Should().Pass();

            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());
        }
Ejemplo n.º 5
0
        public void TestDotnetBuild()
        {
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: NetCoreAppTfm);

            buildCommand.Execute().Should().Pass();

            TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput);
        }
        public void It_skips_build_when_the_no_build_flag_is_passed()
        {
            var buildCommand = new BuildCommand(_projectFilePath);
            var result = buildCommand.Execute();
            result.Should().Pass();

            var testCommand = new DotnetTestCommand();
            result = testCommand.Execute($"{_projectFilePath} -o {_defaultOutputPath} --no-build");
            result.Should().Pass();
        }
Ejemplo n.º 7
0
        private void Setup(string project, ref string projectDir, ref string buildDir, ref string publishDir)
        {
            projectDir = Path.Combine(_testInstance.TestRoot, project);
            buildDir = Path.Combine(projectDir, _buildRelativePath);
            publishDir = Path.Combine(projectDir, "publish");

            var buildCommand = new BuildCommand(projectDir, framework: Framework, runtime: _Runtime);
            buildCommand.Execute().Should().Pass();

            var publishCommand = new PublishCommand(projectDir, output: publishDir, framework: Framework, runtime: _Runtime);
            publishCommand.Execute().Should().Pass();
        }
        public void Compilation_of_app_with_invalid_source_should_fail()
        {
            var testProject = Path.Combine(s_testProjectsRoot, "CompileFailApp", "project.json"); 
            var buildCommand = new BuildCommand(testProject);

            var oldDirectory = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(Path.GetDirectoryName(testProject));

            buildCommand.Execute().Should().Fail();

            Directory.SetCurrentDirectory(oldDirectory);
        }
        public void Compilation_of_valid_app_should_succeed()
        {
            var testProject = Path.Combine(s_testProjectsRoot, "TestAppWithArgs", "project.json"); 
            var buildCommand = new BuildCommand(testProject);

            var oldDirectory = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(Path.GetDirectoryName(testProject));

            buildCommand.Execute().Should().Pass();

            Directory.SetCurrentDirectory(oldDirectory);
        }
        public void Test_Build_Project_with_Resources_with_Space_in_Path_Should_Succeed()
        {
            var spaceBufferDirectory = _root.CreateDirectory("space directory");
            var testAppDir = spaceBufferDirectory.CreateDirectory("TestProjectWithResource");

            CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestProjectWithResource"), testAppDir);

            var testProject = GetProjectPath(testAppDir);
            var buildCommand = new BuildCommand(testProject);

            buildCommand.Execute().Should().Pass();
        }
Ejemplo n.º 11
0
 public void BuildSingleProject(TestInstance instance)
 {
     foreach (var iteration in Benchmark.Iterations)
     {
         var buildCommand = new BuildCommand(instance.TestRoot, buildProfile: false);
         using (iteration.StartMeasurement())
         {
             buildCommand.Execute().Should().Pass();
         }
         TouchSource(instance.TestRoot);
     }
 }
Ejemplo n.º 12
0
        public void TestDotnetBuildNativeCpp()
        {
            if(IsCentOS())
            {
                Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453");
                return;
            }

            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true);

            buildCommand.Execute().Should().Pass();

            var nativeOut = Path.Combine(OutputDirectory, "native");
            TestOutputExecutable(nativeOut, buildCommand.GetOutputExecutableName());
        }
        public GivenThatWeWantToUseDotnetTestE2EInDesignTime()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("ProjectWithTests").WithLockFiles();

            _projectFilePath = Path.Combine(testInstance.TestRoot, "project.json");
            var contexts = ProjectContext.CreateContextForEachFramework(
                _projectFilePath,
                null,
                PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers());
            var runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
            _outputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultFramework, runtime);
            var buildCommand = new BuildCommand(_projectFilePath);
            var result = buildCommand.Execute();

            result.Should().Pass();
        }
Ejemplo n.º 14
0
        public void MeasureDotNetBuild()
        {
            foreach (var iter in Benchmark.Iterations)
            {
                // Setup a new instance of the test project.
                TestInstanceSetup();

                // Setup the build command.
                var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: DefaultFramework);
                using (iter.StartMeasurement())
                {
                    // Execute the build command.
                    buildCommand.Execute();
                }
            }
        }
        public GivenThatWeWantToUseDotnetTestE2EInDesignTime()
        {
            var testInstance = TestAssetsManager.CreateTestInstance(Path.Combine("ProjectsWithTests", "NetCoreAppOnlyProject"));

            _projectFilePath = Path.Combine(testInstance.TestRoot, "project.json");
            var contexts = ProjectContext.CreateContextForEachFramework(
                _projectFilePath,
                null,
                RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());

            // Restore the project again in the destination to resolve projects
            // Since the lock file has project relative paths in it, those will be broken
            // unless we re-restore
            new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute().Should().Pass();

            _outputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0");
            var buildCommand = new BuildCommand(_projectFilePath);
            var result = buildCommand.Execute();

            result.Should().Pass();
        }
Ejemplo n.º 16
0
        public void CrossPublishingSucceedsAndHasExpectedArtifacts()
        {            
            TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("PortableTests"));

            var testProject = Path.Combine(instance.TestRoot, "StandaloneApp", "project.json");
            var workingDirectory = Path.GetDirectoryName(testProject);
            var testNugetCache = Path.Combine(workingDirectory, "packages_cross_publish_test");

            var restoreCommand = new RestoreCommand();

            restoreCommand.WorkingDirectory = workingDirectory;            

            restoreCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
            restoreCommand.Execute().Should().Pass();

            foreach (var testData in CrossPublishTestData)
            {
                var buildCommand = new BuildCommand(testProject, runtime: testData.Rid);

                buildCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
                buildCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
                buildCommand.Execute().Should().Pass();

                var publishCommand = new PublishCommand(testProject, runtime: testData.Rid, noBuild: true);
                publishCommand.Environment["NUGET_PACKAGES"] = testNugetCache;
                publishCommand.WorkingDirectory = Path.GetDirectoryName(testProject);
                publishCommand.Execute().Should().Pass();

                var publishedDir = publishCommand.GetOutputDirectory();
                publishedDir.Should().HaveFile("StandaloneApp"+ testData.HostExtension);

                foreach (var artifact in testData.ExpectedArtifacts)
                {
                    publishedDir.Should().HaveFile(artifact);
                }
            }
        }
Ejemplo n.º 17
0
        public void CompilingAppWithPreserveCompilationContextWithSpaceInThePathShouldSucceed()
        {
            var root = Temp.CreateDirectory();

            var spaceBufferDirectory = root.CreateDirectory("space directory");
            var testAppDir = spaceBufferDirectory.CreateDirectory("TestAppCompilationContext");

            CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir);

            var testProjectDir = Path.Combine(_testProjectsRoot, "TestAppCompilationContext", "TestApp");
            var testProject = Path.Combine(testProjectDir, "project.json");
            
            var buildCommand = new BuildCommand(testProject);

            buildCommand.Execute().Should().Pass();
        }
Ejemplo n.º 18
0
        private string SetupTestProject()
        {
            var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "OutputStandardOutputAndError");

            var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;

            var buildCommand = new BuildCommand(Path.Combine(binTestProjectPath, "project.json"));
            buildCommand.Execute();

            var buildOutputExe = "OutputStandardOutputAndError" + Constants.ExeSuffix;
            var buildOutputPath = Path.Combine(binTestProjectPath, "bin/Debug/dnxcore50", buildOutputExe);

            return buildOutputPath;
        }
Ejemplo n.º 19
0
        public void IncrementalRebuildWithLastChangedInGraph(TestInstance[] instances)
        {
            var instance = instances[0];
            new BuildCommand(instance.TestRoot, buildProfile: false)
                   .Execute().Should().Pass();

            foreach (var iteration in Benchmark.Iterations)
            {
                var buildCommand = new BuildCommand(instance.TestRoot, buildProfile: false);
                using (iteration.StartMeasurement())
                {
                    buildCommand.Execute().Should().Pass();
                }
                TouchSource(instances.Last().TestRoot);
            }
        }
Ejemplo n.º 20
0
        public void BuildAllInGraph(TestInstance[] instances)
        {
            var instance = instances[0];

            foreach (var iteration in Benchmark.Iterations)
            {
                var buildCommand = new BuildCommand(instance.TestRoot, buildProfile: false);
                using (iteration.StartMeasurement())
                {
                    buildCommand.Execute().Should().Pass();
                }
                foreach (var i in instances)
                {
                    TouchSource(i.TestRoot);
                }
            }
        }
Ejemplo n.º 21
0
        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 + "/" + library.Item2]["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");
                }
            }
        }
Ejemplo n.º 22
0
        public void TestDotnetBuildNativeRyuJit()
        {
            if (!IsNativeCompilationSupported())
            {
                return;
            }

            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, framework: NetCoreAppTfm);

            buildCommand.Execute().Should().Pass();

            TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
        }
Ejemplo n.º 23
0
        public void TestDotnetIncrementalBuildDeleteOutputFile()
        {
            TestSetup();

            // first build
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory);
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());

            var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);

            Reporter.Verbose.WriteLine($"Files in {OutputDirectory}");
            foreach (var file in Directory.EnumerateFiles(OutputDirectory))
            {
                Reporter.Verbose.Write($"\t {file}");
            }

            // delete output files
            foreach (var outputFile in Directory.EnumerateFiles(OutputDirectory).Where(f => Path.GetFileName(f).StartsWith(s_testdirName, StringComparison.OrdinalIgnoreCase)))
            {
                Reporter.Verbose.WriteLine($"Delete {outputFile}");

                File.Delete(outputFile);
                Assert.False(File.Exists(outputFile));
            }

            // second build; should get rebuilt since we deleted output items
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());

            var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);
            Assert.NotEqual(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);
        }
Ejemplo n.º 24
0
        public void TestDotnetIncrementalBuild()
        {
            TestSetup();

            // first build
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory);
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());

            var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);

            // second build; should get skipped (incremental because no inputs changed)
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());

            var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);
            Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);

            TouchSourceFileInDirectory(TestDirectory);

            // third build; should get compiled because the source file got touched
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());

            var latestWriteTimeThirdBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);
            Assert.NotEqual(latestWriteTimeSecondBuild, latestWriteTimeThirdBuild);
        }
Ejemplo n.º 25
0
        public void TestDotnetForceIncrementalUnsafe()
        {
            TestSetup();

            // first build
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory);
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());

            var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);

            // second build; will get recompiled due to force unsafe flag
            buildCommand = new BuildCommand(TestProject, output: OutputDirectory, forceIncrementalUnsafe:true);
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName());

            var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);
            Assert.NotEqual(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);
        }
Ejemplo n.º 26
0
        public void TestDotnetCompileNativeCppIncremental()
        {
            if (IsCentOS())
            {
                Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453");
                return;
            }

            var nativeOut = Path.Combine(OutputDirectory, "native");

            // first build
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true);
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(nativeOut, buildCommand.GetOutputExecutableName());

            var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);

            // second build; should be skipped because nothing changed
            buildCommand.Execute().Should().Pass();
            TestOutputExecutable(nativeOut, buildCommand.GetOutputExecutableName());

            var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(OutputDirectory);
            Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild);
        }
Ejemplo n.º 27
0
        public void TestDotnetBuildNativeCpp()
        {
            if(IsCentOS())
            {
                Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453");
                return;
            }

            if (IsWinX86())
            {
                Console.WriteLine("Skipping native compilation tests on Windows x86 - https://github.com/dotnet/cli/issues/1550");
                return;
            }

            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true, framework: DefaultFramework);

            buildCommand.Execute().Should().Pass();

            TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);
        }
Ejemplo n.º 28
0
        public void PublishesWhenPrebuildWithBuildBasePath()
        {
            TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary")
                                                     .WithLockFiles();

            string basePath = Path.Combine(instance.TestRoot, "build");
            string testProject = _getProjectJson(instance.TestRoot, "TestApp");
            var buildCommand = new BuildCommand(testProject, buildBasePath: basePath);
            buildCommand.Execute().Should().Pass();

            var publishCommand = new PublishCommand(testProject, buildBasePath: basePath, noBuild: true);
            publishCommand.Execute().Should().Pass();
        }
Ejemplo n.º 29
0
        public void TestDotnetCompileNativeCppIncremental()
        {
            if (IsCentOS())
            {
                Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453");
                return;
            }

            if (IsWinX86())
            {
                Console.WriteLine("Skipping native compilation tests on Windows x86 - https://github.com/dotnet/cli/issues/1550");
                return;
            }

            // first build
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true, framework: DefaultFramework);
            var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false);

            buildCommand.Execute().Should().Pass();

            TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);

            var latestWriteTimeUtcFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);

            // second build; should be skipped because nothing changed
            buildCommand.Execute().Should().Pass();

            TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);

            var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
            Assert.Equal(latestWriteTimeUtcFirstBuild, latestWriteTimeUtcSecondBuild);
        }
Ejemplo n.º 30
0
        public void TestDotnetCompileNativeCppIncremental()
        {
            if (!IsNativeCompilationSupported())
            {
                return;
            }

            // first build
            var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true, framework: NetCoreAppTfm);
            var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false);

            buildCommand.Execute().Should().Pass();

            TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);

            var latestWriteTimeUtcFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);

            // second build; should be skipped because nothing changed
            buildCommand.Execute().Should().Pass();

            TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput);

            var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory);
            Assert.Equal(latestWriteTimeUtcFirstBuild, latestWriteTimeUtcSecondBuild);
        }