Skip to content

Commit a332e22

Browse files
committed
librustdoc: Unconfigure tests during normal build
1 parent e118eb6 commit a332e22

File tree

11 files changed

+651
-654
lines changed

11 files changed

+651
-654
lines changed

src/librustdoc/clean/cfg.rs

Lines changed: 3 additions & 417 deletions
Large diffs are not rendered by default.

src/librustdoc/clean/cfg/tests.rs

Lines changed: 413 additions & 0 deletions
Large diffs are not rendered by default.

src/librustdoc/html/markdown.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ use crate::test;
3939

4040
use pulldown_cmark::{html, CowStr, Event, Options, Parser, Tag};
4141

42+
#[cfg(test)]
43+
mod tests;
44+
4245
fn opts() -> Options {
4346
Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES
4447
}
@@ -1032,27 +1035,3 @@ impl IdMap {
10321035
id
10331036
}
10341037
}
1035-
1036-
#[cfg(test)]
1037-
#[test]
1038-
fn test_unique_id() {
1039-
let input = ["foo", "examples", "examples", "method.into_iter","examples",
1040-
"method.into_iter", "foo", "main", "search", "methods",
1041-
"examples", "method.into_iter", "assoc_type.Item", "assoc_type.Item"];
1042-
let expected = ["foo", "examples", "examples-1", "method.into_iter", "examples-2",
1043-
"method.into_iter-1", "foo-1", "main", "search", "methods",
1044-
"examples-3", "method.into_iter-2", "assoc_type.Item", "assoc_type.Item-1"];
1045-
1046-
let map = RefCell::new(IdMap::new());
1047-
let test = || {
1048-
let mut map = map.borrow_mut();
1049-
let actual: Vec<String> = input.iter().map(|s| map.derive(s.to_string())).collect();
1050-
assert_eq!(&actual[..], expected);
1051-
};
1052-
test();
1053-
map.borrow_mut().reset();
1054-
test();
1055-
}
1056-
1057-
#[cfg(test)]
1058-
mod tests;

src/librustdoc/html/markdown/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@ use super::plain_summary_line;
33
use std::cell::RefCell;
44
use syntax::edition::{Edition, DEFAULT_EDITION};
55

