Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add linux CI #4444

Merged
merged 14 commits into from
Dec 17, 2020
33 changes: 33 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,36 @@ jobs:
ArtifactName: 'Windows Desktop Spanish'
continueOnError: true
condition: not(succeeded())

- job: Ubuntu
strategy:
maxParallel: 4
matrix:
Debug:
_configuration: Debug
Release:
_configuration: Release
pool:
name: NetCorePublic-Pool
queue: BuildPool.Ubuntu.1604.amd64.Open
timeoutInMinutes: 40
steps:
- checkout: self
clean: true
- script: eng/common/cibuild.sh -configuration $(_configuration) -prepareMachine
displayName: Build and Test

- task: PublishTestResults@2
inputs:
testRunner: XUnit
testResultsFiles: '$(Build.SourcesDirectory)/artifacts/TestResults/$(_configuration)/*.xml'
mergeTestResults: true
testRunTitle: 'Windows $(_configuration)'
condition: always()
- task: PublishBuildArtifacts@1
displayName: Publish Logs
inputs:
PathtoPublish: '$(Build.SourcesDirectory)/artifacts/log/$(_configuration)'
ArtifactName: 'Windows $(_configuration)'
continueOnError: true
condition: always()
7 changes: 6 additions & 1 deletion eng/GenerateAnalyzerNuspec.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<EscapeDirectorySuffix Condition="'$(OS)' == 'Windows_NT'">\</EscapeDirectorySuffix>
</PropertyGroup>

<!-- Config validation tooling does not work on linux -->
<PropertyGroup Condition="'$(OS)' == 'Windows_NT' And '$(ContinuousIntegrationBuild)' == 'true'">
<ValidateConfigFiles>true</ValidateConfigFiles>
</PropertyGroup>

<Target Name="GenerateAnalyzerConfigAndDocumentationFiles"
DependsOnTargets="InitializeSourceControlInformation"
Condition="'@(AnalyzerNupkgAssembly)' != '' or '@(AnalyzerRulesetAssembly)' != ''">
Expand Down Expand Up @@ -97,7 +102,7 @@
</ItemGroup>

<!-- Only run validate only in CI builds. Running them in local builds will prevent refreshing auto-generated files. -->
<Exec Condition="'$(ContinuousIntegrationBuild)' == 'true'"
<Exec Condition="'$(ValidateConfigFiles)' == 'true'"
Command='"$(DotNetExecutable)" "$(_GenerateDocumentationAndConfigFilesPath)" "-validateOnly:true" "$(_GeneratedRulesetsDir)" "$(_GeneratedEditorconfigsDir)" "$(_GeneratedGlobalAnalyzerConfigsDir)" "$(ArtifactsBinDir)$(EscapeDirectorySuffix)" "$(Configuration)" "%(AnalyzerRulesetAssembly.TargetFramework)" "@(AnalyzerRulesetAssembly)" "$(PackagePropsFileDir)" "$(PackagePropsFileName)" "$(PackageTargetsFileDir)" "$(PackageTargetsFileName)" "$(DisableNETAnalyzersPackagePropsFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerDocumentationFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerSarifFileName)" "$(VersionPrefix)" $(NuspecPackageId) $(ContainsPortedFxCopRules) $(GenerateAnalyzerRulesMissingDocumentationFile) "$(ReleaseTrackingOptOut)"' />

<Exec Command='"$(DotNetExecutable)" "$(_GenerateDocumentationAndConfigFilesPath)" "-validateOnly:false" "$(_GeneratedRulesetsDir)" "$(_GeneratedEditorconfigsDir)" "$(_GeneratedGlobalAnalyzerConfigsDir)" "$(ArtifactsBinDir)$(EscapeDirectorySuffix)" "$(Configuration)" "%(AnalyzerRulesetAssembly.TargetFramework)" "@(AnalyzerRulesetAssembly)" "$(PackagePropsFileDir)" "$(PackagePropsFileName)" "$(PackageTargetsFileDir)" "$(PackageTargetsFileName)" "$(DisableNETAnalyzersPackagePropsFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerDocumentationFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerSarifFileName)" "$(VersionPrefix)" $(NuspecPackageId) $(ContainsPortedFxCopRules) $(GenerateAnalyzerRulesMissingDocumentationFile) "$(ReleaseTrackingOptOut)"' />
Expand Down
16 changes: 16 additions & 0 deletions restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

