From c5e782569df83087e06ed507196a582c33ad1353 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 19:12:12 +0000 Subject: [PATCH 01/12] Initial plan From 110be48ed07af3282e51d07ab45288d92ee01b50 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 19:24:23 +0000 Subject: [PATCH 02/12] Update project to align with TemplateDotNetTool template - Update .editorconfig to match template format: - Use LF line endings globally (not CRLF for C# files) - Simplified to cleaner template structure - Upgrade naming convention severity from suggestion to warning - Add csharp_nullable_reference_types = enable - Add csharp_prefer_braces = true:warning (was silent) - Add csharp_style_namespace_declarations = file_scoped:warning - Consolidate XML file groups - Convert all C# source and test files from CRLF to LF line endings - Apply dotnet format to fix new csharp_prefer_braces:warning violations - Update .markdownlint-cli2.jsonc: - Remove MD024 (siblings_only) rule not in template - Fix node_modules ignore pattern ('**/node_modules' -> 'node_modules') - Remove comment blocks not in template - Update .cspell.json ignorePaths to match template: - Remove non-template entries: *.csproj, *spdx.json, TestResults, .vs, *.bak - Fix spdx.json pattern to *.spdx.json - Reorder to match template structure - Update .github/ISSUE_TEMPLATE/config.yml: - Add documentation link matching template structure - Update discussions link name from 'Ask a Question' to 'Discussions' - Keep security issue link (VHDLTest-specific) - Add missing .github/ISSUE_TEMPLATE/question.yml (adapted from template) - Update .github/pull_request_template.md: - Add self-validation tests step with VHDLTest project path - Fix YAML linter command to match template (yamllint .) - Update 'All tests pass' to 'All unit tests pass' to match template - Update AGENTS.md: - Add Agent Selection Guide section - Add Project Structure section - Add Documentation section - Add Markdown Link Style section - Add CI/CD section - Add Agent Report Files section - Update Key Files to reference dotnet reqstream --enforce - Update Requirements section to use reqstream enforcement - Update Code Style section with full details - Update .github/agents/requirements-agent.md: - Add Test Source Filters section (matches template) - Update enforcement command to use dotnet reqstream - Update .github/dependabot.yml: - Rename NuGet group from 'dotnet-dependencies' to 'nuget-dependencies' - Update .github/workflows/build.yaml: - Fix quality check step names to match template: 'Spell Check' -> 'Run spell checker' 'Markdown Lint' -> 'Run markdown linter' 'YAML Lint' -> 'Run YAML linter' - Reorder quality checks: markdown first, then spell check, then YAML - Add name field to build job ('Build ${{ matrix.os }}') - Reorder build job: name, needs, permissions (matches template) - Remove inline comments from build job permissions - Add --pdf-variant pdf/a-3u to all Weasyprint PDF generation steps - Fix SonarMark step to use shell:bash and bash-compatible $SONAR_TOKEN --- .cspell.json | 13 +- .editorconfig | 246 +------ .github/ISSUE_TEMPLATE/config.yml | 5 +- .github/ISSUE_TEMPLATE/question.yml | 82 +++ .github/agents/requirements-agent.md | 18 +- .github/dependabot.yml | 2 +- .github/pull_request_template.md | 7 +- .github/workflows/build.yaml | 32 +- .markdownlint-cli2.jsonc | 5 +- AGENTS.md | 89 ++- src/DEMAConsulting.VHDLTest/ConfigDocument.cs | 128 ++-- src/DEMAConsulting.VHDLTest/Context.cs | 677 +++++++++--------- src/DEMAConsulting.VHDLTest/Options.cs | 112 +-- src/DEMAConsulting.VHDLTest/Program.cs | 330 ++++----- .../Results/TestResult.cs | 134 ++-- .../Results/TestResults.cs | 475 ++++++------ src/DEMAConsulting.VHDLTest/Run/RunLine.cs | 56 +- .../Run/RunLineRule.cs | 88 +-- .../Run/RunLineType.cs | 94 +-- .../Run/RunProcessor.cs | 206 +++--- src/DEMAConsulting.VHDLTest/Run/RunProgram.cs | 136 ++-- src/DEMAConsulting.VHDLTest/Run/RunResults.cs | 128 ++-- .../Simulators/ActiveHdlSimulator.cs | 378 +++++----- .../Simulators/GhdlSimulator.cs | 340 ++++----- .../Simulators/MockSimulator.cs | 310 ++++---- .../Simulators/ModelSimSimulator.cs | 357 ++++----- .../Simulators/NvcSimulator.cs | 338 ++++----- .../Simulators/QuestaSimSimulator.cs | 357 ++++----- .../Simulators/Simulator.cs | 254 +++---- .../Simulators/SimulatorFactory.cs | 122 ++-- .../Simulators/VivadoSimulator.cs | 354 ++++----- src/DEMAConsulting.VHDLTest/Validation.cs | 630 ++++++++-------- .../ActiveHdlSimulatorTests.cs | 416 +++++------ .../ConfigDocumentTests.cs | 172 ++--- .../ContextTests.cs | 542 +++++++------- .../ExitCodeTests.cs | 346 ++++----- .../GhdlSimulatorTests.cs | 416 +++++------ .../GlobalUsings.cs | 48 +- .../ModelSimSimulatorTests.cs | 368 +++++----- .../NvcSimulatorTests.cs | 464 ++++++------ .../OptionsTests.cs | 296 ++++---- .../QuestaSimSimulatorTests.cs | 416 +++++------ .../RunProcessorTests.cs | 184 ++--- test/DEMAConsulting.VHDLTest.Tests/Runner.cs | 130 ++-- .../SimulatorFactoryTests.cs | 200 +++--- .../TestResultTests.cs | 178 ++--- .../TestResultsTests.cs | 500 ++++++------- .../UsageTests.cs | 216 +++--- .../ValidationTests.cs | 256 +++---- .../VersionTests.cs | 154 ++-- .../VivadoSimulatorTests.cs | 368 +++++----- 51 files changed, 6150 insertions(+), 6023 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/question.yml diff --git a/.cspell.json b/.cspell.json index b8cc035..e20a4d3 100644 --- a/.cspell.json +++ b/.cspell.json @@ -71,22 +71,17 @@ ], "ignorePaths": [ "node_modules", + ".git", "bin", "obj", - ".git", - "*.dll", - "*.exe", - "*.pdb", "*.nupkg", "*.snupkg", + "*.dll", + "*.exe", "*.trx", - "*.csproj", - "*spdx.json", + "*.spdx.json", "package-lock.json", "yarn.lock", - "TestResults", - ".vs", - "*.bak", "AGENT_REPORT_*.md" ] } diff --git a/.editorconfig b/.editorconfig index 38f0943..204f58d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,242 +5,66 @@ root = true # All files [*] +charset = utf-8 +end_of_line = lf indent_style = space +indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true -charset = utf-8 - -# Code files -[*.{cs,csx,vb,vbx}] -indent_size = 4 -# XML project files -[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] -indent_size = 2 +# Markdown files +[*.md] +trim_trailing_whitespace = false -# XML config files -[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] +# YAML files +[*.{yml,yaml}] indent_size = 2 # JSON files [*.json] indent_size = 2 -# YAML files -[*.{yml,yaml}] +# XML files +[*.{xml,csproj,props,targets}] indent_size = 2 -# Markdown files -[*.md] -trim_trailing_whitespace = false - -# Shell scripts -[*.sh] -end_of_line = lf - -# Batch files -[*.{cmd,bat}] -end_of_line = crlf - # C# files [*.cs] - -#### Core EditorConfig Options #### - -# Indentation and spacing indent_size = 4 -tab_width = 4 - -# New line preferences -end_of_line = crlf -insert_final_newline = true - -#### .NET Coding Conventions #### - -# Organize usings -dotnet_separate_import_directive_groups = false -dotnet_sort_system_directives_first = true -file_header_template = unset - -# this. and Me. preferences -dotnet_style_qualification_for_event = false:suggestion -dotnet_style_qualification_for_field = false:suggestion -dotnet_style_qualification_for_method = false:suggestion -dotnet_style_qualification_for_property = false:suggestion - -# Language keywords vs BCL types preferences -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion - -# 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:suggestion - -# Expression-level preferences -dotnet_style_coalesce_expression = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_explicit_tuple_names = true:suggestion -dotnet_style_namespace_match_folder = 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:suggestion -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 - -# Suppression preferences -dotnet_remove_unnecessary_suppression_exclusions = none - -#### 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:suggestion -csharp_style_expression_bodied_local_functions = false:silent +# Code style rules +csharp_prefer_braces = true:warning +csharp_prefer_simple_using_statement = true:suggestion +csharp_style_namespace_declarations = file_scoped:warning +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent csharp_style_expression_bodied_operators = false:silent csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false: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_not_pattern = true:suggestion -csharp_style_prefer_pattern_matching = true:silent -csharp_style_prefer_switch_expression = true:suggestion -csharp_style_prefer_extended_property_pattern = true:suggestion - -# Null-checking preferences -csharp_style_conditional_delegate_call = true:suggestion -csharp_style_prefer_parameter_null_checking = 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:suggestion - -# 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_implicit_object_creation_when_type_is_apparent = 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_null_check_over_type_check = 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:silent - -# Namespace preferences -csharp_style_namespace_declarations = file_scoped:suggestion - -#### 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 = true -csharp_indent_labels = one_less_than_current -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 = true - -#### Naming styles #### - -# Naming rules - -dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +# Naming conventions +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 = suggestion +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.non_field_members_should_be_pascal_case.severity = suggestion +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 -dotnet_naming_rule.private_or_internal_field_should_be_begins_with_underscore.severity = suggestion -dotnet_naming_rule.private_or_internal_field_should_be_begins_with_underscore.symbols = private_or_internal_field -dotnet_naming_rule.private_or_internal_field_should_be_begins_with_underscore.style = begins_with_underscore - # 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.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.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 = @@ -250,18 +74,22 @@ dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, int dotnet_naming_symbols.non_field_members.required_modifiers = # Naming styles +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.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 +# Organize usings +dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups = false + +# Code quality - set to suggestion to not break existing code +dotnet_code_quality_unused_parameters = all:suggestion -dotnet_naming_style.begins_with_underscore.required_prefix = _ -dotnet_naming_style.begins_with_underscore.required_suffix = -dotnet_naming_style.begins_with_underscore.word_separator = -dotnet_naming_style.begins_with_underscore.capitalization = camel_case +# Nullable reference types +csharp_nullable_reference_types = enable diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index ee8496e..800e59f 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,7 +1,10 @@ --- blank_issues_enabled: false contact_links: - - name: 💬 Ask a Question + - name: 📚 Documentation + url: https://github.com/demaconsulting/VHDLTest + about: Read the documentation for VHDLTest + - name: 💬 Discussions url: https://github.com/demaconsulting/VHDLTest/discussions about: Ask questions and discuss with the community - name: 🔒 Security Issue diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml new file mode 100644 index 0000000..7699360 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -0,0 +1,82 @@ +--- +name: ❓ Question / Help +description: Ask a usage question or get help with VHDLTest +title: "[Question]: " +labels: ["question"] +assignees: [] +body: + - type: markdown + attributes: + value: | + Thanks for reaching out! Please fill out the sections below so we can help you as quickly as possible. + For general discussion, you can also use + [GitHub Discussions](https://github.com/demaconsulting/VHDLTest/discussions). + + - type: textarea + id: question + attributes: + label: Question + description: A clear and concise description of what you need help with. + placeholder: What would you like to know or understand? + validations: + required: true + + - type: textarea + id: what-tried + attributes: + label: What Have You Tried? + description: Describe what you have already attempted, including any code or configuration you have used. + placeholder: | + ```yaml + # Your configuration here + ``` + render: yaml + + - type: textarea + id: expected + attributes: + label: Expected Outcome + description: A clear and concise description of what you expected to happen or what you are trying to achieve. + placeholder: Describe the outcome you are looking for... + validations: + required: true + + - type: input + id: version + attributes: + label: Tool Version + description: What version of VHDLTest are you using? + placeholder: e.g., 1.0.0 + validations: + required: true + + - type: dropdown + id: dotnet-version + attributes: + label: .NET Version + description: What version of .NET are you using? + options: + - ".NET 8" + - ".NET 9" + - ".NET 10" + - Other (please specify in additional context) + validations: + required: true + + - type: textarea + id: additional-context + attributes: + label: Additional Context + description: Add any other context, screenshots, or links that may help answer your question. + placeholder: Any additional information... + + - type: checkboxes + id: checklist + attributes: + label: Checklist + description: Please confirm the following + options: + - label: I have searched existing issues and discussions to ensure this has not been answered before + required: true + - label: I have provided a clear description of my question + required: true diff --git a/.github/agents/requirements-agent.md b/.github/agents/requirements-agent.md index 66f7650..3085a22 100644 --- a/.github/agents/requirements-agent.md +++ b/.github/agents/requirements-agent.md @@ -46,7 +46,23 @@ Follow the `requirements.yaml` structure: - Clear ID and description - Justification explaining why the requirement is needed - Linked to appropriate test(s) -- Enforced via: `dotnet vhdltest --validate` +- Enforced via: `dotnet reqstream --requirements requirements.yaml --tests "artifacts/**/*.trx" --enforce` + +### Test Source Filters + +Test links in `requirements.yaml` can include a source filter prefix to restrict which test results count as +evidence. This is critical for platform, simulator, and framework requirements - **never remove these filters**. + +- `ghdl@TestName` - proves the test passed using the GHDL simulator +- `nvc@TestName` - proves the test passed using the NVC simulator +- `windows@TestName` - proves the test passed on a Windows platform +- `ubuntu@TestName` - proves the test passed on a Linux (Ubuntu) platform +- `dotnet8.x@TestName` - proves the self-validation test ran on a machine with .NET 8.x runtime +- `dotnet9.x@TestName` - proves the self-validation test ran on a machine with .NET 9.x runtime +- `dotnet10.x@TestName` - proves the self-validation test ran on a machine with .NET 10.x runtime + +Without the source filter, a test result from any platform/simulator/framework satisfies the requirement. Removing +a filter invalidates the evidence for platform/simulator/framework requirements. ## Defer To diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 29d28dd..2e2e574 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,7 +11,7 @@ updates: day: "monday" open-pull-requests-limit: 10 groups: - dotnet-dependencies: + nuget-dependencies: patterns: - "*" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index ad3c25c..53bd811 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -27,7 +27,10 @@ Before submitting this pull request, ensure you have completed the following: ### Build and Test - [ ] Code builds successfully: `dotnet build --configuration Release` -- [ ] All tests pass: `dotnet test --configuration Release` +- [ ] All unit tests pass: `dotnet test --configuration Release` +- [ ] Self-validation tests pass: + `dotnet run --project src/DEMAConsulting.VHDLTest --configuration Release --framework net10.0` + `--no-build -- --validate` - [ ] Code produces zero warnings ### Code Quality @@ -42,7 +45,7 @@ Please run the following checks before submitting: - [ ] **Spell checker passes**: `cspell "**/*.{md,cs}"` - [ ] **Markdown linter passes**: `markdownlint "**/*.md"` -- [ ] **YAML linter passes**: `yamllint '**/*.{yml,yaml}'` +- [ ] **YAML linter passes**: `yamllint .` ### Testing diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ae45c25..fee4368 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,7 +62,12 @@ jobs: # This section runs all quality checks for the project. # Downstream projects: Add any additional quality checks here. - - name: Spell Check + - name: Run markdown linter + uses: DavidAnson/markdownlint-cli2-action@v22 + with: + globs: '**/*.md' + + - name: Run spell checker uses: streetsidesoftware/cspell-action@v8 with: incremental_files_only: false @@ -73,12 +78,7 @@ jobs: **/*.yaml **/*.yml - - name: Markdown Lint - uses: DavidAnson/markdownlint-cli2-action@v22 - with: - globs: '**/*.md' - - - name: YAML Lint + - name: Run YAML linter uses: ibiqlik/action-yamllint@v3 with: config_file: .yamllint.yaml @@ -93,12 +93,11 @@ jobs: # unit-tests operate on all platforms and to run SonarScanner for generating # the code quality report. build: - # Permissions for this job - permissions: - contents: read # To read repository contents - pull-requests: write # To write pull requests analysis - + name: Build ${{ matrix.os }} needs: quality-checks + permissions: + contents: read + pull-requests: write strategy: matrix: @@ -623,6 +622,7 @@ jobs: - name: Convert Requirements HTML to PDF with Weasyprint run: > dotnet weasyprint + --pdf-variant pdf/a-3u docs/requirements/requirements.html "docs/VHDLTest Requirements.pdf" @@ -639,6 +639,7 @@ jobs: - name: Convert Justifications HTML to PDF with Weasyprint run: > dotnet weasyprint + --pdf-variant pdf/a-3u docs/justifications/justifications.html "docs/VHDLTest Requirements Justifications.pdf" @@ -655,6 +656,7 @@ jobs: - name: Convert Trace Matrix HTML to PDF with Weasyprint run: > dotnet weasyprint + --pdf-variant pdf/a-3u docs/tracematrix/tracematrix.html "docs/VHDLTest Trace Matrix.pdf" @@ -671,6 +673,7 @@ jobs: - name: Convert HTML to PDF with Weasyprint run: > dotnet weasyprint + --pdf-variant pdf/a-3u docs/guide/guide.html "docs/VHDLTest User Guide.pdf" @@ -689,6 +692,7 @@ jobs: cat docs/quality/codeql-quality.md - name: Generate Code Quality Report with SonarMark + shell: bash env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: > @@ -696,7 +700,7 @@ jobs: --server https://sonarcloud.io --project-key demaconsulting_VHDLTest --branch ${{ github.ref_name }} - --token "$env:SONAR_TOKEN" + --token "$SONAR_TOKEN" --report docs/quality/sonar-quality.md --report-depth 1 @@ -718,6 +722,7 @@ jobs: - name: Convert Code Quality HTML to PDF with Weasyprint run: > dotnet weasyprint + --pdf-variant pdf/a-3u docs/quality/quality.html "docs/VHDLTest Code Quality.pdf" @@ -764,6 +769,7 @@ jobs: - name: Convert Build Notes HTML to PDF with Weasyprint run: > dotnet weasyprint + --pdf-variant pdf/a-3u docs/buildnotes/buildnotes.html "docs/VHDLTest Build Notes.pdf" diff --git a/.markdownlint-cli2.jsonc b/.markdownlint-cli2.jsonc index f2d1ec7..a46ee1a 100644 --- a/.markdownlint-cli2.jsonc +++ b/.markdownlint-cli2.jsonc @@ -1,18 +1,15 @@ { - // Markdownlint CLI 2 Configuration "config": { "default": true, "MD003": { "style": "atx" }, "MD007": { "indent": 2 }, "MD013": { "line_length": 120 }, - "MD024": { "siblings_only": true }, "MD025": false, "MD033": false, "MD041": false }, - // Ignore patterns "ignores": [ - "**/node_modules", + "node_modules", "**/AGENT_REPORT_*.md" ] } diff --git a/AGENTS.md b/AGENTS.md index c28a3c8..058a00f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,27 +7,39 @@ generating test reports. - **Requirements Agent** - Develops requirements and ensures test coverage linkage - **Technical Writer** - Creates accurate documentation following regulatory best practices -- **Software Developer** - Writes production code in literate style +- **Software Developer** - Writes production code and self-validation tests in literate style - **Test Developer** - Creates unit and integration tests following AAA pattern - **Code Quality Agent** - Enforces linting, static analysis, and security standards - **Repo Consistency Agent** - Ensures VHDLTest remains consistent with TemplateDotNetTool template patterns +## Agent Selection Guide + +- Fix a bug → **Software Developer** +- Add a new feature → **Requirements Agent** → **Software Developer** → **Test Developer** +- Write a test → **Test Developer** +- Fix linting or static analysis issues → **Code Quality Agent** +- Update documentation → **Technical Writer** +- Add or update requirements → **Requirements Agent** +- Ensure test coverage linkage in `requirements.yaml` → **Requirements Agent** +- Run security scanning or address CodeQL alerts → **Code Quality Agent** +- Propagate template changes → **Repo Consistency Agent** + ## Tech Stack -- C# 12, .NET 8.0/9.0/10.0, MSTest, dotnet CLI, NuGet +- C# (latest), .NET 8.0/9.0/10.0, MSTest, dotnet CLI, NuGet - HDL Simulators: GHDL, ModelSim, Vivado, ActiveHDL, NVC ## Key Files -- **`requirements.yaml`** - All requirements with test linkage (enforced via `dotnet vhdltest --validate`) -- **`.editorconfig`** - Code style (file-scoped namespaces, 4-space indent, UTF-8+BOM, LF endings) +- **`requirements.yaml`** - All requirements with test linkage (enforced via `dotnet reqstream --enforce`) +- **`.editorconfig`** - Code style (file-scoped namespaces, 4-space indent, UTF-8, LF endings) - **`.cspell.json`, `.markdownlint-cli2.jsonc`, `.yamllint.yaml`** - Linting configs ## Requirements (VHDLTest-Specific) - Link ALL requirements to tests (prefer `IntegrationTest_*` tests over unit tests) - Not all tests need to be linked to requirements (tests may exist for corner cases, design testing, failure-testing, etc.) -- Enforced: `dotnet vhdltest --validate` generates requirements traceability matrix +- Enforced in CI: `dotnet reqstream --requirements requirements.yaml --tests "artifacts/**/*.trx" --enforce` - When adding features: add requirement + link to test ## Test Source Filters @@ -50,15 +62,69 @@ the filter ensures the CI evidence comes specifically from the required environm - **Test Naming**: `ClassName_MethodUnderTest_Scenario_ExpectedBehavior` (unit tests) or `IntegrationTest_Scenario_ExpectedBehavior` (integration tests) +- **Self-Validation**: Tests run via `--validate` flag and can output TRX/JUnit format - **MSTest v4**: Use modern assertions like `Assert.IsTrue()`, `Assert.AreEqual()` - **Integration Tests**: Prefer tests that run the actual VHDLTest tool (starting with `IntegrationTest_`) ## Code Style (VHDLTest-Specific) - **XML Docs**: On ALL members (public/internal/private) with spaces after `///` +- **Errors**: `ArgumentException` for parsing, `InvalidOperationException` for runtime issues +- **Namespace**: File-scoped namespaces only +- **Using Statements**: Top of file only - **Private fields**: Prefix with underscore (`_fieldName`) +- **String Formatting**: Use interpolated strings ($"") for clarity - **Warnings**: Zero warnings required (`TreatWarningsAsErrors=true`) +## Project Structure + +- **Context.cs**: Handles command-line argument parsing, logging, and output +- **Program.cs**: Main entry point with version/help/validation routing +- **Validation.cs**: Self-validation tests with TRX/JUnit output support +- **Simulators/**: VHDL simulator integration (GHDL, ModelSim, Vivado, ActiveHDL, NVC) + +## Build and Test + +```bash +# Build the project +dotnet build --configuration Release + +# Run unit tests +dotnet test --configuration Release + +# Run self-validation +dotnet run --project src/DEMAConsulting.VHDLTest \ + --configuration Release --framework net10.0 --no-build -- --validate + +# Use convenience scripts +./build.sh # Linux/macOS +build.bat # Windows +``` + +## Documentation + +- **User Guide**: `docs/guide/guide.md` +- **Requirements**: `requirements.yaml` → auto-generated docs +- **Build Notes**: Auto-generated via BuildMark +- **Code Quality**: Auto-generated via CodeQL and SonarMark +- **Trace Matrix**: Auto-generated via ReqStream +- **CHANGELOG.md**: Not present - changes are captured in the auto-generated build notes + +## Markdown Link Style + +- **AI agent markdown files** (`.github/agents/*.md`): Use inline links `[text](url)` so URLs are visible in + agent context +- **README.md**: Use absolute URLs (shipped in NuGet package) +- **All other markdown files**: Use reference-style links `[text][ref]` with `[ref]: url` at document end + +## CI/CD + +- **Quality Checks**: Markdown lint, spell check, YAML lint +- **Build**: Multi-platform (Windows/Linux) +- **CodeQL**: Security scanning +- **VHDL Simulation Tests**: GHDL and NVC on Windows/Linux +- **Documentation**: Auto-generated via Pandoc + Weasyprint + ## Build & Quality (Quick Reference) ```bash @@ -74,9 +140,20 @@ dotnet build --configuration Release && dotnet test --configuration Release # 2. code_review tool # 3. codeql_checker tool # 4. All linters (markdownlint, cspell, yamllint) -# 5. Requirements: dotnet vhdltest --validate +# 5. Requirements: dotnet reqstream --requirements requirements.yaml --tests "artifacts/**/*.trx" --enforce ``` +## Agent Report Files + +When agents need to write report files to communicate with each other or the user, follow these guidelines: + +- **Naming Convention**: Use the pattern `AGENT_REPORT_xxxx.md` (e.g., `AGENT_REPORT_analysis.md`) +- **Purpose**: These files are for temporary inter-agent communication and should not be committed +- **Exclusions**: Files matching `AGENT_REPORT_*.md` are automatically: + - Excluded from git (via .gitignore) + - Excluded from markdown linting + - Excluded from spell checking + ## Custom Agents Delegate tasks to specialized agents for better results: diff --git a/src/DEMAConsulting.VHDLTest/ConfigDocument.cs b/src/DEMAConsulting.VHDLTest/ConfigDocument.cs index ca0671c..cf12bae 100644 --- a/src/DEMAConsulting.VHDLTest/ConfigDocument.cs +++ b/src/DEMAConsulting.VHDLTest/ConfigDocument.cs @@ -1,64 +1,64 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; - -namespace DEMAConsulting.VHDLTest; - -/// -/// Configuration document class -/// -public class ConfigDocument -{ - /// - /// List of VHDL files - /// - public string[] Files { get; set; } = []; - - /// - /// List of tests - /// - public string[] Tests { get; set; } = []; - - /// - /// Read the configuration document from file - /// - /// Configuration file - /// Configuration document - /// Thrown on read error - public static ConfigDocument ReadFile(string filename) - { - // Read the file contents - var content = File.ReadAllText(filename); - - // Build deserializer - var deserializer = new DeserializerBuilder() - .WithNamingConvention(HyphenatedNamingConvention.Instance) - .Build(); - - // Parse the document - var doc = deserializer.Deserialize(content) ?? - throw new InvalidOperationException($"Configuration document {filename} invalid"); - - // Return the document - return doc; - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; + +namespace DEMAConsulting.VHDLTest; + +/// +/// Configuration document class +/// +public class ConfigDocument +{ + /// + /// List of VHDL files + /// + public string[] Files { get; set; } = []; + + /// + /// List of tests + /// + public string[] Tests { get; set; } = []; + + /// + /// Read the configuration document from file + /// + /// Configuration file + /// Configuration document + /// Thrown on read error + public static ConfigDocument ReadFile(string filename) + { + // Read the file contents + var content = File.ReadAllText(filename); + + // Build deserializer + var deserializer = new DeserializerBuilder() + .WithNamingConvention(HyphenatedNamingConvention.Instance) + .Build(); + + // Parse the document + var doc = deserializer.Deserialize(content) ?? + throw new InvalidOperationException($"Configuration document {filename} invalid"); + + // Return the document + return doc; + } +} diff --git a/src/DEMAConsulting.VHDLTest/Context.cs b/src/DEMAConsulting.VHDLTest/Context.cs index 7257577..015be8d 100644 --- a/src/DEMAConsulting.VHDLTest/Context.cs +++ b/src/DEMAConsulting.VHDLTest/Context.cs @@ -1,331 +1,346 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest; - -/// -/// Program Arguments Class -/// -public sealed class Context : IDisposable -{ - /// - /// Output log-file writer (when logging output to file) - /// - private readonly StreamWriter? _log; - - /// - /// Initializes a new instance of the Context class - /// - /// Optional log-file writer - private Context(StreamWriter? log) - { - _log = log; - } - - /// - /// Gets a value indicating the version has been requested - /// - public bool Version { get; private init; } - - /// - /// Gets a value indicating help has been requested - /// - public bool Help { get; private init; } - - /// - /// Gets a value indicating silent-output has been requested - /// - public bool Silent { get; private init; } - - /// - /// Gets a value indicating whether verbose output should be written - /// - public bool Verbose { get; private init; } - - /// - /// Gets a flag indicating whether to force a zero exit-code on test failures - /// - public bool ExitZero { get; private init; } - - /// - /// Gets a flag indicating whether to perform validation - /// - public bool Validate { get; private init; } - - /// - /// Gets the depth of the validation report - /// - public int Depth { get; private init; } - - /// - /// Gets the config file name - /// - public string? ConfigFile { get; private init; } - - /// - /// Gets the results file name - /// - public string? ResultsFile { get; private init; } - - /// - /// Gets the simulator name - /// - public string? Simulator { get; private init; } - - /// - /// Gets the custom tests - /// - public IReadOnlyList? CustomTests { get; private init; } - - /// - /// Gets the errors count - /// - public int Errors { get; private set; } - - /// - /// Gets the proposed exit code - /// - public int ExitCode => Errors > 0 ? 1 : 0; - - /// - /// Dispose of this context - /// - public void Dispose() - { - _log?.Dispose(); - } - - /// - /// Write colored text - /// - /// Text color - /// Text to write - public void Write(ConsoleColor color, string text) - { - // Write to the console if not silent - if (!Silent) - { - Console.ForegroundColor = color; - Console.Write(text); - Console.ResetColor(); - } - - // Write to the optional log - _log?.Write(text); - } - - /// - /// Write text to output - /// - /// Text to write - public void WriteVerboseLine(string text) - { - // Skip if not verbose - if (!Verbose) - return; - - // Write to the console unless silent - if (!Silent) - Console.WriteLine(text); - - // Write to the log if specified - _log?.WriteLine(text); - } - - /// - /// Write text to output - /// - /// Text to write - public void WriteLine(string text) - { - // Write to the console unless silent - if (!Silent) - Console.WriteLine(text); - - // Write to the log if specified - _log?.WriteLine(text); - } - - /// - /// Write an error message to output - /// - /// Error message to write - public void WriteError(string? message) - { - // Increment the number of errors - Errors++; - - // Skip writing if no message provided - if (message == null) - return; - - // Write to the console unless silent - if (!Silent) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(message); - Console.ResetColor(); - } - - // Write to the log if specified - _log?.WriteLine(message); - } - - /// - /// Create the context - /// - /// Program arguments - /// Program context - /// On invalid arguments - public static Context Create(string[] args) - { - // Validate input - ArgumentNullException.ThrowIfNull(args); - - // Process the arguments - var help = false; - var version = false; - var silent = false; - var verbose = false; - var exitZero = false; - var validate = false; - var depth = 1; - string? logFile = null; - string? configFile = null; - string? resultsFile = null; - string? simulator = null; - var customTests = new List(); - var e = args.AsEnumerable().GetEnumerator(); - while (e.MoveNext()) - { - var arg = e.Current; - switch (arg) - { - case "-v": - case "--version": - // Save version query - version = true; - break; - - case "-h": - case "-?": - case "--help": - // Save help query - help = true; - break; - - case "--silent": - // Handle silent flag - silent = true; - break; - - case "--verbose": - // Handle verbose flag - verbose = true; - break; - - case "-0": - case "--exit-0": - // Handle exit-zero flag - exitZero = true; - break; - - case "--validate": - // Handle validate flag - validate = true; - break; - - case "--depth": - // Handle validation markdown depth - depth = int.Parse(GetArgument(e, "Missing depth argument")); - break; - - case "-l": - case "--log": - // Handle logging output - logFile = GetArgument(e, "Missing log output file name"); - break; - - case "-c": - case "--config": - // Handle configuration file - configFile = GetArgument(e, "Missing configuration file name"); - break; - - case "-r": - case "--result": - case "--results": - // Handle results file - resultsFile = GetArgument(e, "Missing results file name"); - break; - - case "-s": - case "--simulator": - // Handle simulator name - simulator = GetArgument(e, "Missing simulator name"); - break; - - case "--": - // Handle custom tests - while (e.MoveNext()) - customTests.Add(e.Current); - break; - - default: - if (arg.StartsWith('-')) - throw new InvalidOperationException($"Unsupported option {arg}"); - - // Handle custom tests - customTests.Add(arg); - break; - } - } - - return new Context(logFile != null ? new StreamWriter(logFile) : null) - { - Version = version, - Help = help, - Silent = silent, - Verbose = verbose, - ExitZero = exitZero, - Validate = validate, - Depth = depth, - ConfigFile = configFile, - ResultsFile = resultsFile, - Simulator = simulator, - CustomTests = customTests.Count > 0 ? customTests.AsReadOnly() : null - }; - } - - /// - /// Get the next argument - /// - /// Argument enumerator - /// Error message if missing - /// Next argument - /// Thrown if missing - private static string GetArgument(IEnumerator enumerator, string message) - { - if (!enumerator.MoveNext()) - throw new InvalidOperationException(message); - - return enumerator.Current; - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest; + +/// +/// Program Arguments Class +/// +public sealed class Context : IDisposable +{ + /// + /// Output log-file writer (when logging output to file) + /// + private readonly StreamWriter? _log; + + /// + /// Initializes a new instance of the Context class + /// + /// Optional log-file writer + private Context(StreamWriter? log) + { + _log = log; + } + + /// + /// Gets a value indicating the version has been requested + /// + public bool Version { get; private init; } + + /// + /// Gets a value indicating help has been requested + /// + public bool Help { get; private init; } + + /// + /// Gets a value indicating silent-output has been requested + /// + public bool Silent { get; private init; } + + /// + /// Gets a value indicating whether verbose output should be written + /// + public bool Verbose { get; private init; } + + /// + /// Gets a flag indicating whether to force a zero exit-code on test failures + /// + public bool ExitZero { get; private init; } + + /// + /// Gets a flag indicating whether to perform validation + /// + public bool Validate { get; private init; } + + /// + /// Gets the depth of the validation report + /// + public int Depth { get; private init; } + + /// + /// Gets the config file name + /// + public string? ConfigFile { get; private init; } + + /// + /// Gets the results file name + /// + public string? ResultsFile { get; private init; } + + /// + /// Gets the simulator name + /// + public string? Simulator { get; private init; } + + /// + /// Gets the custom tests + /// + public IReadOnlyList? CustomTests { get; private init; } + + /// + /// Gets the errors count + /// + public int Errors { get; private set; } + + /// + /// Gets the proposed exit code + /// + public int ExitCode => Errors > 0 ? 1 : 0; + + /// + /// Dispose of this context + /// + public void Dispose() + { + _log?.Dispose(); + } + + /// + /// Write colored text + /// + /// Text color + /// Text to write + public void Write(ConsoleColor color, string text) + { + // Write to the console if not silent + if (!Silent) + { + Console.ForegroundColor = color; + Console.Write(text); + Console.ResetColor(); + } + + // Write to the optional log + _log?.Write(text); + } + + /// + /// Write text to output + /// + /// Text to write + public void WriteVerboseLine(string text) + { + // Skip if not verbose + if (!Verbose) + { + return; + } + + // Write to the console unless silent + if (!Silent) + { + Console.WriteLine(text); + } + + // Write to the log if specified + _log?.WriteLine(text); + } + + /// + /// Write text to output + /// + /// Text to write + public void WriteLine(string text) + { + // Write to the console unless silent + if (!Silent) + { + Console.WriteLine(text); + } + + // Write to the log if specified + _log?.WriteLine(text); + } + + /// + /// Write an error message to output + /// + /// Error message to write + public void WriteError(string? message) + { + // Increment the number of errors + Errors++; + + // Skip writing if no message provided + if (message == null) + { + return; + } + + // Write to the console unless silent + if (!Silent) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(message); + Console.ResetColor(); + } + + // Write to the log if specified + _log?.WriteLine(message); + } + + /// + /// Create the context + /// + /// Program arguments + /// Program context + /// On invalid arguments + public static Context Create(string[] args) + { + // Validate input + ArgumentNullException.ThrowIfNull(args); + + // Process the arguments + var help = false; + var version = false; + var silent = false; + var verbose = false; + var exitZero = false; + var validate = false; + var depth = 1; + string? logFile = null; + string? configFile = null; + string? resultsFile = null; + string? simulator = null; + var customTests = new List(); + var e = args.AsEnumerable().GetEnumerator(); + while (e.MoveNext()) + { + var arg = e.Current; + switch (arg) + { + case "-v": + case "--version": + // Save version query + version = true; + break; + + case "-h": + case "-?": + case "--help": + // Save help query + help = true; + break; + + case "--silent": + // Handle silent flag + silent = true; + break; + + case "--verbose": + // Handle verbose flag + verbose = true; + break; + + case "-0": + case "--exit-0": + // Handle exit-zero flag + exitZero = true; + break; + + case "--validate": + // Handle validate flag + validate = true; + break; + + case "--depth": + // Handle validation markdown depth + depth = int.Parse(GetArgument(e, "Missing depth argument")); + break; + + case "-l": + case "--log": + // Handle logging output + logFile = GetArgument(e, "Missing log output file name"); + break; + + case "-c": + case "--config": + // Handle configuration file + configFile = GetArgument(e, "Missing configuration file name"); + break; + + case "-r": + case "--result": + case "--results": + // Handle results file + resultsFile = GetArgument(e, "Missing results file name"); + break; + + case "-s": + case "--simulator": + // Handle simulator name + simulator = GetArgument(e, "Missing simulator name"); + break; + + case "--": + // Handle custom tests + while (e.MoveNext()) + { + customTests.Add(e.Current); + } + + break; + + default: + if (arg.StartsWith('-')) + { + throw new InvalidOperationException($"Unsupported option {arg}"); + } + + // Handle custom tests + customTests.Add(arg); + break; + } + } + + return new Context(logFile != null ? new StreamWriter(logFile) : null) + { + Version = version, + Help = help, + Silent = silent, + Verbose = verbose, + ExitZero = exitZero, + Validate = validate, + Depth = depth, + ConfigFile = configFile, + ResultsFile = resultsFile, + Simulator = simulator, + CustomTests = customTests.Count > 0 ? customTests.AsReadOnly() : null + }; + } + + /// + /// Get the next argument + /// + /// Argument enumerator + /// Error message if missing + /// Next argument + /// Thrown if missing + private static string GetArgument(IEnumerator enumerator, string message) + { + if (!enumerator.MoveNext()) + { + throw new InvalidOperationException(message); + } + + return enumerator.Current; + } +} diff --git a/src/DEMAConsulting.VHDLTest/Options.cs b/src/DEMAConsulting.VHDLTest/Options.cs index 0b9c480..fc93161 100644 --- a/src/DEMAConsulting.VHDLTest/Options.cs +++ b/src/DEMAConsulting.VHDLTest/Options.cs @@ -1,55 +1,57 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest; - -/// -/// Program Options Class -/// -/// Working directory -/// Configuration options -public record Options(string WorkingDirectory, - ConfigDocument Config) -{ - /// - /// Parse options from command line arguments - /// - /// Command line arguments - /// Options - public static Options Parse(Context args) - { - // Verify a configuration file was specified - if (args.ConfigFile == null) - throw new InvalidOperationException("Configuration file not specified"); - - // Read the configuration file - var config = ConfigDocument.ReadFile(args.ConfigFile); - - // Get the working directory - var absConfigFile = Path.GetFullPath(args.ConfigFile); - var workingDir = Path.GetDirectoryName(absConfigFile) - ?? throw new InvalidOperationException($"Invalid configuration file {absConfigFile}"); - - // Return the new options object - return new Options( - workingDir, - config); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest; + +/// +/// Program Options Class +/// +/// Working directory +/// Configuration options +public record Options(string WorkingDirectory, + ConfigDocument Config) +{ + /// + /// Parse options from command line arguments + /// + /// Command line arguments + /// Options + public static Options Parse(Context args) + { + // Verify a configuration file was specified + if (args.ConfigFile == null) + { + throw new InvalidOperationException("Configuration file not specified"); + } + + // Read the configuration file + var config = ConfigDocument.ReadFile(args.ConfigFile); + + // Get the working directory + var absConfigFile = Path.GetFullPath(args.ConfigFile); + var workingDir = Path.GetDirectoryName(absConfigFile) + ?? throw new InvalidOperationException($"Invalid configuration file {absConfigFile}"); + + // Return the new options object + return new Options( + workingDir, + config); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Program.cs b/src/DEMAConsulting.VHDLTest/Program.cs index 986f19f..7656bfc 100644 --- a/src/DEMAConsulting.VHDLTest/Program.cs +++ b/src/DEMAConsulting.VHDLTest/Program.cs @@ -1,163 +1,167 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Reflection; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest; - -/// -/// VHDLTest program class -/// -public static class Program -{ - /// - /// Gets the version of this programs assembly - /// - public static string Version { get; } = - typeof(Program).Assembly - .GetCustomAttribute() - ?.InformationalVersion ?? "Unknown"; - - /// - /// Application entry point - /// - /// Program arguments - public static void Main(string[] args) - { - try - { - using var context = Context.Create(args); - Run(context); - Environment.ExitCode = context.ExitCode; - } - catch (InvalidOperationException e) - { - // Report standard failure - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Error: {e.Message}"); - Console.ResetColor(); - Environment.Exit(1); - } - catch (Exception e) - { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Error: {e}"); - Console.ResetColor(); - throw; - } - } - - /// - /// Run the program context - /// - /// Program context - public static void Run(Context context) - { - // Handle version query - if (context.Version) - { - context.WriteLine(Version); - return; - } - - // Print version banner - context.WriteLine($"VHDL Test Bench Runner (VHDLTest) {Version}\n"); - - // Handle help query - if (context.Help) - { - PrintUsage(context); - return; - } - - // Handle self-validation - if (context.Validate) - { - Validation.Run(context); - return; - } - - // Handle missing arguments - if (context.ConfigFile == null) - { - context.WriteError("Error: Missing arguments"); - PrintUsage(context); - return; - } - - try - { - // Get the simulator - var simulator = SimulatorFactory.Get(context.Simulator) ?? - throw new InvalidOperationException("Simulator not found"); - - // Execute the build/test and get the results - var options = Options.Parse(context); - var results = TestResults.Execute(context, options, simulator); - - // Print the results summary - results.PrintSummary(context); - - // Save the test results - if (context.ResultsFile != null) - results.SaveResults(context.ResultsFile); - - // If we got failures then exit with an error code - if (!context.ExitZero && results.Fails.Any()) - context.WriteError(null); - } - catch (InvalidOperationException ex) - { - // Report operation error - context.WriteError($"Error: {ex.Message}"); - } - catch (Exception ex) - { - // Report unknown exception - context.WriteError(ex.ToString()); - } - } - - /// - /// Print usage information - /// - /// Program context - private static void PrintUsage(Context context) - { - context.WriteLine( - """ - Usage: VHDLTest [options] [tests] - - Options: - -h, --help Display help - -v, --version Display version - --silent Silence console output - --verbose Verbose output - --validate Perform self-validation - -c, --config Specify configuration - -r, --results Specify test results file - -s, --simulator Specify simulator - -0, --exit-0 Exit with code 0 if test fail - -- End of options - """); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Reflection; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest; + +/// +/// VHDLTest program class +/// +public static class Program +{ + /// + /// Gets the version of this programs assembly + /// + public static string Version { get; } = + typeof(Program).Assembly + .GetCustomAttribute() + ?.InformationalVersion ?? "Unknown"; + + /// + /// Application entry point + /// + /// Program arguments + public static void Main(string[] args) + { + try + { + using var context = Context.Create(args); + Run(context); + Environment.ExitCode = context.ExitCode; + } + catch (InvalidOperationException e) + { + // Report standard failure + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Error: {e.Message}"); + Console.ResetColor(); + Environment.Exit(1); + } + catch (Exception e) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Error: {e}"); + Console.ResetColor(); + throw; + } + } + + /// + /// Run the program context + /// + /// Program context + public static void Run(Context context) + { + // Handle version query + if (context.Version) + { + context.WriteLine(Version); + return; + } + + // Print version banner + context.WriteLine($"VHDL Test Bench Runner (VHDLTest) {Version}\n"); + + // Handle help query + if (context.Help) + { + PrintUsage(context); + return; + } + + // Handle self-validation + if (context.Validate) + { + Validation.Run(context); + return; + } + + // Handle missing arguments + if (context.ConfigFile == null) + { + context.WriteError("Error: Missing arguments"); + PrintUsage(context); + return; + } + + try + { + // Get the simulator + var simulator = SimulatorFactory.Get(context.Simulator) ?? + throw new InvalidOperationException("Simulator not found"); + + // Execute the build/test and get the results + var options = Options.Parse(context); + var results = TestResults.Execute(context, options, simulator); + + // Print the results summary + results.PrintSummary(context); + + // Save the test results + if (context.ResultsFile != null) + { + results.SaveResults(context.ResultsFile); + } + + // If we got failures then exit with an error code + if (!context.ExitZero && results.Fails.Any()) + { + context.WriteError(null); + } + } + catch (InvalidOperationException ex) + { + // Report operation error + context.WriteError($"Error: {ex.Message}"); + } + catch (Exception ex) + { + // Report unknown exception + context.WriteError(ex.ToString()); + } + } + + /// + /// Print usage information + /// + /// Program context + private static void PrintUsage(Context context) + { + context.WriteLine( + """ + Usage: VHDLTest [options] [tests] + + Options: + -h, --help Display help + -v, --version Display version + --silent Silence console output + --verbose Verbose output + --validate Perform self-validation + -c, --config Specify configuration + -r, --results Specify test results file + -s, --simulator Specify simulator + -0, --exit-0 Exit with code 0 if test fail + -- End of options + """); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Results/TestResult.cs b/src/DEMAConsulting.VHDLTest/Results/TestResult.cs index 7cf6e3b..335a0cb 100644 --- a/src/DEMAConsulting.VHDLTest/Results/TestResult.cs +++ b/src/DEMAConsulting.VHDLTest/Results/TestResult.cs @@ -1,67 +1,67 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Results; - -/// -/// Test result class -/// -/// Class name -/// Test name -/// Test run results -public sealed record TestResult(string ClassName, string TestName, RunResults RunResults) -{ - /// - /// Test ID - /// - public Guid TestId { get; init; } = Guid.NewGuid(); - - /// - /// Test Execution ID - /// - public Guid ExecutionId { get; init; } = Guid.NewGuid(); - - /// - /// Gets a value indicating whether the test passed - /// - public bool Passed => RunResults.Summary < RunLineType.Error; - - /// - /// Gets a value indicating whether the test failed - /// - public bool Failed => RunResults.Summary >= RunLineType.Error; - - /// - /// Print a summary line to the console - /// - /// Program context - public void PrintSummary(Context context) - { - // Print the colored summary word - context.Write( - Passed ? ConsoleColor.Green : ConsoleColor.Red, - Passed ? "Passed" : "Failed"); - - // Print test name and duration - context.WriteLine($" {TestName} ({RunResults.Duration:F1} seconds)"); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Results; + +/// +/// Test result class +/// +/// Class name +/// Test name +/// Test run results +public sealed record TestResult(string ClassName, string TestName, RunResults RunResults) +{ + /// + /// Test ID + /// + public Guid TestId { get; init; } = Guid.NewGuid(); + + /// + /// Test Execution ID + /// + public Guid ExecutionId { get; init; } = Guid.NewGuid(); + + /// + /// Gets a value indicating whether the test passed + /// + public bool Passed => RunResults.Summary < RunLineType.Error; + + /// + /// Gets a value indicating whether the test failed + /// + public bool Failed => RunResults.Summary >= RunLineType.Error; + + /// + /// Print a summary line to the console + /// + /// Program context + public void PrintSummary(Context context) + { + // Print the colored summary word + context.Write( + Passed ? ConsoleColor.Green : ConsoleColor.Red, + Passed ? "Passed" : "Failed"); + + // Print test name and duration + context.WriteLine($" {TestName} ({RunResults.Duration:F1} seconds)"); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Results/TestResults.cs b/src/DEMAConsulting.VHDLTest/Results/TestResults.cs index eda0cbf..d568b22 100644 --- a/src/DEMAConsulting.VHDLTest/Results/TestResults.cs +++ b/src/DEMAConsulting.VHDLTest/Results/TestResults.cs @@ -1,234 +1,241 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DemaConsulting.TestResults; -using DemaConsulting.TestResults.IO; -using DEMAConsulting.VHDLTest.Run; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Results; - -/// -/// Test Results class -/// -/// Test Run Name -/// Code Base -public sealed class TestResults(string runName, string codeBase) -{ - /// - /// Gets the Test Run ID - /// - public Guid RunId { get; init; } = Guid.NewGuid(); - - /// - /// Gets the Test Run Name - /// - public string RunName => runName; - - /// - /// Gets the Code Base - /// - public string CodeBase => codeBase; - - /// - /// Gets or sets the build run information - /// - public RunResults? BuildResults { get; set; } - - /// - /// Gets the tests - /// - public List Tests { get; init; } = []; - - /// - /// Gets the passed tests - /// - public IEnumerable Passes => Tests.Where(r => r.Passed); - - /// - /// Gets the failing tests - /// - public IEnumerable Fails => Tests.Where(r => r.Failed); - - /// - /// Execute the requested tests - /// - /// Program context - /// Test options - /// Simulator - /// Test results - public static TestResults Execute(Context context, Options options, Simulator simulator) - { - return Execute( - context, - $"{Environment.UserName}@{Environment.MachineName} {DateTime.Now}", - options.WorkingDirectory, - options, - simulator); - } - - /// - /// Execute the requested tests - /// - /// Program context - /// Run name - /// Code base - /// Test options - /// Simulator - /// Test results - public static TestResults Execute(Context context, string runName, string codeBase, Options options, Simulator simulator) - { - // Construct the results - var results = new TestResults(runName, codeBase); - - // Run the build - context.WriteLine($"Building with {simulator.SimulatorName}..."); - results.BuildResults = simulator.Compile(context, options); - results.BuildResults.Print(context); - if (results.BuildResults.Summary >= RunLineType.Error) - throw new InvalidOperationException("Build Failed"); - - // Report pass of build - context.Write(ConsoleColor.Green, - """ - Build Passed - - - """); - - // Execute the tests - var tests = context.CustomTests ?? options.Config.Tests.AsReadOnly(); - foreach (var test in tests) - { - // Report start of test - context.WriteLine($"Starting {test}"); - - // Run the test - var testResult = simulator.Test(context, options, test); - testResult.RunResults.Print(context); - results.Tests.Add(testResult); - - // Print the result splash - testResult.PrintSummary(context); - context.WriteLine(""); - } - - // Return the results - return results; - } - - /// - /// Save results to a file (TRX or JUnit based on file extension) - /// - /// File name (extension determines format: .trx for TRX, .xml for JUnit, others default to TRX) - /// Thrown when fileName is null or empty - public void SaveResults(string fileName) - { - // Validate parameter - if (string.IsNullOrWhiteSpace(fileName)) - throw new ArgumentException("File name cannot be null or empty", nameof(fileName)); - - // Create the TestResults from the library - var testResults = new DemaConsulting.TestResults.TestResults - { - Id = RunId, - Name = RunName - }; - - // Add each test result - foreach (var test in Tests) - { - var result = new DemaConsulting.TestResults.TestResult - { - TestId = test.TestId, - ExecutionId = test.ExecutionId, - Name = test.TestName, - ClassName = test.ClassName, - CodeBase = CodeBase, - Outcome = test.Passed ? TestOutcome.Passed : TestOutcome.Failed, - StartTime = test.RunResults.Start, - Duration = TimeSpan.FromSeconds(test.RunResults.Duration), - SystemOutput = test.RunResults.Output - }; - - // Add error information if the test failed - if (test.Failed) - { - result.ErrorMessage = string.Join( - '\n', - test.RunResults.Lines - .Where(l => l.Type == RunLineType.Error) - .Select(l => l.Text)); - } - - testResults.Results.Add(result); - } - - // Determine format based on file extension (.xml = JUnit, others = TRX) - var extension = Path.GetExtension(fileName).ToLowerInvariant(); - var content = extension == ".xml" - ? JUnitSerializer.Serialize(testResults) - : TrxSerializer.Serialize(testResults); - - // Save the file - File.WriteAllText(fileName, content); - } - - /// - /// Save results to TRX file (backward compatibility) - /// - /// TRX file name - public void SaveToTrx(string fileName) - { - SaveResults(fileName); - } - - /// - /// Print test results summary - /// - /// Program context - public void PrintSummary(Context context) - { - // Print the summary table - context.WriteLine("==== summary ==========================="); - foreach (var r in Tests) - r.PrintSummary(context); - context.WriteLine("========================================"); - - // Get the totals - var total = Tests.Count; - var passed = Passes.Count(); - var failed = Fails.Count(); - - // Print pass totals - if (passed > 0) - { - context.Write(ConsoleColor.Green, "Passed"); - context.WriteLine($" {passed} of {total} tests"); - } - - // Print fail totals - if (failed > 0) - { - context.Write(ConsoleColor.Red, "Failed"); - context.WriteLine($" {failed} of {total} tests"); - } - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DemaConsulting.TestResults; +using DemaConsulting.TestResults.IO; +using DEMAConsulting.VHDLTest.Run; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Results; + +/// +/// Test Results class +/// +/// Test Run Name +/// Code Base +public sealed class TestResults(string runName, string codeBase) +{ + /// + /// Gets the Test Run ID + /// + public Guid RunId { get; init; } = Guid.NewGuid(); + + /// + /// Gets the Test Run Name + /// + public string RunName => runName; + + /// + /// Gets the Code Base + /// + public string CodeBase => codeBase; + + /// + /// Gets or sets the build run information + /// + public RunResults? BuildResults { get; set; } + + /// + /// Gets the tests + /// + public List Tests { get; init; } = []; + + /// + /// Gets the passed tests + /// + public IEnumerable Passes => Tests.Where(r => r.Passed); + + /// + /// Gets the failing tests + /// + public IEnumerable Fails => Tests.Where(r => r.Failed); + + /// + /// Execute the requested tests + /// + /// Program context + /// Test options + /// Simulator + /// Test results + public static TestResults Execute(Context context, Options options, Simulator simulator) + { + return Execute( + context, + $"{Environment.UserName}@{Environment.MachineName} {DateTime.Now}", + options.WorkingDirectory, + options, + simulator); + } + + /// + /// Execute the requested tests + /// + /// Program context + /// Run name + /// Code base + /// Test options + /// Simulator + /// Test results + public static TestResults Execute(Context context, string runName, string codeBase, Options options, Simulator simulator) + { + // Construct the results + var results = new TestResults(runName, codeBase); + + // Run the build + context.WriteLine($"Building with {simulator.SimulatorName}..."); + results.BuildResults = simulator.Compile(context, options); + results.BuildResults.Print(context); + if (results.BuildResults.Summary >= RunLineType.Error) + { + throw new InvalidOperationException("Build Failed"); + } + + // Report pass of build + context.Write(ConsoleColor.Green, + """ + Build Passed + + + """); + + // Execute the tests + var tests = context.CustomTests ?? options.Config.Tests.AsReadOnly(); + foreach (var test in tests) + { + // Report start of test + context.WriteLine($"Starting {test}"); + + // Run the test + var testResult = simulator.Test(context, options, test); + testResult.RunResults.Print(context); + results.Tests.Add(testResult); + + // Print the result splash + testResult.PrintSummary(context); + context.WriteLine(""); + } + + // Return the results + return results; + } + + /// + /// Save results to a file (TRX or JUnit based on file extension) + /// + /// File name (extension determines format: .trx for TRX, .xml for JUnit, others default to TRX) + /// Thrown when fileName is null or empty + public void SaveResults(string fileName) + { + // Validate parameter + if (string.IsNullOrWhiteSpace(fileName)) + { + throw new ArgumentException("File name cannot be null or empty", nameof(fileName)); + } + + // Create the TestResults from the library + var testResults = new DemaConsulting.TestResults.TestResults + { + Id = RunId, + Name = RunName + }; + + // Add each test result + foreach (var test in Tests) + { + var result = new DemaConsulting.TestResults.TestResult + { + TestId = test.TestId, + ExecutionId = test.ExecutionId, + Name = test.TestName, + ClassName = test.ClassName, + CodeBase = CodeBase, + Outcome = test.Passed ? TestOutcome.Passed : TestOutcome.Failed, + StartTime = test.RunResults.Start, + Duration = TimeSpan.FromSeconds(test.RunResults.Duration), + SystemOutput = test.RunResults.Output + }; + + // Add error information if the test failed + if (test.Failed) + { + result.ErrorMessage = string.Join( + '\n', + test.RunResults.Lines + .Where(l => l.Type == RunLineType.Error) + .Select(l => l.Text)); + } + + testResults.Results.Add(result); + } + + // Determine format based on file extension (.xml = JUnit, others = TRX) + var extension = Path.GetExtension(fileName).ToLowerInvariant(); + var content = extension == ".xml" + ? JUnitSerializer.Serialize(testResults) + : TrxSerializer.Serialize(testResults); + + // Save the file + File.WriteAllText(fileName, content); + } + + /// + /// Save results to TRX file (backward compatibility) + /// + /// TRX file name + public void SaveToTrx(string fileName) + { + SaveResults(fileName); + } + + /// + /// Print test results summary + /// + /// Program context + public void PrintSummary(Context context) + { + // Print the summary table + context.WriteLine("==== summary ==========================="); + foreach (var r in Tests) + { + r.PrintSummary(context); + } + + context.WriteLine("========================================"); + + // Get the totals + var total = Tests.Count; + var passed = Passes.Count(); + var failed = Fails.Count(); + + // Print pass totals + if (passed > 0) + { + context.Write(ConsoleColor.Green, "Passed"); + context.WriteLine($" {passed} of {total} tests"); + } + + // Print fail totals + if (failed > 0) + { + context.Write(ConsoleColor.Red, "Failed"); + context.WriteLine($" {failed} of {total} tests"); + } + } +} diff --git a/src/DEMAConsulting.VHDLTest/Run/RunLine.cs b/src/DEMAConsulting.VHDLTest/Run/RunLine.cs index 19178e0..523cb06 100644 --- a/src/DEMAConsulting.VHDLTest/Run/RunLine.cs +++ b/src/DEMAConsulting.VHDLTest/Run/RunLine.cs @@ -1,28 +1,28 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Run; - -/// -/// Line of text from a run -/// -/// Line Type -/// Line Text -public record RunLine(RunLineType Type, string Text); +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Run; + +/// +/// Line of text from a run +/// +/// Line Type +/// Line Text +public record RunLine(RunLineType Type, string Text); diff --git a/src/DEMAConsulting.VHDLTest/Run/RunLineRule.cs b/src/DEMAConsulting.VHDLTest/Run/RunLineRule.cs index 35fb6fc..82dc5bd 100644 --- a/src/DEMAConsulting.VHDLTest/Run/RunLineRule.cs +++ b/src/DEMAConsulting.VHDLTest/Run/RunLineRule.cs @@ -1,44 +1,44 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text.RegularExpressions; - -namespace DEMAConsulting.VHDLTest.Run; - -/// -/// Run Line Rule Record -/// -/// Run Line Type -/// Text Match Pattern -public record RunLineRule(RunLineType Type, Regex Pattern) -{ - /// - /// Create a new RunLineRule - /// - /// Type - /// Pattern - /// New RunLineRule - public static RunLineRule Create(RunLineType type, string pattern) - { - return new RunLineRule( - type, - new Regex(pattern, RegexOptions.None, TimeSpan.FromMilliseconds(100))); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text.RegularExpressions; + +namespace DEMAConsulting.VHDLTest.Run; + +/// +/// Run Line Rule Record +/// +/// Run Line Type +/// Text Match Pattern +public record RunLineRule(RunLineType Type, Regex Pattern) +{ + /// + /// Create a new RunLineRule + /// + /// Type + /// Pattern + /// New RunLineRule + public static RunLineRule Create(RunLineType type, string pattern) + { + return new RunLineRule( + type, + new Regex(pattern, RegexOptions.None, TimeSpan.FromMilliseconds(100))); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Run/RunLineType.cs b/src/DEMAConsulting.VHDLTest/Run/RunLineType.cs index 58ef979..f04997b 100644 --- a/src/DEMAConsulting.VHDLTest/Run/RunLineType.cs +++ b/src/DEMAConsulting.VHDLTest/Run/RunLineType.cs @@ -1,47 +1,47 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Run; - -/// -/// Type of run line -/// -public enum RunLineType -{ - /// - /// Normal text - /// - Text, - - /// - /// Informational message - /// - Info, - - /// - /// Warning message - /// - Warning, - - /// - /// Error message - /// - Error -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Run; + +/// +/// Type of run line +/// +public enum RunLineType +{ + /// + /// Normal text + /// + Text, + + /// + /// Informational message + /// + Info, + + /// + /// Warning message + /// + Warning, + + /// + /// Error message + /// + Error +} diff --git a/src/DEMAConsulting.VHDLTest/Run/RunProcessor.cs b/src/DEMAConsulting.VHDLTest/Run/RunProcessor.cs index 0109883..eeaa578 100644 --- a/src/DEMAConsulting.VHDLTest/Run/RunProcessor.cs +++ b/src/DEMAConsulting.VHDLTest/Run/RunProcessor.cs @@ -1,102 +1,104 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Run; - -/// -/// Run Processor class -/// -/// Processing rules -public class RunProcessor(RunLineRule[] rules) -{ - /// - /// Run a program and process the results - /// - /// Program to run - /// Working directory - /// Program arguments - /// Run results - public RunResults Execute( - string application, - string workingDirectory = "", - params string[] arguments) - { - // Save the start time - var start = DateTime.Now; - - // Run the application - var exitCode = RunProgram.Run( - out var output, - application, - workingDirectory, - arguments); - - // Save the end time and calculate the duration - var end = DateTime.Now; - - // Parse the output - return Parse(start, end, output, exitCode); - } - - /// - /// Parse the output of a program - /// - /// Start time - /// End time - /// Program output - /// Program exit code - /// Run results - public RunResults Parse( - DateTime start, - DateTime end, - string output, - int exitCode) - { - // Calculate the duration - var duration = (end - start).TotalSeconds; - - // Classify the output lines - var lines = output - .Replace("\r\n", "\n") - .Split('\n') - .Select(line => new RunLine( - Array.Find(rules, r => r.Pattern.IsMatch(line))?.Type ?? RunLineType.Text, - line - )) - .ToArray(); - - // Calculate the summary type - var summary = exitCode != 0 ? RunLineType.Error : RunLineType.Text; - if (lines.Length > 0) - { - var maxLineType = lines.Max(line => line.Type); - if (maxLineType > summary) - summary = maxLineType; - } - - return new RunResults( - summary, - start, - duration, - exitCode, - output, - lines.AsReadOnly()); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Run; + +/// +/// Run Processor class +/// +/// Processing rules +public class RunProcessor(RunLineRule[] rules) +{ + /// + /// Run a program and process the results + /// + /// Program to run + /// Working directory + /// Program arguments + /// Run results + public RunResults Execute( + string application, + string workingDirectory = "", + params string[] arguments) + { + // Save the start time + var start = DateTime.Now; + + // Run the application + var exitCode = RunProgram.Run( + out var output, + application, + workingDirectory, + arguments); + + // Save the end time and calculate the duration + var end = DateTime.Now; + + // Parse the output + return Parse(start, end, output, exitCode); + } + + /// + /// Parse the output of a program + /// + /// Start time + /// End time + /// Program output + /// Program exit code + /// Run results + public RunResults Parse( + DateTime start, + DateTime end, + string output, + int exitCode) + { + // Calculate the duration + var duration = (end - start).TotalSeconds; + + // Classify the output lines + var lines = output + .Replace("\r\n", "\n") + .Split('\n') + .Select(line => new RunLine( + Array.Find(rules, r => r.Pattern.IsMatch(line))?.Type ?? RunLineType.Text, + line + )) + .ToArray(); + + // Calculate the summary type + var summary = exitCode != 0 ? RunLineType.Error : RunLineType.Text; + if (lines.Length > 0) + { + var maxLineType = lines.Max(line => line.Type); + if (maxLineType > summary) + { + summary = maxLineType; + } + } + + return new RunResults( + summary, + start, + duration, + exitCode, + output, + lines.AsReadOnly()); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs b/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs index 933474f..4197c16 100644 --- a/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs +++ b/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs @@ -1,67 +1,69 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Diagnostics; - -namespace DEMAConsulting.VHDLTest.Run; - -/// -/// Class to run a program -/// -public static class RunProgram -{ - /// - /// Run a Program - /// - /// Output text - /// Program name - /// Working directory - /// Program arguments - /// Program exit code - public static int Run( - out string output, - string application, - string workingDirectory = "", - params string[] arguments) - { - // Construct the process start information - var startInfo = new ProcessStartInfo(application) - { - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - WorkingDirectory = workingDirectory - }; - - foreach (var argument in arguments) - startInfo.ArgumentList.Add(argument); - - // Launch the process and ensure proper disposal - using var p = new Process { StartInfo = startInfo }; - p.Start(); - - // Collect all output - output = p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd(); - p.WaitForExit(); - - // Return the output - return p.ExitCode; - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Diagnostics; + +namespace DEMAConsulting.VHDLTest.Run; + +/// +/// Class to run a program +/// +public static class RunProgram +{ + /// + /// Run a Program + /// + /// Output text + /// Program name + /// Working directory + /// Program arguments + /// Program exit code + public static int Run( + out string output, + string application, + string workingDirectory = "", + params string[] arguments) + { + // Construct the process start information + var startInfo = new ProcessStartInfo(application) + { + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + WorkingDirectory = workingDirectory + }; + + foreach (var argument in arguments) + { + startInfo.ArgumentList.Add(argument); + } + + // Launch the process and ensure proper disposal + using var p = new Process { StartInfo = startInfo }; + p.Start(); + + // Collect all output + output = p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd(); + p.WaitForExit(); + + // Return the output + return p.ExitCode; + } +} diff --git a/src/DEMAConsulting.VHDLTest/Run/RunResults.cs b/src/DEMAConsulting.VHDLTest/Run/RunResults.cs index ccf7982..ea261cf 100644 --- a/src/DEMAConsulting.VHDLTest/Run/RunResults.cs +++ b/src/DEMAConsulting.VHDLTest/Run/RunResults.cs @@ -1,64 +1,64 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Collections.ObjectModel; - -namespace DEMAConsulting.VHDLTest.Run; - -/// -/// Run Results Class -/// -/// Result summary -/// Start time -/// Duration -/// Exit code -/// Output text -/// Result lines -public sealed record RunResults( - RunLineType Summary, - DateTime Start, - double Duration, - int ExitCode, - string Output, - ReadOnlyCollection Lines) -{ - /// - /// Print the results to the console colorized - /// - public void Print(Context context) - { - // Filter and write all lines - foreach (var line in Lines.Where(l => context.Verbose || l.Type != RunLineType.Text)) - { - // Pick the desired color - var color = line.Type switch - { - RunLineType.Info => ConsoleColor.White, - RunLineType.Warning => ConsoleColor.Yellow, - RunLineType.Error => ConsoleColor.Red, - _ => ConsoleColor.Gray - }; - - // Write the line - context.Write(color, line.Text); - context.WriteLine(""); - } - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Collections.ObjectModel; + +namespace DEMAConsulting.VHDLTest.Run; + +/// +/// Run Results Class +/// +/// Result summary +/// Start time +/// Duration +/// Exit code +/// Output text +/// Result lines +public sealed record RunResults( + RunLineType Summary, + DateTime Start, + double Duration, + int ExitCode, + string Output, + ReadOnlyCollection Lines) +{ + /// + /// Print the results to the console colorized + /// + public void Print(Context context) + { + // Filter and write all lines + foreach (var line in Lines.Where(l => context.Verbose || l.Type != RunLineType.Text)) + { + // Pick the desired color + var color = line.Type switch + { + RunLineType.Info => ConsoleColor.White, + RunLineType.Warning => ConsoleColor.Yellow, + RunLineType.Error => ConsoleColor.Red, + _ => ConsoleColor.Gray + }; + + // Write the line + context.Write(color, line.Text); + context.WriteLine(""); + } + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs index cc3e83f..bfdece6 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs @@ -1,185 +1,193 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// Active-HDL Simulator Class -/// -public sealed class ActiveHdlSimulator : Simulator -{ - /// - /// Simulation application - /// - private const string SimApp = "vsimsa"; - - /// - /// Compile processor - /// - public static RunProcessor CompileProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Warning, @"KERNEL:\s*Warning:"), - RunLineRule.Create(RunLineType.Error, "Error:"), - RunLineRule.Create(RunLineType.Error, @"RUNTIME:\s*Fatal Error") - ] - ); - - /// - /// Test processor - /// - public static RunProcessor TestProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Text, @"KERNEL:\s*Warning:\s*You are using the Active-HDL Lattice Edition"), - RunLineRule.Create(RunLineType.Text, @"KERNEL:\s*Warning:\s*Contact Aldec for available upgrade options"), - RunLineRule.Create(RunLineType.Warning, @"KERNEL:\s*Warning:"), - RunLineRule.Create(RunLineType.Warning, @"KERNEL:\s*WARNING:"), - RunLineRule.Create(RunLineType.Info, @"EXECUTION::\s*NOTE"), - RunLineRule.Create(RunLineType.Warning, @"EXECUTION::\s*WARNING"), - RunLineRule.Create(RunLineType.Error, @"EXECUTION::\s*ERROR"), - RunLineRule.Create(RunLineType.Error, @"EXECUTION::\s*FAILURE"), - RunLineRule.Create(RunLineType.Error, @"KERNEL:\s*ERROR"), - RunLineRule.Create(RunLineType.Error, @"RUNTIME:\s*Fatal Error:"), - RunLineRule.Create(RunLineType.Error, @"VSIM:\s*Error:") - ] - ); - - /// - /// Active-HDL simulator instance - /// - public static ActiveHdlSimulator Instance { get; } = new(); - - /// - /// Initializes a new instance of the ActiveHdl simulator - /// - private ActiveHdlSimulator() : base("ActiveHdl", FindPath()) - { - } - - /// - public override RunResults Compile(Context context, Options options) - { - // Log the start of the compile command - context.WriteVerboseLine("Starting ActiveHdl compile..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("ActiveHdl Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHdl"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - if (!Directory.Exists(libDir)) - Directory.CreateDirectory(libDir); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("onerror {exit -code 1}"); - writer.AppendLine("alib work VHDLTest.out/ActiveHDL"); - writer.AppendLine("set worklib work"); - foreach (var file in options.Config.Files) - writer.AppendLine($"acom -2008 -dbg {file}"); - - // Write the batch file - var script = Path.Combine(libDir, "compile.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the ActiveHDL compiler - var application = Path.Combine(simPath, SimApp); - context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/compile.do"); - return CompileProcessor.Execute( - application, - options.WorkingDirectory, - "-do", - "VHDLTest.out/ActiveHDL/compile.do"); - } - - /// - public override TestResult Test(Context context, Options options, string test) - { - // Log the start of the compile command - context.WriteVerboseLine($"Starting ActiveHDL test {test}..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("ActiveHDL Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Get the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHDL"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("onerror {exit -code 1}"); - writer.AppendLine("set worklib work"); - writer.AppendLine($"asim {test}"); - writer.AppendLine("run -all"); - writer.AppendLine("endsim"); - writer.AppendLine("exit -code 0"); - - // Write the batch file - var script = Path.Combine(libDir, "test.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the test - var application = Path.Combine(simPath, SimApp); - context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/test.do"); - var testRunResults = TestProcessor.Execute( - Path.Combine(simPath, SimApp), - options.WorkingDirectory, - "-do", - "VHDLTest.out/ActiveHDL/test.do"); - - // Return the test results - return new TestResult( - test, - test, - testRunResults); - } - - /// - /// Find the simulator path - /// - /// Simulator path or null if not found - public static string? FindPath() - { - // Look for an environment variable - var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_ACTIVEHDL_PATH"); - if (simPathEnv != null) - return simPathEnv; - - // Find the path to the simulator application - var simPath = Where(SimApp); - if (simPath == null) - return null; - - // Return the working directory - return Path.GetDirectoryName(simPath); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// Active-HDL Simulator Class +/// +public sealed class ActiveHdlSimulator : Simulator +{ + /// + /// Simulation application + /// + private const string SimApp = "vsimsa"; + + /// + /// Compile processor + /// + public static RunProcessor CompileProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Warning, @"KERNEL:\s*Warning:"), + RunLineRule.Create(RunLineType.Error, "Error:"), + RunLineRule.Create(RunLineType.Error, @"RUNTIME:\s*Fatal Error") + ] + ); + + /// + /// Test processor + /// + public static RunProcessor TestProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Text, @"KERNEL:\s*Warning:\s*You are using the Active-HDL Lattice Edition"), + RunLineRule.Create(RunLineType.Text, @"KERNEL:\s*Warning:\s*Contact Aldec for available upgrade options"), + RunLineRule.Create(RunLineType.Warning, @"KERNEL:\s*Warning:"), + RunLineRule.Create(RunLineType.Warning, @"KERNEL:\s*WARNING:"), + RunLineRule.Create(RunLineType.Info, @"EXECUTION::\s*NOTE"), + RunLineRule.Create(RunLineType.Warning, @"EXECUTION::\s*WARNING"), + RunLineRule.Create(RunLineType.Error, @"EXECUTION::\s*ERROR"), + RunLineRule.Create(RunLineType.Error, @"EXECUTION::\s*FAILURE"), + RunLineRule.Create(RunLineType.Error, @"KERNEL:\s*ERROR"), + RunLineRule.Create(RunLineType.Error, @"RUNTIME:\s*Fatal Error:"), + RunLineRule.Create(RunLineType.Error, @"VSIM:\s*Error:") + ] + ); + + /// + /// Active-HDL simulator instance + /// + public static ActiveHdlSimulator Instance { get; } = new(); + + /// + /// Initializes a new instance of the ActiveHdl simulator + /// + private ActiveHdlSimulator() : base("ActiveHdl", FindPath()) + { + } + + /// + public override RunResults Compile(Context context, Options options) + { + // Log the start of the compile command + context.WriteVerboseLine("Starting ActiveHdl compile..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("ActiveHdl Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Create the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHdl"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + if (!Directory.Exists(libDir)) + { + Directory.CreateDirectory(libDir); + } + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("onerror {exit -code 1}"); + writer.AppendLine("alib work VHDLTest.out/ActiveHDL"); + writer.AppendLine("set worklib work"); + foreach (var file in options.Config.Files) + { + writer.AppendLine($"acom -2008 -dbg {file}"); + } + + // Write the batch file + var script = Path.Combine(libDir, "compile.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the ActiveHDL compiler + var application = Path.Combine(simPath, SimApp); + context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); + context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/compile.do"); + return CompileProcessor.Execute( + application, + options.WorkingDirectory, + "-do", + "VHDLTest.out/ActiveHDL/compile.do"); + } + + /// + public override TestResult Test(Context context, Options options, string test) + { + // Log the start of the compile command + context.WriteVerboseLine($"Starting ActiveHDL test {test}..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("ActiveHDL Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Get the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHDL"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("onerror {exit -code 1}"); + writer.AppendLine("set worklib work"); + writer.AppendLine($"asim {test}"); + writer.AppendLine("run -all"); + writer.AppendLine("endsim"); + writer.AppendLine("exit -code 0"); + + // Write the batch file + var script = Path.Combine(libDir, "test.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the test + var application = Path.Combine(simPath, SimApp); + context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); + context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/test.do"); + var testRunResults = TestProcessor.Execute( + Path.Combine(simPath, SimApp), + options.WorkingDirectory, + "-do", + "VHDLTest.out/ActiveHDL/test.do"); + + // Return the test results + return new TestResult( + test, + test, + testRunResults); + } + + /// + /// Find the simulator path + /// + /// Simulator path or null if not found + public static string? FindPath() + { + // Look for an environment variable + var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_ACTIVEHDL_PATH"); + if (simPathEnv != null) + { + return simPathEnv; + } + + // Find the path to the simulator application + var simPath = Where(SimApp); + if (simPath == null) + { + return null; + } + + // Return the working directory + return Path.GetDirectoryName(simPath); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs index ce15abe..0cfb426 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs @@ -1,166 +1,174 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// GHDL Simulator Class -/// -public sealed class GhdlSimulator : Simulator -{ - /// - /// Compile processor - /// - public static RunProcessor CompileProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Warning, @".*:\d+:\d+:warning:"), - RunLineRule.Create(RunLineType.Error, @".*:\d+:\d+: "), - RunLineRule.Create(RunLineType.Error, ".*:error:"), - RunLineRule.Create(RunLineType.Error, ".*: cannot open") - ] - ); - - /// - /// Test processor - /// - public static RunProcessor TestProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, @".*:\(assertion note\):"), - RunLineRule.Create(RunLineType.Info, @".*:\(report note\):"), - RunLineRule.Create(RunLineType.Warning, @".*:\(assertion warning\):"), - RunLineRule.Create(RunLineType.Warning, @".*:\(report warning\):"), - RunLineRule.Create(RunLineType.Error, @".*:\(assertion error\):"), - RunLineRule.Create(RunLineType.Error, @".*:\(report error\):"), - RunLineRule.Create(RunLineType.Error, @".*:\(assertion failure\):"), - RunLineRule.Create(RunLineType.Error, @".*:\(report failure\):"), - RunLineRule.Create(RunLineType.Error, ".*:error:") - ] - ); - - /// - /// GHDL simulator instance - /// - public static GhdlSimulator Instance { get; } = new(); - - /// - /// Initializes a new instance of the GHDL simulator - /// - private GhdlSimulator() : base("GHDL", FindPath()) - { - } - - /// - public override RunResults Compile(Context context, Options options) - { - // Log the start of the compile command - context.WriteVerboseLine("Starting GHDL compile..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("GHDL Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/GHDL"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - if (!Directory.Exists(libDir)) - Directory.CreateDirectory(libDir); - - // Build the batch file - var writer = new StringBuilder(); - foreach (var file in options.Config.Files) - writer.AppendLine(file); - - // Write the batch file - var script = Path.Combine(libDir, "compile.rsp"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the GHDL compiler - var application = Path.Combine(simPath, "ghdl"); - context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} -a --std=08 --workdir=VHDLTest.out/GHDL @VHDLTest.out/GHDL/compile.rsp"); - return CompileProcessor.Execute( - application, - options.WorkingDirectory, - "-a", - "--std=08", - "--workdir=VHDLTest.out/GHDL", - "@VHDLTest.out/GHDL/compile.rsp"); - } - - /// - public override TestResult Test(Context context, Options options, string test) - { - // Log the start of the compile command - context.WriteVerboseLine($"Starting GHDL test {test}..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("GHDL Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Get the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/GHDL"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - - // Run the test - var application = Path.Combine(simPath, "ghdl"); - context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} -r --std=08 --workdir=VHDLTest.out/GHDL {test}"); - var testRunResults = TestProcessor.Execute( - application, - options.WorkingDirectory, - "-r", - "--std=08", - "--workdir=VHDLTest.out/GHDL", - test); - - // Return the test results - return new TestResult( - test, - test, - testRunResults); - } - - /// - /// Find the simulator path - /// - /// Simulator path or null if not found - public static string? FindPath() - { - // Look for an environment variable - var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_GHDL_PATH"); - if (simPathEnv != null) - return simPathEnv; - - // Find the path to the simulator application - var simPath = Where("ghdl"); - if (simPath == null) - return null; - - // Return the working directory - return Path.GetDirectoryName(simPath); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// GHDL Simulator Class +/// +public sealed class GhdlSimulator : Simulator +{ + /// + /// Compile processor + /// + public static RunProcessor CompileProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Warning, @".*:\d+:\d+:warning:"), + RunLineRule.Create(RunLineType.Error, @".*:\d+:\d+: "), + RunLineRule.Create(RunLineType.Error, ".*:error:"), + RunLineRule.Create(RunLineType.Error, ".*: cannot open") + ] + ); + + /// + /// Test processor + /// + public static RunProcessor TestProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, @".*:\(assertion note\):"), + RunLineRule.Create(RunLineType.Info, @".*:\(report note\):"), + RunLineRule.Create(RunLineType.Warning, @".*:\(assertion warning\):"), + RunLineRule.Create(RunLineType.Warning, @".*:\(report warning\):"), + RunLineRule.Create(RunLineType.Error, @".*:\(assertion error\):"), + RunLineRule.Create(RunLineType.Error, @".*:\(report error\):"), + RunLineRule.Create(RunLineType.Error, @".*:\(assertion failure\):"), + RunLineRule.Create(RunLineType.Error, @".*:\(report failure\):"), + RunLineRule.Create(RunLineType.Error, ".*:error:") + ] + ); + + /// + /// GHDL simulator instance + /// + public static GhdlSimulator Instance { get; } = new(); + + /// + /// Initializes a new instance of the GHDL simulator + /// + private GhdlSimulator() : base("GHDL", FindPath()) + { + } + + /// + public override RunResults Compile(Context context, Options options) + { + // Log the start of the compile command + context.WriteVerboseLine("Starting GHDL compile..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("GHDL Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Create the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/GHDL"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + if (!Directory.Exists(libDir)) + { + Directory.CreateDirectory(libDir); + } + + // Build the batch file + var writer = new StringBuilder(); + foreach (var file in options.Config.Files) + { + writer.AppendLine(file); + } + + // Write the batch file + var script = Path.Combine(libDir, "compile.rsp"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the GHDL compiler + var application = Path.Combine(simPath, "ghdl"); + context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); + context.WriteVerboseLine($" Run Command: {application} -a --std=08 --workdir=VHDLTest.out/GHDL @VHDLTest.out/GHDL/compile.rsp"); + return CompileProcessor.Execute( + application, + options.WorkingDirectory, + "-a", + "--std=08", + "--workdir=VHDLTest.out/GHDL", + "@VHDLTest.out/GHDL/compile.rsp"); + } + + /// + public override TestResult Test(Context context, Options options, string test) + { + // Log the start of the compile command + context.WriteVerboseLine($"Starting GHDL test {test}..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("GHDL Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Get the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/GHDL"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + + // Run the test + var application = Path.Combine(simPath, "ghdl"); + context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); + context.WriteVerboseLine($" Run Command: {application} -r --std=08 --workdir=VHDLTest.out/GHDL {test}"); + var testRunResults = TestProcessor.Execute( + application, + options.WorkingDirectory, + "-r", + "--std=08", + "--workdir=VHDLTest.out/GHDL", + test); + + // Return the test results + return new TestResult( + test, + test, + testRunResults); + } + + /// + /// Find the simulator path + /// + /// Simulator path or null if not found + public static string? FindPath() + { + // Look for an environment variable + var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_GHDL_PATH"); + if (simPathEnv != null) + { + return simPathEnv; + } + + // Find the path to the simulator application + var simPath = Where("ghdl"); + if (simPath == null) + { + return null; + } + + // Return the working directory + return Path.GetDirectoryName(simPath); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/MockSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/MockSimulator.cs index 6e72ba5..1635fa4 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/MockSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/MockSimulator.cs @@ -1,153 +1,157 @@ -// Copyright (c) 2024 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// Mock Simulator Class -/// -public sealed class MockSimulator : Simulator -{ - /// - /// Compile processor - /// - public static RunProcessor CompileProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, "Info:"), - RunLineRule.Create(RunLineType.Warning, "Warning:"), - RunLineRule.Create(RunLineType.Error, "Error:") - ] - ); - - /// - /// Test processor - /// - public static RunProcessor TestProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, "Info:"), - RunLineRule.Create(RunLineType.Warning, "Warning:"), - RunLineRule.Create(RunLineType.Error, "Failure:"), - RunLineRule.Create(RunLineType.Error, "Error:") - ] - ); - - /// - /// Mock simulator instance - /// - public static MockSimulator Instance { get; } = new(); - - /// - /// Initializes a new instance of the Mock simulator - /// - private MockSimulator() : base("Mock", null) - { - } - - /// - public override RunResults Compile(Context context, Options options) - { - // Log the start of the compile command - context.WriteVerboseLine("Starting Mock compile..."); - - // Simulate compiling, and produce output - var output = new StringBuilder(); - var exitCode = 0; - foreach (var file in options.Config.Files) - { - // Use filename to determine type of result - if (file.Contains("_error_")) - { - // File produces error and compile fails - output.AppendLine($"Error: {file}"); - exitCode = 1; - } - else if (file.Contains("_warning_")) - { - // File produces warning - output.AppendLine($"Warning: {file}"); - } - else if (file.Contains("_info_")) - { - // File produces info - output.AppendLine($"Info: {file}"); - } - else - { - // File produces no special output - output.AppendLine($"Compiled {file}"); - } - } - - // Return the compile results - return CompileProcessor.Parse( - DateTime.Now, - DateTime.Now, - output.ToString(), - exitCode); - } - - /// - public override TestResult Test(Context context, Options options, string test) - { - // Log the start of the compile command - context.WriteVerboseLine($"Starting Mock test {test}..."); - - // Simulate test, and produce output - var output = new StringBuilder(); - var exitCode = 0; - - // Add warning if desired - if (test.Contains("_warning_")) - output.AppendLine($"Warning: {test}"); - - // Add info if desired - if (test.Contains("_info_")) - output.AppendLine($"Info: {test}"); - - // Use test name to determine type of result - if (test.Contains("_error_")) - { - output.AppendLine($"Error: {test}"); - exitCode = 1; - } - else if (test.Contains("_fail_")) - { - output.AppendLine($"Failure: {test}"); - } - else - { - output.AppendLine($"Passed: {test}"); - } - - // Return the test results - return new TestResult( - test, - test, - TestProcessor.Parse( - DateTime.Now, - DateTime.Now, - output.ToString(), - exitCode)); - } -} +// Copyright (c) 2024 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// Mock Simulator Class +/// +public sealed class MockSimulator : Simulator +{ + /// + /// Compile processor + /// + public static RunProcessor CompileProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, "Info:"), + RunLineRule.Create(RunLineType.Warning, "Warning:"), + RunLineRule.Create(RunLineType.Error, "Error:") + ] + ); + + /// + /// Test processor + /// + public static RunProcessor TestProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, "Info:"), + RunLineRule.Create(RunLineType.Warning, "Warning:"), + RunLineRule.Create(RunLineType.Error, "Failure:"), + RunLineRule.Create(RunLineType.Error, "Error:") + ] + ); + + /// + /// Mock simulator instance + /// + public static MockSimulator Instance { get; } = new(); + + /// + /// Initializes a new instance of the Mock simulator + /// + private MockSimulator() : base("Mock", null) + { + } + + /// + public override RunResults Compile(Context context, Options options) + { + // Log the start of the compile command + context.WriteVerboseLine("Starting Mock compile..."); + + // Simulate compiling, and produce output + var output = new StringBuilder(); + var exitCode = 0; + foreach (var file in options.Config.Files) + { + // Use filename to determine type of result + if (file.Contains("_error_")) + { + // File produces error and compile fails + output.AppendLine($"Error: {file}"); + exitCode = 1; + } + else if (file.Contains("_warning_")) + { + // File produces warning + output.AppendLine($"Warning: {file}"); + } + else if (file.Contains("_info_")) + { + // File produces info + output.AppendLine($"Info: {file}"); + } + else + { + // File produces no special output + output.AppendLine($"Compiled {file}"); + } + } + + // Return the compile results + return CompileProcessor.Parse( + DateTime.Now, + DateTime.Now, + output.ToString(), + exitCode); + } + + /// + public override TestResult Test(Context context, Options options, string test) + { + // Log the start of the compile command + context.WriteVerboseLine($"Starting Mock test {test}..."); + + // Simulate test, and produce output + var output = new StringBuilder(); + var exitCode = 0; + + // Add warning if desired + if (test.Contains("_warning_")) + { + output.AppendLine($"Warning: {test}"); + } + + // Add info if desired + if (test.Contains("_info_")) + { + output.AppendLine($"Info: {test}"); + } + + // Use test name to determine type of result + if (test.Contains("_error_")) + { + output.AppendLine($"Error: {test}"); + exitCode = 1; + } + else if (test.Contains("_fail_")) + { + output.AppendLine($"Failure: {test}"); + } + else + { + output.AppendLine($"Passed: {test}"); + } + + // Return the test results + return new TestResult( + test, + test, + TestProcessor.Parse( + DateTime.Now, + DateTime.Now, + output.ToString(), + exitCode)); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/ModelSimSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/ModelSimSimulator.cs index 40d6caa..6cc65bd 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/ModelSimSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/ModelSimSimulator.cs @@ -1,174 +1,183 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// ModelSim Simulator Class -/// -public sealed class ModelSimSimulator : Simulator -{ - /// - /// Compile processor - /// - public static RunProcessor CompileProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Error, ".*Error: ") - ] - ); - - /// - /// Test processor - /// - public static RunProcessor TestProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, ".*Note: "), - RunLineRule.Create(RunLineType.Warning, ".*Warning: "), - RunLineRule.Create(RunLineType.Error, ".*Error: "), - RunLineRule.Create(RunLineType.Error, ".*Failure: ") - ] - ); - - /// - /// ModelSim simulator instance - /// - public static ModelSimSimulator Instance { get; } = new(); - - /// - /// Initializes a new instance of the ModelSim simulator - /// - private ModelSimSimulator() : base("ModelSim", FindPath()) - { - } - - /// - public override RunResults Compile(Context context, Options options) - { - // Log the start of the compile command - context.WriteVerboseLine("Starting ModelSim compile..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("ModelSim Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ModelSim"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - if (!Directory.Exists(libDir)) - Directory.CreateDirectory(libDir); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("onerror {exit -code 1}"); - writer.AppendLine("vlib work"); - writer.AppendLine("set worklib work"); - foreach (var file in options.Config.Files) - writer.AppendLine($"vcom -2008 ../../{file}"); - writer.AppendLine("exit -code 0"); - - // Write the batch file - var script = Path.Combine(libDir, "compile.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the ModelSim compiler - var application = Path.Combine(simPath, "vsim"); - context.WriteVerboseLine($" Run Directory: {libDir}"); - context.WriteVerboseLine($" Run Command: {application} -c -do compile.do"); - return CompileProcessor.Execute( - application, - libDir, - "-c", - "-do", - "compile.do"); - } - - /// - public override TestResult Test(Context context, Options options, string test) - { - // Log the start of the compile command - context.WriteVerboseLine($"Starting ModelSim test {test}..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("ModelSim Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Get the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ModelSim"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("onerror {exit -code 1}"); - writer.AppendLine("set worklib work"); - writer.AppendLine($"vsim -quiet {test}"); - writer.AppendLine("run -all"); - writer.AppendLine("endsim"); - writer.AppendLine("exit -code 0"); - - // Write the batch file - var script = Path.Combine(libDir, "test.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the test - var application = Path.Combine(simPath, "vsim"); - context.WriteVerboseLine($" Run Directory: {libDir}"); - context.WriteVerboseLine($" Run Command: {application} -c -do test.do"); - var testRunResults = TestProcessor.Execute( - application, - libDir, - "-c", - "-do", - "test.do"); - - // Return the test results - return new TestResult( - test, - test, - testRunResults); - } - - /// - /// Find the simulator path - /// - /// Simulator path or null if not found - public static string? FindPath() - { - // Look for an environment variable - var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_MODELSIM_PATH"); - if (simPathEnv != null) - return simPathEnv; - - // Find the path to the simulator application - var simPath = Where("vsim"); - if (simPath == null) - return null; - - // Return the working directory - return Path.GetDirectoryName(simPath); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// ModelSim Simulator Class +/// +public sealed class ModelSimSimulator : Simulator +{ + /// + /// Compile processor + /// + public static RunProcessor CompileProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Error, ".*Error: ") + ] + ); + + /// + /// Test processor + /// + public static RunProcessor TestProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, ".*Note: "), + RunLineRule.Create(RunLineType.Warning, ".*Warning: "), + RunLineRule.Create(RunLineType.Error, ".*Error: "), + RunLineRule.Create(RunLineType.Error, ".*Failure: ") + ] + ); + + /// + /// ModelSim simulator instance + /// + public static ModelSimSimulator Instance { get; } = new(); + + /// + /// Initializes a new instance of the ModelSim simulator + /// + private ModelSimSimulator() : base("ModelSim", FindPath()) + { + } + + /// + public override RunResults Compile(Context context, Options options) + { + // Log the start of the compile command + context.WriteVerboseLine("Starting ModelSim compile..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("ModelSim Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Create the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ModelSim"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + if (!Directory.Exists(libDir)) + { + Directory.CreateDirectory(libDir); + } + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("onerror {exit -code 1}"); + writer.AppendLine("vlib work"); + writer.AppendLine("set worklib work"); + foreach (var file in options.Config.Files) + { + writer.AppendLine($"vcom -2008 ../../{file}"); + } + + writer.AppendLine("exit -code 0"); + + // Write the batch file + var script = Path.Combine(libDir, "compile.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the ModelSim compiler + var application = Path.Combine(simPath, "vsim"); + context.WriteVerboseLine($" Run Directory: {libDir}"); + context.WriteVerboseLine($" Run Command: {application} -c -do compile.do"); + return CompileProcessor.Execute( + application, + libDir, + "-c", + "-do", + "compile.do"); + } + + /// + public override TestResult Test(Context context, Options options, string test) + { + // Log the start of the compile command + context.WriteVerboseLine($"Starting ModelSim test {test}..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("ModelSim Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Get the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ModelSim"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("onerror {exit -code 1}"); + writer.AppendLine("set worklib work"); + writer.AppendLine($"vsim -quiet {test}"); + writer.AppendLine("run -all"); + writer.AppendLine("endsim"); + writer.AppendLine("exit -code 0"); + + // Write the batch file + var script = Path.Combine(libDir, "test.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the test + var application = Path.Combine(simPath, "vsim"); + context.WriteVerboseLine($" Run Directory: {libDir}"); + context.WriteVerboseLine($" Run Command: {application} -c -do test.do"); + var testRunResults = TestProcessor.Execute( + application, + libDir, + "-c", + "-do", + "test.do"); + + // Return the test results + return new TestResult( + test, + test, + testRunResults); + } + + /// + /// Find the simulator path + /// + /// Simulator path or null if not found + public static string? FindPath() + { + // Look for an environment variable + var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_MODELSIM_PATH"); + if (simPathEnv != null) + { + return simPathEnv; + } + + // Find the path to the simulator application + var simPath = Where("vsim"); + if (simPath == null) + { + return null; + } + + // Return the working directory + return Path.GetDirectoryName(simPath); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/NvcSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/NvcSimulator.cs index 0432d28..47db228 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/NvcSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/NvcSimulator.cs @@ -1,165 +1,173 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// NVC Simulator Class -/// -public sealed class NvcSimulator : Simulator -{ - /// - /// Compile processor - /// - public static RunProcessor CompileProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, ".* Note:"), - RunLineRule.Create(RunLineType.Warning, ".* Warning:"), - RunLineRule.Create(RunLineType.Error, ".* Error:"), - RunLineRule.Create(RunLineType.Error, ".* Failure:"), - RunLineRule.Create(RunLineType.Error, ".* Fatal:") - ] - ); - - /// - /// Test processor - /// - public static RunProcessor TestProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, ".* Note:"), - RunLineRule.Create(RunLineType.Warning, ".* Warning:"), - RunLineRule.Create(RunLineType.Error, ".* Error:"), - RunLineRule.Create(RunLineType.Error, ".* Failure:"), - RunLineRule.Create(RunLineType.Error, ".* Fatal:") - ] - ); - - /// - /// NVC simulator instance - /// - public static NvcSimulator Instance { get; } = new(); - - /// - /// Initializes a new instance of the NVC simulator - /// - private NvcSimulator() : base("NVC", FindPath()) - { - } - - /// - public override RunResults Compile(Context context, Options options) - { - // Log the start of the compile command - context.WriteVerboseLine("Starting NVC compile..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("NVC Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/NVC"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - if (!Directory.Exists(libDir)) - Directory.CreateDirectory(libDir); - - // Build the batch file - var writer = new StringBuilder(); - foreach (var file in options.Config.Files) - writer.AppendLine(file); - - // Write the batch file - var script = Path.Combine(libDir, "compile.rsp"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the GHDL compiler - var application = Path.Combine(simPath, "nvc"); - context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} --std=08 --work=work:VHDLTest.out/NVC/lib -a @VHDLTest.out/NVC/compile.rsp"); - return CompileProcessor.Execute( - application, - options.WorkingDirectory, - "--std=08", - "--work=work:VHDLTest.out/NVC/lib", - "-a", - "@VHDLTest.out/NVC/compile.rsp"); - } - - /// - public override TestResult Test(Context context, Options options, string test) - { - // Log the start of the compile command - context.WriteVerboseLine($"Starting NVC test {test}..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("NVC Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Get the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/NVC"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - - // Run the test - var application = Path.Combine(simPath, "nvc"); - context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} --std=2008 --work=work:VHDLTest.out/NVC/lib -e {test} -r {test}"); - var testRunResults = TestProcessor.Execute( - application, - options.WorkingDirectory, - "--std=2008", - "--work=work:VHDLTest.out/NVC/lib", - "-e", - test, - "-r", - test); - - // Return the test results - return new TestResult( - test, - test, - testRunResults); - } - - /// - /// Find the simulator path - /// - /// Simulator path or null if not found - public static string? FindPath() - { - // Look for an environment variable - var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_NVC_PATH"); - if (simPathEnv != null) - return simPathEnv; - - // Find the path to the simulator application - var simPath = Where("nvc"); - if (simPath == null) - return null; - - // Return the working directory - return Path.GetDirectoryName(simPath); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// NVC Simulator Class +/// +public sealed class NvcSimulator : Simulator +{ + /// + /// Compile processor + /// + public static RunProcessor CompileProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, ".* Note:"), + RunLineRule.Create(RunLineType.Warning, ".* Warning:"), + RunLineRule.Create(RunLineType.Error, ".* Error:"), + RunLineRule.Create(RunLineType.Error, ".* Failure:"), + RunLineRule.Create(RunLineType.Error, ".* Fatal:") + ] + ); + + /// + /// Test processor + /// + public static RunProcessor TestProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, ".* Note:"), + RunLineRule.Create(RunLineType.Warning, ".* Warning:"), + RunLineRule.Create(RunLineType.Error, ".* Error:"), + RunLineRule.Create(RunLineType.Error, ".* Failure:"), + RunLineRule.Create(RunLineType.Error, ".* Fatal:") + ] + ); + + /// + /// NVC simulator instance + /// + public static NvcSimulator Instance { get; } = new(); + + /// + /// Initializes a new instance of the NVC simulator + /// + private NvcSimulator() : base("NVC", FindPath()) + { + } + + /// + public override RunResults Compile(Context context, Options options) + { + // Log the start of the compile command + context.WriteVerboseLine("Starting NVC compile..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("NVC Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Create the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/NVC"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + if (!Directory.Exists(libDir)) + { + Directory.CreateDirectory(libDir); + } + + // Build the batch file + var writer = new StringBuilder(); + foreach (var file in options.Config.Files) + { + writer.AppendLine(file); + } + + // Write the batch file + var script = Path.Combine(libDir, "compile.rsp"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the GHDL compiler + var application = Path.Combine(simPath, "nvc"); + context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); + context.WriteVerboseLine($" Run Command: {application} --std=08 --work=work:VHDLTest.out/NVC/lib -a @VHDLTest.out/NVC/compile.rsp"); + return CompileProcessor.Execute( + application, + options.WorkingDirectory, + "--std=08", + "--work=work:VHDLTest.out/NVC/lib", + "-a", + "@VHDLTest.out/NVC/compile.rsp"); + } + + /// + public override TestResult Test(Context context, Options options, string test) + { + // Log the start of the compile command + context.WriteVerboseLine($"Starting NVC test {test}..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("NVC Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Get the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/NVC"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + + // Run the test + var application = Path.Combine(simPath, "nvc"); + context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); + context.WriteVerboseLine($" Run Command: {application} --std=2008 --work=work:VHDLTest.out/NVC/lib -e {test} -r {test}"); + var testRunResults = TestProcessor.Execute( + application, + options.WorkingDirectory, + "--std=2008", + "--work=work:VHDLTest.out/NVC/lib", + "-e", + test, + "-r", + test); + + // Return the test results + return new TestResult( + test, + test, + testRunResults); + } + + /// + /// Find the simulator path + /// + /// Simulator path or null if not found + public static string? FindPath() + { + // Look for an environment variable + var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_NVC_PATH"); + if (simPathEnv != null) + { + return simPathEnv; + } + + // Find the path to the simulator application + var simPath = Where("nvc"); + if (simPath == null) + { + return null; + } + + // Return the working directory + return Path.GetDirectoryName(simPath); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/QuestaSimSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/QuestaSimSimulator.cs index 33e32f5..0387563 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/QuestaSimSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/QuestaSimSimulator.cs @@ -1,174 +1,183 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// QuestaSim Simulator Class -/// -public sealed class QuestaSimSimulator : Simulator -{ - /// - /// Compile processor - /// - public static RunProcessor CompileProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Error, ".*Error: ") - ] - ); - - /// - /// Test processor - /// - public static RunProcessor TestProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, ".*Note: "), - RunLineRule.Create(RunLineType.Warning, ".*Warning: "), - RunLineRule.Create(RunLineType.Error, ".*Error: "), - RunLineRule.Create(RunLineType.Error, ".*Failure: ") - ] - ); - - /// - /// QuestaSim simulator instance - /// - public static QuestaSimSimulator Instance { get; } = new(); - - /// - /// Initializes a new instance of the QuestaSim simulator - /// - private QuestaSimSimulator() : base("QuestaSim", FindPath()) - { - } - - /// - public override RunResults Compile(Context context, Options options) - { - // Log the start of the compile command - context.WriteVerboseLine("Starting QuestaSim compile..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("QuestaSim Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/QuestaSim"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - if (!Directory.Exists(libDir)) - Directory.CreateDirectory(libDir); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("onerror {exit -code 1}"); - writer.AppendLine("vlib work"); - writer.AppendLine("set worklib work"); - foreach (var file in options.Config.Files) - writer.AppendLine($"vcom -2008 ../../{file}"); - writer.AppendLine("exit -code 0"); - - // Write the batch file - var script = Path.Combine(libDir, "compile.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the QuestaSim compiler - var application = Path.Combine(simPath, "vsim"); - context.WriteVerboseLine($" Run Directory: {libDir}"); - context.WriteVerboseLine($" Run Command: {application} -c -do compile.do"); - return CompileProcessor.Execute( - application, - libDir, - "-c", - "-do", - "compile.do"); - } - - /// - public override TestResult Test(Context context, Options options, string test) - { - // Log the start of the compile command - context.WriteVerboseLine($"Starting QuestaSim test {test}..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("QuestaSim Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Get the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/QuestaSim"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("onerror {exit -code 1}"); - writer.AppendLine("set worklib work"); - writer.AppendLine($"vsim -quiet {test}"); - writer.AppendLine("run -all"); - writer.AppendLine("endsim"); - writer.AppendLine("exit -code 0"); - - // Write the batch file - var script = Path.Combine(libDir, "test.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the test - var application = Path.Combine(simPath, "vsim"); - context.WriteVerboseLine($" Run Directory: {libDir}"); - context.WriteVerboseLine($" Run Command: {application} -c -do test.do"); - var testRunResults = TestProcessor.Execute( - application, - libDir, - "-c", - "-do", - "test.do"); - - // Return the test results - return new TestResult( - test, - test, - testRunResults); - } - - /// - /// Find the simulator path - /// - /// Simulator path or null if not found - public static string? FindPath() - { - // Look for an environment variable - var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_QUESTASIM_PATH"); - if (simPathEnv != null) - return simPathEnv; - - // Find the path to the simulator application - var simPath = Where("vsim"); - if (simPath == null) - return null; - - // Return the working directory - return Path.GetDirectoryName(simPath); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// QuestaSim Simulator Class +/// +public sealed class QuestaSimSimulator : Simulator +{ + /// + /// Compile processor + /// + public static RunProcessor CompileProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Error, ".*Error: ") + ] + ); + + /// + /// Test processor + /// + public static RunProcessor TestProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, ".*Note: "), + RunLineRule.Create(RunLineType.Warning, ".*Warning: "), + RunLineRule.Create(RunLineType.Error, ".*Error: "), + RunLineRule.Create(RunLineType.Error, ".*Failure: ") + ] + ); + + /// + /// QuestaSim simulator instance + /// + public static QuestaSimSimulator Instance { get; } = new(); + + /// + /// Initializes a new instance of the QuestaSim simulator + /// + private QuestaSimSimulator() : base("QuestaSim", FindPath()) + { + } + + /// + public override RunResults Compile(Context context, Options options) + { + // Log the start of the compile command + context.WriteVerboseLine("Starting QuestaSim compile..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("QuestaSim Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Create the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/QuestaSim"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + if (!Directory.Exists(libDir)) + { + Directory.CreateDirectory(libDir); + } + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("onerror {exit -code 1}"); + writer.AppendLine("vlib work"); + writer.AppendLine("set worklib work"); + foreach (var file in options.Config.Files) + { + writer.AppendLine($"vcom -2008 ../../{file}"); + } + + writer.AppendLine("exit -code 0"); + + // Write the batch file + var script = Path.Combine(libDir, "compile.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the QuestaSim compiler + var application = Path.Combine(simPath, "vsim"); + context.WriteVerboseLine($" Run Directory: {libDir}"); + context.WriteVerboseLine($" Run Command: {application} -c -do compile.do"); + return CompileProcessor.Execute( + application, + libDir, + "-c", + "-do", + "compile.do"); + } + + /// + public override TestResult Test(Context context, Options options, string test) + { + // Log the start of the compile command + context.WriteVerboseLine($"Starting QuestaSim test {test}..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("QuestaSim Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Get the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/QuestaSim"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("onerror {exit -code 1}"); + writer.AppendLine("set worklib work"); + writer.AppendLine($"vsim -quiet {test}"); + writer.AppendLine("run -all"); + writer.AppendLine("endsim"); + writer.AppendLine("exit -code 0"); + + // Write the batch file + var script = Path.Combine(libDir, "test.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the test + var application = Path.Combine(simPath, "vsim"); + context.WriteVerboseLine($" Run Directory: {libDir}"); + context.WriteVerboseLine($" Run Command: {application} -c -do test.do"); + var testRunResults = TestProcessor.Execute( + application, + libDir, + "-c", + "-do", + "test.do"); + + // Return the test results + return new TestResult( + test, + test, + testRunResults); + } + + /// + /// Find the simulator path + /// + /// Simulator path or null if not found + public static string? FindPath() + { + // Look for an environment variable + var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_QUESTASIM_PATH"); + if (simPathEnv != null) + { + return simPathEnv; + } + + // Find the path to the simulator application + var simPath = Where("vsim"); + if (simPath == null) + { + return null; + } + + // Return the working directory + return Path.GetDirectoryName(simPath); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/Simulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/Simulator.cs index d20e0e3..28d16a0 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/Simulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/Simulator.cs @@ -1,125 +1,129 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// Simulator Interface -/// -/// Simulator name -/// Simulator path -public abstract class Simulator(string simulatorName, string? simulatorPath) -{ - /// - /// Gets the name of the simulator - /// - public string SimulatorName => simulatorName; - - /// - /// Gets the path to the simulator - /// - public string? SimulatorPath => simulatorPath; - - /// - /// Test if the simulator is available - /// - /// True if available - public bool Available() - { - return SimulatorPath != null; - } - - /// - /// Compile the simulator library - /// - /// Program context - /// Options - /// Compile Results - public abstract RunResults Compile(Context context, Options options); - - /// - /// Execute a test - /// - /// Program context - /// Options - /// Test name - /// Test Results - public abstract TestResult Test(Context context, Options options, string test); - - /// - /// Find the path of a potential application - /// - /// Application - /// Application path or null if not found - protected static string? Where(string application) - { - // Get the path environment - var searchPath = Environment.GetEnvironmentVariable("PATH"); - if (searchPath == null) - return null; - - // Get all the paths and files to search - var searchPaths = searchPath - .Split(Path.PathSeparator) - .Where(IsPathLegal) - .Select(Path.GetFullPath) - .Distinct() - .ToList(); - var searchFiles = new List { application }; - - // Handle windows specifics - if (OperatingSystem.IsWindows()) - { - // Prepend current directory - searchPaths.Insert(0, Directory.GetCurrentDirectory()); - - // Update the files list considering the executable extensions - var pathExt = Environment.GetEnvironmentVariable("PATHEXT") ?? ".COM;.EXE;.BAT;.CMD"; - var extensions = pathExt.Split(Path.PathSeparator); - searchFiles = [.. extensions.Select(e => $"{application}{e}")]; - } - - // Search every path and file using SelectMany to combine paths and files - var result = searchPaths - .SelectMany(p => searchFiles.Select(f => Path.Combine(p, f))) - .FirstOrDefault(File.Exists); - - // Return result (null if not found) - return result; - } - - /// - /// Test if a path is legal - /// - /// Path to test - /// True if legal - private static bool IsPathLegal(string path) - { - // First check for null or white-space - if (string.IsNullOrWhiteSpace(path)) - return false; - - // Consider other sanity-checks - return true; - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// Simulator Interface +/// +/// Simulator name +/// Simulator path +public abstract class Simulator(string simulatorName, string? simulatorPath) +{ + /// + /// Gets the name of the simulator + /// + public string SimulatorName => simulatorName; + + /// + /// Gets the path to the simulator + /// + public string? SimulatorPath => simulatorPath; + + /// + /// Test if the simulator is available + /// + /// True if available + public bool Available() + { + return SimulatorPath != null; + } + + /// + /// Compile the simulator library + /// + /// Program context + /// Options + /// Compile Results + public abstract RunResults Compile(Context context, Options options); + + /// + /// Execute a test + /// + /// Program context + /// Options + /// Test name + /// Test Results + public abstract TestResult Test(Context context, Options options, string test); + + /// + /// Find the path of a potential application + /// + /// Application + /// Application path or null if not found + protected static string? Where(string application) + { + // Get the path environment + var searchPath = Environment.GetEnvironmentVariable("PATH"); + if (searchPath == null) + { + return null; + } + + // Get all the paths and files to search + var searchPaths = searchPath + .Split(Path.PathSeparator) + .Where(IsPathLegal) + .Select(Path.GetFullPath) + .Distinct() + .ToList(); + var searchFiles = new List { application }; + + // Handle windows specifics + if (OperatingSystem.IsWindows()) + { + // Prepend current directory + searchPaths.Insert(0, Directory.GetCurrentDirectory()); + + // Update the files list considering the executable extensions + var pathExt = Environment.GetEnvironmentVariable("PATHEXT") ?? ".COM;.EXE;.BAT;.CMD"; + var extensions = pathExt.Split(Path.PathSeparator); + searchFiles = [.. extensions.Select(e => $"{application}{e}")]; + } + + // Search every path and file using SelectMany to combine paths and files + var result = searchPaths + .SelectMany(p => searchFiles.Select(f => Path.Combine(p, f))) + .FirstOrDefault(File.Exists); + + // Return result (null if not found) + return result; + } + + /// + /// Test if a path is legal + /// + /// Path to test + /// True if legal + private static bool IsPathLegal(string path) + { + // First check for null or white-space + if (string.IsNullOrWhiteSpace(path)) + { + return false; + } + + // Consider other sanity-checks + return true; + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/SimulatorFactory.cs b/src/DEMAConsulting.VHDLTest/Simulators/SimulatorFactory.cs index a5d3f8f..f958fe3 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/SimulatorFactory.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/SimulatorFactory.cs @@ -1,59 +1,63 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// Simulator Factory Class -/// -public static class SimulatorFactory -{ - /// - /// Array of simulators - /// - private static readonly Simulator[] Simulators = - [ - GhdlSimulator.Instance, - ModelSimSimulator.Instance, - QuestaSimSimulator.Instance, - VivadoSimulator.Instance, - ActiveHdlSimulator.Instance, - NvcSimulator.Instance - ]; - - /// - /// Get a simulator - /// - /// Simulator name - /// Simulator instance or null - public static Simulator? Get(string? name = null) - { - // Only return the mock simulator if explicitly requested - if (name == "mock") - return MockSimulator.Instance; - - // If the simulator is specified then use it - if (name != null) - return Array.Find(Simulators, s => s.SimulatorName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); - - // Return the first available - return Array.Find(Simulators, s => s.Available()); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// Simulator Factory Class +/// +public static class SimulatorFactory +{ + /// + /// Array of simulators + /// + private static readonly Simulator[] Simulators = + [ + GhdlSimulator.Instance, + ModelSimSimulator.Instance, + QuestaSimSimulator.Instance, + VivadoSimulator.Instance, + ActiveHdlSimulator.Instance, + NvcSimulator.Instance + ]; + + /// + /// Get a simulator + /// + /// Simulator name + /// Simulator instance or null + public static Simulator? Get(string? name = null) + { + // Only return the mock simulator if explicitly requested + if (name == "mock") + { + return MockSimulator.Instance; + } + + // If the simulator is specified then use it + if (name != null) + { + return Array.Find(Simulators, s => s.SimulatorName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + } + + // Return the first available + return Array.Find(Simulators, s => s.Available()); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs index a99ea58..7ca5142 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs @@ -1,173 +1,181 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Simulators; - -/// -/// Vivado Simulator Class -/// -public sealed class VivadoSimulator : Simulator -{ - /// - /// Compile processor - /// - public static RunProcessor CompileProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Error, "Error: ") - ] - ); - - /// - /// Test processor - /// - public static RunProcessor TestProcessor { get; } = new( - [ - RunLineRule.Create(RunLineType.Info, "Note: "), - RunLineRule.Create(RunLineType.Warning, "Warning: "), - RunLineRule.Create(RunLineType.Error, "Error: "), - RunLineRule.Create(RunLineType.Error, "Failure: ") - ] - ); - - /// - /// Vivado simulator instance - /// - public static VivadoSimulator Instance { get; } = new(); - - /// - /// Initializes a new instance of the Vivado simulator - /// - private VivadoSimulator() : base("Vivado", FindPath()) - { - } - - /// - public override RunResults Compile(Context context, Options options) - { - // Log the start of the compile command - context.WriteVerboseLine("Starting Vivado compile..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("Vivado Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/Vivado"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - if (!Directory.Exists(libDir)) - Directory.CreateDirectory(libDir); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("-2008"); - writer.AppendLine("-nolog"); - writer.AppendLine("-work work"); - foreach (var file in options.Config.Files) - writer.AppendLine($"../../{file}"); - - // Write the batch file - var script = Path.Combine(libDir, "compile.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the ModelSim compiler - var application = Path.Combine(simPath, "xvhdl"); - context.WriteVerboseLine($" Run Directory: {libDir}"); - context.WriteVerboseLine($" Run Command: cmd /c {application} -file compile.do"); - return CompileProcessor.Execute( - "cmd", - libDir, - "/c", - application, - "-file", - "compile.do"); - } - - /// - public override TestResult Test(Context context, Options options, string test) - { - // Log the start of the compile command - context.WriteVerboseLine($"Starting Vivado test {test}..."); - - // Fail if we cannot find the simulator - var simPath = SimulatorPath ?? - throw new InvalidOperationException("Vivado Simulator not available"); - context.WriteVerboseLine($" Simulator Path: {simPath}"); - - // Get the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/Vivado"); - context.WriteVerboseLine($" Library Directory: {libDir}"); - - // Build the batch file - var writer = new StringBuilder(); - writer.AppendLine("-nolog"); - writer.AppendLine("-standalone"); - writer.AppendLine("-runall"); - writer.AppendLine(test); - - // Write the batch file - var script = Path.Combine(libDir, "test.do"); - context.WriteVerboseLine($" Script File: {script}"); - File.WriteAllText(script, writer.ToString()); - - // Run the test - var application = Path.Combine(simPath, "xelab"); - context.WriteVerboseLine($" Run Directory: {libDir}"); - context.WriteVerboseLine($" Run Command: cmd /c {application} -file test.do"); - var testRunResults = TestProcessor.Execute( - "cmd", - libDir, - "/c", - application, - "-file", - "test.do"); - - // Return the test results - return new TestResult( - test, - test, - testRunResults); - } - - /// - /// Find the simulator path - /// - /// Simulator path or null if not found - public static string? FindPath() - { - // Look for an environment variable - var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_VIVADO_PATH"); - if (simPathEnv != null) - return simPathEnv; - - // Find the path to the simulator application - var simPath = Where("vivado"); - if (simPath == null) - return null; - - // Return the working directory - return Path.GetDirectoryName(simPath); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Simulators; + +/// +/// Vivado Simulator Class +/// +public sealed class VivadoSimulator : Simulator +{ + /// + /// Compile processor + /// + public static RunProcessor CompileProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Error, "Error: ") + ] + ); + + /// + /// Test processor + /// + public static RunProcessor TestProcessor { get; } = new( + [ + RunLineRule.Create(RunLineType.Info, "Note: "), + RunLineRule.Create(RunLineType.Warning, "Warning: "), + RunLineRule.Create(RunLineType.Error, "Error: "), + RunLineRule.Create(RunLineType.Error, "Failure: ") + ] + ); + + /// + /// Vivado simulator instance + /// + public static VivadoSimulator Instance { get; } = new(); + + /// + /// Initializes a new instance of the Vivado simulator + /// + private VivadoSimulator() : base("Vivado", FindPath()) + { + } + + /// + public override RunResults Compile(Context context, Options options) + { + // Log the start of the compile command + context.WriteVerboseLine("Starting Vivado compile..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("Vivado Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Create the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/Vivado"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + if (!Directory.Exists(libDir)) + { + Directory.CreateDirectory(libDir); + } + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("-2008"); + writer.AppendLine("-nolog"); + writer.AppendLine("-work work"); + foreach (var file in options.Config.Files) + { + writer.AppendLine($"../../{file}"); + } + + // Write the batch file + var script = Path.Combine(libDir, "compile.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the ModelSim compiler + var application = Path.Combine(simPath, "xvhdl"); + context.WriteVerboseLine($" Run Directory: {libDir}"); + context.WriteVerboseLine($" Run Command: cmd /c {application} -file compile.do"); + return CompileProcessor.Execute( + "cmd", + libDir, + "/c", + application, + "-file", + "compile.do"); + } + + /// + public override TestResult Test(Context context, Options options, string test) + { + // Log the start of the compile command + context.WriteVerboseLine($"Starting Vivado test {test}..."); + + // Fail if we cannot find the simulator + var simPath = SimulatorPath ?? + throw new InvalidOperationException("Vivado Simulator not available"); + context.WriteVerboseLine($" Simulator Path: {simPath}"); + + // Get the library directory + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/Vivado"); + context.WriteVerboseLine($" Library Directory: {libDir}"); + + // Build the batch file + var writer = new StringBuilder(); + writer.AppendLine("-nolog"); + writer.AppendLine("-standalone"); + writer.AppendLine("-runall"); + writer.AppendLine(test); + + // Write the batch file + var script = Path.Combine(libDir, "test.do"); + context.WriteVerboseLine($" Script File: {script}"); + File.WriteAllText(script, writer.ToString()); + + // Run the test + var application = Path.Combine(simPath, "xelab"); + context.WriteVerboseLine($" Run Directory: {libDir}"); + context.WriteVerboseLine($" Run Command: cmd /c {application} -file test.do"); + var testRunResults = TestProcessor.Execute( + "cmd", + libDir, + "/c", + application, + "-file", + "test.do"); + + // Return the test results + return new TestResult( + test, + test, + testRunResults); + } + + /// + /// Find the simulator path + /// + /// Simulator path or null if not found + public static string? FindPath() + { + // Look for an environment variable + var simPathEnv = Environment.GetEnvironmentVariable("VHDLTEST_VIVADO_PATH"); + if (simPathEnv != null) + { + return simPathEnv; + } + + // Find the path to the simulator application + var simPath = Where("vivado"); + if (simPath == null) + { + return null; + } + + // Return the working directory + return Path.GetDirectoryName(simPath); + } +} diff --git a/src/DEMAConsulting.VHDLTest/Validation.cs b/src/DEMAConsulting.VHDLTest/Validation.cs index 8b70b59..79379ae 100644 --- a/src/DEMAConsulting.VHDLTest/Validation.cs +++ b/src/DEMAConsulting.VHDLTest/Validation.cs @@ -1,308 +1,322 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Collections.ObjectModel; -using System.Runtime.InteropServices; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest; - -/// -/// Validation runner -/// -internal static class Validation -{ - /// - /// Validation folder name - /// - private const string ValidationFolder = "validation.tmp"; - - /// - /// Run self-validation - /// - /// Program context - public static void Run(Context context) - { - // Validate input - ArgumentNullException.ThrowIfNull(context); - - // Write validation header - context.WriteLine($"{new string('#', context.Depth)} DEMAConsulting.VHDLTest"); - context.WriteLine(""); - context.WriteLine("| Information | Value |"); - context.WriteLine("| :------------------ | :------------------------------------------------- |"); - context.WriteLine($"| VHDLTest Version | {Program.Version,-50} |"); - context.WriteLine($"| Machine Name | {Environment.MachineName,-50} |"); - context.WriteLine($"| OS Version | {RuntimeInformation.OSDescription,-50} |"); - context.WriteLine($"| DotNet Runtime | {RuntimeInformation.FrameworkDescription,-50} |"); - context.WriteLine($"| Time Stamp | {$"{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} UTC",-50} |"); - context.WriteLine(""); - context.WriteLine("Tests:"); - context.WriteLine(""); - - // Run validation tests - var results = new TestResults("Validation", "VHDLTest"); - ValidateTestPasses(context, results); - ValidateTestFails(context, results); - - // Save results if requested - if (context.ResultsFile != null) - results.SaveResults(context.ResultsFile); - - // Print summary - var totalTests = results.Tests.Count; - var passedTests = results.Tests.Count(t => t.Passed); - var failedTests = results.Tests.Count(t => !t.Passed); - context.WriteLine(""); - context.WriteLine($"Total Tests: {totalTests}"); - context.WriteLine($"Passed: {passedTests}"); - if (failedTests > 0) - context.WriteError($"Failed: {failedTests}"); - else - context.WriteLine($"Failed: {failedTests}"); - - // If all validations succeeded (no errors) then report validation passed - if (context.Errors == 0) - context.WriteLine("\nValidation Passed"); - } - - /// - /// Validate test passes are reported - /// - /// Program context - /// Test results - public static void ValidateTestPasses(Context context, TestResults results) - { - // Run the validation files - var start = DateTime.UtcNow; - var exitCode = RunValidation(out var output, context.Simulator); - var duration = (DateTime.UtcNow - start).TotalSeconds; - - // Determine if the test succeeded - var succeeded = - exitCode == 0 && - output.Contains("Passed full_adder_pass_tb") && - output.Contains("Passed half_adder_pass_tb"); - - // Report result - ReportTestResult( - context, - results, - "TestPasses", - start, - duration, - exitCode, - output, - succeeded); - } - - /// - /// Validate test fails are reported - /// - /// Program context - /// Test results - public static void ValidateTestFails(Context context, TestResults results) - { - // Run the validation files - var start = DateTime.UtcNow; - var exitCode = RunValidation(out var output, context.Simulator); - var duration = (DateTime.UtcNow - start).TotalSeconds; - - // Determine if the test succeeded - var succeeded = - exitCode == 0 && - output.Contains("Failed full_adder_fail_tb") && - output.Contains("Failed half_adder_fail_tb"); - - // Report result - ReportTestResult( - context, - results, - "TestFails", - start, - duration, - exitCode, - output, - succeeded); - } - - /// - /// Run the simulator - /// - /// Results output - /// Simulator to use - /// Exit code - public static int RunValidation(out string results, string? simulator) - { - try - { - // Create the temporary validation folder - Directory.CreateDirectory(ValidationFolder); - - // Extract the validation resources - ExtractValidationFiles(ValidationFolder); - - // Construct the arguments - var args = new List([ - "--log", "output.log", - "--silent", - "--config", "validate.yaml", - "--exit-0"]); - if (simulator != null) - args.AddRange(["--simulator", simulator]); - - // Run VhdlTest on the validation files - var exitCode = RunVhdlTest(ValidationFolder, [.. args]); - - // Read the output - results = File.Exists($"{ValidationFolder}/output.log") ? - File.ReadAllText($"{ValidationFolder}/output.log") : - ""; - - // Return the exit code - return exitCode; - } - finally - { - // Delete the validation directory - Directory.Delete(ValidationFolder, true); - } - } - - /// - /// Report validation test results - /// - /// Program context - /// Test results - /// Test name - /// Test start time-stamp - /// Test duration - /// Program exit-code - /// Output text - /// True if test succeeded - private static void ReportTestResult( - Context context, - TestResults results, - string testName, - DateTime start, - double duration, - int exitCode, - string output, - bool succeeded) - { - // Report to the context - if (succeeded) - context.WriteLine($"✓ VHDLTest_{testName} - Passed"); - else - context.WriteError($"✗ VHDLTest_{testName} - Failed"); - - // Get the line type - var line = succeeded - ? new RunLine(RunLineType.Info, $"{testName} Passed") - : new RunLine(RunLineType.Error, $"{testName} Failed"); - - // Report failure - results.Tests.Add( - new TestResult( - "VHDLTest.Validation", - $"VHDLTest_{testName}", - new RunResults( - line.Type, - start, - duration, - exitCode, - output, - new ReadOnlyCollection([line]) - ) - ) - ); - } - - /// - /// Extract the validation resources to the specified path - /// - /// Extraction path - /// Thrown on error - private static void ExtractValidationFiles(string path) - { - const string prefix = "DEMAConsulting.VHDLTest.ValidationFiles."; - - // Get the resources to extract - var resources = typeof(Validation) - .Assembly - .GetManifestResourceNames() - .Where(n => n.StartsWith(prefix)) - .ToArray(); - - // Extract the resource files - foreach (var resource in resources) - { - // Get the file name - var name = resource[prefix.Length..]; - var target = Path.Combine(path, name); - - // Get the resource stream - using var stream = typeof(Validation).Assembly.GetManifestResourceStream(resource) ?? - throw new InvalidOperationException($"Resource {resource} not found"); - - // Copy the resource to the file - using var file = File.Create(target); - stream.CopyTo(file); - } - } - - /// - /// Run VhdlTest with the specified arguments - /// - /// Arguments - /// Exit code - internal static int RunVhdlTest(string[] args) - { - // Create the context - using var context = Context.Create(args); - - // Run VhdlTest - Program.Run(context); - - // Return the exit code - return context.ExitCode; - } - - /// - /// Run VhdlTest in the specified folder with the specified arguments - /// - /// Working folder - /// Arguments - /// Exit code - internal static int RunVhdlTest(string workingFolder, string[] args) - { - var cwd = Directory.GetCurrentDirectory(); - try - { - Directory.SetCurrentDirectory(workingFolder); - return RunVhdlTest(args); - } - finally - { - Directory.SetCurrentDirectory(cwd); - } - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Collections.ObjectModel; +using System.Runtime.InteropServices; +using DEMAConsulting.VHDLTest.Results; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest; + +/// +/// Validation runner +/// +internal static class Validation +{ + /// + /// Validation folder name + /// + private const string ValidationFolder = "validation.tmp"; + + /// + /// Run self-validation + /// + /// Program context + public static void Run(Context context) + { + // Validate input + ArgumentNullException.ThrowIfNull(context); + + // Write validation header + context.WriteLine($"{new string('#', context.Depth)} DEMAConsulting.VHDLTest"); + context.WriteLine(""); + context.WriteLine("| Information | Value |"); + context.WriteLine("| :------------------ | :------------------------------------------------- |"); + context.WriteLine($"| VHDLTest Version | {Program.Version,-50} |"); + context.WriteLine($"| Machine Name | {Environment.MachineName,-50} |"); + context.WriteLine($"| OS Version | {RuntimeInformation.OSDescription,-50} |"); + context.WriteLine($"| DotNet Runtime | {RuntimeInformation.FrameworkDescription,-50} |"); + context.WriteLine($"| Time Stamp | {$"{DateTime.UtcNow:yyyy-MM-dd HH:mm:ss} UTC",-50} |"); + context.WriteLine(""); + context.WriteLine("Tests:"); + context.WriteLine(""); + + // Run validation tests + var results = new TestResults("Validation", "VHDLTest"); + ValidateTestPasses(context, results); + ValidateTestFails(context, results); + + // Save results if requested + if (context.ResultsFile != null) + { + results.SaveResults(context.ResultsFile); + } + + // Print summary + var totalTests = results.Tests.Count; + var passedTests = results.Tests.Count(t => t.Passed); + var failedTests = results.Tests.Count(t => !t.Passed); + context.WriteLine(""); + context.WriteLine($"Total Tests: {totalTests}"); + context.WriteLine($"Passed: {passedTests}"); + if (failedTests > 0) + { + context.WriteError($"Failed: {failedTests}"); + } + else + { + context.WriteLine($"Failed: {failedTests}"); + } + + // If all validations succeeded (no errors) then report validation passed + if (context.Errors == 0) + { + context.WriteLine("\nValidation Passed"); + } + } + + /// + /// Validate test passes are reported + /// + /// Program context + /// Test results + public static void ValidateTestPasses(Context context, TestResults results) + { + // Run the validation files + var start = DateTime.UtcNow; + var exitCode = RunValidation(out var output, context.Simulator); + var duration = (DateTime.UtcNow - start).TotalSeconds; + + // Determine if the test succeeded + var succeeded = + exitCode == 0 && + output.Contains("Passed full_adder_pass_tb") && + output.Contains("Passed half_adder_pass_tb"); + + // Report result + ReportTestResult( + context, + results, + "TestPasses", + start, + duration, + exitCode, + output, + succeeded); + } + + /// + /// Validate test fails are reported + /// + /// Program context + /// Test results + public static void ValidateTestFails(Context context, TestResults results) + { + // Run the validation files + var start = DateTime.UtcNow; + var exitCode = RunValidation(out var output, context.Simulator); + var duration = (DateTime.UtcNow - start).TotalSeconds; + + // Determine if the test succeeded + var succeeded = + exitCode == 0 && + output.Contains("Failed full_adder_fail_tb") && + output.Contains("Failed half_adder_fail_tb"); + + // Report result + ReportTestResult( + context, + results, + "TestFails", + start, + duration, + exitCode, + output, + succeeded); + } + + /// + /// Run the simulator + /// + /// Results output + /// Simulator to use + /// Exit code + public static int RunValidation(out string results, string? simulator) + { + try + { + // Create the temporary validation folder + Directory.CreateDirectory(ValidationFolder); + + // Extract the validation resources + ExtractValidationFiles(ValidationFolder); + + // Construct the arguments + var args = new List([ + "--log", "output.log", + "--silent", + "--config", "validate.yaml", + "--exit-0"]); + if (simulator != null) + { + args.AddRange(["--simulator", simulator]); + } + + // Run VhdlTest on the validation files + var exitCode = RunVhdlTest(ValidationFolder, [.. args]); + + // Read the output + results = File.Exists($"{ValidationFolder}/output.log") ? + File.ReadAllText($"{ValidationFolder}/output.log") : + ""; + + // Return the exit code + return exitCode; + } + finally + { + // Delete the validation directory + Directory.Delete(ValidationFolder, true); + } + } + + /// + /// Report validation test results + /// + /// Program context + /// Test results + /// Test name + /// Test start time-stamp + /// Test duration + /// Program exit-code + /// Output text + /// True if test succeeded + private static void ReportTestResult( + Context context, + TestResults results, + string testName, + DateTime start, + double duration, + int exitCode, + string output, + bool succeeded) + { + // Report to the context + if (succeeded) + { + context.WriteLine($"✓ VHDLTest_{testName} - Passed"); + } + else + { + context.WriteError($"✗ VHDLTest_{testName} - Failed"); + } + + // Get the line type + var line = succeeded + ? new RunLine(RunLineType.Info, $"{testName} Passed") + : new RunLine(RunLineType.Error, $"{testName} Failed"); + + // Report failure + results.Tests.Add( + new TestResult( + "VHDLTest.Validation", + $"VHDLTest_{testName}", + new RunResults( + line.Type, + start, + duration, + exitCode, + output, + new ReadOnlyCollection([line]) + ) + ) + ); + } + + /// + /// Extract the validation resources to the specified path + /// + /// Extraction path + /// Thrown on error + private static void ExtractValidationFiles(string path) + { + const string prefix = "DEMAConsulting.VHDLTest.ValidationFiles."; + + // Get the resources to extract + var resources = typeof(Validation) + .Assembly + .GetManifestResourceNames() + .Where(n => n.StartsWith(prefix)) + .ToArray(); + + // Extract the resource files + foreach (var resource in resources) + { + // Get the file name + var name = resource[prefix.Length..]; + var target = Path.Combine(path, name); + + // Get the resource stream + using var stream = typeof(Validation).Assembly.GetManifestResourceStream(resource) ?? + throw new InvalidOperationException($"Resource {resource} not found"); + + // Copy the resource to the file + using var file = File.Create(target); + stream.CopyTo(file); + } + } + + /// + /// Run VhdlTest with the specified arguments + /// + /// Arguments + /// Exit code + internal static int RunVhdlTest(string[] args) + { + // Create the context + using var context = Context.Create(args); + + // Run VhdlTest + Program.Run(context); + + // Return the exit code + return context.ExitCode; + } + + /// + /// Run VhdlTest in the specified folder with the specified arguments + /// + /// Working folder + /// Arguments + /// Exit code + internal static int RunVhdlTest(string workingFolder, string[] args) + { + var cwd = Directory.GetCurrentDirectory(); + try + { + Directory.SetCurrentDirectory(workingFolder); + return RunVhdlTest(args); + } + finally + { + Directory.SetCurrentDirectory(cwd); + } + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/ActiveHdlSimulatorTests.cs b/test/DEMAConsulting.VHDLTest.Tests/ActiveHdlSimulatorTests.cs index 1aff833..5c44dce 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/ActiveHdlSimulatorTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/ActiveHdlSimulatorTests.cs @@ -1,208 +1,208 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for the ActiveHDL simulator -/// -[TestClass] -public class ActiveHdlSimulatorTests -{ - /// - /// Check name of ActiveHDL simulator name - /// - [TestMethod] - public void ActiveHdlSimulator_SimulatorName_ReturnsActiveHDL() - { - Assert.AreEqual("ActiveHdl", ActiveHdlSimulator.Instance.SimulatorName); - } - - /// - /// Test ActiveHDL simulator compile with clean output - /// - [TestMethod] - public void ActiveHdlSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() - { - var results = ActiveHdlSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test ActiveHDL simulator compile with an info message - /// - [TestMethod] - public void ActiveHdlSimulator_CompileProcessor_WarningOutput_ReturnsWarningResult() - { - var results = ActiveHdlSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nKERNEL: Warning: Compile Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nKERNEL: Warning: Compile Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("KERNEL: Warning: Compile Warning", results.Lines[1].Text); - } - - /// - /// Test ActiveHDL simulator compile with an error message - /// - [TestMethod] - public void ActiveHdlSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = ActiveHdlSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nKERNEL: Fatal Error: Compile Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Compile\nKERNEL: Fatal Error: Compile Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("KERNEL: Fatal Error: Compile Error", results.Lines[1].Text); - } - - /// - /// Test ActiveHDL simulator test with clean output - /// - [TestMethod] - public void ActiveHdlSimulator_TestProcessor_CleanOutput_ReturnsTextResult() - { - var results = ActiveHdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test ActiveHDL simulator test with an info message - /// - [TestMethod] - public void ActiveHdlSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() - { - var results = ActiveHdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nEXECUTION:: NOTE Test Note", - 0); - - Assert.AreEqual(RunLineType.Info, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nEXECUTION:: NOTE Test Note", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); - Assert.AreEqual("EXECUTION:: NOTE Test Note", results.Lines[1].Text); - } - - /// - /// Test ActiveHDL simulator test with a warning message - /// - [TestMethod] - public void ActiveHdlSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() - { - var results = ActiveHdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nEXECUTION:: WARNING Test Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nEXECUTION:: WARNING Test Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("EXECUTION:: WARNING Test Warning", results.Lines[1].Text); - } - - /// - /// Test ActiveHDL simulator test with an error message - /// - [TestMethod] - public void ActiveHdlSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = ActiveHdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nEXECUTION:: ERROR Test Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Test\nEXECUTION:: ERROR Test Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("EXECUTION:: ERROR Test Error", results.Lines[1].Text); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for the ActiveHDL simulator +/// +[TestClass] +public class ActiveHdlSimulatorTests +{ + /// + /// Check name of ActiveHDL simulator name + /// + [TestMethod] + public void ActiveHdlSimulator_SimulatorName_ReturnsActiveHDL() + { + Assert.AreEqual("ActiveHdl", ActiveHdlSimulator.Instance.SimulatorName); + } + + /// + /// Test ActiveHDL simulator compile with clean output + /// + [TestMethod] + public void ActiveHdlSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() + { + var results = ActiveHdlSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test ActiveHDL simulator compile with an info message + /// + [TestMethod] + public void ActiveHdlSimulator_CompileProcessor_WarningOutput_ReturnsWarningResult() + { + var results = ActiveHdlSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nKERNEL: Warning: Compile Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nKERNEL: Warning: Compile Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("KERNEL: Warning: Compile Warning", results.Lines[1].Text); + } + + /// + /// Test ActiveHDL simulator compile with an error message + /// + [TestMethod] + public void ActiveHdlSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = ActiveHdlSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nKERNEL: Fatal Error: Compile Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Compile\nKERNEL: Fatal Error: Compile Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("KERNEL: Fatal Error: Compile Error", results.Lines[1].Text); + } + + /// + /// Test ActiveHDL simulator test with clean output + /// + [TestMethod] + public void ActiveHdlSimulator_TestProcessor_CleanOutput_ReturnsTextResult() + { + var results = ActiveHdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test ActiveHDL simulator test with an info message + /// + [TestMethod] + public void ActiveHdlSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() + { + var results = ActiveHdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nEXECUTION:: NOTE Test Note", + 0); + + Assert.AreEqual(RunLineType.Info, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nEXECUTION:: NOTE Test Note", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); + Assert.AreEqual("EXECUTION:: NOTE Test Note", results.Lines[1].Text); + } + + /// + /// Test ActiveHDL simulator test with a warning message + /// + [TestMethod] + public void ActiveHdlSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() + { + var results = ActiveHdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nEXECUTION:: WARNING Test Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nEXECUTION:: WARNING Test Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("EXECUTION:: WARNING Test Warning", results.Lines[1].Text); + } + + /// + /// Test ActiveHDL simulator test with an error message + /// + [TestMethod] + public void ActiveHdlSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = ActiveHdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nEXECUTION:: ERROR Test Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Test\nEXECUTION:: ERROR Test Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("EXECUTION:: ERROR Test Error", results.Lines[1].Text); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/ConfigDocumentTests.cs b/test/DEMAConsulting.VHDLTest.Tests/ConfigDocumentTests.cs index 97341bd..b772276 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/ConfigDocumentTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/ConfigDocumentTests.cs @@ -1,86 +1,86 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for configuration documents -/// -[TestClass] -public class ConfigDocumentTests -{ - /// - /// Configuration file name - /// - private const string ConfigFile = "options-test.yaml"; - - /// - /// Configuration file contents - /// - private const string ConfigContent = - """ - files: - - file1.vhd - - file2.vhd - - tests: - - test1 - - test2 - """; - - /// - /// Test reading a missing configuration file - /// - [TestMethod] - public void ConfigDocument_ReadFile_MissingFile_ThrowsFileNotFoundException() - { - Assert.ThrowsExactly(() => ConfigDocument.ReadFile("invalid-file")); - } - - /// - /// Test reading a valid configuration file - /// - [TestMethod] - public void ConfigDocument_ReadFile_ValidFile_ReadsSuccessfully() - { - try - { - // Write the config file - File.WriteAllText(ConfigFile, ConfigContent); - - // Read the configuration - var config = ConfigDocument.ReadFile(ConfigFile); - - // Check the content - Assert.IsNotNull(config); - Assert.HasCount(2, config.Files); - Assert.AreEqual("file1.vhd", config.Files[0]); - Assert.AreEqual("file2.vhd", config.Files[1]); - Assert.HasCount(2, config.Tests); - Assert.AreEqual("test1", config.Tests[0]); - Assert.AreEqual("test2", config.Tests[1]); - } - finally - { - // Delete the config file - File.Delete(ConfigFile); - } - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for configuration documents +/// +[TestClass] +public class ConfigDocumentTests +{ + /// + /// Configuration file name + /// + private const string ConfigFile = "options-test.yaml"; + + /// + /// Configuration file contents + /// + private const string ConfigContent = + """ + files: + - file1.vhd + - file2.vhd + + tests: + - test1 + - test2 + """; + + /// + /// Test reading a missing configuration file + /// + [TestMethod] + public void ConfigDocument_ReadFile_MissingFile_ThrowsFileNotFoundException() + { + Assert.ThrowsExactly(() => ConfigDocument.ReadFile("invalid-file")); + } + + /// + /// Test reading a valid configuration file + /// + [TestMethod] + public void ConfigDocument_ReadFile_ValidFile_ReadsSuccessfully() + { + try + { + // Write the config file + File.WriteAllText(ConfigFile, ConfigContent); + + // Read the configuration + var config = ConfigDocument.ReadFile(ConfigFile); + + // Check the content + Assert.IsNotNull(config); + Assert.HasCount(2, config.Files); + Assert.AreEqual("file1.vhd", config.Files[0]); + Assert.AreEqual("file2.vhd", config.Files[1]); + Assert.HasCount(2, config.Tests); + Assert.AreEqual("test1", config.Tests[0]); + Assert.AreEqual("test2", config.Tests[1]); + } + finally + { + // Delete the config file + File.Delete(ConfigFile); + } + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/ContextTests.cs b/test/DEMAConsulting.VHDLTest.Tests/ContextTests.cs index f7e12a1..35e79f7 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/ContextTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/ContextTests.cs @@ -1,271 +1,271 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for argument parsing -/// -[TestClass] -public class ContextTests -{ - /// - /// Test parsing arguments with no arguments - /// - [TestMethod] - public void Context_Create_NoArguments_ReturnsDefaultContext() - { - // Arrange - Prepare empty arguments array - - // Act - Parse the arguments - var arguments = Context.Create([]); - - // Assert - Verify default context is returned with all properties set to defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNull(arguments.CustomTests); - } - - /// - /// Test parsing arguments with unknown argument - /// - [TestMethod] - public void Context_Create_UnknownArgument_ThrowsInvalidOperationException() - { - // Act & Assert - Verify InvalidOperationException is thrown for unknown argument - Assert.ThrowsExactly(() => Context.Create(["--unknown"])); - } - - /// - /// Test parsing arguments with a config file - /// - [TestMethod] - public void Context_Create_WithConfigFile_SetsConfigFile() - { - // Arrange - Prepare arguments with config file option - - // Act - Parse the arguments - var arguments = Context.Create(["-c", "config.json"]); - - // Assert - Verify config file is set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.AreEqual("config.json", arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNull(arguments.CustomTests); - } - - /// - /// Test parsing arguments with a missing config file - /// - [TestMethod] - public void Context_Create_MissingConfigValue_ThrowsInvalidOperationException() - { - // Act & Assert - Verify InvalidOperationException is thrown for missing config value - Assert.ThrowsExactly(() => Context.Create(["-c"])); - } - - /// - /// Test parsing arguments with a results file - /// - [TestMethod] - public void Context_Create_WithResultsFile_SetsResultsFile() - { - // Arrange - Prepare arguments with results file option - - // Act - Parse the arguments - var arguments = Context.Create(["-r", "results.trx"]); - - // Assert - Verify results file is set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.AreEqual("results.trx", arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNull(arguments.CustomTests); - } - - /// - /// Test parsing arguments with a missing results file - /// - [TestMethod] - public void Context_Create_MissingResultsValue_ThrowsInvalidOperationException() - { - // Act & Assert - Verify InvalidOperationException is thrown for missing results value - Assert.ThrowsExactly(() => Context.Create(["-r"])); - } - - /// - /// Test parsing arguments with a specified simulator - /// - [TestMethod] - public void Context_Create_WithSimulator_SetsSimulator() - { - // Arrange - Prepare arguments with simulator option - - // Act - Parse the arguments - var arguments = Context.Create(["-s", "GHDL"]); - - // Assert - Verify simulator is set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.AreEqual("GHDL", arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNull(arguments.CustomTests); - } - - /// - /// Test parsing arguments with a missing simulator - /// - [TestMethod] - public void Context_Create_MissingSimulatorValue_ThrowsInvalidOperationException() - { - // Act & Assert - Verify InvalidOperationException is thrown for missing simulator value - Assert.ThrowsExactly(() => Context.Create(["-s"])); - } - - /// - /// Test parsing arguments with verbose - /// - [TestMethod] - public void Context_Create_WithVerbose_SetsVerboseFlag() - { - // Arrange - Prepare arguments with verbose flag - - // Act - Parse the arguments - var arguments = Context.Create(["--verbose"]); - - // Assert - Verify verbose flag is set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsTrue(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNull(arguments.CustomTests); - } - - /// - /// Test parsing arguments with exit-zero flag - /// - [TestMethod] - public void Context_Create_WithExitZero_SetsExitZeroFlag() - { - // Arrange - Prepare arguments with exit-zero flag - - // Act - Parse the arguments - var arguments = Context.Create(["--exit-0"]); - - // Assert - Verify exit-zero flag is set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsTrue(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNull(arguments.CustomTests); - } - - /// - /// Test parsing arguments with validate flag - /// - [TestMethod] - public void Context_Create_WithValidate_SetsValidateFlag() - { - // Arrange - Prepare arguments with validate flag - - // Act - Parse the arguments - var arguments = Context.Create(["--validate"]); - - // Assert - Verify validate flag is set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsTrue(arguments.Validate); - Assert.IsNull(arguments.CustomTests); - } - - /// - /// Test parsing arguments with a custom test - /// - [TestMethod] - public void Context_Create_WithCustomTest_SetsCustomTest() - { - // Arrange - Prepare arguments with single custom test name - - // Act - Parse the arguments - var arguments = Context.Create(["custom_test"]); - - // Assert - Verify custom test is set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNotNull(arguments.CustomTests); - Assert.HasCount(1, arguments.CustomTests); - Assert.AreEqual("custom_test", arguments.CustomTests[0]); - } - - /// - /// Test parsing arguments with multiple custom tests - /// - [TestMethod] - public void Context_Create_WithCustomTests_SetsCustomTests() - { - // Arrange - Prepare arguments with multiple custom test names - - // Act - Parse the arguments - var arguments = Context.Create(["--", "custom_test1", "custom_test2"]); - - // Assert - Verify all custom tests are set and other properties are defaults - Assert.IsNotNull(arguments); - Assert.IsNull(arguments.ConfigFile); - Assert.IsNull(arguments.ResultsFile); - Assert.IsNull(arguments.Simulator); - Assert.IsFalse(arguments.Verbose); - Assert.IsFalse(arguments.ExitZero); - Assert.IsFalse(arguments.Validate); - Assert.IsNotNull(arguments.CustomTests); - Assert.HasCount(2, arguments.CustomTests); - Assert.AreEqual("custom_test1", arguments.CustomTests[0]); - Assert.AreEqual("custom_test2", arguments.CustomTests[1]); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for argument parsing +/// +[TestClass] +public class ContextTests +{ + /// + /// Test parsing arguments with no arguments + /// + [TestMethod] + public void Context_Create_NoArguments_ReturnsDefaultContext() + { + // Arrange - Prepare empty arguments array + + // Act - Parse the arguments + var arguments = Context.Create([]); + + // Assert - Verify default context is returned with all properties set to defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNull(arguments.CustomTests); + } + + /// + /// Test parsing arguments with unknown argument + /// + [TestMethod] + public void Context_Create_UnknownArgument_ThrowsInvalidOperationException() + { + // Act & Assert - Verify InvalidOperationException is thrown for unknown argument + Assert.ThrowsExactly(() => Context.Create(["--unknown"])); + } + + /// + /// Test parsing arguments with a config file + /// + [TestMethod] + public void Context_Create_WithConfigFile_SetsConfigFile() + { + // Arrange - Prepare arguments with config file option + + // Act - Parse the arguments + var arguments = Context.Create(["-c", "config.json"]); + + // Assert - Verify config file is set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.AreEqual("config.json", arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNull(arguments.CustomTests); + } + + /// + /// Test parsing arguments with a missing config file + /// + [TestMethod] + public void Context_Create_MissingConfigValue_ThrowsInvalidOperationException() + { + // Act & Assert - Verify InvalidOperationException is thrown for missing config value + Assert.ThrowsExactly(() => Context.Create(["-c"])); + } + + /// + /// Test parsing arguments with a results file + /// + [TestMethod] + public void Context_Create_WithResultsFile_SetsResultsFile() + { + // Arrange - Prepare arguments with results file option + + // Act - Parse the arguments + var arguments = Context.Create(["-r", "results.trx"]); + + // Assert - Verify results file is set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.AreEqual("results.trx", arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNull(arguments.CustomTests); + } + + /// + /// Test parsing arguments with a missing results file + /// + [TestMethod] + public void Context_Create_MissingResultsValue_ThrowsInvalidOperationException() + { + // Act & Assert - Verify InvalidOperationException is thrown for missing results value + Assert.ThrowsExactly(() => Context.Create(["-r"])); + } + + /// + /// Test parsing arguments with a specified simulator + /// + [TestMethod] + public void Context_Create_WithSimulator_SetsSimulator() + { + // Arrange - Prepare arguments with simulator option + + // Act - Parse the arguments + var arguments = Context.Create(["-s", "GHDL"]); + + // Assert - Verify simulator is set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.AreEqual("GHDL", arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNull(arguments.CustomTests); + } + + /// + /// Test parsing arguments with a missing simulator + /// + [TestMethod] + public void Context_Create_MissingSimulatorValue_ThrowsInvalidOperationException() + { + // Act & Assert - Verify InvalidOperationException is thrown for missing simulator value + Assert.ThrowsExactly(() => Context.Create(["-s"])); + } + + /// + /// Test parsing arguments with verbose + /// + [TestMethod] + public void Context_Create_WithVerbose_SetsVerboseFlag() + { + // Arrange - Prepare arguments with verbose flag + + // Act - Parse the arguments + var arguments = Context.Create(["--verbose"]); + + // Assert - Verify verbose flag is set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsTrue(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNull(arguments.CustomTests); + } + + /// + /// Test parsing arguments with exit-zero flag + /// + [TestMethod] + public void Context_Create_WithExitZero_SetsExitZeroFlag() + { + // Arrange - Prepare arguments with exit-zero flag + + // Act - Parse the arguments + var arguments = Context.Create(["--exit-0"]); + + // Assert - Verify exit-zero flag is set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsTrue(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNull(arguments.CustomTests); + } + + /// + /// Test parsing arguments with validate flag + /// + [TestMethod] + public void Context_Create_WithValidate_SetsValidateFlag() + { + // Arrange - Prepare arguments with validate flag + + // Act - Parse the arguments + var arguments = Context.Create(["--validate"]); + + // Assert - Verify validate flag is set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsTrue(arguments.Validate); + Assert.IsNull(arguments.CustomTests); + } + + /// + /// Test parsing arguments with a custom test + /// + [TestMethod] + public void Context_Create_WithCustomTest_SetsCustomTest() + { + // Arrange - Prepare arguments with single custom test name + + // Act - Parse the arguments + var arguments = Context.Create(["custom_test"]); + + // Assert - Verify custom test is set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNotNull(arguments.CustomTests); + Assert.HasCount(1, arguments.CustomTests); + Assert.AreEqual("custom_test", arguments.CustomTests[0]); + } + + /// + /// Test parsing arguments with multiple custom tests + /// + [TestMethod] + public void Context_Create_WithCustomTests_SetsCustomTests() + { + // Arrange - Prepare arguments with multiple custom test names + + // Act - Parse the arguments + var arguments = Context.Create(["--", "custom_test1", "custom_test2"]); + + // Assert - Verify all custom tests are set and other properties are defaults + Assert.IsNotNull(arguments); + Assert.IsNull(arguments.ConfigFile); + Assert.IsNull(arguments.ResultsFile); + Assert.IsNull(arguments.Simulator); + Assert.IsFalse(arguments.Verbose); + Assert.IsFalse(arguments.ExitZero); + Assert.IsFalse(arguments.Validate); + Assert.IsNotNull(arguments.CustomTests); + Assert.HasCount(2, arguments.CustomTests); + Assert.AreEqual("custom_test1", arguments.CustomTests[0]); + Assert.AreEqual("custom_test2", arguments.CustomTests[1]); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/ExitCodeTests.cs b/test/DEMAConsulting.VHDLTest.Tests/ExitCodeTests.cs index 592266d..99cc4db 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/ExitCodeTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/ExitCodeTests.cs @@ -1,173 +1,173 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for exit code -/// -[TestClass] -public class ExitCodeTests -{ - /// - /// Test non-zero exit code with compile errors - /// - [TestMethod] - public void IntegrationTest_CompileError_ReturnsNonZeroExitCode() - { - try - { - // Write a config file - File.WriteAllText("test_compile_error.yaml", - """ - files: - - file_error_test.vhd - - tests: - - file_error_test_tb - """ - ); - - // Run the application using the mock simulator - var exitCode = Runner.Run( - out _, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--config", "test_compile_error.yaml"); - - // Verify error reported - Assert.AreNotEqual(0, exitCode); - } - finally - { - File.Delete("test_compile_error.yaml"); - } - } - - /// - /// Test non-zero exit code with test-execution errors - /// - [TestMethod] - public void IntegrationTest_TestExecutionError_ReturnsNonZeroExitCode() - { - try - { - // Write a config file - File.WriteAllText("test_execution_error.yaml", - """ - files: - - file_test.vhd - - tests: - - file_error_test_tb - """ - ); - - // Run the application using the mock simulator - var exitCode = Runner.Run( - out _, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--config", "test_execution_error.yaml"); - - // Verify error reported - Assert.AreNotEqual(0, exitCode); - } - finally - { - File.Delete("test_execution_error.yaml"); - } - } - - /// - /// Test non-zero exit code with test-execution errors - /// - [TestMethod] - public void IntegrationTest_TestExecutionErrorWithExit0_ReturnsZeroExitCode() - { - try - { - // Write a config file - File.WriteAllText("test_execution_error.yaml", - """ - files: - - file_test.vhd - - tests: - - file_error_test_tb - """ - ); - - // Run the application using the mock simulator - var exitCode = Runner.Run( - out _, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--config", "test_execution_error.yaml", - "--exit-0"); - - // Verify error suppressed - Assert.AreEqual(0, exitCode); - } - finally - { - File.Delete("test_execution_error.yaml"); - } - } - - /// - /// Test non-zero exit code with test-execution errors - /// - [TestMethod] - public void IntegrationTest_TestsPassed_ReturnsZeroExitCode() - { - try - { - // Write a config file - File.WriteAllText("test_execution_pass.yaml", - """ - files: - - file_test.vhd - - tests: - - file_test_tb - """ - ); - - // Run the application using the mock simulator - var exitCode = Runner.Run( - out _, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--config", "test_execution_pass.yaml"); - - // Verify no error - Assert.AreEqual(0, exitCode); - } - finally - { - File.Delete("test_execution_pass.yaml"); - } - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for exit code +/// +[TestClass] +public class ExitCodeTests +{ + /// + /// Test non-zero exit code with compile errors + /// + [TestMethod] + public void IntegrationTest_CompileError_ReturnsNonZeroExitCode() + { + try + { + // Write a config file + File.WriteAllText("test_compile_error.yaml", + """ + files: + - file_error_test.vhd + + tests: + - file_error_test_tb + """ + ); + + // Run the application using the mock simulator + var exitCode = Runner.Run( + out _, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--config", "test_compile_error.yaml"); + + // Verify error reported + Assert.AreNotEqual(0, exitCode); + } + finally + { + File.Delete("test_compile_error.yaml"); + } + } + + /// + /// Test non-zero exit code with test-execution errors + /// + [TestMethod] + public void IntegrationTest_TestExecutionError_ReturnsNonZeroExitCode() + { + try + { + // Write a config file + File.WriteAllText("test_execution_error.yaml", + """ + files: + - file_test.vhd + + tests: + - file_error_test_tb + """ + ); + + // Run the application using the mock simulator + var exitCode = Runner.Run( + out _, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--config", "test_execution_error.yaml"); + + // Verify error reported + Assert.AreNotEqual(0, exitCode); + } + finally + { + File.Delete("test_execution_error.yaml"); + } + } + + /// + /// Test non-zero exit code with test-execution errors + /// + [TestMethod] + public void IntegrationTest_TestExecutionErrorWithExit0_ReturnsZeroExitCode() + { + try + { + // Write a config file + File.WriteAllText("test_execution_error.yaml", + """ + files: + - file_test.vhd + + tests: + - file_error_test_tb + """ + ); + + // Run the application using the mock simulator + var exitCode = Runner.Run( + out _, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--config", "test_execution_error.yaml", + "--exit-0"); + + // Verify error suppressed + Assert.AreEqual(0, exitCode); + } + finally + { + File.Delete("test_execution_error.yaml"); + } + } + + /// + /// Test non-zero exit code with test-execution errors + /// + [TestMethod] + public void IntegrationTest_TestsPassed_ReturnsZeroExitCode() + { + try + { + // Write a config file + File.WriteAllText("test_execution_pass.yaml", + """ + files: + - file_test.vhd + + tests: + - file_test_tb + """ + ); + + // Run the application using the mock simulator + var exitCode = Runner.Run( + out _, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--config", "test_execution_pass.yaml"); + + // Verify no error + Assert.AreEqual(0, exitCode); + } + finally + { + File.Delete("test_execution_pass.yaml"); + } + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/GhdlSimulatorTests.cs b/test/DEMAConsulting.VHDLTest.Tests/GhdlSimulatorTests.cs index 751c8a4..e9c568e 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/GhdlSimulatorTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/GhdlSimulatorTests.cs @@ -1,208 +1,208 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for GHDL simulator -/// -[TestClass] -public class GhdlSimulatorTests -{ - /// - /// Check name of GHDL simulator - /// - [TestMethod] - public void GhdlSimulator_SimulatorName_ReturnsGHDL() - { - Assert.AreEqual("GHDL", GhdlSimulator.Instance.SimulatorName); - } - - /// - /// Test GHDL simulator compile with clean output - /// - [TestMethod] - public void GhdlSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() - { - var results = GhdlSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test GHDL simulator compile with an info message - /// - [TestMethod] - public void GhdlSimulator_CompileProcessor_WarningOutput_ReturnsWarningResult() - { - var results = GhdlSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nCompile:1:1:warning: Compile Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nCompile:1:1:warning: Compile Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("Compile:1:1:warning: Compile Warning", results.Lines[1].Text); - } - - /// - /// Test GHDL simulator compile with an error message - /// - [TestMethod] - public void GhdlSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = GhdlSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nCompile:error: Compile Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Compile\nCompile:error: Compile Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Compile:error: Compile Error", results.Lines[1].Text); - } - - /// - /// Test GHDL simulator test with clean output - /// - [TestMethod] - public void GhdlSimulator_TestProcessor_CleanOutput_ReturnsTextResult() - { - var results = GhdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test GHDL simulator test with an info message - /// - [TestMethod] - public void GhdlSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() - { - var results = GhdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nTest:(report note): Test Note", - 0); - - Assert.AreEqual(RunLineType.Info, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nTest:(report note): Test Note", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); - Assert.AreEqual("Test:(report note): Test Note", results.Lines[1].Text); - } - - /// - /// Test GHDL simulator test with a warning message - /// - [TestMethod] - public void GhdlSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() - { - var results = GhdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nTest:(report warning): Test Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nTest:(report warning): Test Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("Test:(report warning): Test Warning", results.Lines[1].Text); - } - - /// - /// Test GHDL simulator test with an error message - /// - [TestMethod] - public void GhdlSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = GhdlSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nTest:(report error): Test Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Test\nTest:(report error): Test Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Test:(report error): Test Error", results.Lines[1].Text); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for GHDL simulator +/// +[TestClass] +public class GhdlSimulatorTests +{ + /// + /// Check name of GHDL simulator + /// + [TestMethod] + public void GhdlSimulator_SimulatorName_ReturnsGHDL() + { + Assert.AreEqual("GHDL", GhdlSimulator.Instance.SimulatorName); + } + + /// + /// Test GHDL simulator compile with clean output + /// + [TestMethod] + public void GhdlSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() + { + var results = GhdlSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test GHDL simulator compile with an info message + /// + [TestMethod] + public void GhdlSimulator_CompileProcessor_WarningOutput_ReturnsWarningResult() + { + var results = GhdlSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nCompile:1:1:warning: Compile Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nCompile:1:1:warning: Compile Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("Compile:1:1:warning: Compile Warning", results.Lines[1].Text); + } + + /// + /// Test GHDL simulator compile with an error message + /// + [TestMethod] + public void GhdlSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = GhdlSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nCompile:error: Compile Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Compile\nCompile:error: Compile Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Compile:error: Compile Error", results.Lines[1].Text); + } + + /// + /// Test GHDL simulator test with clean output + /// + [TestMethod] + public void GhdlSimulator_TestProcessor_CleanOutput_ReturnsTextResult() + { + var results = GhdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test GHDL simulator test with an info message + /// + [TestMethod] + public void GhdlSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() + { + var results = GhdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nTest:(report note): Test Note", + 0); + + Assert.AreEqual(RunLineType.Info, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nTest:(report note): Test Note", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); + Assert.AreEqual("Test:(report note): Test Note", results.Lines[1].Text); + } + + /// + /// Test GHDL simulator test with a warning message + /// + [TestMethod] + public void GhdlSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() + { + var results = GhdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nTest:(report warning): Test Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nTest:(report warning): Test Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("Test:(report warning): Test Warning", results.Lines[1].Text); + } + + /// + /// Test GHDL simulator test with an error message + /// + [TestMethod] + public void GhdlSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = GhdlSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nTest:(report error): Test Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Test\nTest:(report error): Test Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Test:(report error): Test Error", results.Lines[1].Text); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/GlobalUsings.cs b/test/DEMAConsulting.VHDLTest.Tests/GlobalUsings.cs index 5ba32b2..d817f04 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/GlobalUsings.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/GlobalUsings.cs @@ -1,24 +1,24 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using Microsoft.VisualStudio.TestTools.UnitTesting; - -// Disable test parallelization to prevent file collisions -[assembly: DoNotParallelize] +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +// Disable test parallelization to prevent file collisions +[assembly: DoNotParallelize] diff --git a/test/DEMAConsulting.VHDLTest.Tests/ModelSimSimulatorTests.cs b/test/DEMAConsulting.VHDLTest.Tests/ModelSimSimulatorTests.cs index 64106c2..7cb5c76 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/ModelSimSimulatorTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/ModelSimSimulatorTests.cs @@ -1,184 +1,184 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for ModelSim simulator -/// -[TestClass] -public class ModelSimSimulatorTests -{ - /// - /// Check name of GHDL simulator - /// - [TestMethod] - public void ModelSimSimulator_SimulatorName_ReturnsModelSim() - { - Assert.AreEqual("ModelSim", ModelSimSimulator.Instance.SimulatorName); - } - - /// - /// Test ModelSim simulator compile with clean output - /// - [TestMethod] - public void ModelSimSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() - { - var results = ModelSimSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test ModelSim simulator compile with an info message - /// - [TestMethod] - public void ModelSimSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = ModelSimSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nError: Compile Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Compile\nError: Compile Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Error: Compile Error", results.Lines[1].Text); - } - - /// - /// Test ModelSim simulator test with clean output - /// - [TestMethod] - public void ModelSimSimulator_TestProcessor_CleanOutput_ReturnsTextResult() - { - var results = ModelSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test ModelSim simulator test with an info message - /// - [TestMethod] - public void ModelSimSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() - { - var results = ModelSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNote: Test Note", - 0); - - Assert.AreEqual(RunLineType.Info, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNote: Test Note", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); - Assert.AreEqual("Note: Test Note", results.Lines[1].Text); - } - - /// - /// Test ModelSim simulator test with a warning message - /// - [TestMethod] - public void ModelSimSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() - { - var results = ModelSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nWarning: Test Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nWarning: Test Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("Warning: Test Warning", results.Lines[1].Text); - } - - /// - /// Test ModelSim simulator test with an error message - /// - [TestMethod] - public void ModelSimSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = ModelSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nError: Test Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Test\nError: Test Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Error: Test Error", results.Lines[1].Text); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for ModelSim simulator +/// +[TestClass] +public class ModelSimSimulatorTests +{ + /// + /// Check name of GHDL simulator + /// + [TestMethod] + public void ModelSimSimulator_SimulatorName_ReturnsModelSim() + { + Assert.AreEqual("ModelSim", ModelSimSimulator.Instance.SimulatorName); + } + + /// + /// Test ModelSim simulator compile with clean output + /// + [TestMethod] + public void ModelSimSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() + { + var results = ModelSimSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test ModelSim simulator compile with an info message + /// + [TestMethod] + public void ModelSimSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = ModelSimSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nError: Compile Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Compile\nError: Compile Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Error: Compile Error", results.Lines[1].Text); + } + + /// + /// Test ModelSim simulator test with clean output + /// + [TestMethod] + public void ModelSimSimulator_TestProcessor_CleanOutput_ReturnsTextResult() + { + var results = ModelSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test ModelSim simulator test with an info message + /// + [TestMethod] + public void ModelSimSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() + { + var results = ModelSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNote: Test Note", + 0); + + Assert.AreEqual(RunLineType.Info, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNote: Test Note", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); + Assert.AreEqual("Note: Test Note", results.Lines[1].Text); + } + + /// + /// Test ModelSim simulator test with a warning message + /// + [TestMethod] + public void ModelSimSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() + { + var results = ModelSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nWarning: Test Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nWarning: Test Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("Warning: Test Warning", results.Lines[1].Text); + } + + /// + /// Test ModelSim simulator test with an error message + /// + [TestMethod] + public void ModelSimSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = ModelSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nError: Test Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Test\nError: Test Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Error: Test Error", results.Lines[1].Text); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/NvcSimulatorTests.cs b/test/DEMAConsulting.VHDLTest.Tests/NvcSimulatorTests.cs index 64e4d69..22a0849 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/NvcSimulatorTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/NvcSimulatorTests.cs @@ -1,232 +1,232 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for NVC simulator -/// -[TestClass] -public class NvcSimulatorTests -{ - /// - /// Check name of NVC simulator - /// - [TestMethod] - public void NvcSimulator_SimulatorName_ReturnsNVC() - { - Assert.AreEqual("NVC", NvcSimulator.Instance.SimulatorName); - } - - /// - /// Test NVC simulator compile with clean output - /// - [TestMethod] - public void NvcSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() - { - var results = NvcSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test NVC simulator compile with an info message - /// - [TestMethod] - public void NvcSimulator_CompileProcessor_InfoOutput_ReturnsInfoResult() - { - var results = NvcSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nCompile Note: Compile Note", - 0); - - Assert.AreEqual(RunLineType.Info, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nCompile Note: Compile Note", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); - Assert.AreEqual("Compile Note: Compile Note", results.Lines[1].Text); - } - - /// - /// Test NVC simulator compile with a warning message - /// - [TestMethod] - public void NvcSimulator_CompileProcessor_WarningOutput_ReturnsWarningResult() - { - var results = NvcSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nCompile Warning: Compile Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nCompile Warning: Compile Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("Compile Warning: Compile Warning", results.Lines[1].Text); - } - - /// - /// Test NVC simulator compile with an error message - /// - [TestMethod] - public void NvcSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = NvcSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nCompile Error: Compile Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Compile\nCompile Error: Compile Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Compile Error: Compile Error", results.Lines[1].Text); - } - - /// - /// Test NVC simulator test with clean output - /// - [TestMethod] - public void NvcSimulator_TestProcessor_CleanOutput_ReturnsTextResult() - { - var results = NvcSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test NVC simulator test with an info message - /// - [TestMethod] - public void NvcSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() - { - var results = NvcSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nTest Note: Test Note", - 0); - - Assert.AreEqual(RunLineType.Info, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nTest Note: Test Note", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); - Assert.AreEqual("Test Note: Test Note", results.Lines[1].Text); - } - - /// - /// Test NVC simulator test with a warning message - /// - [TestMethod] - public void NvcSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() - { - var results = NvcSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nTest Warning: Test Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nTest Warning: Test Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("Test Warning: Test Warning", results.Lines[1].Text); - } - - /// - /// Test NVC simulator test with an error message - /// - [TestMethod] - public void NvcSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = NvcSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nTest Error: Test Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Test\nTest Error: Test Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Test Error: Test Error", results.Lines[1].Text); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for NVC simulator +/// +[TestClass] +public class NvcSimulatorTests +{ + /// + /// Check name of NVC simulator + /// + [TestMethod] + public void NvcSimulator_SimulatorName_ReturnsNVC() + { + Assert.AreEqual("NVC", NvcSimulator.Instance.SimulatorName); + } + + /// + /// Test NVC simulator compile with clean output + /// + [TestMethod] + public void NvcSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() + { + var results = NvcSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test NVC simulator compile with an info message + /// + [TestMethod] + public void NvcSimulator_CompileProcessor_InfoOutput_ReturnsInfoResult() + { + var results = NvcSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nCompile Note: Compile Note", + 0); + + Assert.AreEqual(RunLineType.Info, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nCompile Note: Compile Note", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); + Assert.AreEqual("Compile Note: Compile Note", results.Lines[1].Text); + } + + /// + /// Test NVC simulator compile with a warning message + /// + [TestMethod] + public void NvcSimulator_CompileProcessor_WarningOutput_ReturnsWarningResult() + { + var results = NvcSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nCompile Warning: Compile Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nCompile Warning: Compile Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("Compile Warning: Compile Warning", results.Lines[1].Text); + } + + /// + /// Test NVC simulator compile with an error message + /// + [TestMethod] + public void NvcSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = NvcSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nCompile Error: Compile Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Compile\nCompile Error: Compile Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Compile Error: Compile Error", results.Lines[1].Text); + } + + /// + /// Test NVC simulator test with clean output + /// + [TestMethod] + public void NvcSimulator_TestProcessor_CleanOutput_ReturnsTextResult() + { + var results = NvcSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test NVC simulator test with an info message + /// + [TestMethod] + public void NvcSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() + { + var results = NvcSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nTest Note: Test Note", + 0); + + Assert.AreEqual(RunLineType.Info, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nTest Note: Test Note", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); + Assert.AreEqual("Test Note: Test Note", results.Lines[1].Text); + } + + /// + /// Test NVC simulator test with a warning message + /// + [TestMethod] + public void NvcSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() + { + var results = NvcSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nTest Warning: Test Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nTest Warning: Test Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("Test Warning: Test Warning", results.Lines[1].Text); + } + + /// + /// Test NVC simulator test with an error message + /// + [TestMethod] + public void NvcSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = NvcSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nTest Error: Test Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Test\nTest Error: Test Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Test Error: Test Error", results.Lines[1].Text); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/OptionsTests.cs b/test/DEMAConsulting.VHDLTest.Tests/OptionsTests.cs index 3bfc46c..63ba346 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/OptionsTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/OptionsTests.cs @@ -1,148 +1,148 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for parsing options -/// -[TestClass] -public class OptionsTests -{ - /// - /// Configuration file name - /// - private const string ConfigFile = "options-test.yaml"; - - /// - /// Configuration file contents - /// - private const string ConfigContent = - """ - files: - - file1.vhd - - file2.vhd - - tests: - - test1 - - test2 - """; - - /// - /// Test parsing options with no configuration file - /// - [TestMethod] - public void Options_Parse_NoConfigProvided_ThrowsInvalidOperationException() - { - var arguments = Context.Create([]); - Assert.ThrowsExactly(() => Options.Parse(arguments)); - } - - /// - /// Test parsing options with missing configuration file - /// - [TestMethod] - public void Options_Parse_MissingConfigFile_ThrowsFileNotFoundException() - { - var arguments = Context.Create(["-c", "missing-config.yaml"]); - Assert.ThrowsExactly(() => Options.Parse(arguments)); - } - - /// - /// Test parsing options with configuration file - /// - [TestMethod] - public void Options_Parse_ValidConfigFile_ParsesSuccessfully() - { - try - { - // Write the config file - File.WriteAllText(ConfigFile, ConfigContent); - - // Parse the options - var arguments = Context.Create(["-c", ConfigFile]); - var options = Options.Parse(arguments); - - // Check the options - Assert.IsNotNull(options); - Assert.HasCount(2, options.Config.Files); - Assert.AreEqual("file1.vhd", options.Config.Files[0]); - Assert.AreEqual("file2.vhd", options.Config.Files[1]); - Assert.HasCount(2, options.Config.Tests); - Assert.AreEqual("test1", options.Config.Tests[0]); - Assert.AreEqual("test2", options.Config.Tests[1]); - } - finally - { - // Delete the config file - File.Delete(ConfigFile); - } - } - - /// - /// Test parsing options with verbose flag - /// - [TestMethod] - public void Options_Parse_WithVerboseFlag_ParsesSuccessfully() - { - try - { - // Write the config file - File.WriteAllText(ConfigFile, ConfigContent); - - // Parse the options - var arguments = Context.Create(["-c", ConfigFile, "--verbose"]); - var options = Options.Parse(arguments); - - // Check the options - Assert.IsNotNull(options); - } - finally - { - // Delete the config file - File.Delete(ConfigFile); - } - } - - /// - /// Test parsing options with custom test - /// - [TestMethod] - public void Options_Parse_WithCustomTest_ParsesSuccessfully() - { - try - { - // Write the config file - File.WriteAllText(ConfigFile, ConfigContent); - - // Parse the options - var arguments = Context.Create(["-c", ConfigFile, "custom_test"]); - var options = Options.Parse(arguments); - - // Check the options - Assert.IsNotNull(options); - } - finally - { - // Delete the config file - File.Delete(ConfigFile); - } - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for parsing options +/// +[TestClass] +public class OptionsTests +{ + /// + /// Configuration file name + /// + private const string ConfigFile = "options-test.yaml"; + + /// + /// Configuration file contents + /// + private const string ConfigContent = + """ + files: + - file1.vhd + - file2.vhd + + tests: + - test1 + - test2 + """; + + /// + /// Test parsing options with no configuration file + /// + [TestMethod] + public void Options_Parse_NoConfigProvided_ThrowsInvalidOperationException() + { + var arguments = Context.Create([]); + Assert.ThrowsExactly(() => Options.Parse(arguments)); + } + + /// + /// Test parsing options with missing configuration file + /// + [TestMethod] + public void Options_Parse_MissingConfigFile_ThrowsFileNotFoundException() + { + var arguments = Context.Create(["-c", "missing-config.yaml"]); + Assert.ThrowsExactly(() => Options.Parse(arguments)); + } + + /// + /// Test parsing options with configuration file + /// + [TestMethod] + public void Options_Parse_ValidConfigFile_ParsesSuccessfully() + { + try + { + // Write the config file + File.WriteAllText(ConfigFile, ConfigContent); + + // Parse the options + var arguments = Context.Create(["-c", ConfigFile]); + var options = Options.Parse(arguments); + + // Check the options + Assert.IsNotNull(options); + Assert.HasCount(2, options.Config.Files); + Assert.AreEqual("file1.vhd", options.Config.Files[0]); + Assert.AreEqual("file2.vhd", options.Config.Files[1]); + Assert.HasCount(2, options.Config.Tests); + Assert.AreEqual("test1", options.Config.Tests[0]); + Assert.AreEqual("test2", options.Config.Tests[1]); + } + finally + { + // Delete the config file + File.Delete(ConfigFile); + } + } + + /// + /// Test parsing options with verbose flag + /// + [TestMethod] + public void Options_Parse_WithVerboseFlag_ParsesSuccessfully() + { + try + { + // Write the config file + File.WriteAllText(ConfigFile, ConfigContent); + + // Parse the options + var arguments = Context.Create(["-c", ConfigFile, "--verbose"]); + var options = Options.Parse(arguments); + + // Check the options + Assert.IsNotNull(options); + } + finally + { + // Delete the config file + File.Delete(ConfigFile); + } + } + + /// + /// Test parsing options with custom test + /// + [TestMethod] + public void Options_Parse_WithCustomTest_ParsesSuccessfully() + { + try + { + // Write the config file + File.WriteAllText(ConfigFile, ConfigContent); + + // Parse the options + var arguments = Context.Create(["-c", ConfigFile, "custom_test"]); + var options = Options.Parse(arguments); + + // Check the options + Assert.IsNotNull(options); + } + finally + { + // Delete the config file + File.Delete(ConfigFile); + } + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/QuestaSimSimulatorTests.cs b/test/DEMAConsulting.VHDLTest.Tests/QuestaSimSimulatorTests.cs index 23189d2..615606f 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/QuestaSimSimulatorTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/QuestaSimSimulatorTests.cs @@ -1,208 +1,208 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for QuestaSim simulator -/// -[TestClass] -public class QuestaSimSimulatorTests -{ - /// - /// Check name of QuestaSim simulator - /// - [TestMethod] - public void QuestaSimSimulator_SimulatorName_ReturnsQuestaSim() - { - Assert.AreEqual("QuestaSim", QuestaSimSimulator.Instance.SimulatorName); - } - - /// - /// Test QuestaSim simulator compile with clean output - /// - [TestMethod] - public void QuestaSimSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() - { - var results = QuestaSimSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test QuestaSim simulator compile with an error message - /// - [TestMethod] - public void QuestaSimSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = QuestaSimSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nError: Compile Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Compile\nError: Compile Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Error: Compile Error", results.Lines[1].Text); - } - - /// - /// Test QuestaSim simulator test with clean output - /// - [TestMethod] - public void QuestaSimSimulator_TestProcessor_CleanOutput_ReturnsTextResult() - { - var results = QuestaSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test QuestaSim simulator test with an info message - /// - [TestMethod] - public void QuestaSimSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() - { - var results = QuestaSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNote: Test Note", - 0); - - Assert.AreEqual(RunLineType.Info, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNote: Test Note", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); - Assert.AreEqual("Note: Test Note", results.Lines[1].Text); - } - - /// - /// Test QuestaSim simulator test with a warning message - /// - [TestMethod] - public void QuestaSimSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() - { - var results = QuestaSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nWarning: Test Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nWarning: Test Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("Warning: Test Warning", results.Lines[1].Text); - } - - /// - /// Test QuestaSim simulator test with an error message - /// - [TestMethod] - public void QuestaSimSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = QuestaSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nError: Test Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Test\nError: Test Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Error: Test Error", results.Lines[1].Text); - } - - /// - /// Test QuestaSim simulator test with a failure message - /// - [TestMethod] - public void QuestaSimSimulator_TestProcessor_FailureOutput_ReturnsErrorResult() - { - var results = QuestaSimSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nFailure: Test Failure", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Test\nFailure: Test Failure", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Failure: Test Failure", results.Lines[1].Text); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for QuestaSim simulator +/// +[TestClass] +public class QuestaSimSimulatorTests +{ + /// + /// Check name of QuestaSim simulator + /// + [TestMethod] + public void QuestaSimSimulator_SimulatorName_ReturnsQuestaSim() + { + Assert.AreEqual("QuestaSim", QuestaSimSimulator.Instance.SimulatorName); + } + + /// + /// Test QuestaSim simulator compile with clean output + /// + [TestMethod] + public void QuestaSimSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() + { + var results = QuestaSimSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test QuestaSim simulator compile with an error message + /// + [TestMethod] + public void QuestaSimSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = QuestaSimSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nError: Compile Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Compile\nError: Compile Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Error: Compile Error", results.Lines[1].Text); + } + + /// + /// Test QuestaSim simulator test with clean output + /// + [TestMethod] + public void QuestaSimSimulator_TestProcessor_CleanOutput_ReturnsTextResult() + { + var results = QuestaSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test QuestaSim simulator test with an info message + /// + [TestMethod] + public void QuestaSimSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() + { + var results = QuestaSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNote: Test Note", + 0); + + Assert.AreEqual(RunLineType.Info, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNote: Test Note", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); + Assert.AreEqual("Note: Test Note", results.Lines[1].Text); + } + + /// + /// Test QuestaSim simulator test with a warning message + /// + [TestMethod] + public void QuestaSimSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() + { + var results = QuestaSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nWarning: Test Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nWarning: Test Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("Warning: Test Warning", results.Lines[1].Text); + } + + /// + /// Test QuestaSim simulator test with an error message + /// + [TestMethod] + public void QuestaSimSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = QuestaSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nError: Test Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Test\nError: Test Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Error: Test Error", results.Lines[1].Text); + } + + /// + /// Test QuestaSim simulator test with a failure message + /// + [TestMethod] + public void QuestaSimSimulator_TestProcessor_FailureOutput_ReturnsErrorResult() + { + var results = QuestaSimSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nFailure: Test Failure", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Test\nFailure: Test Failure", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Failure: Test Failure", results.Lines[1].Text); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/RunProcessorTests.cs b/test/DEMAConsulting.VHDLTest.Tests/RunProcessorTests.cs index 3d487d0..f114962 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/RunProcessorTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/RunProcessorTests.cs @@ -1,92 +1,92 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for class. -/// -[TestClass] -public class RunProcessorTests -{ - /// - /// Test running a missing program. - /// - [TestMethod] - public void RunProcessor_Execute_MissingProgram_ThrowsException() - { - // Construct the processor - var processor = new RunProcessor( - [ - RunLineRule.Create(RunLineType.Error, "Error") - ]); - - // Run unknown program - try - { - processor.Execute("unknown-program"); - Assert.Fail("Expected exception"); - } - catch (Exception) - { - // Expected - } - } - - /// - /// Test running a program with an error. - /// - [TestMethod] - public void RunProcessor_Execute_ProgramWithError_ReturnsErrorResult() - { - // Construct the processor - var processor = new RunProcessor( - [ - RunLineRule.Create(RunLineType.Error, "Error") - ]); - - // Run dotnet with unknown command - var result = processor.Execute("dotnet", "", "unknown-command"); - - // Check the result - Assert.AreEqual(RunLineType.Error, result.Summary); - } - - /// - /// Test running a program producing passing output. - /// - [TestMethod] - public void RunProcessor_Execute_ProgramWithSuccess_ReturnsInfoResult() - { - // Construct the processor - var processor = new RunProcessor( - [ - RunLineRule.Create(RunLineType.Info, "Usage") - ]); - - // Run dotnet with help command - var result = processor.Execute("dotnet", "", "help"); - - // Check the result - Assert.AreEqual(RunLineType.Info, result.Summary); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for class. +/// +[TestClass] +public class RunProcessorTests +{ + /// + /// Test running a missing program. + /// + [TestMethod] + public void RunProcessor_Execute_MissingProgram_ThrowsException() + { + // Construct the processor + var processor = new RunProcessor( + [ + RunLineRule.Create(RunLineType.Error, "Error") + ]); + + // Run unknown program + try + { + processor.Execute("unknown-program"); + Assert.Fail("Expected exception"); + } + catch (Exception) + { + // Expected + } + } + + /// + /// Test running a program with an error. + /// + [TestMethod] + public void RunProcessor_Execute_ProgramWithError_ReturnsErrorResult() + { + // Construct the processor + var processor = new RunProcessor( + [ + RunLineRule.Create(RunLineType.Error, "Error") + ]); + + // Run dotnet with unknown command + var result = processor.Execute("dotnet", "", "unknown-command"); + + // Check the result + Assert.AreEqual(RunLineType.Error, result.Summary); + } + + /// + /// Test running a program producing passing output. + /// + [TestMethod] + public void RunProcessor_Execute_ProgramWithSuccess_ReturnsInfoResult() + { + // Construct the processor + var processor = new RunProcessor( + [ + RunLineRule.Create(RunLineType.Info, "Usage") + ]); + + // Run dotnet with help command + var result = processor.Execute("dotnet", "", "help"); + + // Check the result + Assert.AreEqual(RunLineType.Info, result.Summary); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/Runner.cs b/test/DEMAConsulting.VHDLTest.Tests/Runner.cs index 72b1078..c142e51 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/Runner.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/Runner.cs @@ -1,64 +1,66 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Diagnostics; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Program runner class -/// -internal static class Runner -{ - /// - /// Run the specified program - /// - /// Program output - /// Program name - /// Program arguments - /// Program exit code - /// On program start error - public static int Run(out string output, string program, params string[] arguments) - { - // Construct the start information - var startInfo = new ProcessStartInfo(program) - { - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true - }; - - // Add the arguments - foreach (var argument in arguments) - startInfo.ArgumentList.Add(argument); - - // Start the process - var process = Process.Start(startInfo) ?? - throw new InvalidOperationException("Failed to start process"); - - // Wait for the process to exit - process.WaitForExit(); - - // Save the output and return the exit code - output = process.StandardOutput.ReadToEnd(); - return process.ExitCode; - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Diagnostics; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Program runner class +/// +internal static class Runner +{ + /// + /// Run the specified program + /// + /// Program output + /// Program name + /// Program arguments + /// Program exit code + /// On program start error + public static int Run(out string output, string program, params string[] arguments) + { + // Construct the start information + var startInfo = new ProcessStartInfo(program) + { + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + // Add the arguments + foreach (var argument in arguments) + { + startInfo.ArgumentList.Add(argument); + } + + // Start the process + var process = Process.Start(startInfo) ?? + throw new InvalidOperationException("Failed to start process"); + + // Wait for the process to exit + process.WaitForExit(); + + // Save the output and return the exit code + output = process.StandardOutput.ReadToEnd(); + return process.ExitCode; + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/SimulatorFactoryTests.cs b/test/DEMAConsulting.VHDLTest.Tests/SimulatorFactoryTests.cs index a6c3890..1115ec0 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/SimulatorFactoryTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/SimulatorFactoryTests.cs @@ -1,100 +1,100 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for class. -/// -[TestClass] -public class SimulatorFactoryTests -{ - /// - /// Test querying the simulator factory for GHDL - /// - [TestMethod] - public void SimulatorFactory_Get_GhdlSimulator_ReturnsGhdlSimulator() - { - Assert.IsNotNull(SimulatorFactory.Get("ghdl")); - Assert.IsNotNull(SimulatorFactory.Get("GHDL")); - } - - /// - /// Test querying the simulator factory for ModelSim - /// - [TestMethod] - public void SimulatorFactory_Get_ModelSimSimulator_ReturnsModelSimSimulator() - { - Assert.IsNotNull(SimulatorFactory.Get("modelsim")); - Assert.IsNotNull(SimulatorFactory.Get("ModelSim")); - } - - /// - /// Test querying the simulator factory for Vivado - /// - [TestMethod] - public void SimulatorFactory_Get_VivadoSimulator_ReturnsVivadoSimulator() - { - Assert.IsNotNull(SimulatorFactory.Get("vivado")); - Assert.IsNotNull(SimulatorFactory.Get("Vivado")); - } - - /// - /// Test querying the simulator factory for ActiveHDL - /// - [TestMethod] - public void SimulatorFactory_Get_ActiveHDLSimulator_ReturnsActiveHDLSimulator() - { - Assert.IsNotNull(SimulatorFactory.Get("activehdl")); - Assert.IsNotNull(SimulatorFactory.Get("ActiveHDL")); - } - - /// - /// Test querying the simulator factory for NVC - /// - [TestMethod] - public void SimulatorFactory_Get_NVCSimulator_ReturnsNVCSimulator() - { - Assert.IsNotNull(SimulatorFactory.Get("nvc")); - Assert.IsNotNull(SimulatorFactory.Get("NVC")); - } - - /// - /// Test querying the simulator factory for QuestaSim - /// - [TestMethod] - public void SimulatorFactory_Get_QuestaSimSimulator_ReturnsQuestaSimSimulator() - { - Assert.IsNotNull(SimulatorFactory.Get("questasim")); - Assert.IsNotNull(SimulatorFactory.Get("QuestaSim")); - } - - /// - /// Test querying the simulator factory for an unknown simulator - /// - [TestMethod] - public void SimulatorFactory_Get_UnknownSimulator_ReturnsNull() - { - Assert.IsNull(SimulatorFactory.Get("unknown")); - Assert.IsNull(SimulatorFactory.Get("Unknown")); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for class. +/// +[TestClass] +public class SimulatorFactoryTests +{ + /// + /// Test querying the simulator factory for GHDL + /// + [TestMethod] + public void SimulatorFactory_Get_GhdlSimulator_ReturnsGhdlSimulator() + { + Assert.IsNotNull(SimulatorFactory.Get("ghdl")); + Assert.IsNotNull(SimulatorFactory.Get("GHDL")); + } + + /// + /// Test querying the simulator factory for ModelSim + /// + [TestMethod] + public void SimulatorFactory_Get_ModelSimSimulator_ReturnsModelSimSimulator() + { + Assert.IsNotNull(SimulatorFactory.Get("modelsim")); + Assert.IsNotNull(SimulatorFactory.Get("ModelSim")); + } + + /// + /// Test querying the simulator factory for Vivado + /// + [TestMethod] + public void SimulatorFactory_Get_VivadoSimulator_ReturnsVivadoSimulator() + { + Assert.IsNotNull(SimulatorFactory.Get("vivado")); + Assert.IsNotNull(SimulatorFactory.Get("Vivado")); + } + + /// + /// Test querying the simulator factory for ActiveHDL + /// + [TestMethod] + public void SimulatorFactory_Get_ActiveHDLSimulator_ReturnsActiveHDLSimulator() + { + Assert.IsNotNull(SimulatorFactory.Get("activehdl")); + Assert.IsNotNull(SimulatorFactory.Get("ActiveHDL")); + } + + /// + /// Test querying the simulator factory for NVC + /// + [TestMethod] + public void SimulatorFactory_Get_NVCSimulator_ReturnsNVCSimulator() + { + Assert.IsNotNull(SimulatorFactory.Get("nvc")); + Assert.IsNotNull(SimulatorFactory.Get("NVC")); + } + + /// + /// Test querying the simulator factory for QuestaSim + /// + [TestMethod] + public void SimulatorFactory_Get_QuestaSimSimulator_ReturnsQuestaSimSimulator() + { + Assert.IsNotNull(SimulatorFactory.Get("questasim")); + Assert.IsNotNull(SimulatorFactory.Get("QuestaSim")); + } + + /// + /// Test querying the simulator factory for an unknown simulator + /// + [TestMethod] + public void SimulatorFactory_Get_UnknownSimulator_ReturnsNull() + { + Assert.IsNull(SimulatorFactory.Get("unknown")); + Assert.IsNull(SimulatorFactory.Get("Unknown")); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/TestResultTests.cs b/test/DEMAConsulting.VHDLTest.Tests/TestResultTests.cs index 5d77a50..be31590 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/TestResultTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/TestResultTests.cs @@ -1,89 +1,89 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Collections.ObjectModel; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for class. -/// -[TestClass] -public class TestResultTests -{ - /// - /// Test constructing a test result with info - /// - [TestMethod] - public void TestResult_Constructor_WithInfoResult_CreatesPassedTest() - { - // Construct the result - var result = new Results.TestResult( - "test", - "test", - new RunResults( - RunLineType.Info, - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - 5.0, - 0, - "Test\nNo Issues", - new ReadOnlyCollection([ - new RunLine(RunLineType.Text, "Test"), - new RunLine(RunLineType.Text, "No Issues") - ]) - )); - - Assert.AreEqual("test", result.ClassName); - Assert.AreEqual("test", result.TestName); - Assert.AreEqual(RunLineType.Info, result.RunResults.Summary); - Assert.IsTrue(result.Passed); - Assert.IsFalse(result.Failed); - } - - /// - /// Test constructing a test result with error - /// - [TestMethod] - public void TestResult_Constructor_WithErrorResult_CreatesFailedTest() - { - // Construct the result - var result = new Results.TestResult( - "test", - "test", - new RunResults( - RunLineType.Error, - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - 5.0, - 0, - "Test\nError: Some Error", - new ReadOnlyCollection([ - new RunLine(RunLineType.Text, "Test"), - new RunLine(RunLineType.Error, "Error: Some Error") - ]) - )); - - Assert.AreEqual("test", result.ClassName); - Assert.AreEqual("test", result.TestName); - Assert.AreEqual(RunLineType.Error, result.RunResults.Summary); - Assert.IsFalse(result.Passed); - Assert.IsTrue(result.Failed); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Collections.ObjectModel; +using DEMAConsulting.VHDLTest.Run; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for class. +/// +[TestClass] +public class TestResultTests +{ + /// + /// Test constructing a test result with info + /// + [TestMethod] + public void TestResult_Constructor_WithInfoResult_CreatesPassedTest() + { + // Construct the result + var result = new Results.TestResult( + "test", + "test", + new RunResults( + RunLineType.Info, + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + 5.0, + 0, + "Test\nNo Issues", + new ReadOnlyCollection([ + new RunLine(RunLineType.Text, "Test"), + new RunLine(RunLineType.Text, "No Issues") + ]) + )); + + Assert.AreEqual("test", result.ClassName); + Assert.AreEqual("test", result.TestName); + Assert.AreEqual(RunLineType.Info, result.RunResults.Summary); + Assert.IsTrue(result.Passed); + Assert.IsFalse(result.Failed); + } + + /// + /// Test constructing a test result with error + /// + [TestMethod] + public void TestResult_Constructor_WithErrorResult_CreatesFailedTest() + { + // Construct the result + var result = new Results.TestResult( + "test", + "test", + new RunResults( + RunLineType.Error, + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + 5.0, + 0, + "Test\nError: Some Error", + new ReadOnlyCollection([ + new RunLine(RunLineType.Text, "Test"), + new RunLine(RunLineType.Error, "Error: Some Error") + ]) + )); + + Assert.AreEqual("test", result.ClassName); + Assert.AreEqual("test", result.TestName); + Assert.AreEqual(RunLineType.Error, result.RunResults.Summary); + Assert.IsFalse(result.Passed); + Assert.IsTrue(result.Failed); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/TestResultsTests.cs b/test/DEMAConsulting.VHDLTest.Tests/TestResultsTests.cs index a5bd7ed..b74c1d8 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/TestResultsTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/TestResultsTests.cs @@ -1,245 +1,255 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Collections.ObjectModel; -using DEMAConsulting.VHDLTest.Results; -using DEMAConsulting.VHDLTest.Run; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for class. -/// -[TestClass] -public class TestResultsTests -{ - /// - /// Test saving test results to a TRX file. - /// - [TestMethod] - public void TestResults_SaveResults_WithTrxExtension_CreatesTrxFile() - { - var results = new TestResults("TestRun", "TestCodeBase"); - results.Tests.Add( - new Results.TestResult( - "TestClass", "TestName", - new RunResults( - RunLineType.Info, - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - 5.0, - 0, - "Test\nNo Issues", - new ReadOnlyCollection([ - new RunLine(RunLineType.Text, "Test"), - new RunLine(RunLineType.Text, "No Issues") - ]) - ) - ) - ); - - try - { - results.SaveResults("TestResults.trx"); - Assert.IsTrue(File.Exists("TestResults.trx")); - - // Verify it's valid XML - var content = File.ReadAllText("TestResults.trx"); - Assert.Contains(" - /// Test saving test results to a JUnit XML file. - /// - [TestMethod] - public void TestResults_SaveResults_WithXmlExtension_CreatesJUnitFile() - { - var results = new TestResults("TestRun", "TestCodeBase"); - results.Tests.Add( - new Results.TestResult( - "TestClass", "TestName", - new RunResults( - RunLineType.Info, - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - 5.0, - 0, - "Test\nNo Issues", - new ReadOnlyCollection([ - new RunLine(RunLineType.Text, "Test"), - new RunLine(RunLineType.Text, "No Issues") - ]) - ) - ) - ); - - try - { - results.SaveResults("TestResults.xml"); - Assert.IsTrue(File.Exists("TestResults.xml")); - - // Verify it's valid JUnit XML - var content = File.ReadAllText("TestResults.xml"); - Assert.Contains(" - /// Test saving failed test results to a JUnit XML file. - /// - [TestMethod] - public void TestResults_SaveResults_WithFailedTest_CreatesJUnitFileWithFailure() - { - var results = new TestResults("TestRun", "TestCodeBase"); - results.Tests.Add( - new Results.TestResult( - "TestClass", "FailedTest", - new RunResults( - RunLineType.Error, - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - 5.0, - 1, - "Test\nError occurred", - new ReadOnlyCollection([ - new RunLine(RunLineType.Text, "Test"), - new RunLine(RunLineType.Error, "Error occurred") - ]) - ) - ) - ); - - try - { - results.SaveResults("TestResults.xml"); - Assert.IsTrue(File.Exists("TestResults.xml")); - - // Verify it contains failure information - var content = File.ReadAllText("TestResults.xml"); - Assert.Contains("failure", content); - Assert.Contains("Error occurred", content); - } - finally - { - if (File.Exists("TestResults.xml")) - File.Delete("TestResults.xml"); - } - } - - /// - /// Test backward compatibility with SaveToTrx method. - /// - [TestMethod] - public void TestResults_SaveToTrx_WithTestResults_CreatesTrxFile() - { - var results = new TestResults("TestRun", "TestCodeBase"); - results.Tests.Add( - new Results.TestResult( - "TestClass", "TestName", - new RunResults( - RunLineType.Info, - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - 5.0, - 0, - "Test\nNo Issues", - new ReadOnlyCollection([ - new RunLine(RunLineType.Text, "Test"), - new RunLine(RunLineType.Text, "No Issues") - ]) - ) - ) - ); - - try - { - results.SaveToTrx("TestResults.trx"); - Assert.IsTrue(File.Exists("TestResults.trx")); - } - finally - { - if (File.Exists("TestResults.trx")) - File.Delete("TestResults.trx"); - } - } - - /// - /// Test that SaveResults throws ArgumentException for null/empty file name. - /// - [TestMethod] - public void TestResults_SaveResults_WithNullFileName_ThrowsArgumentException() - { - var results = new TestResults("TestRun", "TestCodeBase"); - - Assert.ThrowsExactly(() => results.SaveResults(null!)); - Assert.ThrowsExactly(() => results.SaveResults(string.Empty)); - Assert.ThrowsExactly(() => results.SaveResults(" ")); - } - - /// - /// Test that SaveResults defaults to TRX for unknown extensions. - /// - [TestMethod] - public void TestResults_SaveResults_WithUnknownExtension_CreatesTrxFile() - { - var results = new TestResults("TestRun", "TestCodeBase"); - results.Tests.Add( - new Results.TestResult( - "TestClass", "TestName", - new RunResults( - RunLineType.Info, - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - 5.0, - 0, - "Test\nNo Issues", - new ReadOnlyCollection([ - new RunLine(RunLineType.Text, "Test"), - new RunLine(RunLineType.Text, "No Issues") - ]) - ) - ) - ); - - try - { - results.SaveResults("TestResults.unknown"); - Assert.IsTrue(File.Exists("TestResults.unknown")); - - // Verify it's TRX format - var content = File.ReadAllText("TestResults.unknown"); - Assert.Contains(" +/// Tests for class. +/// +[TestClass] +public class TestResultsTests +{ + /// + /// Test saving test results to a TRX file. + /// + [TestMethod] + public void TestResults_SaveResults_WithTrxExtension_CreatesTrxFile() + { + var results = new TestResults("TestRun", "TestCodeBase"); + results.Tests.Add( + new Results.TestResult( + "TestClass", "TestName", + new RunResults( + RunLineType.Info, + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + 5.0, + 0, + "Test\nNo Issues", + new ReadOnlyCollection([ + new RunLine(RunLineType.Text, "Test"), + new RunLine(RunLineType.Text, "No Issues") + ]) + ) + ) + ); + + try + { + results.SaveResults("TestResults.trx"); + Assert.IsTrue(File.Exists("TestResults.trx")); + + // Verify it's valid XML + var content = File.ReadAllText("TestResults.trx"); + Assert.Contains(" + /// Test saving test results to a JUnit XML file. + /// + [TestMethod] + public void TestResults_SaveResults_WithXmlExtension_CreatesJUnitFile() + { + var results = new TestResults("TestRun", "TestCodeBase"); + results.Tests.Add( + new Results.TestResult( + "TestClass", "TestName", + new RunResults( + RunLineType.Info, + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + 5.0, + 0, + "Test\nNo Issues", + new ReadOnlyCollection([ + new RunLine(RunLineType.Text, "Test"), + new RunLine(RunLineType.Text, "No Issues") + ]) + ) + ) + ); + + try + { + results.SaveResults("TestResults.xml"); + Assert.IsTrue(File.Exists("TestResults.xml")); + + // Verify it's valid JUnit XML + var content = File.ReadAllText("TestResults.xml"); + Assert.Contains(" + /// Test saving failed test results to a JUnit XML file. + /// + [TestMethod] + public void TestResults_SaveResults_WithFailedTest_CreatesJUnitFileWithFailure() + { + var results = new TestResults("TestRun", "TestCodeBase"); + results.Tests.Add( + new Results.TestResult( + "TestClass", "FailedTest", + new RunResults( + RunLineType.Error, + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + 5.0, + 1, + "Test\nError occurred", + new ReadOnlyCollection([ + new RunLine(RunLineType.Text, "Test"), + new RunLine(RunLineType.Error, "Error occurred") + ]) + ) + ) + ); + + try + { + results.SaveResults("TestResults.xml"); + Assert.IsTrue(File.Exists("TestResults.xml")); + + // Verify it contains failure information + var content = File.ReadAllText("TestResults.xml"); + Assert.Contains("failure", content); + Assert.Contains("Error occurred", content); + } + finally + { + if (File.Exists("TestResults.xml")) + { + File.Delete("TestResults.xml"); + } + } + } + + /// + /// Test backward compatibility with SaveToTrx method. + /// + [TestMethod] + public void TestResults_SaveToTrx_WithTestResults_CreatesTrxFile() + { + var results = new TestResults("TestRun", "TestCodeBase"); + results.Tests.Add( + new Results.TestResult( + "TestClass", "TestName", + new RunResults( + RunLineType.Info, + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + 5.0, + 0, + "Test\nNo Issues", + new ReadOnlyCollection([ + new RunLine(RunLineType.Text, "Test"), + new RunLine(RunLineType.Text, "No Issues") + ]) + ) + ) + ); + + try + { + results.SaveToTrx("TestResults.trx"); + Assert.IsTrue(File.Exists("TestResults.trx")); + } + finally + { + if (File.Exists("TestResults.trx")) + { + File.Delete("TestResults.trx"); + } + } + } + + /// + /// Test that SaveResults throws ArgumentException for null/empty file name. + /// + [TestMethod] + public void TestResults_SaveResults_WithNullFileName_ThrowsArgumentException() + { + var results = new TestResults("TestRun", "TestCodeBase"); + + Assert.ThrowsExactly(() => results.SaveResults(null!)); + Assert.ThrowsExactly(() => results.SaveResults(string.Empty)); + Assert.ThrowsExactly(() => results.SaveResults(" ")); + } + + /// + /// Test that SaveResults defaults to TRX for unknown extensions. + /// + [TestMethod] + public void TestResults_SaveResults_WithUnknownExtension_CreatesTrxFile() + { + var results = new TestResults("TestRun", "TestCodeBase"); + results.Tests.Add( + new Results.TestResult( + "TestClass", "TestName", + new RunResults( + RunLineType.Info, + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + 5.0, + 0, + "Test\nNo Issues", + new ReadOnlyCollection([ + new RunLine(RunLineType.Text, "Test"), + new RunLine(RunLineType.Text, "No Issues") + ]) + ) + ) + ); + + try + { + results.SaveResults("TestResults.unknown"); + Assert.IsTrue(File.Exists("TestResults.unknown")); + + // Verify it's TRX format + var content = File.ReadAllText("TestResults.unknown"); + Assert.Contains(" -/// Tests for program usage -/// -[TestClass] -public class UsageTests -{ - /// - /// Test usage information is reported when no arguments are specified - /// - [TestMethod] - public void IntegrationTest_NoArguments_DisplaysUsageAndReturnsError() - { - // Run the application - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll"); - - // Verify error - Assert.AreNotEqual(0, exitCode); - - // Verify usage reported - Assert.Contains("Error: Missing arguments", output); - Assert.Contains("Usage: VHDLTest", output); - } - - /// - /// Test usage information is reported when the '-h' parameter is specified - /// - [TestMethod] - public void IntegrationTest_HelpShortFlag_DisplaysUsageAndReturnsSuccess() - { - // Run the application - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "-h"); - - // Verify no error - Assert.AreEqual(0, exitCode); - - // Verify usage reported - Assert.Contains("Usage: VHDLTest", output); - } - - /// - /// Test usage information is reported when the '-?' parameter is specified - /// - [TestMethod] - public void IntegrationTest_HelpQuestionFlag_DisplaysUsageAndReturnsSuccess() - { - // Run the application - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "-?"); - - // Verify no error - Assert.AreEqual(0, exitCode); - - // Verify usage reported - Assert.Contains("Usage: VHDLTest", output); - } - - /// - /// Test usage information is reported when the '--help' parameter is specified - /// - [TestMethod] - public void IntegrationTest_HelpLongFlag_DisplaysUsageAndReturnsSuccess() - { - // Run the application - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--help"); - - // Verify no error - Assert.AreEqual(0, exitCode); - - // Verify usage reported - Assert.Contains("Usage: VHDLTest", output); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for program usage +/// +[TestClass] +public class UsageTests +{ + /// + /// Test usage information is reported when no arguments are specified + /// + [TestMethod] + public void IntegrationTest_NoArguments_DisplaysUsageAndReturnsError() + { + // Run the application + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll"); + + // Verify error + Assert.AreNotEqual(0, exitCode); + + // Verify usage reported + Assert.Contains("Error: Missing arguments", output); + Assert.Contains("Usage: VHDLTest", output); + } + + /// + /// Test usage information is reported when the '-h' parameter is specified + /// + [TestMethod] + public void IntegrationTest_HelpShortFlag_DisplaysUsageAndReturnsSuccess() + { + // Run the application + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "-h"); + + // Verify no error + Assert.AreEqual(0, exitCode); + + // Verify usage reported + Assert.Contains("Usage: VHDLTest", output); + } + + /// + /// Test usage information is reported when the '-?' parameter is specified + /// + [TestMethod] + public void IntegrationTest_HelpQuestionFlag_DisplaysUsageAndReturnsSuccess() + { + // Run the application + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "-?"); + + // Verify no error + Assert.AreEqual(0, exitCode); + + // Verify usage reported + Assert.Contains("Usage: VHDLTest", output); + } + + /// + /// Test usage information is reported when the '--help' parameter is specified + /// + [TestMethod] + public void IntegrationTest_HelpLongFlag_DisplaysUsageAndReturnsSuccess() + { + // Run the application + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--help"); + + // Verify no error + Assert.AreEqual(0, exitCode); + + // Verify usage reported + Assert.Contains("Usage: VHDLTest", output); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/ValidationTests.cs b/test/DEMAConsulting.VHDLTest.Tests/ValidationTests.cs index 024b5e2..997e31e 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/ValidationTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/ValidationTests.cs @@ -1,128 +1,128 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for validation -/// -[TestClass] -public class ValidationTests -{ - /// - /// Test usage information is reported when no arguments are specified - /// - [TestMethod] - public void IntegrationTest_ValidateFlag_PerformsValidationAndReturnsSuccess() - { - // Run the application - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--validate"); - - // Verify success - Assert.AreEqual(0, exitCode); - - // Verify validation passed - Assert.Contains("Validation Passed", output); - } - - /// - /// Test usage information is reported when no arguments are specified - /// - [TestMethod] - public void IntegrationTest_ValidateFlagWithDepth_PerformsValidationWithDepth() - { - // Run the application - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--validate", - "--depth", "3"); - - // Verify success - Assert.AreEqual(0, exitCode); - - // Verify validation depth - Assert.Contains("### DEMAConsulting.VHDLTest", output); - } - - /// - /// Test validation results can be saved to file - /// - [TestMethod] - public void IntegrationTest_ValidateFlagWithResultsFile_SavesValidationResults() - { - try - { - // Run the application - var exitCode = Runner.Run( - out _, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--validate", - "--results", "validation_results.trx"); - - // Verify success - Assert.AreEqual(0, exitCode); - - // Verify results file written - Assert.IsTrue(File.Exists("validation_results.trx")); - - // Read the results file. - var text = File.ReadAllText("validation_results.trx"); - Assert.Contains("""""", text); - Assert.Contains("""""", text); - Assert.Contains("""""", text); - } - finally - { - // Delete results file - File.Delete("validation_results.trx"); - } - } - - /// - /// Test validation output contains OS Version field in the information table - /// - [TestMethod] - public void IntegrationTest_ValidateFlag_IncludesOSVersionInReport() - { - // Run the application - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--simulator", "mock", - "--validate"); - - // Verify success - Assert.AreEqual(0, exitCode); - - // Verify OS Version field is present in output - Assert.Contains("| OS Version", output); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for validation +/// +[TestClass] +public class ValidationTests +{ + /// + /// Test usage information is reported when no arguments are specified + /// + [TestMethod] + public void IntegrationTest_ValidateFlag_PerformsValidationAndReturnsSuccess() + { + // Run the application + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--validate"); + + // Verify success + Assert.AreEqual(0, exitCode); + + // Verify validation passed + Assert.Contains("Validation Passed", output); + } + + /// + /// Test usage information is reported when no arguments are specified + /// + [TestMethod] + public void IntegrationTest_ValidateFlagWithDepth_PerformsValidationWithDepth() + { + // Run the application + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--validate", + "--depth", "3"); + + // Verify success + Assert.AreEqual(0, exitCode); + + // Verify validation depth + Assert.Contains("### DEMAConsulting.VHDLTest", output); + } + + /// + /// Test validation results can be saved to file + /// + [TestMethod] + public void IntegrationTest_ValidateFlagWithResultsFile_SavesValidationResults() + { + try + { + // Run the application + var exitCode = Runner.Run( + out _, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--validate", + "--results", "validation_results.trx"); + + // Verify success + Assert.AreEqual(0, exitCode); + + // Verify results file written + Assert.IsTrue(File.Exists("validation_results.trx")); + + // Read the results file. + var text = File.ReadAllText("validation_results.trx"); + Assert.Contains("""""", text); + Assert.Contains("""""", text); + Assert.Contains("""""", text); + } + finally + { + // Delete results file + File.Delete("validation_results.trx"); + } + } + + /// + /// Test validation output contains OS Version field in the information table + /// + [TestMethod] + public void IntegrationTest_ValidateFlag_IncludesOSVersionInReport() + { + // Run the application + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--simulator", "mock", + "--validate"); + + // Verify success + Assert.AreEqual(0, exitCode); + + // Verify OS Version field is present in output + Assert.Contains("| OS Version", output); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/VersionTests.cs b/test/DEMAConsulting.VHDLTest.Tests/VersionTests.cs index c87e582..ccc5f58 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/VersionTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/VersionTests.cs @@ -1,77 +1,77 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using System.Text.RegularExpressions; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for program version -/// -[TestClass] -public partial class VersionTests -{ - /// - /// Regular expression to check for version - /// - /// - [GeneratedRegex(@"\d+\.\d+\.\d+.*")] - private static partial Regex VersionRegex(); - - /// - /// Test version information is reported when the '-v' parameter is specified - /// - [TestMethod] - public void IntegrationTest_VersionShortFlag_DisplaysVersionAndReturnsSuccess() - { - // Query version - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "-v"); - - // Verify success - Assert.AreEqual(0, exitCode); - - // Verify version reported - Assert.MatchesRegex(VersionRegex(), output); - } - - /// - /// Test version information is reported when the '--version' parameter is specified - /// - [TestMethod] - public void IntegrationTest_VersionLongFlag_DisplaysVersionAndReturnsSuccess() - { - // Query version - var exitCode = Runner.Run( - out var output, - "dotnet", - "DEMAConsulting.VHDLTest.dll", - "--version"); - - // Verify success - Assert.AreEqual(0, exitCode); - - // Verify version reported - Assert.MatchesRegex(VersionRegex(), output); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System.Text.RegularExpressions; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for program version +/// +[TestClass] +public partial class VersionTests +{ + /// + /// Regular expression to check for version + /// + /// + [GeneratedRegex(@"\d+\.\d+\.\d+.*")] + private static partial Regex VersionRegex(); + + /// + /// Test version information is reported when the '-v' parameter is specified + /// + [TestMethod] + public void IntegrationTest_VersionShortFlag_DisplaysVersionAndReturnsSuccess() + { + // Query version + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "-v"); + + // Verify success + Assert.AreEqual(0, exitCode); + + // Verify version reported + Assert.MatchesRegex(VersionRegex(), output); + } + + /// + /// Test version information is reported when the '--version' parameter is specified + /// + [TestMethod] + public void IntegrationTest_VersionLongFlag_DisplaysVersionAndReturnsSuccess() + { + // Query version + var exitCode = Runner.Run( + out var output, + "dotnet", + "DEMAConsulting.VHDLTest.dll", + "--version"); + + // Verify success + Assert.AreEqual(0, exitCode); + + // Verify version reported + Assert.MatchesRegex(VersionRegex(), output); + } +} diff --git a/test/DEMAConsulting.VHDLTest.Tests/VivadoSimulatorTests.cs b/test/DEMAConsulting.VHDLTest.Tests/VivadoSimulatorTests.cs index 831ef91..500b57d 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/VivadoSimulatorTests.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/VivadoSimulatorTests.cs @@ -1,184 +1,184 @@ -// Copyright (c) 2023 DEMA Consulting -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -using DEMAConsulting.VHDLTest.Run; -using DEMAConsulting.VHDLTest.Simulators; - -namespace DEMAConsulting.VHDLTest.Tests; - -/// -/// Tests for Vivado simulator -/// -[TestClass] -public class VivadoSimulatorTests -{ - /// - /// Check name of Vivado simulator - /// - [TestMethod] - public void VivadoSimulator_SimulatorName_ReturnsVivado() - { - Assert.AreEqual("Vivado", VivadoSimulator.Instance.SimulatorName); - } - - /// - /// Test Vivado simulator compile with clean output - /// - [TestMethod] - public void VivadoSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() - { - var results = VivadoSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Compile\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test Vivado simulator compile with an error message - /// - [TestMethod] - public void VivadoSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = VivadoSimulator.CompileProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Compile\nError: Compile Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Compile\nError: Compile Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Compile", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Error: Compile Error", results.Lines[1].Text); - } - - /// - /// Test Vivado simulator test with clean output - /// - [TestMethod] - public void VivadoSimulator_TestProcessor_CleanOutput_ReturnsTextResult() - { - var results = VivadoSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNo Issues", - 0); - - Assert.AreEqual(RunLineType.Text, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNo Issues", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); - Assert.AreEqual("No Issues", results.Lines[1].Text); - } - - /// - /// Test Vivado simulator test with an info message - /// - [TestMethod] - public void VivadoSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() - { - var results = VivadoSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nNote: Test Note", - 0); - - Assert.AreEqual(RunLineType.Info, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nNote: Test Note", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); - Assert.AreEqual("Note: Test Note", results.Lines[1].Text); - } - - /// - /// Test Vivado simulator test with a warning message - /// - [TestMethod] - public void VivadoSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() - { - var results = VivadoSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nWarning: Test Warning", - 0); - - Assert.AreEqual(RunLineType.Warning, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(0, results.ExitCode); - Assert.AreEqual("Test\nWarning: Test Warning", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); - Assert.AreEqual("Warning: Test Warning", results.Lines[1].Text); - } - - /// - /// Test Vivado simulator test with an error message - /// - [TestMethod] - public void VivadoSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() - { - var results = VivadoSimulator.TestProcessor.Parse( - new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), - new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), - "Test\nError: Test Error", - 1); - - Assert.AreEqual(RunLineType.Error, results.Summary); - Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); - Assert.AreEqual(5.0, results.Duration, 0.1); - Assert.AreEqual(1, results.ExitCode); - Assert.AreEqual("Test\nError: Test Error", results.Output); - Assert.HasCount(2, results.Lines); - Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); - Assert.AreEqual("Test", results.Lines[0].Text); - Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); - Assert.AreEqual("Error: Test Error", results.Lines[1].Text); - } -} +// Copyright (c) 2023 DEMA Consulting +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using DEMAConsulting.VHDLTest.Run; +using DEMAConsulting.VHDLTest.Simulators; + +namespace DEMAConsulting.VHDLTest.Tests; + +/// +/// Tests for Vivado simulator +/// +[TestClass] +public class VivadoSimulatorTests +{ + /// + /// Check name of Vivado simulator + /// + [TestMethod] + public void VivadoSimulator_SimulatorName_ReturnsVivado() + { + Assert.AreEqual("Vivado", VivadoSimulator.Instance.SimulatorName); + } + + /// + /// Test Vivado simulator compile with clean output + /// + [TestMethod] + public void VivadoSimulator_CompileProcessor_CleanOutput_ReturnsTextResult() + { + var results = VivadoSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Compile\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test Vivado simulator compile with an error message + /// + [TestMethod] + public void VivadoSimulator_CompileProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = VivadoSimulator.CompileProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Compile\nError: Compile Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Compile\nError: Compile Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Compile", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Error: Compile Error", results.Lines[1].Text); + } + + /// + /// Test Vivado simulator test with clean output + /// + [TestMethod] + public void VivadoSimulator_TestProcessor_CleanOutput_ReturnsTextResult() + { + var results = VivadoSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNo Issues", + 0); + + Assert.AreEqual(RunLineType.Text, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNo Issues", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Text, results.Lines[1].Type); + Assert.AreEqual("No Issues", results.Lines[1].Text); + } + + /// + /// Test Vivado simulator test with an info message + /// + [TestMethod] + public void VivadoSimulator_TestProcessor_InfoOutput_ReturnsInfoResult() + { + var results = VivadoSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nNote: Test Note", + 0); + + Assert.AreEqual(RunLineType.Info, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nNote: Test Note", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Info, results.Lines[1].Type); + Assert.AreEqual("Note: Test Note", results.Lines[1].Text); + } + + /// + /// Test Vivado simulator test with a warning message + /// + [TestMethod] + public void VivadoSimulator_TestProcessor_WarningOutput_ReturnsWarningResult() + { + var results = VivadoSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nWarning: Test Warning", + 0); + + Assert.AreEqual(RunLineType.Warning, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(0, results.ExitCode); + Assert.AreEqual("Test\nWarning: Test Warning", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Warning, results.Lines[1].Type); + Assert.AreEqual("Warning: Test Warning", results.Lines[1].Text); + } + + /// + /// Test Vivado simulator test with an error message + /// + [TestMethod] + public void VivadoSimulator_TestProcessor_ErrorOutput_ReturnsErrorResult() + { + var results = VivadoSimulator.TestProcessor.Parse( + new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), + new DateTime(2024, 08, 10, 0, 0, 5, DateTimeKind.Utc), + "Test\nError: Test Error", + 1); + + Assert.AreEqual(RunLineType.Error, results.Summary); + Assert.AreEqual(new DateTime(2024, 08, 10, 0, 0, 0, DateTimeKind.Utc), results.Start); + Assert.AreEqual(5.0, results.Duration, 0.1); + Assert.AreEqual(1, results.ExitCode); + Assert.AreEqual("Test\nError: Test Error", results.Output); + Assert.HasCount(2, results.Lines); + Assert.AreEqual(RunLineType.Text, results.Lines[0].Type); + Assert.AreEqual("Test", results.Lines[0].Text); + Assert.AreEqual(RunLineType.Error, results.Lines[1].Type); + Assert.AreEqual("Error: Test Error", results.Lines[1].Text); + } +} From 4e610d6343840f5b20c5567f90bf5a326d0a3a0d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 19:43:22 +0000 Subject: [PATCH 03/12] Add macOS support from template PR #54: build/test-ghdl matrices, OS_SHORT fix, requirements, AGENTS Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- .github/workflows/build.yaml | 15 ++++++++------- AGENTS.md | 5 +++-- requirements.yaml | 12 ++++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fee4368..26418d6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -101,7 +101,7 @@ jobs: strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} @@ -131,6 +131,7 @@ jobs: update: true - uses: nickg/setup-nvc-ci@v1 + if: matrix.os != 'macos-latest' with: version: latest @@ -147,8 +148,8 @@ jobs: run: | mkdir -p artifacts echo "Capturing tool versions..." - # Create short job ID: build-win, build-ubuntu - OS_SHORT=$(echo "${{ matrix.os }}" | sed 's/windows-latest/win/;s/ubuntu-latest/ubuntu/') + # Create short job ID: build-windows, build-ubuntu, build-macos + OS_SHORT=$(echo "${{ matrix.os }}" | sed 's/-latest//') JOB_ID="build-${OS_SHORT}" dotnet versionmark --capture --job-id "${JOB_ID}" \ --output "artifacts/versionmark-${JOB_ID}.json" -- \ @@ -245,7 +246,7 @@ jobs: strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] dotnet: [8.x, 9.x, 10.x] runs-on: ${{ matrix.os }} @@ -272,7 +273,7 @@ jobs: - uses: ghdl/setup-ghdl@v1 with: version: 5.1.1 - backend: mcode + backend: ${{ matrix.os == 'macos-latest' && 'llvm' || 'mcode' }} - name: Download Artifacts uses: actions/download-artifact@v8 @@ -302,7 +303,7 @@ jobs: mkdir -p artifacts echo "Capturing tool versions..." # Create appropriate job ID for the test job - OS_SHORT=$(echo "${{ matrix.os }}" | sed 's/windows-latest/win/;s/ubuntu-latest/ubuntu/') + OS_SHORT=$(echo "${{ matrix.os }}" | sed 's/-latest//') DOTNET_SHORT=$(echo "${{ matrix.dotnet }}" | sed 's/\.x$//') SIMULATOR="ghdl" JOB_ID="int-${SIMULATOR}-${OS_SHORT}-${DOTNET_SHORT}" @@ -408,7 +409,7 @@ jobs: mkdir -p artifacts echo "Capturing tool versions..." # Create appropriate job ID for the test job - OS_SHORT=$(echo "${{ matrix.os }}" | sed 's/windows-latest/win/;s/ubuntu-latest/ubuntu/') + OS_SHORT=$(echo "${{ matrix.os }}" | sed 's/-latest//') DOTNET_SHORT=$(echo "${{ matrix.dotnet }}" | sed 's/\.x$//') SIMULATOR="nvc" JOB_ID="int-${SIMULATOR}-${OS_SHORT}-${DOTNET_SHORT}" diff --git a/AGENTS.md b/AGENTS.md index 058a00f..309684b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -51,6 +51,7 @@ evidence. This is critical for platform, simulator, and framework requirements - - `nvc@TestName` - proves the test passed using the NVC simulator - `windows@TestName` - proves the test passed on a Windows platform - `ubuntu@TestName` - proves the test passed on a Linux (Ubuntu) platform +- `macos@TestName` - proves the test passed on a macOS platform - `dotnet8.x@TestName` - proves the self-validation test ran on a machine with .NET 8.x runtime - `dotnet9.x@TestName` - proves the self-validation test ran on a machine with .NET 9.x runtime - `dotnet10.x@TestName` - proves the self-validation test ran on a machine with .NET 10.x runtime @@ -120,9 +121,9 @@ build.bat # Windows ## CI/CD - **Quality Checks**: Markdown lint, spell check, YAML lint -- **Build**: Multi-platform (Windows/Linux) +- **Build**: Multi-platform (Windows/Linux/macOS) - **CodeQL**: Security scanning -- **VHDL Simulation Tests**: GHDL and NVC on Windows/Linux +- **VHDL Simulation Tests**: GHDL on Windows/Linux/macOS, NVC on Windows/Linux - **Documentation**: Auto-generated via Pandoc + Weasyprint ## Build & Quality (Quick Reference) diff --git a/requirements.yaml b/requirements.yaml index f2c972b..4fbf8bc 100644 --- a/requirements.yaml +++ b/requirements.yaml @@ -21,6 +21,7 @@ # nvc@TestName - proves the test passed using the NVC simulator # windows@TestName - proves the test passed on a Windows platform # ubuntu@TestName - proves the test passed on a Linux (Ubuntu) platform +# macos@TestName - proves the test passed on a macOS platform # dotnet8.x@TestName - proves the self-validation test ran with .NET 8.x runtime # dotnet9.x@TestName - proves the self-validation test ran with .NET 9.x runtime # dotnet10.x@TestName - proves the self-validation test ran with .NET 10.x runtime @@ -225,6 +226,17 @@ sections: - windows@VHDLTest_TestPasses - windows@VHDLTest_TestFails + - id: VHDLTest-Plt-MacOS + title: VHDLTest shall run on macOS operating systems. + justification: | + macOS is widely used by developers working in Apple ecosystems and for desktop-based + FPGA development. Supporting macOS ensures VHDLTest is accessible to the broadest + possible user base including developers using Apple hardware. + tests: + # Tests link to "macos" to ensure results come from macOS platform + - macos@VHDLTest_TestPasses + - macos@VHDLTest_TestFails + - id: VHDLTest-Plt-Net8 title: VHDLTest shall support .NET 8.0 runtime. justification: | From f22bdd3778d3321a5f6a2539fe0d76c18402ed2c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 19:50:49 +0000 Subject: [PATCH 04/12] Add brew install nvc for macOS, use mcode backend for GHDL, add macOS to test-nvc matrix Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- .github/workflows/build.yaml | 13 +++++++++++-- AGENTS.md | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 26418d6..e411293 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -135,6 +135,10 @@ jobs: with: version: latest + - name: Install NVC (macOS) + if: matrix.os == 'macos-latest' + run: brew install nvc + - name: Restore Tools run: > dotnet tool restore @@ -273,7 +277,7 @@ jobs: - uses: ghdl/setup-ghdl@v1 with: version: 5.1.1 - backend: ${{ matrix.os == 'macos-latest' && 'llvm' || 'mcode' }} + backend: mcode - name: Download Artifacts uses: actions/download-artifact@v8 @@ -353,7 +357,7 @@ jobs: strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest, macos-latest] dotnet: [8.x, 9.x, 10.x] runs-on: ${{ matrix.os }} @@ -378,9 +382,14 @@ jobs: update: true - uses: nickg/setup-nvc-ci@v1 + if: matrix.os != 'macos-latest' with: version: latest + - name: Install NVC (macOS) + if: matrix.os == 'macos-latest' + run: brew install nvc + - name: Download Artifacts uses: actions/download-artifact@v8 with: diff --git a/AGENTS.md b/AGENTS.md index 309684b..81f055a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -123,7 +123,7 @@ build.bat # Windows - **Quality Checks**: Markdown lint, spell check, YAML lint - **Build**: Multi-platform (Windows/Linux/macOS) - **CodeQL**: Security scanning -- **VHDL Simulation Tests**: GHDL on Windows/Linux/macOS, NVC on Windows/Linux +- **VHDL Simulation Tests**: GHDL on Windows/Linux/macOS, NVC on Windows/Linux/macOS - **Documentation**: Auto-generated via Pandoc + Weasyprint ## Build & Quality (Quick Reference) From 1b757571e2d1c3c92caaf1669449ae33c1df6781 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 19:56:59 +0000 Subject: [PATCH 05/12] Fix MD024 lint failure by enabling siblings_only for duplicate headings Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- .markdownlint-cli2.jsonc | 1 + 1 file changed, 1 insertion(+) diff --git a/.markdownlint-cli2.jsonc b/.markdownlint-cli2.jsonc index a46ee1a..94acac4 100644 --- a/.markdownlint-cli2.jsonc +++ b/.markdownlint-cli2.jsonc @@ -4,6 +4,7 @@ "MD003": { "style": "atx" }, "MD007": { "indent": 2 }, "MD013": { "line_length": 120 }, + "MD024": { "siblings_only": true }, "MD025": false, "MD033": false, "MD041": false From 9b22bf5e1bfbaa79bff7c22a279db4e845b7333e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 20:11:53 +0000 Subject: [PATCH 06/12] Restore llvm backend for GHDL on macOS (mcode unsupported) Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e411293..c395b2a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -277,7 +277,7 @@ jobs: - uses: ghdl/setup-ghdl@v1 with: version: 5.1.1 - backend: mcode + backend: ${{ matrix.os == 'macos-latest' && 'llvm' || 'mcode' }} - name: Download Artifacts uses: actions/download-artifact@v8 From 1bf97725bc9ed88b0da87f947ac418bc3f516d5b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 20:32:33 +0000 Subject: [PATCH 07/12] Add diagnostic output (exit code + simulator log) on validation test failure Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- src/DEMAConsulting.VHDLTest/Validation.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/DEMAConsulting.VHDLTest/Validation.cs b/src/DEMAConsulting.VHDLTest/Validation.cs index 79379ae..c4bbf3f 100644 --- a/src/DEMAConsulting.VHDLTest/Validation.cs +++ b/src/DEMAConsulting.VHDLTest/Validation.cs @@ -225,7 +225,23 @@ private static void ReportTestResult( } else { + // Write the primary failure line context.WriteError($"✗ VHDLTest_{testName} - Failed"); + + // Write the exit code so the caller knows what the simulator returned + context.WriteError($" Exit code: {exitCode}"); + + // Write each line of the captured output indented so it is visually grouped + // under the failure — trim first to avoid spurious blank trailing lines. + // Split on both CR and LF to handle Windows (CRLF) and Unix (LF) line endings. + var trimmedOutput = output.Trim(); + if (trimmedOutput.Length > 0) + { + foreach (var outputLine in trimmedOutput.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries)) + { + context.WriteError($" {outputLine}"); + } + } } // Get the line type From 4584da552ae3545235e3f42052b4daf87e14a070 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 21:02:20 +0000 Subject: [PATCH 08/12] Add GHDL elaboration step (-e) before run (-r) to fix llvm backend on macOS Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- .../Simulators/GhdlSimulator.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs index 0cfb426..0b3e671 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs @@ -117,7 +117,7 @@ public override RunResults Compile(Context context, Options options) /// public override TestResult Test(Context context, Options options, string test) { - // Log the start of the compile command + // Log the start of the test command context.WriteVerboseLine($"Starting GHDL test {test}..."); // Fail if we cannot find the simulator @@ -129,9 +129,25 @@ public override TestResult Test(Context context, Options options, string test) var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/GHDL"); context.WriteVerboseLine($" Library Directory: {libDir}"); - // Run the test + // Elaborate the test - required for the llvm backend (e.g. macOS) and harmless for mcode var application = Path.Combine(simPath, "ghdl"); context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); + context.WriteVerboseLine($" Elaborate Command: {application} -e --std=08 --workdir=VHDLTest.out/GHDL {test}"); + var elabResults = CompileProcessor.Execute( + application, + options.WorkingDirectory, + "-e", + "--std=08", + "--workdir=VHDLTest.out/GHDL", + test); + + // Return elaboration failure immediately without attempting to run + if (elabResults.Summary >= RunLineType.Error) + { + return new TestResult(test, test, elabResults); + } + + // Run the test context.WriteVerboseLine($" Run Command: {application} -r --std=08 --workdir=VHDLTest.out/GHDL {test}"); var testRunResults = TestProcessor.Execute( application, From b73cccfdaad585a32d91b7b6a3250153fb1cc58c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 21:09:00 +0000 Subject: [PATCH 09/12] Fix cspell: rename elabResults to elaborateResults Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs index 0b3e671..5f85063 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/GhdlSimulator.cs @@ -133,7 +133,7 @@ public override TestResult Test(Context context, Options options, string test) var application = Path.Combine(simPath, "ghdl"); context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); context.WriteVerboseLine($" Elaborate Command: {application} -e --std=08 --workdir=VHDLTest.out/GHDL {test}"); - var elabResults = CompileProcessor.Execute( + var elaborateResults = CompileProcessor.Execute( application, options.WorkingDirectory, "-e", @@ -142,9 +142,9 @@ public override TestResult Test(Context context, Options options, string test) test); // Return elaboration failure immediately without attempting to run - if (elabResults.Summary >= RunLineType.Error) + if (elaborateResults.Summary >= RunLineType.Error) { - return new TestResult(test, test, elabResults); + return new TestResult(test, test, elaborateResults); } // Run the test From 4162ad5163990b2ff867c7e1fa890645b697734f Mon Sep 17 00:00:00 2001 From: Malcolm Nixon Date: Fri, 6 Mar 2026 16:19:12 -0500 Subject: [PATCH 10/12] Update .github/agents/requirements-agent.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/agents/requirements-agent.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/agents/requirements-agent.md b/.github/agents/requirements-agent.md index 3085a22..ebe36d8 100644 --- a/.github/agents/requirements-agent.md +++ b/.github/agents/requirements-agent.md @@ -57,6 +57,7 @@ evidence. This is critical for platform, simulator, and framework requirements - - `nvc@TestName` - proves the test passed using the NVC simulator - `windows@TestName` - proves the test passed on a Windows platform - `ubuntu@TestName` - proves the test passed on a Linux (Ubuntu) platform +- `macos@TestName` - proves the test passed on a macOS platform - `dotnet8.x@TestName` - proves the self-validation test ran on a machine with .NET 8.x runtime - `dotnet9.x@TestName` - proves the self-validation test ran on a machine with .NET 9.x runtime - `dotnet10.x@TestName` - proves the self-validation test ran on a machine with .NET 10.x runtime From 0e27b6305c6f51caddc7ae50cb84ba663248bbaa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 21:20:01 +0000 Subject: [PATCH 11/12] Fix ActiveHdlSimulator: standardize output directory to VHDLTest.out/ActiveHDL Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs index bfdece6..12ec9ec 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs @@ -88,7 +88,7 @@ public override RunResults Compile(Context context, Options options) context.WriteVerboseLine($" Simulator Path: {simPath}"); // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHdl"); + var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHDL"); context.WriteVerboseLine($" Library Directory: {libDir}"); if (!Directory.Exists(libDir)) { From fd67f99d2d26b3013183c3059dd8cebfbc74d777 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Mar 2026 21:25:10 +0000 Subject: [PATCH 12/12] Fix deadlock risks in RunProgram/Runner; add const for ActiveHDL dir; fix VivadoSimulator comment Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --- src/DEMAConsulting.VHDLTest/Run/RunProgram.cs | 8 ++++++-- .../Simulators/ActiveHdlSimulator.cs | 19 ++++++++++++------- .../Simulators/VivadoSimulator.cs | 2 +- test/DEMAConsulting.VHDLTest.Tests/Runner.cs | 6 +++++- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs b/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs index 4197c16..d3611d9 100644 --- a/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs +++ b/src/DEMAConsulting.VHDLTest/Run/RunProgram.cs @@ -59,10 +59,14 @@ public static int Run( using var p = new Process { StartInfo = startInfo }; p.Start(); - // Collect all output - output = p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd(); + // Read both streams asynchronously to prevent deadlock if either buffer fills + var stdoutTask = p.StandardOutput.ReadToEndAsync(); + var stderrTask = p.StandardError.ReadToEndAsync(); p.WaitForExit(); + // Collect all output + output = stdoutTask.GetAwaiter().GetResult() + stderrTask.GetAwaiter().GetResult(); + // Return the output return p.ExitCode; } diff --git a/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs index 12ec9ec..8a462e3 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/ActiveHdlSimulator.cs @@ -34,6 +34,11 @@ public sealed class ActiveHdlSimulator : Simulator /// private const string SimApp = "vsimsa"; + /// + /// Library output directory path (relative to working directory) + /// + private const string LibDirPath = "VHDLTest.out/ActiveHDL"; + /// /// Compile processor /// @@ -88,7 +93,7 @@ public override RunResults Compile(Context context, Options options) context.WriteVerboseLine($" Simulator Path: {simPath}"); // Create the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHDL"); + var libDir = Path.Combine(options.WorkingDirectory, LibDirPath); context.WriteVerboseLine($" Library Directory: {libDir}"); if (!Directory.Exists(libDir)) { @@ -98,7 +103,7 @@ public override RunResults Compile(Context context, Options options) // Build the batch file var writer = new StringBuilder(); writer.AppendLine("onerror {exit -code 1}"); - writer.AppendLine("alib work VHDLTest.out/ActiveHDL"); + writer.AppendLine($"alib work {LibDirPath}"); writer.AppendLine("set worklib work"); foreach (var file in options.Config.Files) { @@ -113,12 +118,12 @@ public override RunResults Compile(Context context, Options options) // Run the ActiveHDL compiler var application = Path.Combine(simPath, SimApp); context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/compile.do"); + context.WriteVerboseLine($" Run Command: {application} -do {LibDirPath}/compile.do"); return CompileProcessor.Execute( application, options.WorkingDirectory, "-do", - "VHDLTest.out/ActiveHDL/compile.do"); + $"{LibDirPath}/compile.do"); } /// @@ -133,7 +138,7 @@ public override TestResult Test(Context context, Options options, string test) context.WriteVerboseLine($" Simulator Path: {simPath}"); // Get the library directory - var libDir = Path.Combine(options.WorkingDirectory, "VHDLTest.out/ActiveHDL"); + var libDir = Path.Combine(options.WorkingDirectory, LibDirPath); context.WriteVerboseLine($" Library Directory: {libDir}"); // Build the batch file @@ -153,12 +158,12 @@ public override TestResult Test(Context context, Options options, string test) // Run the test var application = Path.Combine(simPath, SimApp); context.WriteVerboseLine($" Run Directory: {options.WorkingDirectory}"); - context.WriteVerboseLine($" Run Command: {application} -do VHDLTest.out/ActiveHDL/test.do"); + context.WriteVerboseLine($" Run Command: {application} -do {LibDirPath}/test.do"); var testRunResults = TestProcessor.Execute( Path.Combine(simPath, SimApp), options.WorkingDirectory, "-do", - "VHDLTest.out/ActiveHDL/test.do"); + $"{LibDirPath}/test.do"); // Return the test results return new TestResult( diff --git a/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs b/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs index 7ca5142..ee8112c 100644 --- a/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs +++ b/src/DEMAConsulting.VHDLTest/Simulators/VivadoSimulator.cs @@ -96,7 +96,7 @@ public override RunResults Compile(Context context, Options options) context.WriteVerboseLine($" Script File: {script}"); File.WriteAllText(script, writer.ToString()); - // Run the ModelSim compiler + // Run the Vivado compiler var application = Path.Combine(simPath, "xvhdl"); context.WriteVerboseLine($" Run Directory: {libDir}"); context.WriteVerboseLine($" Run Command: cmd /c {application} -file compile.do"); diff --git a/test/DEMAConsulting.VHDLTest.Tests/Runner.cs b/test/DEMAConsulting.VHDLTest.Tests/Runner.cs index c142e51..cb27ccb 100644 --- a/test/DEMAConsulting.VHDLTest.Tests/Runner.cs +++ b/test/DEMAConsulting.VHDLTest.Tests/Runner.cs @@ -56,11 +56,15 @@ public static int Run(out string output, string program, params string[] argumen var process = Process.Start(startInfo) ?? throw new InvalidOperationException("Failed to start process"); + // Read both streams asynchronously to prevent deadlock if either buffer fills + var stdoutTask = process.StandardOutput.ReadToEndAsync(); + var stderrTask = process.StandardError.ReadToEndAsync(); + // Wait for the process to exit process.WaitForExit(); // Save the output and return the exit code - output = process.StandardOutput.ReadToEnd(); + output = stdoutTask.GetAwaiter().GetResult() + stderrTask.GetAwaiter().GetResult(); return process.ExitCode; } }