Skip to content

Commit 5e33e6a

Browse files
committed
Rename TestOptions to GlobalTestOptions
It seems to apply to all doctests in the crate.
1 parent b345e18 commit 5e33e6a

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

Diff for: src/librustdoc/doctest.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ use crate::html::markdown::{self, ErrorCodes, Ignore, LangString};
3434
use crate::lint::init_lints;
3535
use crate::passes::span_of_attrs;
3636

37+
/// Options that apply to all doctests in a crate or Markdown file (for `rustdoc foo.md`).
3738
#[derive(Clone, Default)]
38-
crate struct TestOptions {
39+
crate struct GlobalTestOptions {
3940
/// Whether to disable the default `extern crate my_crate;` when creating doctests.
4041
crate no_crate_inject: bool,
4142
/// Additional crate-level attributes to add to doctests.
@@ -214,10 +215,10 @@ crate fn run_tests(mut test_args: Vec<String>, nocapture: bool, tests: Vec<test:
214215
}
215216

216217
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
217-
fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions {
218+
fn scrape_test_config(attrs: &[ast::Attribute]) -> GlobalTestOptions {
218219
use rustc_ast_pretty::pprust;
219220

220-
let mut opts = TestOptions { no_crate_inject: false, attrs: Vec::new() };
221+
let mut opts = GlobalTestOptions { no_crate_inject: false, attrs: Vec::new() };
221222

222223
let test_attrs: Vec<_> = attrs
223224
.iter()
@@ -298,7 +299,7 @@ fn run_test(
298299
runtool: Option<String>,
299300
runtool_args: Vec<String>,
300301
target: TargetTriple,
301-
opts: &TestOptions,
302+
opts: &GlobalTestOptions,
302303
edition: Edition,
303304
outdir: DirState,
304305
path: PathBuf,
@@ -484,7 +485,7 @@ crate fn make_test(
484485
s: &str,
485486
crate_name: Option<&str>,
486487
dont_insert_main: bool,
487-
opts: &TestOptions,
488+
opts: &GlobalTestOptions,
488489
edition: Edition,
489490
test_id: Option<&str>,
490491
) -> (String, usize, bool) {
@@ -805,7 +806,7 @@ crate struct Collector {
805806
use_headers: bool,
806807
enable_per_target_ignores: bool,
807808
crate_name: Symbol,
808-
opts: TestOptions,
809+
opts: GlobalTestOptions,
809810
position: Span,
810811
source_map: Option<Lrc<SourceMap>>,
811812
filename: Option<PathBuf>,
@@ -819,7 +820,7 @@ impl Collector {
819820
crate_name: Symbol,
820821
options: Options,
821822
use_headers: bool,
822-
opts: TestOptions,
823+
opts: GlobalTestOptions,
823824
source_map: Option<Lrc<SourceMap>>,
824825
filename: Option<PathBuf>,
825826
enable_per_target_ignores: bool,

Diff for: src/librustdoc/doctest/tests.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use super::{make_test, TestOptions};
1+
use super::{make_test, GlobalTestOptions};
22
use rustc_span::edition::DEFAULT_EDITION;
33

44
#[test]
55
fn make_test_basic() {
66
//basic use: wraps with `fn main`, adds `#![allow(unused)]`
7-
let opts = TestOptions::default();
7+
let opts = GlobalTestOptions::default();
88
let input = "assert_eq!(2+2, 4);";
99
let expected = "#![allow(unused)]
1010
fn main() {
@@ -19,7 +19,7 @@ assert_eq!(2+2, 4);
1919
fn make_test_crate_name_no_use() {
2020
// If you give a crate name but *don't* use it within the test, it won't bother inserting
2121
// the `extern crate` statement.
22-
let opts = TestOptions::default();
22+
let opts = GlobalTestOptions::default();
2323
let input = "assert_eq!(2+2, 4);";
2424
let expected = "#![allow(unused)]
2525
fn main() {
@@ -34,7 +34,7 @@ assert_eq!(2+2, 4);
3434
fn make_test_crate_name() {
3535
// If you give a crate name and use it within the test, it will insert an `extern crate`
3636
// statement before `fn main`.
37-
let opts = TestOptions::default();
37+
let opts = GlobalTestOptions::default();
3838
let input = "use asdf::qwop;
3939
assert_eq!(2+2, 4);";
4040
let expected = "#![allow(unused)]
@@ -52,7 +52,7 @@ assert_eq!(2+2, 4);
5252
fn make_test_no_crate_inject() {
5353
// Even if you do use the crate within the test, setting `opts.no_crate_inject` will skip
5454
// adding it anyway.
55-
let opts = TestOptions { no_crate_inject: true, attrs: vec![] };
55+
let opts = GlobalTestOptions { no_crate_inject: true, attrs: vec![] };
5656
let input = "use asdf::qwop;
5757
assert_eq!(2+2, 4);";
5858
let expected = "#![allow(unused)]
@@ -70,7 +70,7 @@ fn make_test_ignore_std() {
7070
// Even if you include a crate name, and use it in the doctest, we still won't include an
7171
// `extern crate` statement if the crate is "std" -- that's included already by the
7272
// compiler!
73-
let opts = TestOptions::default();
73+
let opts = GlobalTestOptions::default();
7474
let input = "use std::*;
7575
assert_eq!(2+2, 4);";
7676
let expected = "#![allow(unused)]
@@ -87,7 +87,7 @@ assert_eq!(2+2, 4);
8787
fn make_test_manual_extern_crate() {
8888
// When you manually include an `extern crate` statement in your doctest, `make_test`
8989
// assumes you've included one for your own crate too.
90-
let opts = TestOptions::default();
90+
let opts = GlobalTestOptions::default();
9191
let input = "extern crate asdf;
9292
use asdf::qwop;
9393
assert_eq!(2+2, 4);";
@@ -104,7 +104,7 @@ assert_eq!(2+2, 4);
104104

105105
#[test]
106106
fn make_test_manual_extern_crate_with_macro_use() {
107-
let opts = TestOptions::default();
107+
let opts = GlobalTestOptions::default();
108108
let input = "#[macro_use] extern crate asdf;
109109
use asdf::qwop;
110110
assert_eq!(2+2, 4);";
@@ -123,7 +123,7 @@ assert_eq!(2+2, 4);
123123
fn make_test_opts_attrs() {
124124
// If you supplied some doctest attributes with `#![doc(test(attr(...)))]`, it will use
125125
// those instead of the stock `#![allow(unused)]`.
126-
let mut opts = TestOptions::default();
126+
let mut opts = GlobalTestOptions::default();
127127
opts.attrs.push("feature(sick_rad)".to_string());
128128
let input = "use asdf::qwop;
129129
assert_eq!(2+2, 4);";
@@ -155,7 +155,7 @@ assert_eq!(2+2, 4);
155155
fn make_test_crate_attrs() {
156156
// Including inner attributes in your doctest will apply them to the whole "crate", pasting
157157
// them outside the generated main function.
158-
let opts = TestOptions::default();
158+
let opts = GlobalTestOptions::default();
159159
let input = "#![feature(sick_rad)]
160160
assert_eq!(2+2, 4);";
161161
let expected = "#![allow(unused)]
@@ -171,7 +171,7 @@ assert_eq!(2+2, 4);
171171
#[test]
172172
fn make_test_with_main() {
173173
// Including your own `fn main` wrapper lets the test use it verbatim.
174-
let opts = TestOptions::default();
174+
let opts = GlobalTestOptions::default();
175175
let input = "fn main() {
176176
assert_eq!(2+2, 4);
177177
}";
@@ -187,7 +187,7 @@ fn main() {
187187
#[test]
188188
fn make_test_fake_main() {
189189
// ... but putting it in a comment will still provide a wrapper.
190-
let opts = TestOptions::default();
190+
let opts = GlobalTestOptions::default();
191191
let input = "//Ceci n'est pas une `fn main`
192192
assert_eq!(2+2, 4);";
193193
let expected = "#![allow(unused)]
@@ -203,7 +203,7 @@ assert_eq!(2+2, 4);
203203
#[test]
204204
fn make_test_dont_insert_main() {
205205
// Even with that, if you set `dont_insert_main`, it won't create the `fn main` wrapper.
206-
let opts = TestOptions::default();
206+
let opts = GlobalTestOptions::default();
207207
let input = "//Ceci n'est pas une `fn main`
208208
assert_eq!(2+2, 4);";
209209
let expected = "#![allow(unused)]
@@ -216,7 +216,7 @@ assert_eq!(2+2, 4);"
216216

217217
#[test]
218218
fn make_test_issues_21299_33731() {
219-
let opts = TestOptions::default();
219+
let opts = GlobalTestOptions::default();
220220

221221
let input = "// fn main
222222
assert_eq!(2+2, 4);";
@@ -248,7 +248,7 @@ assert_eq!(asdf::foo, 4);
248248

249249
#[test]
250250
fn make_test_main_in_macro() {
251-
let opts = TestOptions::default();
251+
let opts = GlobalTestOptions::default();
252252
let input = "#[macro_use] extern crate my_crate;
253253
test_wrapper! {
254254
fn main() {}
@@ -267,7 +267,7 @@ test_wrapper! {
267267
#[test]
268268
fn make_test_returns_result() {
269269
// creates an inner function and unwraps it
270-
let opts = TestOptions::default();
270+
let opts = GlobalTestOptions::default();
271271
let input = "use std::io;
272272
let mut input = String::new();
273273
io::stdin().read_line(&mut input)?;
@@ -287,7 +287,7 @@ Ok::<(), io:Error>(())
287287
#[test]
288288
fn make_test_named_wrapper() {
289289
// creates an inner function with a specific name
290-
let opts = TestOptions::default();
290+
let opts = GlobalTestOptions::default();
291291
let input = "assert_eq!(2+2, 4);";
292292
let expected = "#![allow(unused)]
293293
fn main() { #[allow(non_snake_case)] fn _doctest_main__some_unique_name() {

Diff for: src/librustdoc/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::source_map::DUMMY_SP;
77
use rustc_span::Symbol;
88

99
use crate::config::{Options, RenderOptions};
10-
use crate::doctest::{Collector, TestOptions};
10+
use crate::doctest::{Collector, GlobalTestOptions};
1111
use crate::html::escape::Escape;
1212
use crate::html::markdown;
1313
use crate::html::markdown::{
@@ -129,7 +129,7 @@ crate fn render<P: AsRef<Path>>(
129129
crate fn test(options: Options) -> Result<(), String> {
130130
let input_str = read_to_string(&options.input)
131131
.map_err(|err| format!("{}: {}", options.input.display(), err))?;
132-
let mut opts = TestOptions::default();
132+
let mut opts = GlobalTestOptions::default();
133133
opts.no_crate_inject = true;
134134
let mut collector = Collector::new(
135135
Symbol::intern(&options.input.display().to_string()),

0 commit comments

Comments
 (0)