6+
#[test]
7+
fn test_unique_id() {
8+
let input = ["foo", "examples", "examples", "method.into_iter","examples",
9+
"method.into_iter", "foo", "main", "search", "methods",
10+
"examples", "method.into_iter", "assoc_type.Item", "assoc_type.Item"];
11+
let expected = ["foo", "examples", "examples-1", "method.into_iter", "examples-2",
12+
"method.into_iter-1", "foo-1", "main", "search", "methods",
13+
"examples-3", "method.into_iter-2", "assoc_type.Item", "assoc_type.Item-1"];
14+
15+
let map = RefCell::new(IdMap::new());
16+
let test = || {
17+
let mut map = map.borrow_mut();
18+
let actual: Vec<String> = input.iter().map(|s| map.derive(s.to_string())).collect();
19+
assert_eq!(&actual[..], expected);
20+
};
21+
test();
22+
map.borrow_mut().reset();
23+
test();
24+
}
25+
626
#[test]
727
fn test_lang_string_parse() {
828
fn t(s: &str,

src/librustdoc/html/render.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ use crate::html::{highlight, layout, static_files};
7575

7676
use minifier;
7777

78+
#[cfg(test)]
79+
mod tests;
80+
7881
/// A pair of name and its optional document.
7982
pub type NameDoc = (String, Option<String>);
8083

@@ -5238,33 +5241,3 @@ fn get_generics(clean_type: &clean::Type) -> Option<Vec<String>> {
52385241
pub fn cache() -> Arc<Cache> {
52395242
CACHE_KEY.with(|c| c.borrow().clone())
52405243
}
5241-
5242-
#[cfg(test)]
5243-
#[test]
5244-
fn test_name_key() {
5245-
assert_eq!(name_key("0"), ("", 0, 1));
5246-
assert_eq!(name_key("123"), ("", 123, 0));
5247-
assert_eq!(name_key("Fruit"), ("Fruit", 0, 0));
5248-
assert_eq!(name_key("Fruit0"), ("Fruit", 0, 1));
5249-
assert_eq!(name_key("Fruit0000"), ("Fruit", 0, 4));
5250-
assert_eq!(name_key("Fruit01"), ("Fruit", 1, 1));
5251-
assert_eq!(name_key("Fruit10"), ("Fruit", 10, 0));
5252-
assert_eq!(name_key("Fruit123"), ("Fruit", 123, 0));
5253-
}
5254-
5255-
#[cfg(test)]
5256-
#[test]
5257-
fn test_name_sorting() {
5258-
let names = ["Apple",
5259-
"Banana",
5260-
"Fruit", "Fruit0", "Fruit00",
5261-
"Fruit1", "Fruit01",
5262-
"Fruit2", "Fruit02",
5263-
"Fruit20",
5264-
"Fruit30x",
5265-
"Fruit100",
5266-
"Pear"];
5267-
let mut sorted = names.to_owned();
5268-
sorted.sort_by_key(|&s| name_key(s));
5269-
assert_eq!(names, sorted);
5270-
}

src/librustdoc/html/render/tests.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use super::*;
2+
3+
#[test]
4+
fn test_name_key() {
5+
assert_eq!(name_key("0"), ("", 0, 1));
6+
assert_eq!(name_key("123"), ("", 123, 0));
7+
assert_eq!(name_key("Fruit"), ("Fruit", 0, 0));
8+
assert_eq!(name_key("Fruit0"), ("Fruit", 0, 1));
9+
assert_eq!(name_key("Fruit0000"), ("Fruit", 0, 4));
10+
assert_eq!(name_key("Fruit01"), ("Fruit", 1, 1));
11+
assert_eq!(name_key("Fruit10"), ("Fruit", 10, 0));
12+
assert_eq!(name_key("Fruit123"), ("Fruit", 123, 0));
13+
}
14+
15+
#[test]
16+
fn test_name_sorting() {
17+
let names = ["Apple",
18+
"Banana",
19+
"Fruit", "Fruit0", "Fruit00",
20+
"Fruit1", "Fruit01",
21+
"Fruit2", "Fruit02",
22+
"Fruit20",
23+
"Fruit30x",
24+
"Fruit100",
25+
"Pear"];
26+
let mut sorted = names.to_owned();
27+
sorted.sort_by_key(|&s| name_key(s));
28+
assert_eq!(names, sorted);
29+
}

src/librustdoc/passes/unindent_comments.rs

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use crate::core::DocContext;
77
use crate::fold::{self, DocFolder};
88
use crate::passes::Pass;
99

10+
#[cfg(test)]
11+
mod tests;
12+
1013
pub const UNINDENT_COMMENTS: Pass = Pass {
1114
name: "unindent-comments",
1215
pass: unindent_comments,
@@ -102,79 +105,3 @@ fn unindent(s: &str) -> String {
102105
s.to_string()
103106
}
104107
}
105-
106-
#[cfg(test)]
107-
mod unindent_tests {
108-
use super::unindent;
109-
110-
#[test]
111-
fn should_unindent() {
112-
let s = " line1\n line2".to_string();
113-
let r = unindent(&s);
114-
assert_eq!(r, "line1\nline2");
115-
}
116-
117-
#[test]
118-
fn should_unindent_multiple_paragraphs() {
119-
let s = " line1\n\n line2".to_string();
120-
let r = unindent(&s);
121-
assert_eq!(r, "line1\n\nline2");
122-
}
123-
124-
#[test]
125-
fn should_leave_multiple_indent_levels() {
126-
// Line 2 is indented another level beyond the
127-
// base indentation and should be preserved
128-
let s = " line1\n\n line2".to_string();
129-
let r = unindent(&s);
130-
assert_eq!(r, "line1\n\n line2");
131-
}
132-
133-
#[test]
134-
fn should_ignore_first_line_indent() {
135-
// The first line of the first paragraph may not be indented as
136-
// far due to the way the doc string was written:
137-
//
138-
// #[doc = "Start way over here
139-
// and continue here"]
140-
let s = "line1\n line2".to_string();
141-
let r = unindent(&s);
142-
assert_eq!(r, "line1\nline2");
143-
}
144-
145-
#[test]
146-
fn should_not_ignore_first_line_indent_in_a_single_line_para() {
147-
let s = "line1\n\n line2".to_string();
148-
let r = unindent(&s);
149-
assert_eq!(r, "line1\n\n line2");
150-
}
151-
152-
#[test]
153-
fn should_unindent_tabs() {
154-
let s = "\tline1\n\tline2".to_string();
155-
let r = unindent(&s);
156-
assert_eq!(r, "line1\nline2");
157-
}
158-
159-
#[test]
160-
fn should_trim_mixed_indentation() {
161-
let s = "\t line1\n\t line2".to_string();
162-
let r = unindent(&s);
163-
assert_eq!(r, "line1\nline2");
164-
165-
let s = " \tline1\n \tline2".to_string();
166-
let r = unindent(&s);
167-
assert_eq!(r, "line1\nline2");
168-
}
169-
170-
#[test]
171-
fn should_not_trim() {
172-
let s = "\t line1 \n\t line2".to_string();
173-
let r = unindent(&s);
174-
assert_eq!(r, "line1 \nline2");
175-
176-
let s = " \tline1 \n \tline2".to_string();
177-
let r = unindent(&s);
178-
assert_eq!(r, "line1 \nline2");
179-
}
180-
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
use super::*;
2+
3+
#[test]
4+
fn should_unindent() {
5+
let s = " line1\n line2".to_string();
6+
let r = unindent(&s);
7+
assert_eq!(r, "line1\nline2");
8+
}
9+
10+
#[test]
11+
fn should_unindent_multiple_paragraphs() {
12+
let s = " line1\n\n line2".to_string();
13+
let r = unindent(&s);
14+
assert_eq!(r, "line1\n\nline2");
15+
}
16+
17+
#[test]
18+
fn should_leave_multiple_indent_levels() {
19+
// Line 2 is indented another level beyond the
20+
// base indentation and should be preserved
21+
let s = " line1\n\n line2".to_string();
22+
let r = unindent(&s);
23+
assert_eq!(r, "line1\n\n line2");
24+
}
25+
26+
#[test]
27+
fn should_ignore_first_line_indent() {
28+
// The first line of the first paragraph may not be indented as
29+
// far due to the way the doc string was written:
30+
//
31+
// #[doc = "Start way over here
32+
// and continue here"]
33+
let s = "line1\n line2".to_string();
34+
let r = unindent(&s);
35+
assert_eq!(r, "line1\nline2");
36+
}
37+
38+
#[test]
39+
fn should_not_ignore_first_line_indent_in_a_single_line_para() {
40+
let s = "line1\n\n line2".to_string();
41+
let r = unindent(&s);
42+
assert_eq!(r, "line1\n\n line2");
43+
}
44+
45+
#[test]
46+
fn should_unindent_tabs() {
47+
let s = "\tline1\n\tline2".to_string();
48+
let r = unindent(&s);
49+
assert_eq!(r, "line1\nline2");
50+
}
51+
52+
#[test]
53+
fn should_trim_mixed_indentation() {
54+
let s = "\t line1\n\t line2".to_string();
55+
let r = unindent(&s);
56+
assert_eq!(r, "line1\nline2");
57+
58+
let s = " \tline1\n \tline2".to_string();
59+
let r = unindent(&s);
60+
assert_eq!(r, "line1\nline2");
61+
}
62+
63+
#[test]
64+
fn should_not_trim() {
65+
let s = "\t line1 \n\t line2".to_string();
66+
let r = unindent(&s);
67+
assert_eq!(r, "line1 \nline2");
68+
69+
let s = " \tline1 \n \tline2".to_string();
70+
let r = unindent(&s);
71+
assert_eq!(r, "line1 \nline2");
72+
}

0 commit comments

Comments
 (0)