Abstract over `DiagnosticsStream` for tests · github/codeql@9dc9925 · GitHub
Skip to content

Commit 9dc9925

Browse files
committed
Abstract over DiagnosticsStream for tests
1 parent df6f5d5 commit 9dc9925

5 files changed

Lines changed: 49 additions & 5 deletions

File tree

‎cpp/autobuilder/Semmle.Autobuild.Cpp.Tests/BuildScripts.cs‎

Lines changed: 10 additions & 1 deletion

‎csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ public void DownloadFile(string address, string fileName)
210210
if (!DownloadFiles.Contains((address, fileName)))
211211
throw new ArgumentException($"Missing DownloadFile, {address}, {fileName}");
212212
}
213+
214+
215+
public IDiagnosticsWriter CreateDiagnosticsWriter(string filename) => new TestDiagnosticWriter();
216+
}
217+
218+
internal class TestDiagnosticWriter : IDiagnosticsWriter
219+
{
220+
public IList<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>();
221+
222+
public void AddEntry(DiagnosticMessage message) => this.Diagnostics.Add(message);
213223
}
214224

215225
/// <summary>
@@ -401,7 +411,7 @@ private CSharpAutobuilder CreateAutoBuilder(bool isWindows,
401411
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_TRAP_DIR"] = "";
402412
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_SOURCE_ARCHIVE_DIR"] = "";
403413
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_ROOT"] = $@"C:\codeql\{codeqlUpperLanguage.ToLowerInvariant()}";
404-
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_DIAGNOSTIC_DIR"] = Path.GetTempPath();
414+
actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_DIAGNOSTIC_DIR"] = "";
405415
actions.GetEnvironmentVariable["CODEQL_JAVA_HOME"] = @"C:\codeql\tools\java";
406416
actions.GetEnvironmentVariable["CODEQL_PLATFORM"] = isWindows ? "win64" : "linux64";
407417
actions.GetEnvironmentVariable["LGTM_INDEX_VSTOOLS_VERSION"] = vsToolsVersion;

‎csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected Autobuilder(IBuildActions actions, TAutobuildOptions options, Diagnost
241241
SourceArchiveDir = RequireEnvironmentVariable(EnvVars.SourceArchiveDir(this.Options.Language));
242242
DiagnosticsDir = RequireEnvironmentVariable(EnvVars.DiagnosticDir(this.Options.Language));
243243

244-
this.diagnostics = new DiagnosticsStream(Path.Combine(DiagnosticsDir, $"autobuilder-{DateTime.UtcNow:yyyyMMddHHmm}.jsonc"));
244+
this.diagnostics = actions.CreateDiagnosticsWriter(Path.Combine(DiagnosticsDir, $"autobuilder-{DateTime.UtcNow:yyyyMMddHHmm}.jsonc"));
245245
}
246246

247247
/// <summary>
@@ -269,7 +269,7 @@ protected string RequireEnvironmentVariable(string name)
269269

270270
private readonly ILogger logger = new ConsoleLogger(Verbosity.Info);
271271

272-
private readonly DiagnosticsStream diagnostics;
272+
private readonly IDiagnosticsWriter diagnostics;
273273

274274
/// <summary>
275275
/// Makes <see cref="path" /> relative to the root source directory.

‎csharp/autobuilder/Semmle.Autobuild.Shared/BuildActions.cs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ public interface IBuildActions
167167
/// Downloads the resource with the specified URI to a local file.
168168
/// </summary>
169169
void DownloadFile(string address, string fileName);
170+
171+
/// <summary>
172+
/// Creates an <see cref="IDiagnosticsWriter" /> for the given <paramref name="filename" />.
173+
/// </summary>
174+
/// <param name="filename">
175+
/// The path suggesting where the diagnostics should be written to.
176+
/// </param>
177+
/// <returns>
178+
/// A <see cref="IDiagnosticsWriter" /> to which diagnostic entries can be added.
179+
/// </returns>
180+
IDiagnosticsWriter CreateDiagnosticsWriter(string filename);
170181
}
171182

172183
/// <summary>
@@ -288,6 +299,8 @@ private static async Task DownloadFileAsync(string address, string filename)
288299
public void DownloadFile(string address, string fileName) =>
289300
DownloadFileAsync(address, fileName).Wait();
290301

302+
public IDiagnosticsWriter CreateDiagnosticsWriter(string filename) => new DiagnosticsStream(filename);
303+
291304
public static IBuildActions Instance { get; } = new SystemBuildActions();
292305
}
293306
}

‎csharp/extractor/Semmle.Util/ToolStatusPage.cs‎

Lines changed: 13 additions & 1 deletion

0 commit comments

Comments
 (0)