Skip to content

Commit 3a5be63

Browse files
authored
Minor fixes: build/extension warnings, dead links, improved formatting (#20)
* 🔧 Update remote URL pattern and ignore src-trace warnings in ubproject configuration * 📝 Fix formatting in sphinx needs setup * 📝 Removed broken ref from codeblock * 🔧 Fix duplicate DOWNLOAD_EXTRACT_TIMESTAMP in FetchContent_Declare for googletest * 📝 Repalced deprecated eac-cpp --------- Co-authored-by: Arnaud Riess <arnaud.riess@gmail.com>
1 parent 6e5bd1e commit 3a5be63

6 files changed

Lines changed: 206 additions & 165 deletions

File tree

docs/how-to-guides/testing/index.rst

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
.. _testing:
22

33
:octicon:`beaker` Test Management and Traceability
4-
===================================================
4+
==================================================
55

6-
.. toctree::
6+
.. toctree:: requirements
77
:maxdepth: 1
88
:hidden:
99

10-
requirements
11-
12-
This guide demonstrates how to integrate test reports into your documentation with full traceability between test specifications, test cases, source code, and test results.
10+
This guide demonstrates how to integrate test reports into your
11+
documentation with full traceability between test specifications, test
12+
cases, source code, and test results.
1313

1414
Overview
1515
--------
@@ -22,12 +22,14 @@ A comprehensive testing approach includes:
2222
* **Traceability**: Links between all these elements
2323
* **Test Reports**: Results from test execution
2424

25-
By using Sphinx-Needs for test specifications, sphinx-codelinks for code tracing, and sphinx-test-reports for test results, we create a complete traceable testing ecosystem.
25+
By using Sphinx-Needs for test specifications, sphinx-codelinks for
26+
code tracing, and sphinx-test-reports for test results, we create a
27+
complete traceable testing ecosystem.
2628

2729
Workflow
2830
--------
2931

30-
.. mermaid::
32+
.. mermaid::
3133

3234
graph LR
3335
REQ[Requirements] --> TS[Test Specifications]
@@ -36,7 +38,7 @@ Workflow
3638
TC --> RUN[Test Execution]
3739
RUN --> REPORT[Test Reports]
3840
REPORT --> DOC[Documentation]
39-
41+
4042
style REQ fill:#FFB300
4143
style TS fill:#A6BDD7
4244
style TC fill:#A6BDD7
@@ -45,40 +47,44 @@ Workflow
4547
style DOC fill:#F6768E
4648

4749
Step 1: Define Test Specifications
48-
-----------------------------------
50+
----------------------------------
4951

50-
Create test specifications using the ``test-spec`` directive to define what needs to be tested:
52+
Create test specifications using the ``test-spec`` directive to define
53+
what needs to be tested:
5154

5255
.. test-spec:: Factorial Function Test Specification
5356
:id: TS_FACTORIAL
5457
:status: open
5558
:tags: factorial, math
5659

5760
Test the factorial function for:
58-
61+
5962
* Negative numbers (should return 1)
6063
* Zero (should return 1)
6164
* Positive numbers (should return correct factorial)
62-
63-
The factorial function is critical for mathematical operations and must handle edge cases correctly.
65+
66+
The factorial function is critical for mathematical operations and
67+
must handle edge cases correctly.
6468

6569
.. test-spec:: Prime Number Check Test Specification
6670
:id: TS_PRIME
6771
:status: open
6872
:tags: prime, math
6973

7074
Test the IsPrime function for:
71-
75+
7276
* Negative numbers (should return false)
7377
* Trivial cases (0, 1, 2, 3)
7478
* Positive numbers (both prime and composite)
75-
76-
Prime number detection is used in cryptographic operations and must be accurate.
79+
80+
Prime number detection is used in cryptographic operations and must be
81+
accurate.
7782

7883
Step 2: Annotate Test Cases in Code
79-
------------------------------------
84+
-----------------------------------
8085

81-
Add sphinx-codelinks annotations to your test cases. The annotation format is e.g.:
86+
Add sphinx-codelinks annotations to your test cases. The annotation
87+
format is e.g.:
8288

8389
.. code-block:: cpp
8490
@@ -94,20 +100,25 @@ Example from ``sample1_unittest.cpp``:
94100
:lines: 76-88
95101
:caption: Annotated test case with GTest properties
96102

97-
The annotation ``@Test negative factorial values, T_FACT_001, test`` creates a traceable link between the test code and the documentation.
103+
The annotation ``@Test negative factorial values, T_FACT_001, test``
104+
creates a traceable link between the test code and the documentation.
98105

99106
**GTest Properties** (``RecordProperty``):
100107

101-
* ``need_id``: Links the test execution result to the test case need (T_FACT_001)
108+
* ``need_id``: Links the test execution result to the test case need
109+
(T_FACT_001)
102110
* ``requirement``: Links to the requirement being tested (REQ_MATH_001)
103111
* ``test_spec``: Links to the test specification (TS_FACTORIAL)
104112

105-
These properties are included in the XML test report and enable automatic linking between test results and documentation needs.
113+
These properties are included in the XML test report and enable
114+
automatic linking between test results and documentation needs.
106115

107116
Step 3: Link Test Cases to Specifications
108-
------------------------------------------
117+
-----------------------------------------
109118

110-
Test cases are automatically discovered from source code using sphinx-codelinks. The test files contain ``@`` annotations that define test needs:
119+
Test cases are automatically discovered from source code using
120+
sphinx-codelinks. The test files contain ``@`` annotations that define
121+
test needs:
111122

112123
.. code-block:: cpp
113124
@@ -119,35 +130,40 @@ Test cases are automatically discovered from source code using sphinx-codelinks.
119130
// ... test implementation
120131
}
121132
122-
These annotations are parsed by sphinx-codelinks and automatically create test needs. Below are all test cases discovered from the test files:
133+
These annotations are parsed by sphinx-codelinks and automatically
134+
create test needs. Below are all test cases discovered from the test
135+
files:
123136

