public void WriteProjectInfo_AnalysisFileList_HasFiles() { // The analysis file list should be created with the expected files // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "content.X.proj.txt"); ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Files we expect to be included string file1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Content, "false"); string file2 = AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, "FALSE"); string file3 = AddFileToProject(projectRoot, TargetProperties.ItemType_Content, null); // no metadata // Files we don't expect to be included AddFileToProject(projectRoot, TargetProperties.ItemType_Content, "true"); AddFileToProject(projectRoot, TargetProperties.ItemType_Content, "TRUE"); AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, "true"); AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, "TRUE"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder); // Assert AssertResultFileExists(projectInfo, AnalysisType.FilesToAnalyze, file1, file2, file3); }
public void WriteProjectInfo_AnalysisFileList_AutoGenFilesIgnored() { // The content file list should not include items with <AutoGen>true</AutoGen> metadata // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "agC.proj.txt"); ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Files we don't expect to be included AddFileToProject(projectRoot, TargetProperties.ItemType_Content, null, "TRUE"); // only AutoGen, set to true AddFileToProject(projectRoot, TargetProperties.ItemType_Content, "false", "truE"); // exclude=false, autogen=true AddFileToProject(projectRoot, TargetProperties.ItemType_Content, "true", "false"); // exclude=true, autogen=false // Files we expect to be included string content1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Content, null, null); // no metadata string compile1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, null, null); // no metadata string autogenContentFalseAndIncluded = AddFileToProject(projectRoot, TargetProperties.ItemType_Content, "false", "FALSe"); // exclude=false, autogen=false string autogenCompileFalseAndIncluded = AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, "false", "faLSE"); // exclude=false, autogen=false // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder); // Assert AssertResultFileExists(projectInfo, AnalysisType.FilesToAnalyze, compile1, content1, autogenContentFalseAndIncluded, autogenCompileFalseAndIncluded); }
public void WriteProjectInfo_AnalysisFileList_FilesTypes_OnlySpecified() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "fileTypes.proj.txt"); ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Files we don't expect to be included by default string fooType1 = AddFileToProject(projectRoot, "fooType", sonarQubeExclude: null); string xxxType1 = AddFileToProject(projectRoot, "xxxType", sonarQubeExclude: null); AddFileToProject(projectRoot, "barType", sonarQubeExclude: null); // Files we'd normally expect to be included by default AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, sonarQubeExclude: null); AddFileToProject(projectRoot, TargetProperties.ItemType_Content, sonarQubeExclude: null); projectRoot.AddProperty("SQAnalysisFileItemTypes", "fooType;xxxType"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder); // Assert AssertResultFileExists(projectInfo, AnalysisType.FilesToAnalyze, fooType1, xxxType1); }
public void WriteProjectInfo_AnalysisFileList_FilesTypes_Defaults() { // Check that all default item types are included for analysis // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "fileTypes.proj.txt"); ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Files we don't expect to be included by default AddFileToProject(projectRoot, "fooType"); AddFileToProject(projectRoot, "barType"); // Files we expect to be included by default string managed1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, sonarQubeExclude: null); string content1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Content, sonarQubeExclude: null); string embedded1 = AddFileToProject(projectRoot, "EmbeddedResource", sonarQubeExclude: null); string none1 = AddFileToProject(projectRoot, "None", sonarQubeExclude: null); string nativeCompile1 = AddFileToProject(projectRoot, "ClCompile", sonarQubeExclude: null); string page1 = AddFileToProject(projectRoot, "Page", sonarQubeExclude: null); string typeScript1 = AddFileToProject(projectRoot, "TypeScriptCompile", sonarQubeExclude: null); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder); // Assert AssertResultFileExists(projectInfo, AnalysisType.FilesToAnalyze, managed1, content1, embedded1, none1, nativeCompile1, page1, typeScript1); projectRoot.AddProperty("SQAnalysisFileItemTypes", "$(SQAnalysisFileItemTypes);fooType;barType;"); }
public void WriteProjectInfo_AnalysisFileList_FilesTypes_SpecifiedPlusDefaults() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "fileTypes.proj.txt"); ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Files we don't expect to be included by default string fooType1 = AddFileToProject(projectRoot, "fooType", sonarQubeExclude: null); string xxxType1 = AddFileToProject(projectRoot, "xxxType", sonarQubeExclude: null); AddFileToProject(projectRoot, "barType", sonarQubeExclude: null); // Files we'd normally expect to be included by default string managed1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Compile, sonarQubeExclude: null); string content1 = AddFileToProject(projectRoot, TargetProperties.ItemType_Content, sonarQubeExclude: null); // Update the "item types" property to add some extra item type // NB this has to be done *after* the integration targets have been imported ProjectPropertyGroupElement group = projectRoot.CreatePropertyGroupElement(); projectRoot.AppendChild(group); group.AddProperty("SQAnalysisFileItemTypes", "fooType;$(SQAnalysisFileItemTypes);xxxType"); projectRoot.Save(); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder); // Assert AssertResultFileExists(projectInfo, AnalysisType.FilesToAnalyze, fooType1, xxxType1, content1, managed1); }
[TestCategory("E2E"), TestCategory("Targets")] // SONARMSBRU-12: Analysis build fails if the build definition name contains brackets public void E2E_UsingTaskHandlesBracketsInName() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "folder with brackets in name (SONARMSBRU-12)"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); AddEmptyAnalysedCodeFile(descriptor, rootInputFolder); // Copy the task assembly to a folder with brackets in the name string taskAssemblyFilePath = typeof(WriteProjectInfoFile).Assembly.Location; string asmName = Path.GetFileName(taskAssemblyFilePath); string copiedTaskAssemblyFilePath = Path.Combine(rootInputFolder, Path.GetFileName(asmName)); File.Copy(taskAssemblyFilePath, copiedTaskAssemblyFilePath); // Set the project property to use that file. To reproduce the bug, we need to have MSBuild search for // the assembly using "GetDirectoryNameOfFileAbove". string val = @"$([MSBuild]::GetDirectoryNameOfFileAbove('{0}', '{1}'))\{1}"; val = string.Format(System.Globalization.CultureInfo.InvariantCulture, val, rootInputFolder, asmName); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.Add(TargetProperties.SonarBuildTasksAssemblyFile, val); // Act string projectDir = CreateAndBuildSonarProject(descriptor, rootOutputFolder, preImportProperties); AssertFileExists(projectDir, ExpectedAnalysisFilesListFileName); CheckProjectOutputFolder(descriptor, projectDir); }
public void E2E_HasManagedAndContentFiles_VB() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); descriptor.ProjectLanguage = ProjectLanguages.VisualBasic; AddEmptyAnalysedCodeFile(descriptor, rootInputFolder, ".vb"); AddEmptyAnalysedCodeFile(descriptor, rootInputFolder, ".vb"); AddEmptyContentFile(descriptor, rootInputFolder); AddEmptyContentFile(descriptor, rootInputFolder); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); // Act string projectDir = CreateAndBuildSonarProject(descriptor, rootOutputFolder, preImportProperties); AssertFileExists(projectDir, ExpectedAnalysisFilesListFileName); CheckProjectOutputFolder(descriptor, projectDir); }
public void WriteProjectInfo_AnalysisSettings() { // Check analysis settings are correctly passed from the targets to the task // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "content.proj.txt"); ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Invalid items AddItem(projectRoot, "UnrelatedItemType", "irrelevantItem"); // should be ignored AddItem(projectRoot, TargetProperties.ItemType_Compile, "IrrelevantFile.cs"); // should be ignored AddItem(projectRoot, BuildTaskConstants.SettingItemName, "invalid.settings.no.value.metadata"); // invalid -> ignored // Module-level settings AddItem(projectRoot, BuildTaskConstants.SettingItemName, "valid.setting1", BuildTaskConstants.SettingValueMetadataName, "value1"); AddItem(projectRoot, BuildTaskConstants.SettingItemName, "valid.setting2...", BuildTaskConstants.SettingValueMetadataName, "value 2 with spaces"); AddItem(projectRoot, BuildTaskConstants.SettingItemName, "valid.path", BuildTaskConstants.SettingValueMetadataName, @"d:\aaa\bbb.txt"); AddItem(projectRoot, BuildTaskConstants.SettingItemName, "common.setting.name", BuildTaskConstants.SettingValueMetadataName, @"local value"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder, noWarningOrErrors: false /* expecting warnings */); // Assert AssertSettingExists(projectInfo, "valid.setting1", "value1"); AssertSettingExists(projectInfo, "valid.setting2...", "value 2 with spaces"); AssertSettingExists(projectInfo, "valid.path", @"d:\aaa\bbb.txt"); AssertSettingExists(projectInfo, "common.setting.name", "local value"); // Additional settings might be added by other targets so we won't check the total number of settings }
public void WriteProjectInfo_FakesProjects_ExplicitSonarTestPropertyIsIgnored() { // Checks that fakes projects are recognised and marked as test // projects, irrespective of whether the SonarQubeTestProject is // already set. // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); EnsureAnalysisConfig(rootInputFolder, "pattern that won't match anything"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.SonarTestProject = "false"; preImportProperties.AssemblyName = "MyFakeProject.fakes"; ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "f.proj"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsTestProject(projectInfo); AssertProjectIsExcluded(projectInfo); }
[TestCategory("E2E"), TestCategory("Targets")] // SONARMSBRU-104: files under the obj folder should be excluded from analysis public void E2E_IntermediateOutputFilesAreExcluded() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); // Create a new project ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); string projectFolder = descriptor.FullDirectoryPath; // Add files that should be analysed string nonObjFolder = Path.Combine(projectFolder, "foo"); Directory.CreateDirectory(nonObjFolder); AddEmptyAnalysedCodeFile(descriptor, rootInputFolder); AddEmptyAnalysedCodeFile(descriptor, nonObjFolder); // Add files under the obj folder that should not be analysed string objFolder = Path.Combine(projectFolder, "obj"); string objSubFolder1 = Path.Combine(objFolder, "debug"); string objSubFolder2 = Path.Combine(objFolder, "xxx"); // any folder under obj should be ignored Directory.CreateDirectory(objSubFolder1); Directory.CreateDirectory(objSubFolder2); // File in obj string filePath = CreateEmptyFile(objFolder, "cs"); descriptor.AddCompileInputFile(filePath, false); // File in obj\debug filePath = CreateEmptyFile(objSubFolder1, "cs"); descriptor.AddCompileInputFile(filePath, false); // File in obj\xxx filePath = CreateEmptyFile(objSubFolder2, "vb"); descriptor.AddCompileInputFile("obj\\xxx\\" + Path.GetFileName(filePath), false); // reference the file using a relative path WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); // Act string projectDir = CreateAndBuildSonarProject(descriptor, rootOutputFolder, preImportProperties); AssertFileExists(projectDir, ExpectedAnalysisFilesListFileName); CheckProjectOutputFolder(descriptor, projectDir); }
public void WriteProjectInfo_ProjectWithNoCodePage() { // Arrange var rootInputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Inputs"); var rootOutputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Outputs"); var descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); descriptor.Encoding = null; var projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Act var projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder, noWarningOrErrors: false /* expecting warnings */); // Assert projectInfo.Encoding.Should().BeNull(); }
public void WriteProjectInfo_ProjectWithNoCodePage() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); descriptor.Encoding = null; ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder, noWarningOrErrors: false /* expecting warnings */); // Assert Assert.AreEqual(null, projectInfo.Encoding); }
public void WriteProjectInfo_AnalysisFileList_NoFiles() { // The content file list should not be created if there are no files // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "content.proj.txt"); ProjectRootElement projectRoot = CreateInitializedProject(descriptor, new WellKnownProjectProperties(), rootOutputFolder); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(projectRoot, rootOutputFolder); // Assert AssertResultFileDoesNotExist(projectInfo, AnalysisType.FilesToAnalyze); }
public void WriteProjectInfo_SqlServerProjectsAreNotExcluded() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties["SqlTargetName"] = "non-empty"; ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertProjectIsNotExcluded(projectInfo); }
public void E2E_NoContentOrManagedFiles() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); // Act string projectDir = CreateAndBuildSonarProject(descriptor, rootOutputFolder, preImportProperties); AssertFileDoesNotExist(projectDir, ExpectedAnalysisFilesListFileName); // Specify the expected analysis results CheckProjectOutputFolder(descriptor, projectDir); }
public void WriteProjectInfo_WpfTmpCases_ProjectIsExcluded() { // Used by inner method as a way to change directory name int counter = 0; WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("f.tmp_proj", expectedExclusionState: true); WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("f.TMP_PROJ", expectedExclusionState: true); WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("f_wpftmp.csproj", expectedExclusionState: true); WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("f_WpFtMp.csproj", expectedExclusionState: true); WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("f_wpftmp.vbproj", expectedExclusionState: true); WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("WpfApplication.csproj", expectedExclusionState: false); WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("ftmp_proj.csproj", expectedExclusionState: false); WriteProjectInfo_WpfTmpCase_ProjectIsExcluded("wpftmp.csproj", expectedExclusionState: false); void WriteProjectInfo_WpfTmpCase_ProjectIsExcluded(string projectName, bool expectedExclusionState) { // Arrange var rootInputFolder = TestUtils.CreateTestSpecificFolder(TestContext, counter.ToString(), "Inputs"); var rootOutputFolder = TestUtils.CreateTestSpecificFolder(TestContext, counter.ToString(), "Outputs"); counter++; EnsureAnalysisConfig(rootInputFolder, "pattern that won't match anything"); var preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); var descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, projectName); // Act var projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsNotTestProject(projectInfo); if (expectedExclusionState) { AssertProjectIsExcluded(projectInfo); } else { AssertProjectIsNotExcluded(projectInfo); } } }
public void WriteProjectInfo_TestProject_WildcardMatch_Default_NoMatch() { // Check the default wildcard matching // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "foo.proj"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsProductProject(projectInfo); AssertProjectIsNotExcluded(projectInfo); }
public void E2E_OutputFolderStructure() { // Checks the output folder structure is correct for a simple solution // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); AddEmptyCodeFile(descriptor, rootInputFolder); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); // Act string projectSpecificOutputDir = CreateAndBuildSonarProject(descriptor, rootOutputFolder, preImportProperties); // Assert CheckProjectOutputFolder(descriptor, projectSpecificOutputDir); }
public void E2E_ExcludedProjects() { // Project info should still be written for files with $(SonarQubeExclude) set to true // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); descriptor.IsExcluded = true; WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.SonarQubeExclude = "tRUe"; // Act string projectDir = CreateAndBuildSonarProject(descriptor, rootOutputFolder, preImportProperties); CheckProjectOutputFolder(descriptor, projectDir); }
public void E2E_NoContentFiles() { // Arrange var rootInputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Inputs"); var rootOutputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Outputs"); var descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder); AddEmptyAnalysedCodeFile(descriptor, rootInputFolder); AddEmptyAnalysedCodeFile(descriptor, rootInputFolder); AddEmptyAnalysedCodeFile(descriptor, rootInputFolder); var preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); // Act var projectDir = CreateAndBuildSonarProject(descriptor, rootOutputFolder, preImportProperties); AssertFileExists(projectDir, ExpectedAnalysisFilesListFileName); CheckProjectOutputFolder(descriptor, projectDir); }
public void WriteProjectInfo_TestProject_WildcardMatch_UserSpecified_Match() { // Check user-specified wildcard matching // Arrange var rootInputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Inputs"); var rootOutputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Outputs"); EnsureAnalysisConfig(rootInputFolder, ".*foo.*"); var preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); var descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "fOO.proj"); // Act var projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsTestProject(projectInfo); AssertProjectIsNotExcluded(projectInfo); }
public void WriteProjectInfo_TestProject_WildcardMatch_UserSpecified_NoMatch() { // Check user-specified wildcard matching // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); EnsureAnalysisConfig(rootInputFolder, ".*foo.*"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); // Use project name that will be recognised as a test by the default regex ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "TestafoXB.proj"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsProductProject(projectInfo); AssertProjectIsNotExcluded(projectInfo); }
[TestCategory("ProjectInfo")] // SONARMSBRU-26: MS Fakes should be excluded from analysis public void WriteProjectInfo_FakesProjectsAreExcluded() { // Checks that fakes projects are excluded from analysis // Arrange var rootInputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Inputs"); var rootOutputFolder = TestUtils.CreateTestSpecificFolder(TestContext, "Outputs"); EnsureAnalysisConfig(rootInputFolder, "pattern that won't match anything"); var preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.AssemblyName = "f.fAKes"; var descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "f.proj"); // Act var projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsTestProject(projectInfo); AssertProjectIsExcluded(projectInfo); }
public void WriteProjectInfo_TestProject_HasTestGuid_LowerCase() { // Checks the MSTest project type guid is recognised // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); EnsureAnalysisConfig(rootInputFolder, "pattern that won't match anything"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.ProjectTypeGuids = "X" + TargetConstants.MsTestProjectTypeGuid.ToLowerInvariant() + "Y"; ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "a.b"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsTestProject(projectInfo); AssertProjectIsNotExcluded(projectInfo); }
public void WriteProjectInfo_FakesProjects_FakesInName() { // Checks that projects with ".fakes" in the name are not excluded // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); EnsureAnalysisConfig(rootInputFolder, "pattern that won't match anything"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.AssemblyName = "f.fakes.proj"; ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "f.proj"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsProductProject(projectInfo); AssertProjectIsNotExcluded(projectInfo); }
public void WriteProjectInfo_TestProject_ExplicitMarking_False() { // If the project is explicitly marked as not a test then the other condition should be ignored // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); EnsureAnalysisConfig(rootInputFolder, "*.*"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.SonarTestProject = "false"; preImportProperties.ProjectTypeGuids = "X;" + TargetConstants.MsTestProjectTypeGuid.ToUpperInvariant() + ";Y"; ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "foo.proj"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsProductProject(projectInfo); AssertProjectIsNotExcluded(projectInfo); }
public void WriteProjectInfo_TestProject_ExplicitMarking_True() { // If the project is explicitly marked as a test then the other condition should be ignored // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); WellKnownProjectProperties preImportProperties = CreateDefaultAnalysisProperties(rootInputFolder, rootOutputFolder); preImportProperties.SonarTestProject = "true"; preImportProperties.AssemblyName = "MyTest.proj"; EnsureAnalysisConfig(rootInputFolder, "pattern that won't match anything"); ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "test.proj"); // Act ProjectInfo projectInfo = ExecuteWriteProjectInfo(descriptor, preImportProperties, rootOutputFolder); // Assert AssertIsTestProject(projectInfo); AssertProjectIsNotExcluded(projectInfo); }
public void E2E_FxCop_TestProject_TestProjectByName() { // Arrange string rootInputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Inputs"); string rootOutputFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "Outputs"); string fxCopLogFile = Path.Combine(rootInputFolder, "FxCopResults.xml"); WellKnownProjectProperties preImportProperties = new WellKnownProjectProperties(); preImportProperties.SonarQubeTempPath = rootOutputFolder; // FIXME preImportProperties.SonarQubeOutputPath = rootOutputFolder; preImportProperties.CodeAnalysisLogFile = fxCopLogFile; preImportProperties.CodeAnalysisRuleset = "specifiedInProject.ruleset"; preImportProperties.SonarQubeConfigPath = rootInputFolder; preImportProperties[TargetProperties.SonarQubeConfigPath] = rootInputFolder; CreateValidFxCopRuleset(rootInputFolder, string.Format(TargetProperties.SonarQubeRulesetFormat, "cs")); // Create a config file in the config folder containing a reg ex to identify tests projects AnalysisConfig config = new AnalysisConfig(); config.LocalSettings = new AnalysisProperties(); config.LocalSettings.Add(new Property() { Id = IsTestFileByName.TestRegExSettingId, Value = ".testp." }); string configFullPath = Path.Combine(rootInputFolder, FileConstants.ConfigFileName); config.Save(configFullPath); // Create a project with a file name that will match the reg ex ProjectDescriptor descriptor = BuildUtilities.CreateValidProjectDescriptor(rootInputFolder, "MyTestProject.proj"); ProjectRootElement projectRoot = BuildUtilities.CreateInitializedProjectRoot(this.TestContext, descriptor, preImportProperties); // Add a file to the project string itemPath = CreateTextFile(rootInputFolder, "code1.cs", "class myclassXXX{}"); projectRoot.AddItem(TargetProperties.ItemType_Compile, itemPath); projectRoot.Save(); BuildLogger logger = new BuildLogger(); // Act BuildResult result = BuildUtilities.BuildTargets(projectRoot, logger); // Assert BuildAssertions.AssertTargetSucceeded(result, TargetConstants.DefaultBuildTarget); logger.AssertExpectedTargetOrdering( TargetConstants.CategoriseProjectTarget, TargetConstants.OverrideFxCopSettingsTarget, TargetConstants.FxCopTarget, TargetConstants.DefaultBuildTarget, TargetConstants.CalculateFilesToAnalyzeTarget, TargetConstants.WriteProjectDataTarget); // We expect the FxCop target to be executed... logger.AssertTargetExecuted(TargetConstants.FxCopTarget); // ... but we don't expect the FxCop *task* to have executed logger.AssertTaskNotExecuted(TargetConstants.FxCopTask); logger.AssertTargetNotExecuted(TargetConstants.SetFxCopResultsTarget); ProjectInfo projectInfo = ProjectInfoAssertions.AssertProjectInfoExists(rootOutputFolder, projectRoot.FullPath); ProjectInfoAssertions.AssertAnalysisResultDoesNotExists(projectInfo, AnalysisType.FxCop.ToString()); }