Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #9 from justaprogrammer/report-writing
Browse files Browse the repository at this point in the history
Report writing
  • Loading branch information
StanleyGoldman authored Nov 6, 2018
2 parents 44b93e7 + 7ec3e5f commit 19e7279
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 92 deletions.
22 changes: 19 additions & 3 deletions src/BCC.MSBuildLog.Tests/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ public void ShouldNotCallForInvalidArguments()

program.Run(new string[0]);
commandLineParser.Received(1).Parse(Arg.Any<string[]>());
buildLogProcessor.DidNotReceive().Proces(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>());
buildLogProcessor.DidNotReceive().Proces(
Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<string>(),
Arg.Any<string>());
}

[Fact]
Expand All @@ -34,15 +40,25 @@ public void ShouldCallForValidArguments()
var applicationArguments = new ApplicationArguments()
{
OutputFile = Faker.System.FilePath(),
InputFile = Faker.System.FilePath()
InputFile = Faker.System.FilePath(),
Repo = Faker.Random.Word(),
Owner = Faker.Random.Word(),
Hash = Faker.Random.String(10),
CloneRoot = Faker.System.DirectoryPath()
};

commandLineParser.Parse(Arg.Any<string[]>()).Returns(applicationArguments);

var program = new Program(commandLineParser, buildLogProcessor);

program.Run(new string[0]);
buildLogProcessor.Received(1).Proces(applicationArguments.InputFile, applicationArguments.OutputFile, Arg.Any<string>());
buildLogProcessor.Received(1).Proces(
applicationArguments.InputFile,
applicationArguments.OutputFile,
applicationArguments.CloneRoot,
applicationArguments.Owner,
applicationArguments.Repo,
applicationArguments.Hash);
}
}
}
60 changes: 44 additions & 16 deletions src/BCC.MSBuildLog.Tests/Services/BinaryLogProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using BCC.Core.Model.CheckRunSubmission;
using BCC.MSBuildLog.Model;
using BCC.MSBuildLog.Services;
Expand Down Expand Up @@ -36,7 +37,7 @@ static BinaryLogProcessorTests()
public void Should_TestConsoleApp1_Warning()
{
var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot);
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(1);
Expand All @@ -51,6 +52,8 @@ public void Should_TestConsoleApp1_Warning()
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
}
);

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
Expand All @@ -69,7 +72,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Warning_For_Other_Code()
};

var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, checkRunConfiguration);
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10), checkRunConfiguration);

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(1);
Expand All @@ -84,6 +87,8 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Warning_For_Other_Code()
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
}
);

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
Expand All @@ -102,7 +107,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Warning()
};

var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, checkRunConfiguration);
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10), checkRunConfiguration);

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(1);
Expand All @@ -117,6 +122,8 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Warning()
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
}
);

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
Expand All @@ -135,7 +142,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Notice()
};

var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, checkRunConfiguration);
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10), checkRunConfiguration);

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(1);
Expand All @@ -150,6 +157,8 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Notice()
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
}
);

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
Expand All @@ -168,7 +177,7 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Error()
};

var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, checkRunConfiguration);
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10), checkRunConfiguration);

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(1);
Expand All @@ -183,6 +192,8 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Error()
Title = "CS0219: TestConsoleApp1/Program.cs(13)"
}
);

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
Expand All @@ -201,15 +212,17 @@ public void Should_TestConsoleApp1_Warning_ConfigureAs_Ignore()
};

var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, checkRunConfiguration);
var logData = ProcessLog("testconsoleapp1-1warning.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10), checkRunConfiguration);
logData.Annotations.Should().BeEmpty();

logData.Report.Should().BeNullOrWhiteSpace();
}

