Skip to content

Commit 747f263

Browse files
author
Marek Suchánek
committed
Add pseudo-integration tests that verify the module content in the output
1 parent 8228c19 commit 747f263

File tree

5 files changed

+296
-0
lines changed

5 files changed

+296
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
////
2+
Retains the context of the parent assembly if this assembly is nested within another assembly.
3+
For more information about nesting assemblies, see: https://redhat-documentation.github.io/modular-docs/#nesting-assemblies
4+
See also the complementary step on the last line of this file.
5+
////
6+
7+
ifdef::context[:parent-context-of-assembly_testing-that-an-assembly-forms-properly: {context}]
8+
9+
////
10+
Base the file name and the ID on the assembly title. For example:
11+
* file name: assembly-my-user-story.adoc
12+
* ID: [id="assembly-my-user-story_{context}"]
13+
* Title: = My user story
14+
15+
The ID is an anchor that links to the module. Avoid changing it after the module has been published to ensure existing links are not broken. Include {context} in the ID so the assembly can be reused.
16+
////
17+
18+
ifndef::context[]
19+
[id="assembly_testing-that-an-assembly-forms-properly"]
20+
endif::[]
21+
ifdef::context[]
22+
[id="assembly_testing-that-an-assembly-forms-properly_{context}"]
23+
endif::[]
24+
= Testing that an assembly forms properly
25+
////
26+
If the assembly covers a task, start the title with a verb in the gerund form, such as Creating or Configuring.
27+
////
28+
29+
:context: assembly_testing-that-an-assembly-forms-properly
30+
31+
////
32+
The `context` attribute enables module reuse. Every module ID includes {context}, which ensures that the module has a unique ID so you can include it multiple times in the same guide.
33+
////
34+
35+
[role="_abstract"]
36+
This paragraph is the assembly introduction. It explains what the user will accomplish by working through the modules in the assembly and sets the context for the user story the assembly is based on. The text that immediately follows the `[role="_abstract"]` tag is used for search metadata.
37+
38+
== Prerequisites
39+
40+
* A bulleted list of conditions that must be satisfied before the user starts following this assembly.
41+
* You can also link to other modules or assemblies the user must follow before starting this assembly.
42+
* Delete the section title and bullets if the assembly has no prerequisites.
43+
* X is installed. For information about installing X, see <link>.
44+
* You can log in to X with administrator privileges.
45+
46+
////
47+
The following include statements pull in the module files that comprise the assembly. Include any combination of concept, procedure, or reference modules required to cover the user story. You can also include other assemblies.
48+
49+
include::modules/TEMPLATE_CONCEPT_explaining_a_concept.adoc[leveloffset=+1]
50+
////
51+
52+
Include modules here.
53+
54+
////
55+
[leveloffset=+1] ensures that when a module title is a level 1 heading (= Title), the heading will be interpreted as a level-2 heading (== Title) in the assembly. Use [leveloffset=+2] and [leveloffset=+3] to nest modules in an assembly.
56+
57+
include::modules/TEMPLATE_PROCEDURE_doing_one_procedure.adoc[leveloffset=+2]
58+
59+
include::modules/TEMPLATE_PROCEDURE_reference-material.adoc[leveloffset=2]
60+
////
61+
62+
[role="_additional-resources"]
63+
== Additional resources (or Next steps)
64+
////
65+
Optional. Delete if not used.
66+
////
67+
68+
* A bulleted list of links to other material closely related to the contents of the assembly, including xref links to other assemblies in your collection.
69+
* For more details on writing assemblies, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
70+
* Use a consistent system for file names, IDs, and titles. For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
71+
72+
////
73+
Restore the context to what it was before this assembly.
74+
////
75+
ifdef::parent-context-of-assembly_testing-that-an-assembly-forms-properly[:context: {parent-context-of-assembly_testing-that-an-assembly-forms-properly}]
76+
ifndef::parent-context-of-assembly_testing-that-an-assembly-forms-properly[:!context:]
77+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
////
2+
Base the file name and the ID on the module title. For example:
3+
* file name: con-my-concept-module-a.adoc
4+
* ID: [id="con-my-concept-module-a_{context}"]
5+
* Title: = My concept module A
6+
////
7+
8+
////
9+
The ID is an anchor that links to the module. Avoid changing it after the module has been published to ensure existing links are not broken.
10+
11+
The `context` attribute enables module reuse. Every module ID includes {context}, which ensures that the module has a unique ID so you can include it multiple times in the same guide.
12+
////
13+
14+
[id="con_a-title-that-tests-a-concept_{context}"]
15+
= A title that tests a concept
16+
////
17+
In the title of concept modules, include nouns or noun phrases that are used in the body text. This helps readers and search engines find the information quickly. Do not start the title of concept modules with a verb. See also _Wording of headings_ in _The IBM Style Guide_.
18+
////
19+
20+
[role="_abstract"]
21+
Write a short introductory paragraph that provides an overview of the module. The text that immediately follows the `[role="_abstract"]` tag is used for search metadata.
22+
23+
The contents of a concept module give the user descriptions and explanations needed to understand and use a product.
24+
25+
* Look at nouns and noun phrases in related procedure modules and assemblies to find the concepts to explain to users.
26+
* Explain only things that are visible to users. Even if a concept is interesting, it probably does not require explanation if it is not visible to users.
27+
* Do not include any instructions to perform an action, such as executing a command. Action items belong in procedure modules.
28+
29+
[role="_additional-resources"]
30+
.Additional resources
31+
////
32+
Optional. Delete if not used.
33+
////
34+
* A bulleted list of links to other material closely related to the contents of the concept module.
35+
* Currently, modules cannot include xrefs, so you cannot include links to other content in your collection. If you need to link to another assembly, add the xref to the assembly that includes this module.
36+
* For more details on writing concept modules, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
37+
* Use a consistent system for file names, IDs, and titles. For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
38+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
////
2+
Base the file name and the ID on the module title. For example:
3+
* file name: proc-doing-procedure-a.adoc
4+
* ID: [id="doing-procedure-a_{context}"]
5+
* Title: = Doing procedure A
6+
7+
The ID is an anchor that links to the module. Avoid changing it after the module has been published to ensure existing links are not broken.
8+
9+
The `context` attribute enables module reuse. Every module ID includes {context}, which ensures that the module has a unique ID even if it is reused multiple times in a guide.
10+
////
11+
12+
[id="proc_testing-a-procedure_{context}"]
13+
= Testing a procedure
14+
////
15+
Start the title of a procedure module with a verb, such as Creating or Create. See also _Wording of headings_ in _The IBM Style Guide_.
16+
////
17+
18+
[role="_abstract"]
19+
Write a short introductory paragraph that provides an overview of the module. Procedure modules should include the steps that users perform and address user motivation.The text that immediately follows the `[role="_abstract"]` tag is used for search metadata.
20+
21+
.Prerequisites
22+
23+
* A bulleted list of conditions that must be satisfied before the user starts following this module.
24+
* You can also link to other modules or assemblies the user must follow before starting this module.
25+
* Delete the section title and bullets if the module has no prerequisites.
26+
27+
.Procedure
28+
29+
. Start each step with an active verb.
30+
31+
. Include one command or action for each step with the exception of simple follow-step, for example:
32+
.. Do this thing and then select *Next*.
33+
.. Do this other thing and then select *Next*.
34+
35+
. Use an unnumbered bullet (*) if the procedure includes only one step.
36+
37+
.Verification
38+
////
39+
Delete this section if it does not apply to your module. Provide the user with verification methods for the procedure, such as expected output or commands that confirm success or failure.
40+
////
41+
42+
. Start each step with an active verb.
43+
44+
. Include one command or action per step.
45+
46+
. Use an unnumbered bullet (*) if the procedure includes only one step.
47+
48+
49+
[role="_additional-resources"]
50+
.Additional resources
51+
////
52+
Optional. Delete if not used.
53+
////
54+
* A bulleted list of links to other material closely related to the contents of the procedure module.
55+
* Currently, modules cannot include xrefs, so you cannot include links to other content in your collection. If you need to link to another assembly, add the xref to the assembly that includes this module.
56+
* For more details on writing procedure modules, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
57+
* Use a consistent system for file names, IDs, and titles. For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
58+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
////
2+
Base the file name and the ID on the module title. For example:
3+
* file name: ref-my-reference-a.adoc
4+
* ID: [id="ref-my-reference-a_{context}"]
5+
* Title: = My reference A
6+
7+
The ID is an anchor that links to the module. Avoid changing it after the module has been published to ensure existing links are not broken.
8+
9+
The `context` attribute enables module reuse. Every module ID includes {context}, which ensures that the module has a unique ID even if it is reused multiple times in a guide.
10+
////
11+
12+
[id="ref_the-lines-in-a-reference-module_{context}"]
13+
= The lines in a reference module
14+
////
15+
In the title of a reference module, include nouns that are used in the body text. For example, "Keyboard shortcuts for ___" or "Command options for ___." This helps readers and search engines find the information quickly.
16+
////
17+
18+
[role="_abstract"]
19+
Write a short introductory paragraph that provides an overview of the module. The text that immediately follows the `[role="_abstract"]` tag is used for search metadata. A reference module provides data that users might want to look up, but do not need to remember.
20+
It has a very strict structure, often in the form of a list or a table.
21+
A well-organized reference module enables users to scan it quickly to find the details they want.
22+
AsciiDoc markup to consider for reference data:
23+
24+
.Unordered list
25+
* For more details on writing reference modules, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
26+
* Use a consistent system for file names, IDs, and titles.
27+
For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
28+
29+
.Labeled list
30+
Term 1:: Definition
31+
Term 2:: Definition
32+
33+
.Table
34+
[options="header"]
35+
|====
36+
|Column 1|Column 2|Column 3
37+
|Row 1, column 1|Row 1, column 2|Row 1, column 3
38+
|Row 2, column 1|Row 2, column 2|Row 2, column 3
39+
|====
40+
41+
[role="_additional-resources"]
42+
.Additional resources
43+
////
44+
Optional. Delete if not used.
45+
////
46+
* A bulleted list of links to other material closely related to the contents of the concept module.
47+
* Currently, modules cannot include xrefs, so you cannot include links to other content in your collection. If you need to link to another assembly, add the xref to the assembly that includes this module.
48+
* For more details on writing reference modules, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
49+
* Use a consistent system for file names, IDs, and titles. For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
50+