124-
.. src-trace::
125-
:project: eac-cpp
137+
.. src-trace::
138+
:project: x-as-code-cpp
126139
:file: sample1_unittest.cpp
127140

128141
The test cases link to:
129142

130-
* **Test specifications** (e.g., ``TS_FACTORIAL``) via the ``:spec:`` field
131-
* **Implementation** (e.g., ``IMPL_2``) via the ``:implements:`` field
143+
* **Test specifications** (e.g., ``TS_FACTORIAL``) via the ``:spec:``
144+
field
145+
* **Implementation** (e.g., ``IMPL_2``) via the ``:implements:`` field
132146
* **Requirements** (e.g., ``REQ_MATH_001``) via GTest properties
133147

134148
Step 4: Show Code Traceability
135-
-------------------------------
149+
------------------------------
136150

137151
Use sphinx-codelinks to display where test cases are implemented:
138152

139153
.. code-block:: rst
140154
141-
.. src-trace:: Test Case Implementation
142-
:project: eac-cpp
143-
:directory: src
155+
.. src-trace:: Test Case Implementation
156+
:project: x-as-code-cpp
157+
:directory: src
144158
145-
This shows all annotated code locations, creating bidirectional links between documentation and source code.
159+
This shows all annotated code locations, creating bidirectional links
160+
between documentation and source code.
146161

147162
Step 5: Integrate Test Reports
148-
-------------------------------
163+
------------------------------
149164

150-
After running tests, integrate the test results using sphinx-test-reports:
165+
After running tests, integrate the test results using
166+
sphinx-test-reports:
151167

152168
.. code-block:: bash
153169
@@ -158,13 +174,14 @@ After running tests, integrate the test results using sphinx-test-reports:
158174
cd build
159175
./eac_test --gtest_output=xml:test-results.xml
160176
161-
The test results XML file contains properties that link back to the test case needs, enabling complete traceability.
177+
The test results XML file contains properties that link back to the
178+
test case needs, enabling complete traceability.
162179

163180
Traceability Matrix
164181
-------------------
165182

166183
Test Specifications to Test Cases
167-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
184+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168185

169186
View which test cases implement each test specification:
170187

@@ -174,7 +191,7 @@ View which test cases implement each test specification:
174191
:style: table
175192

176193
Test Cases to Implementation
177-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178195

179196
View the connection between test cases and the code they test:
180197

@@ -191,7 +208,7 @@ To generate code coverage reports with line-level detail:
191208
192209
# Run tests with coverage
193210
./scripts/test_with_coverage.sh
194-
211+
195212
# View coverage report
196213
open src/build/coverage_html/index.html
197214
@@ -214,20 +231,20 @@ Integrate testing into your CI/CD pipeline:
214231
cd src
215232
cmake -S . -B build
216233
cmake --build build
217-
234+
218235
- name: Run Tests
219236
run: |
220237
cd src/build
221238
./eac_test --gtest_output=xml:test-results.xml
222-
239+
223240
- name: Upload Test Results
224241
uses: actions/upload-artifact@v4
225242
with:
226243
name: test-results
227244
path: src/build/test-results.xml
228245
229246
Complete Traceability Flow
230-
---------------------------
247+
--------------------------
231248

232249
The complete flow from requirements to test results:
233250

@@ -254,16 +271,15 @@ By combining:
254271

255272
You create a fully traceable testing ecosystem where:
256273

257-
✅ Every test links to its specification
258-
✅ Every test links to the code it verifies
259-
✅ Test results are automatically integrated
260-
✅ Coverage is measured and reported
261-
✅ Traceability is bidirectional and complete
274+
✅ Every test links to its specification ✅ Every test links to the
275+
code it verifies ✅ Test results are automatically integrated ✅
276+
Coverage is measured and reported ✅ Traceability is bidirectional and
277+
complete
262278

263279
Additional Resources
264280
--------------------
265281