[Fact]
public void Should_TestConsoleApp1_Error()
{
var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-1error.binlog", cloneRoot);
var logData = ProcessLog("testconsoleapp1-1error.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));

logData.ErrorCount.Should().Be(1);
logData.WarningCount.Should().Be(0);
Expand All @@ -225,13 +238,15 @@ public void Should_TestConsoleApp1_Error()
Title = "CS1002: TestConsoleApp1/Program.cs(13)"
}
);

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
public void Should_TestConsoleApp1_CodeAnalysis()
{
var cloneRoot = @"C:\projects\testconsoleapp1\";
var logData = ProcessLog("testconsoleapp1-codeanalysis.binlog", cloneRoot);
var logData = ProcessLog("testconsoleapp1-codeanalysis.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(1);
Expand All @@ -247,13 +262,15 @@ public void Should_TestConsoleApp1_CodeAnalysis()
Title = "CA2213: TestConsoleApp1/Program.cs(20)"
}
);

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
public void Should_MSBLOC()
{
var cloneRoot = @"C:\projects\msbuildlogoctokitchecker\";
var logData = ProcessLog("msbloc.binlog", cloneRoot);
var logData = ProcessLog("msbloc.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(10);
Expand Down Expand Up @@ -281,13 +298,15 @@ public void Should_MSBLOC()
{
Title = "CS0219: MSBLOC.Core.Tests/Services/BinaryLogProcessorTests.cs(83)"
});

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
public void Should_Parse_OctokitGraphQL()
{
var cloneRoot = @"C:\projects\octokit-graphql\";
var logData = ProcessLog("octokit.graphql.binlog", cloneRoot);
var logData = ProcessLog("octokit.graphql.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(803);
Expand Down Expand Up @@ -315,55 +334,64 @@ public void Should_Parse_OctokitGraphQL()
{
Title = "CS1591: Octokit.GraphQL.Core/Connection.cs(44)"
});

logData.Report.Should().NotBeNullOrWhiteSpace();
}

[Fact]
public void Should_Parse_GitHubVisualStudio()
{
var cloneRoot = @"c:\users\spade\projects\github\visualstudio\";
var logData = ProcessLog("visualstudio.binlog", cloneRoot);
var logData = ProcessLog("visualstudio.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(1556);

logData.Report.Should().NotBeNullOrWhiteSpace();

var reportKbytes = Encoding.Unicode.GetByteCount(logData.Report) / 1024.0;
reportKbytes.Should().BeLessThan(128.0);
}

[Fact]
public void Should_Parse_DBATools()
{
var cloneRoot = @"c:\github\dbatools\bin\projects\dbatools\";
var logData = ProcessLog("dbatools.binlog", cloneRoot);
var logData = ProcessLog("dbatools.binlog", cloneRoot, Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));

logData.ErrorCount.Should().Be(0);
logData.WarningCount.Should().Be(0);

logData.Annotations.Length.Should().Be(0);

logData.Report.Should().BeNullOrWhiteSpace();
}

[Fact]
public void Should_ThrowWhen_BuildPath_Outisde_CloneRoot()
{
var invalidOperationException = Assert.Throws<InvalidOperationException>(() =>
{
ProcessLog("testconsoleapp1-1warning.binlog", @"C:\projects\testconsoleapp2\");
ProcessLog("testconsoleapp1-1warning.binlog", @"C:\projects\testconsoleapp2\", Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));
});

invalidOperationException.Message.Should().Be(@"FilePath `C:\projects\testconsoleapp1\TestConsoleApp1\Program.cs` is not a child of `C:\projects\testconsoleapp2\`");

invalidOperationException = Assert.Throws<InvalidOperationException>(() =>
{
ProcessLog("testconsoleapp1-1error.binlog", @"C:\projects\testconsoleapp2\");
ProcessLog("testconsoleapp1-1error.binlog", @"C:\projects\testconsoleapp2\", Faker.Internet.UserName(), Faker.Random.Word(), Faker.Random.String(10));
});
invalidOperationException.Message.Should().Be(@"FilePath `C:\projects\testconsoleapp1\TestConsoleApp1\Program.cs` is not a child of `C:\projects\testconsoleapp2\`");
}

private LogData ProcessLog(string resourceName, string cloneRoot, CheckRunConfiguration checkRunConfiguration = null)
private LogData ProcessLog(string resourceName, string cloneRoot, string userName, string repo, string hash, CheckRunConfiguration checkRunConfiguration = null)
{
var resourcePath = TestUtils.GetResourcePath(resourceName);
File.Exists(resourcePath).Should().BeTrue();

var binaryLogReader = new BinaryLogReader();
var logProcessor = new BinaryLogProcessor(binaryLogReader, TestLogger.Create<BinaryLogProcessor>(_testOutputHelper));
return logProcessor.ProcessLog(resourcePath, cloneRoot, checkRunConfiguration);
return logProcessor.ProcessLog(resourcePath, cloneRoot, userName, repo, hash, checkRunConfiguration);
}
}
}
Loading

0 comments on commit 19e7279

Please sign in to comment.