mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Abstract over DiagnosticsStream for tests
This commit is contained in:
@@ -194,6 +194,15 @@ namespace Semmle.Autobuild.Cpp.Tests
|
|||||||
if (!DownloadFiles.Contains((address, fileName)))
|
if (!DownloadFiles.Contains((address, fileName)))
|
||||||
throw new ArgumentException($"Missing DownloadFile, {address}, {fileName}");
|
throw new ArgumentException($"Missing DownloadFile, {address}, {fileName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IDiagnosticsWriter CreateDiagnosticsWriter(string filename) => new TestDiagnosticWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TestDiagnosticWriter : IDiagnosticsWriter
|
||||||
|
{
|
||||||
|
public IList<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>();
|
||||||
|
|
||||||
|
public void AddEntry(DiagnosticMessage message) => this.Diagnostics.Add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -253,7 +262,7 @@ namespace Semmle.Autobuild.Cpp.Tests
|
|||||||
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_TRAP_DIR"] = "";
|
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_TRAP_DIR"] = "";
|
||||||
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_SOURCE_ARCHIVE_DIR"] = "";
|
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_SOURCE_ARCHIVE_DIR"] = "";
|
||||||
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_ROOT"] = $@"C:\codeql\{codeqlUpperLanguage.ToLowerInvariant()}";
|
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_ROOT"] = $@"C:\codeql\{codeqlUpperLanguage.ToLowerInvariant()}";
|
||||||
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_DIAGNOSTIC_DIR"] = Path.GetTempPath();
|
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_DIAGNOSTIC_DIR"] = "";
|
||||||
Actions.GetEnvironmentVariable["CODEQL_JAVA_HOME"] = @"C:\codeql\tools\java";
|
Actions.GetEnvironmentVariable["CODEQL_JAVA_HOME"] = @"C:\codeql\tools\java";
|
||||||
Actions.GetEnvironmentVariable["CODEQL_PLATFORM"] = "win64";
|
Actions.GetEnvironmentVariable["CODEQL_PLATFORM"] = "win64";
|
||||||
Actions.GetEnvironmentVariable["SEMMLE_DIST"] = @"C:\odasa";
|
Actions.GetEnvironmentVariable["SEMMLE_DIST"] = @"C:\odasa";
|
||||||
|
|||||||
@@ -210,6 +210,16 @@ namespace Semmle.Autobuild.CSharp.Tests
|
|||||||
if (!DownloadFiles.Contains((address, fileName)))
|
if (!DownloadFiles.Contains((address, fileName)))
|
||||||
throw new ArgumentException($"Missing DownloadFile, {address}, {fileName}");
|
throw new ArgumentException($"Missing DownloadFile, {address}, {fileName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public IDiagnosticsWriter CreateDiagnosticsWriter(string filename) => new TestDiagnosticWriter();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TestDiagnosticWriter : IDiagnosticsWriter
|
||||||
|
{
|
||||||
|
public IList<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>();
|
||||||
|
|
||||||
|
public void AddEntry(DiagnosticMessage message) => this.Diagnostics.Add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -401,7 +411,7 @@ namespace Semmle.Autobuild.CSharp.Tests
|
|||||||
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_TRAP_DIR"] = "";
|
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_TRAP_DIR"] = "";
|
||||||
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_SOURCE_ARCHIVE_DIR"] = "";
|
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_SOURCE_ARCHIVE_DIR"] = "";
|
||||||
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_ROOT"] = $@"C:\codeql\{codeqlUpperLanguage.ToLowerInvariant()}";
|
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_ROOT"] = $@"C:\codeql\{codeqlUpperLanguage.ToLowerInvariant()}";
|
||||||
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_DIAGNOSTIC_DIR"] = Path.GetTempPath();
|
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_DIAGNOSTIC_DIR"] = "";
|
||||||
actions.GetEnvironmentVariable["CODEQL_JAVA_HOME"] = @"C:\codeql\tools\java";
|
actions.GetEnvironmentVariable["CODEQL_JAVA_HOME"] = @"C:\codeql\tools\java";
|
||||||
actions.GetEnvironmentVariable["CODEQL_PLATFORM"] = isWindows ? "win64" : "linux64";
|
actions.GetEnvironmentVariable["CODEQL_PLATFORM"] = isWindows ? "win64" : "linux64";
|
||||||
actions.GetEnvironmentVariable["LGTM_INDEX_VSTOOLS_VERSION"] = vsToolsVersion;
|
actions.GetEnvironmentVariable["LGTM_INDEX_VSTOOLS_VERSION"] = vsToolsVersion;
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ namespace Semmle.Autobuild.Shared
|
|||||||
SourceArchiveDir = RequireEnvironmentVariable(EnvVars.SourceArchiveDir(this.Options.Language));
|
SourceArchiveDir = RequireEnvironmentVariable(EnvVars.SourceArchiveDir(this.Options.Language));
|
||||||
DiagnosticsDir = RequireEnvironmentVariable(EnvVars.DiagnosticDir(this.Options.Language));
|
DiagnosticsDir = RequireEnvironmentVariable(EnvVars.DiagnosticDir(this.Options.Language));
|
||||||
|
|
||||||
this.diagnostics = new DiagnosticsStream(Path.Combine(DiagnosticsDir, $"autobuilder-{DateTime.UtcNow:yyyyMMddHHmm}.jsonc"));
|
this.diagnostics = actions.CreateDiagnosticsWriter(Path.Combine(DiagnosticsDir, $"autobuilder-{DateTime.UtcNow:yyyyMMddHHmm}.jsonc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -269,7 +269,7 @@ namespace Semmle.Autobuild.Shared
|
|||||||
|
|
||||||
private readonly ILogger logger = new ConsoleLogger(Verbosity.Info);
|
private readonly ILogger logger = new ConsoleLogger(Verbosity.Info);
|
||||||
|
|
||||||
private readonly DiagnosticsStream diagnostics;
|
private readonly IDiagnosticsWriter diagnostics;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Makes <see cref="path" /> relative to the root source directory.
|
/// Makes <see cref="path" /> relative to the root source directory.
|
||||||
|
|||||||
@@ -167,6 +167,17 @@ namespace Semmle.Autobuild.Shared
|
|||||||
/// Downloads the resource with the specified URI to a local file.
|
/// Downloads the resource with the specified URI to a local file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void DownloadFile(string address, string fileName);
|
void DownloadFile(string address, string fileName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an <see cref="IDiagnosticsWriter" /> for the given <paramref name="filename" />.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">
|
||||||
|
/// The path suggesting where the diagnostics should be written to.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// A <see cref="IDiagnosticsWriter" /> to which diagnostic entries can be added.
|
||||||
|
/// </returns>
|
||||||
|
IDiagnosticsWriter CreateDiagnosticsWriter(string filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -288,6 +299,8 @@ namespace Semmle.Autobuild.Shared
|
|||||||
public void DownloadFile(string address, string fileName) =>
|
public void DownloadFile(string address, string fileName) =>
|
||||||
DownloadFileAsync(address, fileName).Wait();
|
DownloadFileAsync(address, fileName).Wait();
|
||||||
|
|
||||||
|
public IDiagnosticsWriter CreateDiagnosticsWriter(string filename) => new DiagnosticsStream(filename);
|
||||||
|
|
||||||
public static IBuildActions Instance { get; } = new SystemBuildActions();
|
public static IBuildActions Instance { get; } = new SystemBuildActions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,11 +174,23 @@ namespace Semmle.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides the ability to write diagnostic messages to some output.
|
||||||
|
/// </summary>
|
||||||
|
public interface IDiagnosticsWriter
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds <paramref name="message" /> as a new diagnostics entry.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The diagnostics entry to add.</param>
|
||||||
|
void AddEntry(DiagnosticMessage message);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A wrapper around an underlying <see cref="StreamWriter" /> which allows
|
/// A wrapper around an underlying <see cref="StreamWriter" /> which allows
|
||||||
/// <see cref="DiagnosticMessage" /> objects to be serialized to it.
|
/// <see cref="DiagnosticMessage" /> objects to be serialized to it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class DiagnosticsStream : IDisposable
|
public sealed class DiagnosticsStream : IDiagnosticsWriter, IDisposable
|
||||||
{
|
{
|
||||||
private readonly JsonSerializer serializer;
|
private readonly JsonSerializer serializer;
|
||||||
private readonly StreamWriter writer;
|
private readonly StreamWriter writer;
|
||||||
|
|||||||
Reference in New Issue
Block a user