Skip to content

Commit 93c76e7

Browse files
author
Marek Suchánek
committed
Create real integration tests
1 parent e2d60fd commit 93c76e7

File tree

2 files changed

+163
-169
lines changed

2 files changed

+163
-169
lines changed

src/lib.rs

Lines changed: 6 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ mod templating;
88
mod validation;
99
mod write;
1010

11-
use module::{Input, Module, ModuleType};
11+
pub use module::{Input, Module, ModuleType};
1212

1313
/// This struct stores options based on the command-line arguments,
1414
/// and is passed to various functions across the program.
1515
#[derive(Debug, Clone)]
1616
pub struct Options {
17-
comments: bool,
18-
prefixes: bool,
19-
examples: bool,
20-
target_dir: String,
21-
verbosity: Verbosity,
17+
pub comments: bool,
18+
pub prefixes: bool,
19+
pub examples: bool,
20+
pub target_dir: String,
21+
pub verbosity: Verbosity,
2222
}
2323

2424
impl Options {
@@ -137,166 +137,3 @@ fn process_module_type(
137137

138138
modules_from_type.collect()
139139
}
140-
141-
// These tests act as pseudo-integration tests. They let the top-level functions generate
142-
// each module type and then they compare the generated content with a pre-generated specimen
143-
// to check that we introduce no changes unknowingly.
144-
#[cfg(test)]
145-
mod tests {
146-
use super::*;
147-
148-
// These values represent the default newdoc options.
149-
fn basic_options() -> Options {
150-
Options {
151-
comments: true,
152-
prefixes: true,
153-
examples: true,
154-
target_dir: ".".to_string(),
155-
verbosity: Verbosity::Default,
156-
}
157-
}
158-
159-
/// Test that we generate the assembly that we expect.
160-
#[test]
161-
fn test_assembly() {
162-
let mod_type = ModuleType::Assembly;
163-
let mod_title = "Testing that an assembly forms properly";
164-
let options = basic_options();
165-
let assembly = Module::new(mod_type, mod_title, &options);
166-
167-
let pre_generated =
168-
include_str!("../data/generated/assembly_testing-that-an-assembly-forms-properly.adoc");
169-
170-
assert_eq!(assembly.text, pre_generated);
171-
}
172-
173-
/// Test that we generate the concept module that we expect.
174-
#[test]
175-
fn test_concept_module() {
176-
let mod_type = ModuleType::Concept;
177-
let mod_title = "A title that tests a concept";
178-
let options = basic_options();
179-
let concept = Module::new(mod_type, mod_title, &options);
180-
181-
let pre_generated = include_str!("../data/generated/con_a-title-that-tests-a-concept.adoc");
182-
183-
assert_eq!(concept.text, pre_generated);
184-
}
185-
186-
/// Test that we generate the procedure module that we expect.
187-
#[test]
188-
fn test_procedure_module() {
189-
let mod_type = ModuleType::Procedure;
190-
let mod_title = "Testing a procedure";
191-
let options = basic_options();
192-
let procedure = Module::new(mod_type, mod_title, &options);
193-
194-
let pre_generated = include_str!("../data/generated/proc_testing-a-procedure.adoc");
195-
196-
assert_eq!(procedure.text, pre_generated);
197-
}
198-
199-
/// Test that we generate the reference module that we expect.
200-
#[test]
201-
fn test_reference_module() {
202-
let mod_type = ModuleType::Reference;
203-
let mod_title = "The lines in a reference module";
204-
let options = basic_options();
205-
let reference = Module::new(mod_type, mod_title, &options);
206-
207-
let pre_generated =
208-
include_str!("../data/generated/ref_the-lines-in-a-reference-module.adoc");
209-
210-
assert_eq!(reference.text, pre_generated);
211-
}
212-
213-
/// Test that we generate the snippet file that we expect.
214-
#[test]
215-
fn test_snippet_file() {
216-
let mod_type = ModuleType::Snippet;
217-
let mod_title = "Some notes in a snippet file";
218-
let options = basic_options();
219-
let snippet = Module::new(mod_type, mod_title, &options);
220-
221-
let pre_generated =
222-
include_str!("../data/generated/snip_some-notes-in-a-snippet-file.adoc");
223-
224-
assert_eq!(snippet.text, pre_generated);
225-
}
226-
227-
// These values strip down the modules to the bare minimum.
228-
fn minimal_options() -> Options {
229-
Options {
230-
comments: false,
231-
prefixes: false,
232-
examples: false,
233-
target_dir: ".".to_string(),
234-
verbosity: Verbosity::Default,
235-
}
236-
}
237-
238-
/// Test that we generate the assembly that we expect.
239-
#[test]
240-
fn test_minimal_assembly() {
241-
let mod_type = ModuleType::Assembly;
242-
let mod_title = "Minimal assembly";
243-
let options = minimal_options();
244-
let assembly = Module::new(mod_type, mod_title, &options);
245-
246-
let pre_generated = include_str!("../data/generated/minimal-assembly.adoc");
247-
248-
assert_eq!(assembly.text, pre_generated);
249-
}
250-
251-
/// Test that we generate the concept module that we expect.
252-
#[test]
253-
fn test_minimal_concept() {
254-
let mod_type = ModuleType::Concept;
255-
let mod_title = "Minimal concept";
256-
let options = minimal_options();
257-
let concept = Module::new(mod_type, mod_title, &options);
258-
259-
let pre_generated = include_str!("../data/generated/minimal-concept.adoc");
260-
261-
assert_eq!(concept.text, pre_generated);
262-
}
263-
264-
/// Test that we generate the procedure module that we expect.
265-
#[test]
266-
fn test_minimal_procedure() {
267-
let mod_type = ModuleType::Procedure;
268-
let mod_title = "Minimal procedure";
269-
let options = minimal_options();
270-
let procedure = Module::new(mod_type, mod_title, &options);
271-
272-
let pre_generated = include_str!("../data/generated/minimal-procedure.adoc");
273-
274-
assert_eq!(procedure.text, pre_generated);
275-
}
276-
277-
/// Test that we generate the reference module that we expect.
278-
#[test]
279-
fn test_minimal_reference() {
280-
let mod_type = ModuleType::Reference;
281-
let mod_title = "Minimal reference";
282-
let options = minimal_options();
283-
let reference = Module::new(mod_type, mod_title, &options);
284-
285-
let pre_generated = include_str!("../data/generated/minimal-reference.adoc");
286-
287-
assert_eq!(reference.text, pre_generated);
288-
}
289-
290-
/// Test that we generate the snippet file that we expect.
291-
#[test]
292-
fn test_minimal_snippet() {
293-
let mod_type = ModuleType::Snippet;
294-
let mod_title = "Minimal snippet";
295-
let options = minimal_options();
296-
let snippet = Module::new(mod_type, mod_title, &options);
297-
298-
let pre_generated = include_str!("../data/generated/minimal-snippet.adoc");
299-
300-
assert_eq!(snippet.text, pre_generated);
301-
}
302-
}

tests/integration.rs

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/// These are integration tests. They let the top-level functions generate
2+
/// each module type and then they compare the generated content with a pre-generated specimen
3+
/// to check that we introduce no changes unknowingly.
4+
use newdoc::*;
5+
6+
// These values represent the default newdoc options.
7+
fn basic_options() -> Options {
8+
Options {
9+
comments: true,
10+
prefixes: true,
11+
examples: true,
12+
target_dir: ".".to_string(),
13+
verbosity: Verbosity::Default,
14+
}
15+
}
16+
17+
/// Test that we generate the assembly that we expect.
18+
#[test]
19+
fn test_assembly() {
20+
let mod_type = ModuleType::Assembly;
21+
let mod_title = "Testing that an assembly forms properly";
22+
let options = basic_options();
23+
let assembly = Module::new(mod_type, mod_title, &options);
24+
25+
let pre_generated =
26+
include_str!("../data/generated/assembly_testing-that-an-assembly-forms-properly.adoc");
27+
28+
assert_eq!(assembly.text, pre_generated);
29+
}
30+
31+
/// Test that we generate the concept module that we expect.
32+
#[test]
33+
fn test_concept_module() {
34+
let mod_type = ModuleType::Concept;
35+
let mod_title = "A title that tests a concept";
36+
let options = basic_options();
37+
let concept = Module::new(mod_type, mod_title, &options);
38+
39+
let pre_generated = include_str!("../data/generated/con_a-title-that-tests-a-concept.adoc");
40+
41+
assert_eq!(concept.text, pre_generated);
42+
}
43+
44+
/// Test that we generate the procedure module that we expect.
45+
#[test]
46+
fn test_procedure_module() {
47+
let mod_type = ModuleType::Procedure;
48+
let mod_title = "Testing a procedure";
49+
let options = basic_options();
50+
let procedure = Module::new(mod_type, mod_title, &options);
51+
52+
let pre_generated = include_str!("../data/generated/proc_testing-a-procedure.adoc");
53+
54+
assert_eq!(procedure.text, pre_generated);
55+
}
56+
57+
/// Test that we generate the reference module that we expect.
58+
#[test]
59+
fn test_reference_module() {
60+
let mod_type = ModuleType::Reference;
61+
let mod_title = "The lines in a reference module";
62+
let options = basic_options();
63+
let reference = Module::new(mod_type, mod_title, &options);
64+
65+
let pre_generated = include_str!("../data/generated/ref_the-lines-in-a-reference-module.adoc");
66+
67+
assert_eq!(reference.text, pre_generated);
68+
}
69+
70+
/// Test that we generate the snippet file that we expect.
71+
#[test]
72+
fn test_snippet_file() {
73+
let mod_type = ModuleType::Snippet;
74+
let mod_title = "Some notes in a snippet file";
75+
let options = basic_options();
76+
let snippet = Module::new(mod_type, mod_title, &options);
77+
78+
let pre_generated = include_str!("../data/generated/snip_some-notes-in-a-snippet-file.adoc");
79+
80+
assert_eq!(snippet.text, pre_generated);
81+
}
82+
83+
// These values strip down the modules to the bare minimum.
84+
fn minimal_options() -> Options {
85+
Options {
86+
comments: false,
87+
prefixes: false,
88+
examples: false,
89+
target_dir: ".".to_string(),
90+
verbosity: Verbosity::Default,
91+
}
92+
}
93+
94+
/// Test that we generate the assembly that we expect.
95+
#[test]
96+
fn test_minimal_assembly() {
97+
let mod_type = ModuleType::Assembly;
98+
let mod_title = "Minimal assembly";
99+
let options = minimal_options();
100+
let assembly = Module::new(mod_type, mod_title, &options);
101+
102+
let pre_generated = include_str!("../data/generated/minimal-assembly.adoc");
103+
104+
assert_eq!(assembly.text, pre_generated);
105+
}
106+
107+
/// Test that we generate the concept module that we expect.
108+
#[test]
109+
fn test_minimal_concept() {
110+
let mod_type = ModuleType::Concept;
111+
let mod_title = "Minimal concept";
112+
let options = minimal_options();
113+
let concept = Module::new(mod_type, mod_title, &options);
114+
115+
let pre_generated = include_str!("../data/generated/minimal-concept.adoc");
116+
117+
assert_eq!(concept.text, pre_generated);
118+
}
119+
120+
/// Test that we generate the procedure module that we expect.
121+
#[test]
122+
fn test_minimal_procedure() {
123+
let mod_type = ModuleType::Procedure;
124+
let mod_title = "Minimal procedure";
125+
let options = minimal_options();
126+
let procedure = Module::new(mod_type, mod_title, &options);
127+
128+
let pre_generated = include_str!("../data/generated/minimal-procedure.adoc");
129+
130+
assert_eq!(procedure.text, pre_generated);
131+
}
132+
133+
/// Test that we generate the reference module that we expect.
134+
#[test]
135+
fn test_minimal_reference() {
136+
let mod_type = ModuleType::Reference;
137+
let mod_title = "Minimal reference";
138+
let options = minimal_options();
139+
let reference = Module::new(mod_type, mod_title, &options);
140+
141+
let pre_generated = include_str!("../data/generated/minimal-reference.adoc");
142+
143+
assert_eq!(reference.text, pre_generated);
144+
}
145+
146+
/// Test that we generate the snippet file that we expect.
147+
#[test]
148+
fn test_minimal_snippet() {
149+
let mod_type = ModuleType::Snippet;
150+
let mod_title = "Minimal snippet";
151+
let options = minimal_options();
152+
let snippet = Module::new(mod_type, mod_title, &options);
153+
154+
let pre_generated = include_str!("../data/generated/minimal-snippet.adoc");
155+
156+
assert_eq!(snippet.text, pre_generated);
157+
}

0 commit comments

Comments
 (0)