diff --git a/.editorconfig b/.editorconfig index dea2e7c8..35791e9f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,9 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true +[.cs] + + # This may not be needed, but kept for compatibility with VS [*.{sln,csproj}] end_of_line = crlf @@ -29,15 +32,7 @@ end_of_line = crlf [*.sh] end_of_line = lf -[*.{yml,yaml}] -indent_size = 2 - # The visual studio code file # requires the use of crlf line endings [tasks.json] end_of_line = crlf - -# default for ide0065 contradicts sa1200 -# see https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019 -# and https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md -csharp_using_directive_placement = outside_namespace \ No newline at end of file diff --git a/.github/workflows/publishDocs.yml b/.github/workflows/publishDocs.yml new file mode 100644 index 00000000..b3e2d4c6 --- /dev/null +++ b/.github/workflows/publishDocs.yml @@ -0,0 +1,25 @@ +name: Publish Documentation + +on: + workflow_dispatch + +env: + WYAM_ACCESS_TOKEN: ${{ secrets.API_TOKEN }} + # secrets.GITHUB_TOKEN has no permissions to push, sadly. + WYAM_DEPLOY_BRANCH: 'gh-pages' + #WYAM_DEPLOY_REMOTE: does not exist in any context, will be dynamically set - see below + +jobs: + cake: + runs-on: windows-latest + + steps: + - name: checkout + uses: actions/checkout@v2 #https://github.com/actions/checkout + with: + fetch-depth: 0 # GitVersion is somewhat irritated when fetch-depth is "1".... + + - name: call cake + run: | + $env:WYAM_DEPLOY_REMOTE = $( git remote get-url --push origin ) + .\build.ps1 -Target PublishDocs -Verbosity Diagnostic diff --git a/.gitignore b/.gitignore index 83d6d57c..8fe89cfe 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,6 @@ docs/input/tasks/* # Wyam related config.wyam.* + +#Testresults +[Tt]est[Rr]esults diff --git a/Changelog.md b/Changelog.md deleted file mode 100644 index f016c64f..00000000 --- a/Changelog.md +++ /dev/null @@ -1,34 +0,0 @@ -# Changelog -Changelog for Cake.AsciiDoctorJ - -_The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)._ - -## [Unreleased] -### Changed - -## [1.0.2] - 2019-09-02 -### Changed -- (GH-3) removed code warnings -- (GH-4) added some wyam documentation - -## [1.0.1] - 2019-09-01 -### Changed -- moved project into cake-contrib -- created a changelog -- (GH-2) many changes to internal project-structure - -## [1.0.0] - 2019-08-13 -### Added -- inline documentation - -## [0.0.1] - 2019-08-12 -### Added -- Initial idea - working version mostly without documentation - - -[Unreleased]: https://github.com/cake-contrib/cake.asciidoctorj/compare/1.0.2...HEAD -[1.0.2]: https://github.com/cake-contrib/cake.asciidoctorj/compare/1.0.1...1.0.2 -[1.0.1]: https://github.com/cake-contrib/cake.asciidoctorj/compare/v1.0.0...1.0.1 -[1.0.0]: https://github.com/cake-contrib/cake.asciidoctorj/compare/v0.0.1...v1.0.0 -[0.0.1]: https://github.com/cake-contrib/cake.asciidoctorj/tree/v0.0.1 \ No newline at end of file diff --git a/recipe.cake b/recipe.cake index 38a18460..e795259d 100644 --- a/recipe.cake +++ b/recipe.cake @@ -1,4 +1,4 @@ -#load nuget:?package=Cake.Recipe&version=1.0.0 +#load nuget:?package=Cake.Recipe&version=1.1.2 Environment.SetVariableNames(); diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 00000000..061b57d6 --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,236 @@ +# C# files +[*.cs] + +#### Core EditorConfig Options #### + +# Indentation and spacing +indent_size = 4 +indent_style = space +tab_width = 4 + +# New line preferences +end_of_line = crlf +insert_final_newline = true + +#### .NET Coding Conventions #### + +# Organize usings +dotnet_separate_import_directive_groups = true +dotnet_sort_system_directives_first = true +file_header_template = unset + +# this. and Me. preferences +dotnet_style_qualification_for_event = false:warning +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_property = false:warning + +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent + +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning + +# Expression-level preferences +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_object_initializer = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion + +# Field preferences +dotnet_style_readonly_field = true:suggestion + +# Parameter preferences +dotnet_code_quality_unused_parameters = all:suggestion + +#### C# Coding Conventions #### + +# var preferences +csharp_style_var_elsewhere = false:silent +csharp_style_var_for_built_in_types = false:silent +csharp_style_var_when_type_is_apparent = false:silent + +# Expression-bodied members +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent + +# Pattern matching preferences +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_prefer_switch_expression = true:suggestion + +# Null-checking preferences +csharp_style_conditional_delegate_call = true:suggestion + +# Modifier preferences +csharp_prefer_static_local_function = true:suggestion +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent + +# Code-block preferences +csharp_prefer_braces = true:silent +csharp_prefer_simple_using_statement = true:suggestion + +# Expression-level preferences +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_pattern_local_over_anonymous_function = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent + +# 'using' directive preferences +csharp_using_directive_placement = outside_namespace:warning + +#### C# Formatting Rules #### + +# New line preferences +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +# Indentation preferences +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = false +csharp_indent_labels = flush_left +csharp_indent_switch_labels = true + +# Space preferences +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# Wrapping preferences +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = false + +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = warning +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.method_should_be_pascal_case.severity = warning +dotnet_naming_rule.method_should_be_pascal_case.symbols = method +dotnet_naming_rule.method_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.severity = warning +dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.symbols = public_or_protected_field +dotnet_naming_rule.public_or_protected_field_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.private_or_internal_static_field_should_be_pascal_case.severity = warning +dotnet_naming_rule.private_or_internal_static_field_should_be_pascal_case.symbols = private_or_internal_static_field +dotnet_naming_rule.private_or_internal_static_field_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.private_or_internal_field_should_be_camelcase.severity = warning +dotnet_naming_rule.private_or_internal_field_should_be_camelcase.symbols = private_or_internal_field +dotnet_naming_rule.private_or_internal_field_should_be_camelcase.style = camelcase + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.method.applicable_kinds = method +dotnet_naming_symbols.method.applicable_accessibilities = public +dotnet_naming_symbols.method.required_modifiers = + +dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field +dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected +dotnet_naming_symbols.public_or_protected_field.required_modifiers = + +dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field +dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected +dotnet_naming_symbols.private_or_internal_field.required_modifiers = + +dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field +dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private, private_protected +dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.camelcase.required_prefix = +dotnet_naming_style.camelcase.required_suffix = +dotnet_naming_style.camelcase.word_separator = +dotnet_naming_style.camelcase.capitalization = camel_case + diff --git a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJAliasesFixture.cs b/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJAliasesFixture.cs deleted file mode 100644 index 7724e634..00000000 --- a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJAliasesFixture.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace Cake.AsciiDoctorJ.Tests -{ - using Cake.Core; - using Cake.Core.IO; - using Cake.Testing; - using Moq; - - public class AsciiDoctorJAliasesFixture : AsciiDoctorJRunnerFixture - { - internal ICakeContext _context; - - public AsciiDoctorJAliasesFixture() - { - var argumentsMoq = new Mock(); - var registryMoq = new Mock(); - var dataService = new Mock(); - _context = new CakeContext( - FileSystem, - Environment, - Globber, - new FakeLog(), - argumentsMoq.Object, - ProcessRunner, - registryMoq.Object, - Tools, dataService.Object, - Configuration); - } - - protected override void RunTool() - { - if (Settings == null) - { - AsciiDoctorJAliases.AsciiDoctorJ(_context); - } - else - { - AsciiDoctorJAliases.AsciiDoctorJ(_context, Settings); - } - } - } -} diff --git a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJAliasesTests.cs b/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJAliasesTests.cs index 55ae6b9e..040a5871 100644 --- a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJAliasesTests.cs +++ b/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJAliasesTests.cs @@ -1,28 +1,64 @@ +using System; + +using Cake.AsciiDoctorJ.Tests.Fixtures; + +using FluentAssertions; + +using Xunit; + namespace Cake.AsciiDoctorJ.Tests { - using System; - using Cake.Core; - using FluentAssertions; - using Moq; - using NUnit.Framework; - - [TestFixture] - [TestOf(typeof(AsciiDoctorJAliases))] public class AsciiDoctorJAliasesTests { - private ICakeContext context; + [Fact] + public void Should_throw_if_settings_are_null() + { + var fixture = new AsciiDoctorJAliasesFixture(); + fixture.GivenSettingsIsNull(); - [SetUp] - public void Setup() + Action action = () => fixture.Run(); + action.Should().Throw().WithMessage("*settings"); + } + + [Fact] + public void Should_not_throw_if_settings_are_set() { - context = new Mock().Object; // TODO: Is there nothin in Cake.Testing?! + var fixture = new AsciiDoctorJAliasesFixture(); + + var actual = fixture.Run(); + + actual.Args.Should().Be(""); } - [Test] - public void Should_Throw_If_Settings_Are_Null() + [Fact] + public void Should_not_throw_if_settings_are_null_but_called_fluently() { - Action action = () => AsciiDoctorJAliases.AsciiDoctorJ(context, (AsciiDoctorJRunnerSettings)null); - action.Should().Throw().WithMessage("*settings"); + var fixture = new AsciiDoctorJAliasesFixture(); + fixture.GivenSettingsIsNull(); + + var actual = fixture.RunFluent(x => { }); + + actual.Args.Should().Be(""); + } + + [Fact] + public void Should_throw_if_context_is_null() + { + var fixture = new AsciiDoctorJAliasesFixture(); + fixture.GivenContextIsNull(); + + Action action = () => fixture.Run(); + action.Should().Throw().WithMessage("*context"); + } + + [Fact] + public void Should_throw_if_context_is_null_called_fluently() + { + var fixture = new AsciiDoctorJAliasesFixture(); + fixture.GivenContextIsNull(); + + Action action = () => fixture.RunFluent(x => { }); + action.Should().Throw().WithMessage("*context"); } } } diff --git a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJRunnerFixture.cs b/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJRunnerFixture.cs deleted file mode 100644 index 5eb9c156..00000000 --- a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJRunnerFixture.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Cake.AsciiDoctorJ.Tests -{ - using Cake.Testing.Fixtures; - - public class AsciiDoctorJRunnerFixture : ToolFixture - { - public AsciiDoctorJRunnerFixture() - : base("AsciiDoctorJ.exe") - { - } - - protected override void RunTool() - { - var tool = new AsciiDoctorJRunner(FileSystem, Environment, ProcessRunner, Tools); - tool.Run(Settings); - } - } -} diff --git a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJRunnerTests.cs b/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJRunnerTests.cs index c68d9c49..385a7d34 100644 --- a/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJRunnerTests.cs +++ b/src/Cake.AsciiDoctorJ.Tests/AsciiDoctorJRunnerTests.cs @@ -1,17 +1,33 @@ +using System; + +using Cake.AsciiDoctorJ.Tests.Fixtures; +using Cake.Core; +using Cake.Testing; + +using FluentAssertions; + +using Xunit; + namespace Cake.AsciiDoctorJ.Tests { - using System; - using Cake.Core; - using Cake.Testing; - using FluentAssertions; - using NUnit.Framework; - - [TestFixture] - [TestOf(typeof(AsciiDoctorJRunner))] public class AsciiDoctorJRunnerTests { - [Test] - public void Should_Throw_If_AsciiDoctorJ_Executable_Was_Not_Found() + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + var fixture = new AsciiDoctorJRunnerFixture(); + fixture.GivenSettingsIsNull(); + + Action result = () => + { + fixture.Run(); + }; + + result.Should().Throw(); + } + + [Fact] + public void Should_throw_if_asciidoctorj_executable_was_not_found() { var fixture = new AsciiDoctorJRunnerFixture(); fixture.GivenDefaultToolDoNotExist(); @@ -20,5 +36,39 @@ public void Should_Throw_If_AsciiDoctorJ_Executable_Was_Not_Found() Action result = () => fixture.Run(); result.Should().Throw().Where(ex => ex.Message.Contains(expectedMessage)); } + + [Fact] + public void Should_not_throw_if_asciidoctorj_executable_was_found() + { + var fixture = new AsciiDoctorJRunnerFixture(); + + var actual = fixture.RunFluent(x => { }); + + actual.Args.Should().Be(""); + } + + [Fact] + public void Should_not_throw_if_settings_are_null_on_fluent_invocation() + { + var fixture = new AsciiDoctorJRunnerFixture(); + fixture.GivenSettingsIsNull(); + + var actual = fixture.RunFluent(x => { }); + + actual.Args.Should().Be(""); + } + + [Fact] + public void Should_not_throw_if_settings_and_action_are_null_on_fluent_invocation() + { + var fixture = new AsciiDoctorJRunnerFixture + { + Settings = null + }; + + var actual = fixture.RunFluent(null); + + actual.Args.Should().Be(""); + } } } diff --git a/src/Cake.AsciiDoctorJ.Tests/Cake.AsciiDoctorJ.Tests.csproj b/src/Cake.AsciiDoctorJ.Tests/Cake.AsciiDoctorJ.Tests.csproj index a06581ca..b344e85c 100644 --- a/src/Cake.AsciiDoctorJ.Tests/Cake.AsciiDoctorJ.Tests.csproj +++ b/src/Cake.AsciiDoctorJ.Tests/Cake.AsciiDoctorJ.Tests.csproj @@ -1,11 +1,13 @@ - netcoreapp2.0 + netcoreapp2.1 $(TargetFrameworks);net461 + ..\Cake.AsciiDoctorJ.ruleset false - + + Cake.AsciiDoctorJ.Tests @@ -19,10 +21,19 @@ + - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + runtime; build; native; contentfiles; analyzers + all + diff --git a/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJAliasesFixture.cs b/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJAliasesFixture.cs new file mode 100644 index 00000000..b76cf296 --- /dev/null +++ b/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJAliasesFixture.cs @@ -0,0 +1,50 @@ +using System; +using System.Linq; + +using Cake.Core; +using Cake.Core.IO; +using Cake.Testing; +using Cake.Testing.Fixtures; + +using Moq; + +namespace Cake.AsciiDoctorJ.Tests.Fixtures +{ + internal class AsciiDoctorJAliasesFixture : AsciiDoctorJRunnerFixture + { + private ICakeContext context; + + public AsciiDoctorJAliasesFixture() + { + var argumentsMoq = new Mock(); + var registryMoq = new Mock(); + var dataService = new Mock(); + context = new CakeContext( + FileSystem, + Environment, + Globber, + new FakeLog(), + argumentsMoq.Object, + ProcessRunner, + registryMoq.Object, + Tools, dataService.Object, + Configuration); + } + + internal void GivenContextIsNull() + { + context = null; + } + + internal new ToolFixtureResult RunFluent(Action configure) + { + context.AsciiDoctorJ(configure); + return ProcessRunner.Results.LastOrDefault(); + } + + protected override void RunTool() + { + context.AsciiDoctorJ(Settings); + } + } +} diff --git a/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJRunnerFixture.cs b/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJRunnerFixture.cs new file mode 100644 index 00000000..4d8ebb4a --- /dev/null +++ b/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJRunnerFixture.cs @@ -0,0 +1,33 @@ +using System; +using System.Linq; + +using Cake.Testing.Fixtures; + +namespace Cake.AsciiDoctorJ.Tests.Fixtures +{ + public class AsciiDoctorJRunnerFixture : ToolFixture + { + public AsciiDoctorJRunnerFixture() + : base("asciidoctorj.exe") + { + } + + public void GivenSettingsIsNull() + { + Settings = null; + } + + public ToolFixtureResult RunFluent(Action configure) + { + var tool = new AsciiDoctorJRunner(FileSystem, Environment, ProcessRunner, Tools); + tool.Run(configure, Settings); + return ProcessRunner.Results.LastOrDefault(); + } + + protected override void RunTool() + { + var tool = new AsciiDoctorJRunner(FileSystem, Environment, ProcessRunner, Tools); + tool.Run(Settings); + } + } +} diff --git a/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJRunnerSettingsExtensionsFixture.cs b/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJRunnerSettingsExtensionsFixture.cs new file mode 100644 index 00000000..c6c13f19 --- /dev/null +++ b/src/Cake.AsciiDoctorJ.Tests/Fixtures/AsciiDoctorJRunnerSettingsExtensionsFixture.cs @@ -0,0 +1,18 @@ +using Cake.Core.IO; +using Cake.Testing; + +namespace Cake.AsciiDoctorJ.Tests.Fixtures +{ + public class AsciiDoctorJRunnerSettingsExtensionsFixture + { + public string EvaluateArgs(AsciiDoctorJRunnerSettings settings) + { + var args = new ProcessArgumentBuilder(); + var environment = FakeEnvironment.CreateWindowsEnvironment(); + + settings.Evaluate(args, environment); + + return args.Render(); + } + } +} diff --git a/src/Cake.AsciiDoctorJ.Tests/SettingsExtensionsTests.cs b/src/Cake.AsciiDoctorJ.Tests/SettingsExtensionsTests.cs index a980144b..a82fb5e0 100644 --- a/src/Cake.AsciiDoctorJ.Tests/SettingsExtensionsTests.cs +++ b/src/Cake.AsciiDoctorJ.Tests/SettingsExtensionsTests.cs @@ -1,88 +1,233 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +using Cake.AsciiDoctorJ.Tests.Fixtures; +using Cake.Core.IO; + +using FluentAssertions; + +using Xunit; + namespace Cake.AsciiDoctorJ.Tests { - using Cake.Core; - using Cake.Core.IO; - using NUnit.Framework; - using FluentAssertions; - using Cake.Testing; - - [TestFixture] - [TestOf(typeof(AsciiDoctorJRunnerSettingsExtensions))] public class SettingsExtensionsTests { - // TODO: It would be better (i.e. more isolated) to test whether the extensions use the settings "correctly"... - - private ICakeEnvironment environment; - - [SetUp] - public void Setup() - { - environment = FakeEnvironment.CreateWindowsEnvironment(); - } - - [TestCase("WithVersion", "--version")] - [TestCase("WithVerbose", "--verbose")] - [TestCase("WithTimingsMode", "--timings")] - [TestCase("WithSectionNumbers", "--section-numbers")] - [TestCase("WithRequire", "--require")] - [TestCase("WithQuiet", "--quiet")] - [TestCase("WithSuppressHeaderAndFooter", "--no-header-footer")] - [TestCase("WithCompact", "--compact")] - public void Should_Convert_All_Flags_To_Arguments(string extensionName, string expectedParam) + [Theory] + [ClassData(typeof(TestData))] + public void Should_convert_all_extensions_to_arguments(Action setFlag, string expectedParam) { - var args = new ProcessArgumentBuilder(); + var fixture = new AsciiDoctorJRunnerSettingsExtensionsFixture(); var sut = new AsciiDoctorJRunnerSettings(); - var ext = typeof(AsciiDoctorJRunnerSettingsExtensions).GetMethod(extensionName, - System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); - ext.Invoke(null, new object[] { sut }); + setFlag(sut); - sut.Evaluate(args, environment); - - var actual = args.Render(); + var actual = fixture.EvaluateArgs(sut); actual.Should().Contain(expectedParam); } - [TestCase(SafeMode.Safe, "--safe-mode safe")] - [TestCase(SafeMode.Unsafe, "--safe-mode unsafe")] - [TestCase(SafeMode.Secure, "--safe-mode secure")] - [TestCase(SafeMode.Server, "--safe-mode server")] - public void Should_Convert_SafeMode_Settings_To_Arguments(SafeMode mode, string expected) + [Theory] + [ClassData(typeof(ArgSetterTestData))] + public void Should_convert_all_extensions_to_setArgs( + Action setFlag, + Func getFlag, + object expected) { - var args = new ProcessArgumentBuilder(); - var sut = new AsciiDoctorJRunnerSettings().WithSafeMode(mode); - - sut.Evaluate(args, environment); - - var actual = args.Render(); - actual.Should().Contain(expected); + var sut = new AsciiDoctorJRunnerSettings(); + setFlag(sut); + + var actual = getFlag(sut); + + if (!(actual is string) && actual is IEnumerable enumerable) + { + enumerable.Should().BeEquivalentTo((IEnumerable)expected); + } + else + { + actual.Should().Be(expected); + } } - [TestCase(ERuby.Erb, "--eruby erb")] - [TestCase(ERuby.Erubis, "--eruby erubis")] - public void Should_Convert_Eruby_Settings_To_Arguments(ERuby eruby, string expected) + [Theory] + [ClassData(typeof(RetValTestData))] + public void Should_return_the_settings_for_fluent_re_use(Func fluentMethod) { - var args = new ProcessArgumentBuilder(); - var sut = new AsciiDoctorJRunnerSettings().WithERuby(eruby); + var sut = new AsciiDoctorJRunnerSettings(); - sut.Evaluate(args, environment); + var actual = fluentMethod(sut); - var actual = args.Render(); - actual.Should().Contain(expected); + actual.Should().Be(sut); } - [TestCase(DocType.Article, "--doctype article")] - [TestCase(DocType.Book, "--doctype book")] - [TestCase(DocType.Inline, "--doctype inline")] - public void Should_Convert_DocType_Settings_To_Arguments(DocType type, string expected) + private class TestData : IEnumerable { - var args = new ProcessArgumentBuilder(); - var sut = new AsciiDoctorJRunnerSettings().WithDocType(type); + private IEnumerable<(Action, string)> GetTestData() + { + // flags + yield return (s => s.WithVersion(), "--version"); + yield return (s => s.WithVerbose(), "--verbose"); + yield return (s => s.WithTimingsMode(), "--timings"); + yield return (s => s.WithSectionNumbers(), "--section-numbers"); + yield return (s => s.WithRequire(), "--require"); + yield return (s => s.WithQuiet(), "--quiet"); + yield return (s => s.WithSuppressHeaderAndFooter(), "--no-header-footer"); + yield return (s => s.WithCompact(), "--compact"); + + // safemode-arg + yield return (s => s.WithSafeMode(SafeMode.Safe), "--safe-mode safe"); + yield return (s => s.WithSafeMode(SafeMode.Unsafe), "--safe-mode unsafe"); + yield return (s => s.WithSafeMode(SafeMode.Secure), "--safe-mode secure"); + yield return (s => s.WithSafeMode(SafeMode.Server), "--safe-mode server"); + + // eruby-arg + yield return (s => s.WithERuby(ERuby.Erb), "--eruby erb"); + yield return (s => s.WithERuby(ERuby.Erubis), "--eruby erubis"); + + // doctype-arg + yield return (s => s.WithDocType(DocType.Article), "--doctype article"); + yield return (s => s.WithDocType(DocType.Book), "--doctype book"); + yield return (s => s.WithDocType(DocType.Inline), "--doctype inline"); + + // builtin backend - arg + yield return (s => s.WithBuiltinBackend(BuiltinBackend.DocBook), "--backend docbook"); + yield return (s => s.WithBuiltinBackend(BuiltinBackend.DocBook5), "--backend docbook5"); + yield return (s => s.WithBuiltinBackend(BuiltinBackend.Html), "--backend html"); + yield return (s => s.WithBuiltinBackend(BuiltinBackend.Html5), "--backend html5"); + yield return (s => s.WithBuiltinBackend(BuiltinBackend.Manpage), "--backend manpage"); + yield return (s => s.WithBuiltinBackend(BuiltinBackend.Xhtml), "--backend xhtml"); + yield return (s => s.WithBuiltinBackend(BuiltinBackend.Xhtml5), "--backend xhtml5"); + + // misc args + yield return (s => s.WithTemplateEngine("some-engine"), "--template-engine some-engine"); + yield return (s => s.WithTemplateDir(new DirectoryPath("/foo")), "--template-dir \"/foo\""); + yield return (s => s.WithOutputFile(new FilePath("/foo.pdf")), "--out-file \"/foo.pdf\""); + yield return (s => s.WithLoadPath(new DirectoryPath("/foo")), "--load-path \"/foo\""); + yield return (s => s.WithLoadPaths(new[] { new DirectoryPath("/foo"), new DirectoryPath("/bar") }), "--load-path \"/foo\" --load-path \"/bar\""); + yield return (s => s.WithDestinationDir(new DirectoryPath("/foo")), "--destination-dir \"/foo\""); + yield return (s => s.WithClassPath(new DirectoryPath("/foo")), "--classpath \"/foo\""); + yield return (s => s.WithClassPaths(new[] { new DirectoryPath("/foo"), new DirectoryPath("/bar") }), "--classpath \"/foo\" --classpath \"/bar\""); + yield return (s => s.WithBaseDir(new DirectoryPath("/foo")), "--base-dir \"/foo\""); + yield return (s => s.WithBackend("pdf"), "--backend pdf"); + yield return (s => s.WithAttribute("foo", "bar"), "--attribute foo=bar"); + yield return (s => s.WithAttributes(new Dictionary { { "foo", "bar" }, { "bim", "bam" } }), "--attribute foo=bar --attribute bim=bam"); + yield return (s => s.WithInputFile(new FilePath("/foo.adoc")), "/foo.adoc"); + yield return (s => s.WithInputFiles(new[] { new FilePath("/foo.adoc"), new FilePath("/bar.adoc") }), "\"/foo.adoc\" \"/bar.adoc\""); + } + + public IEnumerator GetEnumerator() + { + return GetTestData().Select(x => new[] { (object)x.Item1, x.Item2 }).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } - sut.Evaluate(args, environment); + private class ArgSetterTestData : IEnumerable + { + private IEnumerable<(Action, + Func, + object)> GetTestData() + { + // flags + yield return (s => s.WithVersion(), s => s.Version, true); + yield return (s => s.WithVerbose(), s => s.Verbose, true); + yield return (s => s.WithTimingsMode(), s => s.TimingsMode, true); + yield return (s => s.WithSectionNumbers(), s => s.SectionNumbers, true); + yield return (s => s.WithRequire(), s => s.Require, true); + yield return (s => s.WithQuiet(), s => s.Quiet, true); + yield return (s => s.WithSuppressHeaderAndFooter(), s => s.SuppressHeaderAndFooter, true); + yield return (s => s.WithCompact(), s => s.Compact, true); + + // safemode-arg + yield return (s => s.WithSafeMode(SafeMode.Safe), s => s.SafeMode, SafeMode.Safe); + yield return (s => s.WithSafeMode(SafeMode.Unsafe), s => s.SafeMode, SafeMode.Unsafe); + yield return (s => s.WithSafeMode(SafeMode.Secure), s => s.SafeMode, SafeMode.Secure); + yield return (s => s.WithSafeMode(SafeMode.Server), s => s.SafeMode, SafeMode.Server); + + // eruby-arg + yield return (s => s.WithERuby(ERuby.Erb), s => s.ERuby, ERuby.Erb); + yield return (s => s.WithERuby(ERuby.Erubis), s => s.ERuby, ERuby.Erubis); + + // doctype-arg + yield return (s => s.WithDocType(DocType.Article), s => s.DocType, DocType.Article); + yield return (s => s.WithDocType(DocType.Book), s => s.DocType, DocType.Book); + yield return (s => s.WithDocType(DocType.Inline), s => s.DocType, DocType.Inline); + + // misc args + var fooDir = new DirectoryPath("/foo"); + var barDir = new DirectoryPath("/bar"); + var fooPdf = new FilePath("foo.pdf"); + var fooAdoc = new FilePath("foo.adoc"); + var barAdoc = new FilePath("bar.adoc"); + var fooBar = new KeyValuePair("foo", "bar"); + var bimBam = new KeyValuePair("bim", "bam"); + yield return (s => s.WithTemplateEngine("some-engine"), s => s.TemplateEngine, "some-engine"); + yield return (s => s.WithTemplateDir(fooDir), s => s.TemplateDir, fooDir); + yield return (s => s.WithOutputFile(fooPdf), s => s.Output, fooPdf); + yield return (s => s.WithLoadPath(fooDir), s => s.LoadPath, new[] { fooDir }); + yield return (s => s.WithLoadPaths(new[] { fooDir, barDir }), s => s.LoadPath, new[] { fooDir, barDir }); + yield return (s => s.WithDestinationDir(fooDir), s => s.DestinationDir, fooDir); + yield return (s => s.WithClassPath(fooDir), s => s.ClassPath, new[] { fooDir }); + yield return (s => s.WithClassPaths(new[] { fooDir, barDir }), s => s.ClassPath, new[] { fooDir, barDir }); + yield return (s => s.WithBaseDir(fooDir), s => s.BaseDir, fooDir); + yield return (s => s.WithBackend("pdf"), s => s.Backend, "pdf"); + yield return (s => s.WithBuiltinBackend(BuiltinBackend.Html), s => s.Backend, "html"); + yield return (s => s.WithAttribute(fooBar.Key, fooBar.Value), s => s.Attributes, new[] { fooBar }); + yield return (s => s.WithAttributes(new[] { fooBar, bimBam }), s => s.Attributes, new[] { fooBar, bimBam }); + yield return (s => s.WithInputFile(fooAdoc), s => s.InputFiles, new[] { fooAdoc }); + yield return (s => s.WithInputFiles(new[] { fooAdoc, barAdoc }), s => s.InputFiles, new[] { fooAdoc, barAdoc }); + } + + public IEnumerator GetEnumerator() + { + return GetTestData().Select(x => new[] { (object)x.Item1, x.Item2, x.Item3 }).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } - var actual = args.Render(); - actual.Should().Contain(expected); + private class RetValTestData : IEnumerable + { + private IEnumerable> GetTestData() + { + // flags + yield return s => s.WithVersion(); + yield return s => s.WithVerbose(); + yield return s => s.WithTimingsMode(); + yield return s => s.WithSectionNumbers(); + yield return s => s.WithRequire(); + yield return s => s.WithQuiet(); + yield return s => s.WithSuppressHeaderAndFooter(); + yield return s => s.WithCompact(); + + // args + yield return s => s.WithSafeMode(SafeMode.Safe); + yield return s => s.WithERuby(ERuby.Erubis); + yield return s => s.WithDocType(DocType.Inline); + yield return s => s.WithTemplateEngine("some-engine"); + yield return s => s.WithTemplateDir(new DirectoryPath("/foo")); + yield return s => s.WithOutputFile(new FilePath("/foo.pdf")); + yield return s => s.WithLoadPath(new DirectoryPath("/foo")); + yield return s => s.WithLoadPaths(new[] { new DirectoryPath("/foo"), new DirectoryPath("/bar") }); + yield return s => s.WithDestinationDir(new DirectoryPath("/foo")); + yield return s => s.WithClassPath(new DirectoryPath("/foo")); + yield return s => s.WithClassPaths(new[] { new DirectoryPath("/foo"), new DirectoryPath("/bar") }); + yield return s => s.WithBaseDir(new DirectoryPath("/foo")); + yield return s => s.WithBuiltinBackend(BuiltinBackend.Html); + yield return s => s.WithBackend("pdf"); + yield return s => s.WithAttribute("foo", "bar"); + yield return s => s.WithAttributes(new Dictionary { { "foo", "bar" }, { "bim", "bam" } }); + yield return s => s.WithInputFile(new FilePath("/foo.adoc")); + yield return s => s.WithInputFiles(new[] { new FilePath("/foo.adoc"), new FilePath("/bar.adoc") }); + } + + public IEnumerator GetEnumerator() + { + return GetTestData().Select(x => new[] { (object)x }).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } } diff --git a/src/Cake.AsciiDoctorJ.Tests/SettingsTests.cs b/src/Cake.AsciiDoctorJ.Tests/SettingsTests.cs index 50afb9ad..93bbf212 100644 --- a/src/Cake.AsciiDoctorJ.Tests/SettingsTests.cs +++ b/src/Cake.AsciiDoctorJ.Tests/SettingsTests.cs @@ -1,94 +1,77 @@ +using FluentAssertions; +using Xunit; +using System.Collections; +using System.Collections.Generic; +using System; +using Cake.AsciiDoctorJ.Tests.Fixtures; +using System.Linq; +using Cake.Core.IO; + namespace Cake.AsciiDoctorJ.Tests { - using Cake.Core; - using Cake.Core.IO; - using NUnit.Framework; - using FluentAssertions; - using Cake.Testing; - - [TestFixture] - [TestOf(typeof(AsciiDoctorJRunnerSettings))] public class SettingsTests { - private ICakeEnvironment environment; - - [SetUp] - public void Setup() + [Theory] + [ClassData(typeof(TestData))] + public void Should_convert_all_setters_to_arguments(Action setFlag, string expectedParam) { - environment = FakeEnvironment.CreateWindowsEnvironment(); - } - - [TestCase("Version", "--version")] - [TestCase("Verbose", "--verbose")] - [TestCase("TimingsMode", "--timings")] - [TestCase("SectionNumbers", "--section-numbers")] - [TestCase("Require", "--require")] - [TestCase("Quiet", "--quiet")] - [TestCase("SuppressHeaderAndFooter", "--no-header-footer")] - [TestCase("Compact", "--compact")] - public void Should_Convert_All_Flags_To_Arguments(string propertyName, string expectedParam) - { - var args = new ProcessArgumentBuilder(); + var fixture = new AsciiDoctorJRunnerSettingsExtensionsFixture(); var sut = new AsciiDoctorJRunnerSettings(); - var prop = typeof(AsciiDoctorJRunnerSettings).GetProperty(propertyName); - prop.SetValue(sut, true); - - sut.Evaluate(args, environment); + setFlag(sut); - var actual = args.Render(); + var actual = fixture.EvaluateArgs(sut); actual.Should().Contain(expectedParam); } - [TestCase(SafeMode.Safe, "--safe-mode safe")] - [TestCase(SafeMode.Unsafe, "--safe-mode unsafe")] - [TestCase(SafeMode.Secure, "--safe-mode secure")] - [TestCase(SafeMode.Server, "--safe-mode server")] - public void Should_Convert_SafeMode_Settings_To_Arguments(SafeMode mode, string expected) + private class TestData : IEnumerable { - var args = new ProcessArgumentBuilder(); - var sut = new AsciiDoctorJRunnerSettings + private IEnumerable<(Action, string)> GetTestData() { - SafeMode = mode - }; + // flags + yield return (s => s.Version = true, "--version"); + yield return (s => s.Verbose = true, "--verbose"); + yield return (s => s.TimingsMode = true, "--timings"); + yield return (s => s.SectionNumbers = true, "--section-numbers"); + yield return (s => s.Require = true, "--require"); + yield return (s => s.Quiet = true, "--quiet"); + yield return (s => s.SuppressHeaderAndFooter = true, "--no-header-footer"); + yield return (s => s.Compact = true, "--compact"); - sut.Evaluate(args, environment); + // safemode-arg + yield return (s => s.SafeMode = SafeMode.Safe, "--safe-mode safe"); + yield return (s => s.SafeMode = SafeMode.Unsafe, "--safe-mode unsafe"); + yield return (s => s.SafeMode = SafeMode.Secure, "--safe-mode secure"); + yield return (s => s.SafeMode = SafeMode.Server, "--safe-mode server"); - var actual = args.Render(); - actual.Should().Contain(expected); - } + // eruby-arg + yield return (s => s.ERuby = ERuby.Erb, "--eruby erb"); + yield return (s => s.ERuby = ERuby.Erubis, "--eruby erubis"); - [TestCase(ERuby.Erb, "--eruby erb")] - [TestCase(ERuby.Erubis, "--eruby erubis")] - public void Should_Convert_Eruby_Settings_To_Arguments(ERuby eruby, string expected) - { - var args = new ProcessArgumentBuilder(); - var sut = new AsciiDoctorJRunnerSettings - { - ERuby = eruby - }; + // doctype-arg + yield return (s => s.DocType = DocType.Article, "--doctype article"); + yield return (s => s.DocType = DocType.Book, "--doctype book"); + yield return (s => s.DocType = DocType.Inline, "--doctype inline"); - sut.Evaluate(args, environment); + // misc args + yield return (s => s.TemplateEngine = "some-engine", "--template-engine some-engine"); + yield return (s => s.TemplateDir = new DirectoryPath("/foo"), "--template-dir \"/foo\""); + yield return (s => s.Output = new FilePath("/foo.pdf"), "--out-file \"/foo.pdf\""); + yield return (s => s.LoadPath.Add(new DirectoryPath("/foo")), "--load-path \"/foo\""); + yield return (s => s.DestinationDir = new DirectoryPath("/foo"), "--destination-dir \"/foo\""); + yield return (s => s.ClassPath.Add(new DirectoryPath("/foo")), "--classpath \"/foo\""); + yield return (s => s.BaseDir = new DirectoryPath("/foo"), "--base-dir \"/foo\""); + yield return (s => s.Backend = "pdf", "--backend pdf"); + yield return (s => s.Attributes.Add("foo", "bar"), "--attribute foo=bar"); + yield return (s => s.InputFiles.Add(new FilePath("/foo.adoc")), "\"/foo.adoc\""); + } - var actual = args.Render(); - actual.Should().Contain(expected); - } - - [TestCase(DocType.Article, "--doctype article")] - [TestCase(DocType.Book, "--doctype book")] - [TestCase(DocType.Inline, "--doctype inline")] - public void Should_Convert_DocType_Settings_To_Arguments(DocType type, string expected) - { - var args = new ProcessArgumentBuilder(); - var sut = new AsciiDoctorJRunnerSettings + public IEnumerator GetEnumerator() { - DocType = type - }; - - sut.Evaluate(args, environment); + return GetTestData().Select(x => new[] { (object)x.Item1, x.Item2 }).GetEnumerator(); + } - var actual = args.Render(); - actual.Should().Contain(expected); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } } diff --git a/src/Cake.AsciiDoctorJ.ruleset b/src/Cake.AsciiDoctorJ.ruleset new file mode 100644 index 00000000..48e4826c --- /dev/null +++ b/src/Cake.AsciiDoctorJ.ruleset @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Cake.AsciiDoctorJ.sln b/src/Cake.AsciiDoctorJ.sln index 1391ee91..0b619f70 100644 --- a/src/Cake.AsciiDoctorJ.sln +++ b/src/Cake.AsciiDoctorJ.sln @@ -1,15 +1,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 MinimumVisualStudioVersion = 15.0.26124.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.AsciiDoctorJ", "Cake.AsciiDoctorJ\Cake.AsciiDoctorJ.csproj", "{9C63DC31-720C-4593-A5B7-142B117A88A0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.AsciiDoctorJ", "Cake.AsciiDoctorJ\Cake.AsciiDoctorJ.csproj", "{9C63DC31-720C-4593-A5B7-142B117A88A0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.AsciiDoctorJ.Tests", "Cake.AsciiDoctorJ.Tests\Cake.AsciiDoctorJ.Tests.csproj", "{21300EC0-81FE-4956-A067-5A085F1535B1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cake.AsciiDoctorJ.Tests", "Cake.AsciiDoctorJ.Tests\Cake.AsciiDoctorJ.Tests.csproj", "{21300EC0-81FE-4956-A067-5A085F1535B1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{923BD407-CE67-4226-8AE7-8A4910190545}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + Cake.AsciiDoctorJ.ruleset = Cake.AsciiDoctorJ.ruleset + Cake.AsciiDoctorJ.sln.vsspell = Cake.AsciiDoctorJ.sln.vsspell + EndProjectSection EndProject Global - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -24,4 +28,10 @@ Global {21300EC0-81FE-4956-A067-5A085F1535B1}.Release|Any CPU.ActiveCfg = Release|Any CPU {21300EC0-81FE-4956-A067-5A085F1535B1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F178A886-E28A-400D-9A63-011B6C9CE2A8} + EndGlobalSection EndGlobal diff --git a/src/Cake.AsciiDoctorJ.sln.DotSettings b/src/Cake.AsciiDoctorJ.sln.DotSettings new file mode 100644 index 00000000..ed3964a6 --- /dev/null +++ b/src/Cake.AsciiDoctorJ.sln.DotSettings @@ -0,0 +1,3 @@ + + DO_NOT_SHOW + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> \ No newline at end of file diff --git a/src/Cake.AsciiDoctorJ.sln.vsspell b/src/Cake.AsciiDoctorJ.sln.vsspell new file mode 100644 index 00000000..158b2c3f --- /dev/null +++ b/src/Cake.AsciiDoctorJ.sln.vsspell @@ -0,0 +1,33 @@ + + + + True + True + + en-US + + + False + False + False + False + False + False + False + + True + + False + + vsspell.ignoredWords.txt + True + False + + *Tests.cs + Outputs.cs + + False + + + \ No newline at end of file diff --git a/src/Cake.AsciiDoctorJ/AsciiDoctorJAliases.cs b/src/Cake.AsciiDoctorJ/AsciiDoctorJAliases.cs index e98e686e..2531e011 100644 --- a/src/Cake.AsciiDoctorJ/AsciiDoctorJAliases.cs +++ b/src/Cake.AsciiDoctorJ/AsciiDoctorJAliases.cs @@ -1,13 +1,14 @@ +using System; + +using Cake.Core; +using Cake.Core.Annotations; + namespace Cake.AsciiDoctorJ { - using System; - using Cake.Core; - using Cake.Core.Annotations; - /// /// Functions to call AsciiDoctorJ. /// - /// In order to use this addin add the following to your build.cake. + /// In order to use this add-in, add the following to your build.cake. /// @@ -16,7 +17,7 @@ namespace Cake.AsciiDoctorJ public static class AsciiDoctorJAliases { /// - /// Runs the tool using an action to configure seetings. + /// Runs the tool using an action to configure settings. /// /// The . /// An action to configure the . diff --git a/src/Cake.AsciiDoctorJ/AsciiDoctorJRunner.cs b/src/Cake.AsciiDoctorJ/AsciiDoctorJRunner.cs index 9738c4c0..267ee115 100644 --- a/src/Cake.AsciiDoctorJ/AsciiDoctorJRunner.cs +++ b/src/Cake.AsciiDoctorJ/AsciiDoctorJRunner.cs @@ -1,13 +1,14 @@ +using System; +using System.Collections.Generic; + +using Cake.Core; +using Cake.Core.IO; +using Cake.Core.Tooling; + [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Cake.AsciiDoctorJ.Tests")] namespace Cake.AsciiDoctorJ { - using System; - using System.Collections.Generic; - using Cake.Core; - using Cake.Core.IO; - using Cake.Core.Tooling; - /// /// This is the runner. . /// @@ -30,12 +31,17 @@ internal AsciiDoctorJRunner(IFileSystem fileSystem, ICakeEnvironment environment } /// - /// Runs the tool using an action to configure seetings. + /// Runs the tool using an action to configure settings. /// /// The configuration action. - internal void Run(Action configure = null) + /// The settings. + internal void Run(Action configure = null, AsciiDoctorJRunnerSettings settings = null) { - var settings = new AsciiDoctorJRunnerSettings(); + if (settings == null) + { + settings = new AsciiDoctorJRunnerSettings(); + } + configure?.Invoke(settings); Run(settings); } @@ -46,8 +52,13 @@ internal void Run(Action configure = null) /// The settings. internal void Run(AsciiDoctorJRunnerSettings settings) { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + var args = new ProcessArgumentBuilder(); - settings?.Evaluate(args, environment); + settings.Evaluate(args, environment); Run(settings, args); } diff --git a/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettings.cs b/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettings.cs index a3dc468d..2c7ccbba 100644 --- a/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettings.cs +++ b/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettings.cs @@ -1,12 +1,12 @@ +using System; +using System.Collections.Generic; + +using Cake.Core; +using Cake.Core.IO; +using Cake.Core.Tooling; + namespace Cake.AsciiDoctorJ { - using System; - using System.Collections.Generic; - using System.Globalization; - using Cake.Core; - using Cake.Core.IO; - using Cake.Core.Tooling; - /// /// The settings to configure the run of AsciiDoctorJ. /// @@ -110,13 +110,13 @@ public AsciiDoctorJRunnerSettings() /// /// Gets the list of input files to be processed. /// - public IList InputFiles { get; private set; } + public IList InputFiles { get; } /// /// Gets the list of directories to add to the $LOAD_PATH. /// corresponds to: -I, --load-path. /// - public IList LoadPath { get; private set; } + public IList LoadPath { get; } /// /// Gets or sets a value to @@ -154,7 +154,7 @@ public AsciiDoctorJRunnerSettings() /// Gets the list of directories to add to the classpath. /// corresponds to: -cp, -classpath, --classpath. /// - public IList ClassPath { get; private set; } + public IList ClassPath { get; } /// /// Gets or sets a value indicating the @@ -177,7 +177,7 @@ public AsciiDoctorJRunnerSettings() /// Default: []. /// corresponds to: -a, --attribute. /// - public IDictionary Attributes { get; private set; } + public IDictionary Attributes { get; } /// /// Processes the given settings and modifies the . @@ -218,7 +218,10 @@ internal void Evaluate(ProcessArgumentBuilder args, ICakeEnvironment environment if (SafeMode.HasValue) { - args.Append("--safe-mode " + Enum.GetName(typeof(SafeMode), SafeMode.Value).ToLower(CultureInfo.InvariantCulture)); + // ReSharper disable PossibleNullReferenceException + args.Append("--safe-mode " + Enum.GetName(typeof(SafeMode), SafeMode.Value).ToLowerInvariant()); + + // ReSharper enable PossibleNullReferenceException } if (Require) @@ -248,17 +251,23 @@ internal void Evaluate(ProcessArgumentBuilder args, ICakeEnvironment environment if (ERuby.HasValue) { - args.Append("--eruby " + Enum.GetName(typeof(ERuby), ERuby.Value).ToLower(CultureInfo.InvariantCulture)); + // ReSharper disable PossibleNullReferenceException + args.Append("--eruby " + Enum.GetName(typeof(ERuby), ERuby.Value).ToLowerInvariant()); + + // ReSharper enable PossibleNullReferenceException } if (DocType.HasValue) { - args.Append("--doctype " + Enum.GetName(typeof(DocType), DocType.Value).ToLower(CultureInfo.InvariantCulture)); + args.Append("--doctype " + Enum.GetName(typeof(DocType), DocType.Value).ToLowerInvariant()); } if (DestinationDir != null) { + // ReSharper disable PossibleNullReferenceException args.Append("--destination-dir " + DestinationDir.MakeAbsolute(environment).FullPath.Quote()); + + // ReSharper enable PossibleNullReferenceException } if (Compact) diff --git a/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettingsExtensions.cs b/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettingsExtensions.cs index 2b464a40..3e46623d 100644 --- a/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettingsExtensions.cs +++ b/src/Cake.AsciiDoctorJ/AsciiDoctorJRunnerSettingsExtensions.cs @@ -1,10 +1,10 @@ +using System; +using System.Collections.Generic; + +using Cake.Core.IO; + namespace Cake.AsciiDoctorJ { - using System; - using System.Collections.Generic; - using System.Globalization; - using Cake.Core.IO; - /// /// Extensions for fluent writing of . /// @@ -305,7 +305,10 @@ public static AsciiDoctorJRunnerSettings WithBackend(this AsciiDoctorJRunnerSett /// The reference to the . public static AsciiDoctorJRunnerSettings WithBuiltinBackend(this AsciiDoctorJRunnerSettings @this, BuiltinBackend backend) { - @this.Backend = Enum.GetName(typeof(BuiltinBackend), backend).ToLower(CultureInfo.InvariantCulture); + // ReSharper disable PossibleNullReferenceException + @this.Backend = Enum.GetName(typeof(BuiltinBackend), backend).ToLowerInvariant(); + + // ReSharper enable PossibleNullReferenceException return @this; } diff --git a/src/Cake.AsciiDoctorJ/Cake.AsciiDoctorJ.csproj b/src/Cake.AsciiDoctorJ/Cake.AsciiDoctorJ.csproj index 7744d884..7d9b16cf 100644 --- a/src/Cake.AsciiDoctorJ/Cake.AsciiDoctorJ.csproj +++ b/src/Cake.AsciiDoctorJ/Cake.AsciiDoctorJ.csproj @@ -2,9 +2,10 @@ netstandard2.0;net461 true - true - snupkg - + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + ..\Cake.AsciiDoctorJ.ruleset @@ -17,19 +18,43 @@ Nils Andresen Copyright © $(FullYear) — Nils Andresen makes [asciidoctorj](https://github.com/asciidoctor/asciidoctorj) available as a tool in [cake](https://cakebuild.net/) - https://cdn.jsdelivr.net/gh/cake-contrib/graphics/png/cake-contrib-medium.png MIT https://cake-contrib.github.io/Cake.AsciiDoctorJ cake;addin;asciidoctorj https://github.com/cake-contrib/Cake.AsciiDoctorJ.git https://github.com/cake-contrib/Cake.AsciiDoctorJ/releases/tag/$(Version) + icon.png + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers all + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + True + + \ No newline at end of file diff --git a/src/Cake.AsciiDoctorJ/GlobalSuppressions.cs b/src/Cake.AsciiDoctorJ/GlobalSuppressions.cs deleted file mode 100644 index cdce3b1b..00000000 --- a/src/Cake.AsciiDoctorJ/GlobalSuppressions.cs +++ /dev/null @@ -1,2 +0,0 @@ -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Not needed here.")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "I don't like that...")] diff --git a/src/Cake.AsciiDoctorJ/icon.png b/src/Cake.AsciiDoctorJ/icon.png new file mode 100644 index 00000000..9881edc4 Binary files /dev/null and b/src/Cake.AsciiDoctorJ/icon.png differ diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 00000000..96fe0f51 --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,6 @@ + + + + 7.3 + + \ No newline at end of file diff --git a/src/vsspell.ignoredWords.txt b/src/vsspell.ignoredWords.txt new file mode 100644 index 00000000..c189f794 --- /dev/null +++ b/src/vsspell.ignoredWords.txt @@ -0,0 +1,10 @@ +backend +dir +classpath +doctype +inline +eruby +pdf +builtin +backends +asciidoctorj