-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into minor-improvements
- Loading branch information
Showing
18 changed files
with
404 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ trigger: | |
- '*' | ||
branches: | ||
include: | ||
- main | ||
- release/* | ||
|
||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
tests/Buildalyzer.Tests/TestTools/BuildalyzerTestContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace Buildalyzer.TestTools; | ||
|
||
/// <summary>Creates a test context for testing <see cref="IProjectAnalyzer"/>s.</summary> | ||
/// <remarks> | ||
/// The context ensures an fresh build (deletes previous artifacts in advance). | ||
/// The context logs to the console in DEBUG mode. | ||
/// </remarks> | ||
public sealed class BuildalyzerTestContext : IDisposable | ||
{ | ||
public TextWriter Log => IsDisposed ? throw new ObjectDisposedException(GetType().FullName) : log; | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
private readonly TextWriter log = new StringWriter(); | ||
|
||
public BuildalyzerTestContext(FileInfo projectFile) | ||
{ | ||
ProjectFile = projectFile; | ||
Manager = new AnalyzerManager( | ||
new AnalyzerManagerOptions | ||
{ | ||
LogWriter = Log, | ||
}); | ||
|
||
Analyzer = Manager.GetProject(projectFile.FullName); | ||
|
||
DebugMode(ref InDebugMode); | ||
AddBinaryLogger(); | ||
DeleteSubDirectory("bin"); | ||
DeleteSubDirectory("obj"); | ||
} | ||
|
||
public FileInfo ProjectFile { get; } | ||
|
||
public AnalyzerManager Manager { get; } | ||
|
||
public IProjectAnalyzer Analyzer { get; } | ||
|
||
/// <inheritdoc /> | ||
public void Dispose() | ||
{ | ||
if (!IsDisposed) | ||
{ | ||
if (InDebugMode) | ||
{ | ||
Console.WriteLine(Log.ToString()); | ||
} | ||
Log.Dispose(); | ||
|
||
IsDisposed = true; | ||
} | ||
} | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
private bool IsDisposed; | ||
|
||
/// <summary>Ensures that the analysis is done ignoring previous results.</summary> | ||
private void DeleteSubDirectory(string path) | ||
{ | ||
var directory = new DirectoryInfo(Path.Combine(ProjectFile.Directory!.FullName, path)); | ||
|
||
if (directory.Exists) | ||
{ | ||
try | ||
{ | ||
directory.Delete(true); | ||
Log.WriteLine($"Deleted all files at {directory}"); | ||
} | ||
catch (Exception x) | ||
{ | ||
Log.WriteLine(x); | ||
} | ||
} | ||
} | ||
|
||
[Conditional("BinaryLog")] | ||
private void AddBinaryLogger() | ||
{ | ||
Analyzer.AddBinaryLogger(Path.Combine(@"C:\Temp\", Path.ChangeExtension(ProjectFile.Name, ".core.binlog"))); | ||
} | ||
|
||
/// <summary>Sets <paramref name="inDebugMode"/> to true when run in DEBUG mode.</summary> | ||
[Conditional("DEBUG")] | ||
private void DebugMode(ref bool inDebugMode) => inDebugMode = true; | ||
|
||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
private readonly bool InDebugMode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Diagnostics.Contracts; | ||
using System.IO; | ||
|
||
namespace Buildalyzer.TestTools; | ||
|
||
public static class Context | ||
{ | ||
[Pure] | ||
public static BuildalyzerTestContext ForProject(string path) => new(GetProjectPath(path)); | ||
|
||
private static FileInfo GetProjectPath(string file) | ||
{ | ||
var location = new FileInfo(typeof(Context).Assembly.Location).Directory!; | ||
return new FileInfo(Path.Combine( | ||
location.FullName, | ||
"..", | ||
"..", | ||
"..", | ||
"..", | ||
"projects", | ||
file)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.