Skip to content

Commit

Permalink
Merge pull request #271 from Microsoft/sarif-logger-version
Browse files Browse the repository at this point in the history
Populate tool.sarifLoggerVersion property.
  • Loading branch information
michaelcfanning committed May 13, 2016
2 parents 939c28f + b36184f commit e346750
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/Sarif.UnitTests/Writers/SarifLoggerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
Expand Down Expand Up @@ -69,6 +70,32 @@ public void SarifLogger_RedactedCommandLine()
}
}

[TestMethod]
public void SarifLogger_WritesSarifLoggerVersion()
{
var sb = new StringBuilder();

using (var textWriter = new StringWriter(sb))
{
using (var sarifLogger = new SarifLogger(
textWriter,
analysisTargets: new string[] { @"foo.cpp" },
verbose: false,
computeTargetsHash: false,
logEnvironment: false,
prereleaseInfo: null,
invocationTokensToRedact: null)) { }
}

string result = sb.ToString();
var sarifLog = JsonConvert.DeserializeObject<SarifLog>(result);

string sarifLoggerLocation = typeof(SarifLogger).Assembly.Location;
string expectedVersion = FileVersionInfo.GetVersionInfo(sarifLoggerLocation).FileVersion;

sarifLog.Runs[0].Tool.SarifLoggerVersion.Should().Be(expectedVersion);
}

[TestMethod]
public void SarifLogger_WritesFileData()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif/Autogenerated/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SarifNodeKind SarifNodeKind
public Invocation Invocation { get; set; }

/// <summary>
/// The file that the analysis tool was instructed to scan. This member is only populated if the run is directated against a single analysis target.
/// The file that the analysis tool was instructed to scan. This member is only populated if the run is directed against a single analysis target.
/// </summary>
[DataMember(Name = "analysisTarget", IsRequired = false, EmitDefaultValue = false)]
public PhysicalLocation AnalysisTarget { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions src/Sarif/Writers/SarifLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ public SarifLogger(
private void SetSarifLoggerVersion(Tool tool)
{
string sarifLoggerLocation = typeof(SarifLogger).Assembly.Location;

tool.SetProperty("SarifLoggerVersion", FileVersionInfo.GetVersionInfo(sarifLoggerLocation).FileVersion);
tool.SarifLoggerVersion = FileVersionInfo.GetVersionInfo(sarifLoggerLocation).FileVersion;
}

public SarifLogger(TextWriter textWriter, bool verbose)
Expand Down

0 comments on commit e346750

Please sign in to comment.