Exemplo n.º 1
0
        public void Exe_PreProcFails()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();

            using (InitializeNonTeamBuildEnvironment(RootDir))
            {
                MockProcessors(false, true);

                // Act
                var logger = CheckExecutionFails(AnalysisPhase.PreProcessing, true,
                                                 null,
                                                 "/install:true", // this argument should just pass through
                                                 "/d:sonar.verbose=true",
                                                 "/d:sonar.host.url=http://host:9",
                                                 "/d:another.key=will be ignored");

                // Assert
                logger.AssertWarningsLogged(0);
                logger.AssertVerbosity(LoggerVerbosity.Debug);

                AssertPreProcessorArgs("/install:true",
                                       "/d:sonar.verbose=true",
                                       "/d:sonar.host.url=http://host:9",
                                       "/d:another.key=will be ignored");

                AssertPostProcessorNotCalled();
            }
        }
 public void Initialize()
 {
     // The project setup means the default properties file will automatically
     // be copied alongside the product binaries.st of these tests assume
     // the default properties file does not exist so we'll ensure it doesn't.
     // Any tests that do require default properties file should re-create it
     // with known content.
     BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();
 }
Exemplo n.º 3
0
        public void Exe_PreProcSucceeds()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();

            using (InitializeNonTeamBuildEnvironment(RootDir))
            {
                // Act
                var logger = CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, null, "/d:sonar.host.url=http://anotherHost");

                // Assert
                logger.AssertWarningsLogged(0);
                logger.AssertVerbosity(VerbosityCalculator.DefaultLoggingVerbosity);

                AssertPreProcessorArgs("/d:sonar.host.url=http://anotherHost");
            }
        }
Exemplo n.º 4
0
        public void CopyDlls_WhenFileExistAndAreLockedButDifferentVersion_Fails()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();

            using (InitializeNonTeamBuildEnvironment(RootDir))
            {
                Directory.CreateDirectory(Path.Combine(TempDir, "bin"));
                var file1 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll"));
                var file2 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll"));

                int callCount = 0;
                Func <string, Version> getAssemblyVersion = _ =>
                {
                    if (callCount == 0)
                    {
                        callCount++;
                        return(new Version("1.0"));
                    }

                    return(new Version("2.0"));
                };

                // Act
                var logger = CheckExecutionFails(AnalysisPhase.PreProcessing, false, getAssemblyVersion, "/d:sonar.host.url=http://anotherHost");

                // Assert
                File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Should().BeTrue();
                File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Should().BeTrue();

                logger.DebugMessages.Should().HaveCount(3);
                logger.DebugMessages[0].Should().Match(@"Cannot delete directory: '*\.sonarqube\bin' because The process cannot access the file 'SonarScanner.MSBuild.Common.dll' because it is being used by another process..");
                logger.DebugMessages[1].Should().Match(@"Cannot delete file: '*\.sonarqube\bin\SonarScanner.MSBuild.Common.dll' because The process cannot access the file '*\.sonarqube\bin\SonarScanner.MSBuild.Common.dll' because it is being used by another process..");
                logger.DebugMessages[2].Should().Match(@"Cannot delete file: '*\.sonarqube\bin\SonarScanner.MSBuild.Tasks.dll' because The process cannot access the file '*\.sonarqube\bin\SonarScanner.MSBuild.Tasks.dll' because it is being used by another process..");

                logger.AssertErrorLogged(@"Cannot copy a different version of the SonarScanner for MSBuild assemblies because they are used by a running MSBuild/.Net Core process. To resolve this problem try one of the following:
- Analyze this project using the same version of SonarScanner for MSBuild
- Build your project with the '/nr:false' switch");

                // Do not close before to ensure the file is locked
                file1.Close();
                file2.Close();
            }
        }
Exemplo n.º 5
0
        public void CopyDlls_WhenFileExistButAreNotLocked_FilesAreCopied()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();

            using (InitializeNonTeamBuildEnvironment(RootDir))
            {
                Directory.CreateDirectory(Path.Combine(TempDir, "bin"));
                File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Close();
                File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Close();

                // Act
                CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, null, "/d:sonar.host.url=http://anotherHost");

                // Assert
                File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Should().BeTrue();
                File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Should().BeTrue();
            }
        }
Exemplo n.º 6
0
        public void Exe_PreProcCleansTemp()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();

            using (InitializeNonTeamBuildEnvironment(RootDir))
            {
                // Create dummy file in Temp
                var filePath = Path.Combine(TempDir, "myfile");
                Directory.CreateDirectory(TempDir);
                var stream = File.Create(filePath);
                stream.Close();
                File.Exists(filePath).Should().BeTrue();

                // Act
                CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, null, "/d:sonar.host.url=http://anotherHost");

                // Assert
                File.Exists(filePath).Should().BeFalse();
            }
        }
Exemplo n.º 7
0
        public void CopyDlls_WhenFileExistAndAreLockedButSameVersion_DoNothing()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();

            using (InitializeNonTeamBuildEnvironment(RootDir))
            {
                Directory.CreateDirectory(Path.Combine(TempDir, "bin"));
                var file1 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll"));
                var file2 = File.Create(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll"));

                // Act
                CheckExecutionSucceeds(AnalysisPhase.PreProcessing, false, _ => new Version(), "/d:sonar.host.url=http://anotherHost");

                // Assert
                File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Common.dll")).Should().BeTrue();
                File.Exists(Path.Combine(TempDir, "bin", "SonarScanner.MSBuild.Tasks.dll")).Should().BeTrue();

                // Do not close before to ensure the file is locked
                file1.Close();
                file2.Close();
            }
        }