Skip to content

Commit

Permalink
Addressed more review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaMilosavljevic committed Sep 6, 2023
1 parent b64d812 commit 72aacfc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ internal static class Config
{
public const string DotNetDirectoryEnv = "SMOKE_TESTS_DOTNET_DIR";
public const string ExcludeOmniSharpEnv = "SMOKE_TESTS_EXCLUDE_OMNISHARP";
public const string ExcludeSourcelinkEnv = "SMOKE_TESTS_EXCLUDE_SOURCELINK";
public const string MsftSdkTarballPathEnv = "SMOKE_TESTS_MSFT_SDK_TARBALL_PATH";
public const string PoisonReportPathEnv = "SMOKE_TESTS_POISON_REPORT_PATH";
public const string PortableRidEnv = "SMOKE_TESTS_PORTABLE_RID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public static (Process Process, string StdOut, string StdErr) ExecuteProcess(
string args,
ITestOutputHelper outputHelper,
bool logOutput = false,
bool logInfo = true,
bool excludeInfo = false,
Action<Process>? configureCallback = null,
int millisecondTimeout = -1)
{
if (logInfo)
if (!excludeInfo)
{
outputHelper.WriteLine($"Executing: {fileName} {args}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class OmniSharpTests : SmokeTests
// Update version as new releases become available: https://github.com/OmniSharp/omnisharp-roslyn/releases
private const string OmniSharpReleaseVersion = "1.39.8";

private string OmniSharpDirectory { get; } = Path.Combine(Directory.GetCurrentDirectory(), "omnisharp");
private string OmniSharpDirectory { get; } = Path.Combine(Directory.GetCurrentDirectory(), nameof(OmniSharpTests));

public OmniSharpTests(ITestOutputHelper outputHelper) : base(outputHelper) { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace Microsoft.DotNet.SourceBuild.SmokeTests;

public class SourcelinkTests : SmokeTests
{
private static string SourcelinkRoot { get; } = Path.Combine(Directory.GetCurrentDirectory(), "sourcelink");
private static string SourcelinkRoot { get; } = Path.Combine(Directory.GetCurrentDirectory(), nameof(SourcelinkTests));

public SourcelinkTests(ITestOutputHelper outputHelper) : base(outputHelper) { }

/// <summary>
/// Verifies that all symbols have valid sourcelinks.
/// </summary>
[SkippableFact(Config.ExcludeSourcelinkEnv, skipOnTrueEnv: true)]
[Fact]
public void VerifySourcelinks()
{
if (Directory.Exists(SourcelinkRoot))
Expand All @@ -32,25 +32,29 @@ public void VerifySourcelinks()
}
Directory.CreateDirectory(SourcelinkRoot);

IList<string> failedFiles = ValidateAllFiles(ExtractPackages(GetAllSymbolsPackages()), GetSourcelinkToolPath());
IList<string> failedFiles = ValidateSymbols(ExtractSymbolsPackages(GetAllSymbolsPackages()), InitializeSourcelinkTool());

foreach (string file in failedFiles)
if (failedFiles.Count > 0)
{
OutputHelper.WriteLine($"Failed sourcelink verification: {file}");
OutputHelper.WriteLine($"Sourcelink verification failed for the following files:");
foreach (string file in failedFiles)
{
OutputHelper.WriteLine(file);
}
}

Assert.True(failedFiles.Count == 0);
}

/// <summary>
/// Gets the path to sourcelink binary.
/// Initializes sourcelink tool.
/// Extracts the dotnet-sourcelink tool package from PSB arhive.
/// </summary>
/// <returns>Path to sourcelink tool binary.</returns>
private string GetSourcelinkToolPath()
private string InitializeSourcelinkTool()
{
const string SourcelinkToolPackageNamePattern = "dotnet-sourcelink*nupkg";
const string SourcelinkToolBinaryFilenamePattern = "dotnet-sourcelink.dll";
const string SourcelinkToolBinaryFilename = "dotnet-sourcelink.dll";

string toolPackageDir = Directory.CreateDirectory(Path.Combine(SourcelinkRoot, "sourcelink-tool")).FullName;
Utilities.ExtractTarball(Config.SourceBuiltArtifactsPath, toolPackageDir, SourcelinkToolPackageNamePattern);
Expand All @@ -61,9 +65,9 @@ private string GetSourcelinkToolPath()
string extractedToolPath = Directory.CreateDirectory(Path.Combine(toolPackageDir, "extracted")).FullName;
Utilities.ExtractNupkg(files[0], extractedToolPath);

files = Directory.GetFiles(extractedToolPath, SourcelinkToolBinaryFilenamePattern, SearchOption.AllDirectories);
Assert.False(files.Length > 1, $"Unexpected - found more than one sourcelink tool binary with filename pattern: {SourcelinkToolBinaryFilenamePattern}");
Assert.False(files.Length == 0, $"Did not find sourcelink tool binary with expected filename pattern: {SourcelinkToolBinaryFilenamePattern}");
files = Directory.GetFiles(extractedToolPath, SourcelinkToolBinaryFilename, SearchOption.AllDirectories);
Assert.False(files.Length > 1, $"Unexpected - found more than one sourcelink tool binary: {SourcelinkToolBinaryFilename}");
Assert.False(files.Length == 0, $"Did not find sourcelink tool binary: {SourcelinkToolBinaryFilename}");

return files[0];
}
Expand All @@ -88,10 +92,10 @@ At the moment we validate sourcelinks from runtime symbols package.
}

/// <summary>
/// Extracts packages to subdirectories of the common symbols root directory.
/// Extracts symbols packages to subdirectories of the common symbols root directory.
/// </summary>
/// <returns>Path to common symbols root directory.</returns>
private string ExtractPackages(IEnumerable<string> packages)
private string ExtractSymbolsPackages(IEnumerable<string> packages)
{
string symbolsRoot = Directory.CreateDirectory(Path.Combine(SourcelinkRoot, "symbols")).FullName;

Expand All @@ -105,7 +109,7 @@ private string ExtractPackages(IEnumerable<string> packages)
return symbolsRoot;
}

private IList<string> ValidateAllFiles(string path, string sourcelinkToolPath)
private IList<string> ValidateSymbols(string path, string sourcelinkToolPath)
{
Assert.True(Directory.Exists(path), $"Path, with symbol files to validate, does not exist: {path}");

Expand All @@ -119,7 +123,7 @@ private IList<string> ValidateAllFiles(string path, string sourcelinkToolPath)
$"{sourcelinkToolPath} test --offline {file}",
OutputHelper,
logOutput: false,
logInfo: false, // Do not log process cmd line, as there can be 1,000+
excludeInfo: true, // Exclude info messages, as there can be 1,000+ processes
millisecondTimeout: 5000,
configureCallback: (process) => DotNetHelper.ConfigureProcess(process, null));

Expand Down

0 comments on commit 72aacfc

Please sign in to comment.