src/main.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,76 @@ fn process_module_type(
106106

107107
modules_from_type
108108
}
109+
110+
111+
// These tests act as pseudo-integration tests. They let the top-level functions generate
112+
// each module type and then they compare the generated content with a pre-generated specimen
113+
// to check that we introduce no changes unknowingly.
114+
#[cfg(test)]
115+
mod tests {
116+
use crate::module::Module;
117+
use crate::module::ModuleType;
118+
use crate::Options;
119+
120+
fn basic_options() -> Options {
121+
Options {
122+
comments: true,
123+
prefixes: true,
124+
examples: true,
125+
target_dir: ".".to_string(),
126+
detect_directory: false,
127+
}
128+
}
129+
130+
/// Test that we generate the assembly that we expect.
131+
#[test]
132+
fn test_assembly() {
133+
let mod_type = ModuleType::Assembly;
134+
let mod_title = "Testing that an assembly forms properly";
135+
let options = basic_options();
136+
let assembly = Module::new(mod_type, mod_title, &options);
137+
138+
let pre_generated = include_str!("../data/generated/assembly_testing-that-an-assembly-forms-properly.adoc");
139+
140+
assert_eq!(assembly.text, pre_generated);
141+
}
142+
143+
/// Test that we generate the concept module that we expect.
144+
#[test]
145+
fn test_concept_module() {
146+
let mod_type = ModuleType::Concept;
147+
let mod_title = "A title that tests a concept";
148+
let options = basic_options();
149+
let concept = Module::new(mod_type, mod_title, &options);
150+
151+
let pre_generated = include_str!("../data/generated/con_a-title-that-tests-a-concept.adoc");
152+
153+
assert_eq!(concept.text, pre_generated);
154+
}
155+
156+
/// Test that we generate the procedure module that we expect.
157+
#[test]
158+
fn test_procedure_module() {
159+
let mod_type = ModuleType::Procedure;
160+
let mod_title = "Testing a procedure";
161+
let options = basic_options();
162+
let procedure = Module::new(mod_type, mod_title, &options);
163+
164+
let pre_generated = include_str!("../data/generated/proc_testing-a-procedure.adoc");
165+
166+
assert_eq!(procedure.text, pre_generated);
167+
}
168+
169+
/// Test that we generate the reference module that we expect.
170+
#[test]
171+
fn test_reference_module() {
172+
let mod_type = ModuleType::Reference;
173+
let mod_title = "The lines in a reference module";
174+
let options = basic_options();
175+
let reference = Module::new(mod_type, mod_title, &options);
176+
177+
let pre_generated = include_str!("../data/generated/ref_the-lines-in-a-reference-module.adoc");
178+
179+
assert_eq!(reference.text, pre_generated);
180+
}
181+
}

0 commit comments

Comments
 (0)