forked from cake-contrib/Cake.Issues
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cake-contrib#14 from cake-contrib/feature/cake-con…
…tribgh-12 (cake-contribGH-12) Add support for markdownlint-cli
- Loading branch information
Showing
16 changed files
with
746 additions
and
118 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
3 changes: 2 additions & 1 deletion
3
...ests/MarkdownlintIssuesProviderFixture.cs → ...lint/MarkdownlintIssuesProviderFixture.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
3 changes: 2 additions & 1 deletion
3
....Tests/MarkdownlintIssuesProviderTests.cs → ...wnlint/MarkdownlintIssuesProviderTests.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
3 changes: 2 additions & 1 deletion
3
....Tests/MarkdownlintIssuesSettingsTests.cs → ...wnlint/MarkdownlintIssuesSettingsTests.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
48 changes: 48 additions & 0 deletions
48
src/Cake.Issues.Markdownlint.Tests/MarkdownlintCli/MarkdownlintCliIssuesProviderFixture.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,48 @@ | ||
namespace Cake.Issues.Markdownlint.Tests.MarkdownlintCli | ||
{ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Cake.Issues.Markdownlint.MarkdownlintCli; | ||
using Cake.Testing; | ||
using Core.Diagnostics; | ||
|
||
internal class MarkdownlintCliIssuesProviderFixture | ||
{ | ||
public MarkdownlintCliIssuesProviderFixture(string fileResourceName) | ||
{ | ||
this.Log = new FakeLog { Verbosity = Verbosity.Normal }; | ||
|
||
using (var stream = this.GetType().Assembly.GetManifestResourceStream("Cake.Issues.Markdownlint.Tests.Testfiles." + fileResourceName)) | ||
{ | ||
using (var sr = new StreamReader(stream)) | ||
{ | ||
this.Settings = | ||
MarkdownlintCliIssuesSettings.FromContent( | ||
sr.ReadToEnd()); | ||
} | ||
} | ||
|
||
this.RepositorySettings = | ||
new RepositorySettings(@"c:\Source\Cake.Issues"); | ||
} | ||
|
||
public FakeLog Log { get; set; } | ||
|
||
public MarkdownlintCliIssuesSettings Settings { get; set; } | ||
|
||
public RepositorySettings RepositorySettings { get; set; } | ||
|
||
public MarkdownlintCliIssuesProvider Create() | ||
{ | ||
var provider = new MarkdownlintCliIssuesProvider(this.Log, this.Settings); | ||
provider.Initialize(this.RepositorySettings); | ||
return provider; | ||
} | ||
|
||
public IEnumerable<IIssue> ReadIssues() | ||
{ | ||
var issueProvider = this.Create(); | ||
return issueProvider.ReadIssues(IssueCommentFormat.PlainText); | ||
} | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
src/Cake.Issues.Markdownlint.Tests/MarkdownlintCli/MarkdownlintCliIssuesProviderTests.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,156 @@ | ||
namespace Cake.Issues.Markdownlint.Tests.MarkdownlintCli | ||
{ | ||
using System.Linq; | ||
using Cake.Issues.Markdownlint.MarkdownlintCli; | ||
using Cake.Testing; | ||
using Core.IO; | ||
using Shouldly; | ||
using Testing; | ||
using Xunit; | ||
|
||
public sealed class MarkdownlintCliIssuesProviderTests | ||
{ | ||
public sealed class TheCtor | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Log_Is_Null() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => | ||
new MarkdownlintCliIssuesProvider( | ||
null, | ||
MarkdownlintCliIssuesSettings.FromContent("Foo"))); | ||
|
||
// Then | ||
result.IsArgumentNullException("log"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
var result = Record.Exception(() => | ||
new MarkdownlintCliIssuesProvider( | ||
new FakeLog(), | ||
null)); | ||
|
||
// Then | ||
result.IsArgumentNullException("settings"); | ||
} | ||
} | ||
|
||
public sealed class TheReadIssuesMethod | ||
{ | ||
[Fact] | ||
public void Should_Read_Issue_Correct() | ||
{ | ||
// Given | ||
var fixture = new MarkdownlintCliIssuesProviderFixture("markdownlint-cli.log"); | ||
|
||
// When | ||
var issues = fixture.ReadIssues().ToList(); | ||
|
||
// Then | ||
issues.Count.ShouldBe(8); | ||
CheckIssue( | ||
issues[0], | ||
@"docs/index.md", | ||
1, | ||
"MD022", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md022", | ||
0, | ||
"Headers should be surrounded by blank lines [Context: \"# foo\"]"); | ||
CheckIssue( | ||
issues[1], | ||
@"docs/index.md", | ||
2, | ||
"MD009", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md009", | ||
0, | ||
"Trailing spaces [Expected: 2; Actual: 1]"); | ||
CheckIssue( | ||
issues[2], | ||
@"docs/index.md", | ||
2, | ||
"MD013", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md013", | ||
0, | ||
"Line length [Expected: 100; Actual: 811]"); | ||
CheckIssue( | ||
issues[3], | ||
@"docs/index.md", | ||
4, | ||
"MD022", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md022", | ||
0, | ||
"Headers should be surrounded by blank lines [Context: \"# bar\"]"); | ||
CheckIssue( | ||
issues[4], | ||
@"docs/index.md", | ||
4, | ||
"MD025", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md025", | ||
0, | ||
"Multiple top level headers in the same document [Context: \"# bar\"]"); | ||
CheckIssue( | ||
issues[5], | ||
@"docs/index.md", | ||
5, | ||
"MD031", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md031", | ||
0, | ||
"Fenced code blocks should be surrounded by blank lines [Context: \"```\"]"); | ||
CheckIssue( | ||
issues[6], | ||
@"docs/index.md", | ||
5, | ||
"MD040", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md040", | ||
0, | ||
"Fenced code blocks should have a language specified [Context: \"```\"]"); | ||
CheckIssue( | ||
issues[7], | ||
@"docs/index.md", | ||
6, | ||
"MD009", | ||
"https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md#md009", | ||
0, | ||
"Trailing spaces [Expected: 2; Actual: 1]"); | ||
} | ||
|
||
private static void CheckIssue( | ||
IIssue issue, | ||
string affectedFileRelativePath, | ||
int? line, | ||
string rule, | ||
string ruleUrl, | ||
int priority, | ||
string message) | ||
{ | ||
if (issue.AffectedFileRelativePath == null) | ||
{ | ||
affectedFileRelativePath.ShouldBeNull(); | ||
} | ||
else | ||
{ | ||
issue.AffectedFileRelativePath.ToString().ShouldBe(new FilePath(affectedFileRelativePath).ToString()); | ||
issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "Issue path is not relative"); | ||
} | ||
|
||
issue.Line.ShouldBe(line); | ||
issue.Rule.ShouldBe(rule); | ||
|
||
if (issue.RuleUrl == null) | ||
{ | ||
ruleUrl.ShouldBeNull(); | ||
} | ||
else | ||
{ | ||
issue.RuleUrl.ToString().ShouldBe(ruleUrl); | ||
} | ||
|
||
issue.Priority.ShouldBe(priority); | ||
issue.Message.ShouldBe(message); | ||
} | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
src/Cake.Issues.Markdownlint.Tests/MarkdownlintCli/MarkdownlintCliIssuesSettingsTests.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,112 @@ | ||
namespace Cake.Issues.Markdownlint.Tests.MarkdownlintCli | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using Cake.Issues.Markdownlint.MarkdownlintCli; | ||
using Shouldly; | ||
using Testing; | ||
using Xunit; | ||
|
||
public sealed class MarkdownlintCliIssuesSettingsTests | ||
{ | ||
public sealed class TheCtor | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_LogFilePath_Is_Null() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => | ||
MarkdownlintCliIssuesSettings.FromFilePath(null)); | ||
|
||
// Then | ||
result.IsArgumentNullException("logFilePath"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_LogFileContent_Is_Null() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => | ||
MarkdownlintCliIssuesSettings.FromContent(null)); | ||
|
||
// Then | ||
result.IsArgumentNullException("logFileContent"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_LogFileContent_Is_Empty() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => | ||
MarkdownlintCliIssuesSettings.FromContent(string.Empty)); | ||
|
||
// Then | ||
result.IsArgumentOutOfRangeException("logFileContent"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_LogFileContent_Is_WhiteSpace() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => | ||
MarkdownlintCliIssuesSettings.FromContent(" ")); | ||
|
||
// Then | ||
result.IsArgumentOutOfRangeException("logFileContent"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Property_Values_Passed_To_Constructor() | ||
{ | ||
// Given | ||
const string logFileContent = "foo"; | ||
|
||
// When | ||
var settings = MarkdownlintCliIssuesSettings.FromContent(logFileContent); | ||
|
||
// Then | ||
settings.LogFileContent.ShouldBe(logFileContent); | ||
} | ||
|
||
[Fact] | ||
public void Should_Read_File_From_Disk() | ||
{ | ||
var fileName = Path.GetTempFileName(); | ||
try | ||
{ | ||
// Given | ||
string expected; | ||
using (var ms = new MemoryStream()) | ||
using (var stream = this.GetType().Assembly.GetManifestResourceStream("Cake.Issues.Markdownlint.Tests.Testfiles.markdownlint-cli.log")) | ||
{ | ||
stream.CopyTo(ms); | ||
var data = ms.ToArray(); | ||
|
||
using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) | ||
{ | ||
file.Write(data, 0, data.Length); | ||
} | ||
|
||
expected = Encoding.UTF8.GetString(data); | ||
} | ||
|
||
// When | ||
var settings = | ||
MarkdownlintCliIssuesSettings.FromFilePath(fileName); | ||
|
||
// Then | ||
settings.LogFileContent.ShouldBe(expected); | ||
} | ||
finally | ||
{ | ||
if (File.Exists(fileName)) | ||
{ | ||
File.Delete(fileName); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Cake.Issues.Markdownlint.Tests/Testfiles/markdownlint-cli.log
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,8 @@ | ||
C:/Git/Test/Cake.Prca/docs/index.md: 1: MD022/blanks-around-headers Headers should be surrounded by blank lines [Context: "# foo"] | ||
C:/Git/Test/Cake.Prca/docs/index.md: 2: MD009/no-trailing-spaces Trailing spaces [Expected: 2; Actual: 1] | ||
C:/Git/Test/Cake.Prca/docs/index.md: 2: MD013/line-length Line length [Expected: 100; Actual: 811] | ||
C:/Git/Test/Cake.Prca/docs/index.md: 4: MD022/blanks-around-headers Headers should be surrounded by blank lines [Context: "# bar"] | ||
C:/Git/Test/Cake.Prca/docs/index.md: 4: MD025/single-h1 Multiple top level headers in the same document [Context: "# bar"] | ||
C:/Git/Test/Cake.Prca/docs/index.md: 5: MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] | ||
C:/Git/Test/Cake.Prca/docs/index.md: 5: MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"] | ||
C:/Git/Test/Cake.Prca/docs/index.md: 6: MD009/no-trailing-spaces Trailing spaces [Expected: 2; Actual: 1] |
Oops, something went wrong.