Skip to content

Commit 3778045

Browse files
Backport test fixes from main (#1145)
1 parent 1dd9567 commit 3778045

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

azure-pipelines/builds/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extends:
2929
# All of the SBRPs must be ignored because it is possible some of them are for vulnerable versions.
3030
# Because they are reference only packages they are not vulnerable themselves.
3131
ignoreDirectories: |
32-
artifacts/sb,
32+
artifacts/source-build/self,
3333
src/referencePackages
3434
sourceAnalysisPool:
3535
name: $(DncEngInternalBuildPool)

tests/GenerateScriptTests/GenerateScriptTests.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.IO;
78
using System.Runtime.InteropServices;
89
using Xunit;
@@ -20,20 +21,20 @@ public enum PackageType
2021

2122
public static IEnumerable<object[]> Data => new List<object[]>
2223
{
23-
new object[] { "System.Xml.ReaderWriter", "4.0.11", PackageType.Reference },
24+
new object[] { "System.Xml.ReaderWriter", "4.3.0", PackageType.Reference },
2425
new object[] { "Microsoft.Extensions.Logging.Abstractions", "7.0.1", PackageType.Reference },
2526
new object[] { "Microsoft.CodeAnalysis.CSharp", "3.11.0", PackageType.Reference },
26-
new object[] { "System.Security.Cryptography.Pkcs", "7.0.2", PackageType.Reference },
27+
new object[] { "System.Security.Cryptography.Encoding", "4.3.0", PackageType.Reference },
2728
new object[] { "Microsoft.Build.NoTargets", "3.7.0", PackageType.Text },
2829
};
2930

3031
public string SandboxDirectory { get; set; }
3132
public string RepoRoot { get; set; }
32-
public ITestOutputHelper output { get; set; }
33+
public ITestOutputHelper Output { get; set; }
3334

3435
public GenerateScriptTests(ITestOutputHelper output)
3536
{
36-
this.output = output;
37+
Output = output;
3738
RepoRoot = Environment.CurrentDirectory.Substring(0, Environment.CurrentDirectory.IndexOf("artifacts"));
3839
SandboxDirectory = Path.Combine(Environment.CurrentDirectory, $"GenerateTests-{DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()}");
3940
Directory.CreateDirectory(SandboxDirectory);
@@ -45,21 +46,38 @@ public void VerifyGenerateScript(string package, string version, PackageType typ
4546
{
4647
string command = Path.Combine(RepoRoot, RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "generate.cmd" : "generate.sh");
4748
string arguments = $"-p {package},{version} -x -d {SandboxDirectory}";
48-
string packageSrcDirectory = string.Empty;
49-
string sandboxPackageGeneratedDirecotry = Path.Combine(SandboxDirectory, package.ToLower(), version);
49+
string pkgSrcDirectory;
50+
string pkgSandboxDirectory = Path.Combine(SandboxDirectory, package.ToLower(), version);
5051

5152
switch (type)
5253
{
5354
case PackageType.Reference:
54-
packageSrcDirectory = Path.Combine(RepoRoot, "src", "referencePackages", "src", package.ToLower(), version);
55+
pkgSrcDirectory = Path.Combine(RepoRoot, "src", "referencePackages", "src", package.ToLower(), version);
5556
break;
5657
case PackageType.Text:
5758
arguments += " -t text";
58-
packageSrcDirectory = Path.Combine(RepoRoot, "src", "textOnlyPackages", "src", package.ToLower(), version);
59+
pkgSrcDirectory = Path.Combine(RepoRoot, "src", "textOnlyPackages", "src", package.ToLower(), version);
5960
break;
61+
default:
62+
throw new ArgumentException($"Unknown package type '{type}'");
6063
}
6164

62-
ExecuteHelper.ExecuteProcess(command, arguments, output);
63-
Assert.Empty(ExecuteHelper.ExecuteProcess("git", $"diff --no-index {packageSrcDirectory} {sandboxPackageGeneratedDirecotry}", output, true).StdOut);
65+
Assert.True(Directory.Exists(pkgSrcDirectory), $"Source directory '{pkgSrcDirectory}' does not exist.");
66+
67+
ExecuteHelper.ExecuteProcessValidateExitCode(command, arguments, Output);
68+
69+
(Process Process, string StdOut, string StdErr) result =
70+
ExecuteHelper.ExecuteProcess("git", $"diff --no-index {pkgSrcDirectory} {pkgSandboxDirectory}", Output, true);
71+
72+
string diff = result.StdOut;
73+
if (diff != string.Empty)
74+
{
75+
Assert.Fail($"Regenerated package '{package}, {version}' does not match the checked-in content. {Environment.NewLine}"
76+
+ $"{diff}{Environment.NewLine}");
77+
}
78+
else if (result.Process.ExitCode != 0)
79+
{
80+
Assert.Fail($"Unexpected git diff failure on '{package}, {version}'. {Environment.NewLine}{result.StdErr}{Environment.NewLine}");
81+
}
6482
}
6583
}

0 commit comments

Comments
 (0)