source="${BASH_SOURCE[0]}"

# resolve $SOURCE until the file is no longer a symlink
while [[ -h $source ]]; do
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
source="$(readlink "$source")"

# if $source was a relative symlink, we need to resolve it relative to the path where the
# symlink file was located
[[ $source != /* ]] && source="$scriptroot/$source"
done

scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
"$scriptroot/eng/common/build.sh" --restore $@
Original file line number Diff line number Diff line change
Expand Up @@ -4273,7 +4273,7 @@ End Class
GetRS1007ExpectedDiagnostic(2));
}

[Fact, WorkItem(3958, "https://github.com/dotnet/roslyn-analyzers/issues/3958")]
[WindowsOnlyFact, WorkItem(3958, "https://github.com/dotnet/roslyn-analyzers/issues/3958")]
public async Task RS1033_LeadingOrTrailingWhitespaces_Diagnostic()
{
var additionalFileName = "Resources.resx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void Initialize(AnalysisContext context) {{ }}
await VerifyCSharpAsync(source, shippedText, unshippedText);
}

[Fact]
[WindowsOnlyFact]
public async Task TestCodeFixToEnableAnalyzerReleaseTracking()
{
var source = @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public async Task TestConflictingAnalyzerOptionsForPartials(bool hasConflict)

if (!hasConflict)
{
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic().WithSpan(@"z:\folder1\Test0.cs", 1, 26, 1, 27).WithSpan(@"z:\folder2\Test1.cs", 1, 26, 1, 27));
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic().WithSpan(@"/folder1/Test0.cs", 1, 26, 1, 27).WithSpan(@"/folder2\Test1.cs", 1, 26, 1, 27));
}

await csTest.RunAsync();
Expand All @@ -310,7 +310,7 @@ End Interface"

if (!hasConflict)
{
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic().WithSpan(@"z:\folder1\Test0.vb", 2, 26, 2, 27).WithSpan(@"z:\folder2\Test1.vb", 2, 26, 2, 27));
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic().WithSpan(@"/folder1/Test0.vb", 2, 26, 2, 27).WithSpan(@"/folder2/Test1.vb", 2, 26, 2, 27));
}

await vbTest.RunAsync();
Expand All @@ -319,15 +319,15 @@ End Interface"
Solution ApplyTransform(Solution solution, ProjectId projectId)
{
var project = solution.GetProject(projectId)!;
var projectFilePath = project.Language == LanguageNames.CSharp ? @"z:\Test.csproj" : @"z:\Test.vbproj";
var projectFilePath = project.Language == LanguageNames.CSharp ? @"/Test.csproj" : @"/Test.vbproj";
solution = solution.WithProjectFilePath(projectId, projectFilePath);

var documentExtension = project.Language == LanguageNames.CSharp ? "cs" : "vb";
var document1EditorConfig = $"[*.{documentExtension}]" + Environment.NewLine + "dotnet_code_quality.api_surface = public";
var document2OptionValue = hasConflict ? "internal" : "public";
var document2EditorConfig = $"[*.{documentExtension}]" + Environment.NewLine + $"dotnet_code_quality.api_surface = {document2OptionValue}";

var document1Folder = $@"z:\folder1";
var document1Folder = $@"/folder1";
solution = solution.WithDocumentFilePath(project.DocumentIds[0], $@"{document1Folder}\Test0.{documentExtension}");
solution = solution.GetProject(projectId)!
.AddAnalyzerConfigDocument(
Expand All @@ -336,7 +336,7 @@ Solution ApplyTransform(Solution solution, ProjectId projectId)
filePath: $@"{document1Folder}\.editorconfig")
.Project.Solution;

var document2Folder = $@"z:\folder2";
var document2Folder = $@"/folder2";
solution = solution.WithDocumentFilePath(project.DocumentIds[1], $@"{document2Folder}\Test1.{documentExtension}");
return solution.GetProject(projectId)!
.AddAnalyzerConfigDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public async Task TestConflictingAnalyzerOptionsForPartials(string editorConfigT

if (expectDiagnostic)
{
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic(IdentifiersShouldNotMatchKeywordsAnalyzer.TypeRule).WithSpan(@"z:\folder1\Test0.cs", 1, 22, 1, 28).WithSpan(@"z:\folder2\Test1.cs", 1, 22, 1, 28).WithArguments("class", "class"));
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic(IdentifiersShouldNotMatchKeywordsAnalyzer.TypeRule).WithSpan(@"/folder1/Test0.cs", 1, 22, 1, 28).WithSpan(@"/folder2/Test1.cs", 1, 22, 1, 28).WithArguments("class", "class"));
}

await csTest.RunAsync();
Expand All @@ -280,7 +280,7 @@ End Class"

if (expectDiagnostic)
{
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic(IdentifiersShouldNotMatchKeywordsAnalyzer.TypeRule).WithSpan(@"z:\folder1\Test0.vb", 2, 22, 2, 29).WithSpan(@"z:\folder2\Test1.vb", 2, 22, 2, 29).WithArguments("Class", "Class"));
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic(IdentifiersShouldNotMatchKeywordsAnalyzer.TypeRule).WithSpan(@"/folder1\Test0.vb", 2, 22, 2, 29).WithSpan(@"/folder2\Test1.vb", 2, 22, 2, 29).WithArguments("Class", "Class"));
}

await vbTest.RunAsync();
Expand All @@ -289,14 +289,14 @@ End Class"
Solution ApplyTransform(Solution solution, ProjectId projectId)
{
var project = solution.GetProject(projectId)!;
var projectFilePath = project.Language == LanguageNames.CSharp ? @"z:\Test.csproj" : @"z:\Test.vbproj";
var projectFilePath = project.Language == LanguageNames.CSharp ? @"/Test.csproj" : @"/Test.vbproj";
solution = solution.WithProjectFilePath(projectId, projectFilePath);

var documentExtension = project.Language == LanguageNames.CSharp ? "cs" : "vb";
var document1EditorConfig = $"[*.{documentExtension}]" + Environment.NewLine + editorConfigText1;
var document2EditorConfig = $"[*.{documentExtension}]" + Environment.NewLine + editorConfigText2;

var document1Folder = $@"z:\folder1";
var document1Folder = $@"/folder1";
solution = solution.WithDocumentFilePath(project.DocumentIds[0], $@"{document1Folder}\Test0.{documentExtension}");
solution = solution.GetProject(projectId)!
.AddAnalyzerConfigDocument(
Expand All @@ -305,7 +305,7 @@ Solution ApplyTransform(Solution solution, ProjectId projectId)
filePath: $@"{document1Folder}\.editorconfig")
.Project.Solution;

var document2Folder = $@"z:\folder2";
var document2Folder = $@"/folder2";
solution = solution.WithDocumentFilePath(project.DocumentIds[1], $@"{document2Folder}\Test1.{documentExtension}");
return solution.GetProject(projectId)!
.AddAnalyzerConfigDocument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ public class C

if (expectDiagnostic)
{
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic().WithSpan(@"z:\Test0.cs", 4, 23, 4, 29).WithArguments("unused", "M"));
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic().WithSpan(@"/Test0.cs", 4, 23, 4, 29).WithArguments("unused", "M"));
}

await csTest.RunAsync();
Expand All @@ -945,7 +945,7 @@ End Class"

if (expectDiagnostic)
{
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic().WithSpan(@"z:\Test0.vb", 3, 18, 3, 24).WithArguments("unused", "M"));
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic().WithSpan(@"/Test0.vb", 3, 18, 3, 24).WithArguments("unused", "M"));
}

await vbTest.RunAsync();
Expand All @@ -954,18 +954,18 @@ End Class"
Solution WithAnalyzerConfigDocument(Solution solution, ProjectId projectId)
{
var project = solution.GetProject(projectId)!;
var projectFilePath = project.Language == LanguageNames.CSharp ? @"z:\Test.csproj" : @"z:\Test.vbproj";
var projectFilePath = project.Language == LanguageNames.CSharp ? @"/Test.csproj" : @"/Test.vbproj";
solution = solution.WithProjectFilePath(projectId, projectFilePath);

var documentId = project.DocumentIds.Single();
var documentExtension = project.Language == LanguageNames.CSharp ? "cs" : "vb";
solution = solution.WithDocumentFilePath(documentId, $@"z:\Test0.{documentExtension}");
solution = solution.WithDocumentFilePath(documentId, $@"/Test0.{documentExtension}");

return solution.GetProject(projectId)!
.AddAnalyzerConfigDocument(
".editorconfig",
SourceText.From($"[*.{documentExtension}]" + Environment.NewLine + editorConfigText),
filePath: @"z:\.editorconfig")
filePath: @"/.editorconfig")
.Project.Solution;
}
}
Expand Down Expand Up @@ -1009,7 +1009,7 @@ public class C

if (expectDiagnostic)
{
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic().WithSpan(@"z:\Test0.cs", 4, 23, 4, 29).WithArguments("unused", "M"));
csTest.ExpectedDiagnostics.Add(VerifyCS.Diagnostic().WithSpan(@"/Test0.cs", 4, 23, 4, 29).WithArguments("unused", "M"));
}

await csTest.RunAsync();
Expand All @@ -1033,7 +1033,7 @@ End Class"

if (expectDiagnostic)
{
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic().WithSpan(@"z:\Test0.vb", 3, 18, 3, 24).WithArguments("unused", "M"));
vbTest.ExpectedDiagnostics.Add(VerifyVB.Diagnostic().WithSpan(@"/Test0.vb", 3, 18, 3, 24).WithArguments("unused", "M"));
}

await vbTest.RunAsync();
Expand All @@ -1042,18 +1042,18 @@ End Class"
Solution WithAnalyzerConfigDocument(Solution solution, ProjectId projectId)
{
var project = solution.GetProject(projectId)!;
var projectFilePath = project.Language == LanguageNames.CSharp ? @"z:\Test.csproj" : @"z:\Test.vbproj";
var projectFilePath = project.Language == LanguageNames.CSharp ? @"/Test.csproj" : @"/Test.vbproj";
solution = solution.WithProjectFilePath(projectId, projectFilePath);

var documentId = project.DocumentIds.Single();
var documentExtension = project.Language == LanguageNames.CSharp ? "cs" : "vb";
solution = solution.WithDocumentFilePath(documentId, $@"z:\Test0.{documentExtension}");
solution = solution.WithDocumentFilePath(documentId, $@"/Test0.{documentExtension}");

return solution.GetProject(projectId)!
.AddAnalyzerConfigDocument(
".editorconfig",
SourceText.From($"[*.{documentExtension}]" + Environment.NewLine + editorConfigText),
filePath: @"z:\.editorconfig")
filePath: @"/.editorconfig")
.Project.Solution;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ End Class
");
}

[Fact]
[WindowsOnlyFact]
public async Task ParameterWithLocalizableAttribute_MultipleLineStringLiteralArgument_Method_Diagnostic()
{
await VerifyCS.VerifyAnalyzerAsync(@"
Expand All @@ -200,11 +200,11 @@ public class Test
{
public void M1(C c)
{
var str = ""a\na"";
var str = ""a\r\na"";
c.M(str);
}
}
",
".NormalizeLineEndings(),
// Test0.cs(16,13): warning CA1303: Method 'void Test.M1(C c)' passes a literal string as parameter 'param' of a call to 'void C.M(string param)'. Retrieve the following string(s) from a resource table instead: "a a".
GetCSharpResultAt(16, 13, "void Test.M1(C c)", "param", "void C.M(string param)", "a a"));

Expand All @@ -223,7 +223,7 @@ Public Sub M1(c As C)
c.M(str)
End Sub
End Class
",
".NormalizeLineEndings(),
// Test0.vb(13,13): warning CA1303: Method 'Sub Test.M1(c As C)' passes a literal string as parameter 'param' of a call to 'Sub C.M(param As String)'. Retrieve the following string(s) from a resource table instead: "a a".
GetBasicResultAt(13, 13, "Sub Test.M1(c As C)", "param", "Sub C.M(param As String)", "a a"));
}
Expand Down Expand Up @@ -1793,7 +1793,7 @@ public void M1()
await csharpTest.RunAsync();
}

[Theory]
[WindowsOnlyTheory]
[InlineData(null)]
[InlineData(PointsToAnalysisKind.None)]
[InlineData(PointsToAnalysisKind.PartialWithoutTrackingFieldsAndProperties)]
Expand All @@ -1819,11 +1819,11 @@ public class Test
private string str;
public void M1(C c)
{
str = ""a\na"";
str = ""a\r\na"";
c.M(str);
}
}
";
".NormalizeLineEndings();
var csTest = new VerifyCS.Test()
{
TestCode = csCode,
Expand Down Expand Up @@ -1855,7 +1855,7 @@ Public Sub M1(c As C)
c.M(str)
End Sub
End Class
";
".NormalizeLineEndings();
var vbTest = new VerifyVB.Test()
{
TestCode = vbCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using Test.Utilities;
using Xunit;
using VerifyCS = Test.Utilities.CSharpSecurityCodeFixVerifier<
Microsoft.NetCore.Analyzers.Security.UseDefaultDllImportSearchPathsAttribute,
Expand Down Expand Up @@ -523,7 +524,7 @@ public void TestMethod()
}

// [DllImport] is set with an absolute path, which will let the [DefaultDllImportSearchPaths] be ignored.
[Fact]
[WindowsOnlyFact]
public async Task Test_DllImportAttributeWithAbsolutePath_DefaultDllImportSearchPaths_NoDiagnostic()
{
await VerifyCS.VerifyAnalyzerAsync(@"
Expand All @@ -544,7 +545,7 @@ public void TestMethod()
}

// [DllImport] is set with an absolute path.
[Fact]
[WindowsOnlyFact]
public async Task Test_DllImportAttributeWithAbsolutePath_NoDiagnostic()
{
await VerifyCS.VerifyAnalyzerAsync(@"
Expand All @@ -563,7 +564,7 @@ public void TestMethod()
}");
}

[Fact]
[WindowsOnlyFact]
public async Task Test_UsingNonexistentAbsolutePath_NoDiagnostic()
{
await VerifyCS.VerifyAnalyzerAsync(@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ public class {|RS0016:{|RS0016:C2|}|} { }
await VerifyCSharpAdditionalFileFixAsync(source, shippedText, unshippedText, fixedUnshippedText);
}

[Theory]
[WindowsOnlyTheory]
[InlineData("", "")]
[InlineData("\r\n", "\r\n")]
[InlineData("\r\n\r\n", "\r\n")]
Expand All @@ -2112,7 +2112,11 @@ public class C
C.NewField -> int
C.Property.get -> int{expectedEndOfFile}";

await VerifyCSharpAdditionalFileFixAsync(source, shippedText, unshippedText, fixedUnshippedText);
await VerifyCSharpAdditionalFileFixAsync(
source.NormalizeLineEndings(),
shippedText,
unshippedText.NormalizeLineEndings(),
fixedUnshippedText.NormalizeLineEndings());
}

[Fact]
Expand Down
Loading