266282
* `GoogleTest Documentation <https://google.github.io/googletest/>`_
267283
* `Sphinx-Test-Reports <https://sphinx-test-reports.readthedocs.io/>`_
268284
* `Sphinx-Codelinks <https://codelinks.useblocks.com/>`_
269-
* `Code Coverage with lcov <https://github.com/linux-test-project/lcov>`_
285+
* `Code Coverage with lcov <https://github.com/linux-test-project/lcov>`_

docs/how-to-guides/trace-code/index.rst

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,86 @@
33
:octicon:`link` Tracing Source Code
44
===================================
55

6-
This guide explains how to use CodeLinks to trace source code files and lines to needs in your documentation.
6+
This guide explains how to use CodeLinks to trace source code files
7+
and lines to needs in your documentation.
78

89
**Step 1: Install CodeLinks**
910

1011
Follow the installation instructions in the `CodeLinks documentation <https://codelinks.useblocks.com/basics/installation.html>`__.
1112

1213
**Step 2: Configure CodeLinks**
1314

14-
Create a file named ``src_trace.toml`` in your ``docs`` folder (next to ``conf.py``) with the following content:
15+
Create a file named ``src_trace.toml`` in your ``docs`` folder (next
16+
to ``conf.py``) with the following content:
1517

1618
.. literalinclude:: ../../src_trace.toml
17-
:language: toml
18-
:caption: src_trace.toml
19+
:language: toml
20+
:caption: src_trace.toml
1921

2022
**Step 3: Add the src-trace Directive**
2123

22-
In your documentation files, add the following directive to display traced source code links:
24+
In your documentation files, add the following directive to display
25+
traced source code links:
2326

2427
.. code-block:: rst
2528
26-
.. src-trace::
27-
:project: eac-cpp
28-
:directory: .
29+
.. src-trace::
30+
:project: x-as-code-cpp
31+
:directory: .
2932
3033
**Step 4: Annotate Your Source Code**
3134

32-
Add comments to your source code files to link code lines to needs. For example, in ``src/main.cpp``:
35+
Add comments to your source code files to link code lines to needs.
36+
For example, in ``src/main.cpp``:
3337

3438
.. literalinclude:: ../../../src/main.cpp
35-
:language: cpp
36-
:caption: src/main.cpp
39+
:language: cpp
40+
:caption: src/main.cpp
3741

3842
**Step 5: View Traced Files and Lines**
3943

40-
After following the steps above, the documentation will show the traced files and lines for each need in the specified project (``eac-cpp``). Here we show only the implementation files (not test files):
44+
After following the steps above, the documentation will show the
45+
traced files and lines for each need in the specified project (``x-as-code-cpp``).
46+
Here we show only the implementation files (not test files):
4147

42-
.. src-trace::
43-
:project: eac-cpp
44-
:file: main.cpp
48+
.. src-trace::
49+
:project: x-as-code-cpp
50+
:file: main.cpp
4551

46-
.. src-trace::
47-
:project: eac-cpp
48-
:file: sample1.cpp
52+
.. src-trace::
53+
:project: x-as-code-cpp
54+
:file: sample1.cpp
4955

50-
.. src-trace::
51-
:project: eac-cpp
52-
:file: sample2.cpp
56+
.. src-trace::
57+
:project: x-as-code-cpp
58+
:file: sample2.cpp
5359

54-
**Note**: Test files are traced separately in the :ref:`testing guide <testing>` to avoid duplicate need IDs.
60+
**Note**: Test files are traced separately in the :ref:`testing guide <testing>`
61+
to avoid duplicate need IDs.
5562

5663
**Summary**
5764

58-
By following these steps, you can easily trace source code to requirements, improving traceability and documentation quality.
65+
By following these steps, you can easily trace source code to
66+
requirements, improving traceability and documentation quality.
5967

6068
Advanced configuration options and features are available in the `CodeLinks documentation <https://codelinks.useblocks.com/components/configuration.html>`__.
6169

6270
Linking Requirements to Code
63-
-----------------------------
71+
----------------------------
6472

6573
Finally you can link from/to the traced source code lines like this:
6674

6775
.. req:: Requirement linking to source code
6876
:id: REQ_0815
6977
:status: open
7078

71-
This is a requirement that links to a need that has traced source code lines.
79+
This is a requirement that links to a need that has traced source code
80+
lines.
7281

7382
.. note::
7483

75-
Current limitation: ``ubCode`` is not aware of this need id yet. This means that
76-
the ``ubCode`` navigation inside Visual Studio Code will not work and jumping from
77-
this ``rst`` file to the source code line will not work. This will be implemented
78-
and supported in a future release.
84+
Current limitation: ``ubCode`` is not aware of this need id yet. This
85+
means that the ``ubCode`` navigation inside Visual Studio Code will
86+
not work and jumping from this ``rst`` file to the source code line
87+
will not work. This will be implemented and supported in a future
88+
release.

0 commit comments

Comments
 (0)