-
Notifications
You must be signed in to change notification settings - Fork 66
feat(treemap): allow configurable test dir #2805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| from dataclasses import dataclass, field | ||
| from enum import Enum | ||
| from pathlib import Path | ||
| from typing import Any, Dict, List, Optional, Tuple | ||
| from typing import Any, Dict, List, Optional, Tuple, Pattern | ||
|
|
||
| import toml | ||
|
|
||
|
|
@@ -123,6 +123,7 @@ def __init__( | |
| exclude_source_paths: Optional[List[str]] = None, | ||
| grammars: Optional[Dict[str, str]] = None, | ||
| test_report_root_dict: Optional[Dict[str, str]] = None, | ||
| tree_map_test_path_pattern: Optional[str] = None, | ||
| source_nodes: Optional[List[SourceNodesEntry]] = None, | ||
| html2pdf_strict: bool = False, | ||
| html2pdf_template: Optional[str] = None, | ||
|
|
@@ -293,6 +294,12 @@ def __init__( | |
| self.test_report_root_dict: Dict[str, str] = ( | ||
| test_report_root_dict if test_report_root_dict is not None else {} | ||
| ) | ||
| self.tree_map_test_path_pattern: Pattern[str] = re.compile( | ||
| tree_map_test_path_pattern | ||
| if tree_map_test_path_pattern is not None | ||
| else r"tests/" | ||
| ) | ||
|
|
||
| self.source_nodes: List[SourceNodesEntry] = ( | ||
| source_nodes if source_nodes is not None else [] | ||
| ) | ||
|
|
@@ -896,6 +903,7 @@ def _load_from_dictionary( | |
| include_source_paths: List[str] = [] | ||
| exclude_source_paths: List[str] = [] | ||
| test_report_root_dict: Dict[str, str] = {} | ||
| tree_map_test_path_pattern: Optional[str] = None | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious if there is an opportunity for reusing the already implemented filtering mechanism. Could we use the same approach that is used for See around these lines: This way the new
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will look into this! I would like the properties of "tests are within a certain path" but also allow "this path contains both tests & implementation" to coexist (for example to cover the go convention). I wonder what inline test definitions next to implementation (rust example) would look like, too 🤔 |
||
| source_nodes: List[SourceNodesEntry] = [] | ||
| html2pdf_strict: bool = False | ||
| html2pdf_template: Optional[str] = None | ||
|
|
@@ -1003,6 +1011,10 @@ def _load_from_dictionary( | |
| assert isinstance(test_report_root_entry_, dict) | ||
| test_report_root_dict.update(test_report_root_entry_) | ||
|
|
||
| tree_map_test_path_pattern = project_content.get( | ||
| "tree_map_test_path_pattern", tree_map_test_path_pattern | ||
| ) | ||
|
|
||
| section_behavior = project_content.get( | ||
| "section_behavior", section_behavior | ||
| ) | ||
|
|
@@ -1051,6 +1063,7 @@ def _load_from_dictionary( | |
| include_source_paths=include_source_paths, | ||
| exclude_source_paths=exclude_source_paths, | ||
| test_report_root_dict=test_report_root_dict, | ||
| tree_map_test_path_pattern=tree_map_test_path_pattern, | ||
| source_nodes=source_nodes, | ||
| html2pdf_strict=html2pdf_strict, | ||
| html2pdf_template=html2pdf_template, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| !reports/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied a nearby test, which is not super slim & focused at the new change..
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, copying is of course fine but let's reduce it to the bare minimum we need to exercise this new feature. In particular, let's remove this XML file. And also I think it should be enough to only leave this test function in the test file as it is the only one you are actually testing against: (the background for this is that StrictDoc has lots of test boilerplate and I try to reduce how much boilerplate is needed and used by each test) |
||
| <testsuite name="(empty)" | ||
| tests="5" | ||
| failures="0" | ||
| disabled="0" | ||
| skipped="0" | ||
| hostname="" | ||
| time="0" | ||
| timestamp="2025-03-18T16:42:24" | ||
| > | ||
| <testcase name="MyTestSuiteName.TestName" classname="MyTestSuiteName.TestName" time="0.00497625" status="run"> | ||
| <properties/> | ||
| <system-out>Running main() from /home/johan/Development/projects/line/build/_deps/googletest-src/googletest/src/gtest_main.cc | ||
| Note: Google Test filter = MyTestSuiteName.TestName | ||
| [==========] Running 1 test from 1 test suite. | ||
| [----------] Global test environment set-up. | ||
| [----------] 1 test from MyTestSuiteName | ||
| [ RUN ] MyTestSuiteName.TestName | ||
| [ OK ] MyTestSuiteName.TestName (0 ms) | ||
| [----------] 1 test from MyTestSuiteName (0 ms total) | ||
|
|
||
| [----------] Global test environment tear-down | ||
| [==========] 1 test from 1 test suite ran. (0 ms total) | ||
| [ PASSED ] 1 test. | ||
| </system-out> | ||
| </testcase> | ||
| <testcase name="MyTestHelper.TestName2" classname="MyTestHelper.TestName2" time="0.00496465" status="run"> | ||
| <properties/> | ||
| <system-out>Running main() from /home/johan/Development/projects/line/build/_deps/googletest-src/googletest/src/gtest_main.cc | ||
| Note: Google Test filter = MyTestHelper.TestName2 | ||
| [==========] Running 1 test from 1 test suite. | ||
| [----------] Global test environment set-up. | ||
| [----------] 1 test from MyTestHelper | ||
| [ RUN ] MyTestHelper.TestName2 | ||
| [ OK ] MyTestHelper.TestName2 (0 ms) | ||
| [----------] 1 test from MyTestHelper (0 ms total) | ||
|
|
||
| [----------] Global test environment tear-down | ||
| [==========] 1 test from 1 test suite ran. (0 ms total) | ||
| [ PASSED ] 1 test. | ||
| </system-out> | ||
| </testcase> | ||
| <testcase name="MyTestPattern/MyTestHelperPattern.TestName3/1" classname="MyTestPattern/MyTestHelperPattern.TestName3/1" time="0.00425819" status="run"> | ||
| <properties/> | ||
| <system-out>Running main() from /home/johan/Development/projects/line/build/_deps/googletest-src/googletest/src/gtest_main.cc | ||
| Note: Google Test filter = MyTestPattern/MyTestHelperPattern.TestName3/0 | ||
| [==========] Running 1 test from 1 test suite. | ||
| [----------] Global test environment set-up. | ||
| [----------] 1 test from MyTestPattern/MyTestHelperPattern | ||
| [ RUN ] MyTestPattern/MyTestHelperPattern.TestName3/0 | ||
| [ OK ] MyTestPattern/MyTestHelperPattern.TestName3/0 (0 ms) | ||
| [----------] 1 test from MyTestPattern/MyTestHelperPattern (0 ms total) | ||
|
|
||
| [----------] Global test environment tear-down | ||
| [==========] 1 test from 1 test suite ran. (0 ms total) | ||
| [ PASSED ] 1 test. | ||
| </system-out> | ||
| </testcase> | ||
| <testcase name="MyTestPattern/MyTestHelperPattern.TestName3/2" classname="MyTestPattern/MyTestHelperPattern.TestName3/2" time="0.00458189" status="run"> | ||
| <properties/> | ||
| <system-out>Running main() from /home/johan/Development/projects/line/build/_deps/googletest-src/googletest/src/gtest_main.cc | ||
| Note: Google Test filter = MyTestPattern/MyTestHelperPattern.TestName3/1 | ||
| [==========] Running 1 test from 1 test suite. | ||
| [----------] Global test environment set-up. | ||
| [----------] 1 test from MyTestPattern/MyTestHelperPattern | ||
| [ RUN ] MyTestPattern/MyTestHelperPattern.TestName3/1 | ||
| [ OK ] MyTestPattern/MyTestHelperPattern.TestName3/1 (0 ms) | ||
| [----------] 1 test from MyTestPattern/MyTestHelperPattern (0 ms total) | ||
|
|
||
| [----------] Global test environment tear-down | ||
| [==========] 1 test from 1 test suite ran. (0 ms total) | ||
| [ PASSED ] 1 test. | ||
| </system-out> | ||
| </testcase> | ||
| <testcase name="MyTestPattern/MyTestHelperPattern.TestName3/3" classname="MyTestPattern/MyTestHelperPattern.TestName3/3" time="0.00450156" status="run"> | ||
| <properties/> | ||
| <system-out>Running main() from /home/johan/Development/projects/line/build/_deps/googletest-src/googletest/src/gtest_main.cc | ||
| Note: Google Test filter = MyTestPattern/MyTestHelperPattern.TestName3/2 | ||
| [==========] Running 1 test from 1 test suite. | ||
| [----------] Global test environment set-up. | ||
| [----------] 1 test from MyTestPattern/MyTestHelperPattern | ||
| [ RUN ] MyTestPattern/MyTestHelperPattern.TestName3/2 | ||
| [ OK ] MyTestPattern/MyTestHelperPattern.TestName3/2 (0 ms) | ||
| [----------] 1 test from MyTestPattern/MyTestHelperPattern (0 ms total) | ||
|
|
||
| [----------] Global test environment tear-down | ||
| [==========] 1 test from 1 test suite ran. (0 ms total) | ||
| [ PASSED ] 1 test. | ||
| </system-out> | ||
| </testcase> | ||
| </testsuite> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [project] | ||
|
|
||
| features = [ | ||
| "REQUIREMENT_TO_SOURCE_TRACEABILITY", | ||
| "SOURCE_FILE_LANGUAGE_PARSERS", | ||
| "TREE_MAP_SCREEN", | ||
| ] | ||
|
|
||
| tree_map_test_path_pattern = "verification/" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # This test mainly verifies that the test results are resolved for multiple test | ||
| # cases and multiple files. | ||
|
|
||
| RUN: %strictdoc export %S --output-dir %T | filecheck %s --dump-input=fail | ||
|
|
||
| # Ensure that the test report document is generated. | ||
| CHECK: Published: Test report: (empty) | ||
| RUN: %check_exists --file "%T/html/%THIS_TEST_FOLDER/reports/tests_unit.ctest.junit.html" | ||
|
|
||
| # Ensure that the source and test files are generated. | ||
| RUN: %check_exists --file "%T/html/_source_files/verification/test1.cpp.html" | ||
|
|
||
| # Ensure that the test report document has the right content. | ||
| RUN: %cat "%T/html/%THIS_TEST_FOLDER/reports/tests_unit.ctest.junit.html" | filecheck %s --check-prefix CHECK-TEST-REPORT | ||
| CHECK-TEST-REPORT:href="../../_source_files/verification/test1.cpp.html#MyTestSuiteName.TestName#17#21"> | ||
| CHECK-TEST-REPORT: verification/test1.cpp, <i>lines: 17-21</i>, function TEST(MyTestSuiteName, TestName) | ||
|
|
||
| RUN: %cat "%T/html/tree_map.html" | filecheck %s --check-prefix CHECK-TREE-MAP | ||
| CHECK-TREE-MAP: matches "verification/" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #include <gtest/gtest.h> | ||
|
|
||
| // | ||
| // Code that we want to test | ||
| // | ||
|
|
||
| int Multiplication(int value1, int value2) | ||
| { | ||
| // Multiply like a boss | ||
| return value1 * value2; | ||
| } | ||
|
|
||
| // | ||
| // GTest code below | ||
| // | ||
|
|
||
| TEST(MyTestSuiteName, TestName) | ||
| { | ||
| // Test it | ||
| EXPECT_EQ(Multiplication(2, 2), 4); | ||
| } | ||
|
|
||
| class MyTestHelper : public testing::Test | ||
| { | ||
| protected: | ||
| MyTestHelper() | ||
| { | ||
| // Setup MyTestHelper | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(MyTestHelper, TestName2) | ||
| { | ||
| // Test it | ||
| EXPECT_EQ(Multiplication(1, 4), 4); | ||
| } | ||
|
|
||
| class MyTestHelperPattern : public testing::TestWithParam<int> | ||
| { | ||
| }; | ||
|
|
||
| INSTANTIATE_TEST_SUITE_P(MyTestPattern, MyTestHelperPattern, testing::Values(1, 2, 3)); | ||
|
|
||
| TEST_P(MyTestHelperPattern, TestName3) | ||
| { | ||
| // Test it | ||
| EXPECT_NE(Multiplication(GetParam(), GetParam()), 0); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.