3
3
//! This module contains the logic to extract doctests and output a JSON containing this
4
4
//! information.
5
5
6
+ use rustc_span:: edition:: Edition ;
6
7
use serde:: Serialize ;
7
8
8
9
use super :: make:: DocTestWrapResult ;
@@ -35,7 +36,16 @@ impl ExtractedDocTests {
35
36
options : & RustdocOptions ,
36
37
) {
37
38
let edition = scraped_test. edition ( options) ;
39
+ self . add_test_with_edition ( scraped_test, opts, edition)
40
+ }
38
41
42
+ /// This method is used by unit tests to not have to provide a `RustdocOptions`.
43
+ pub ( crate ) fn add_test_with_edition (
44
+ & mut self ,
45
+ scraped_test : ScrapedDocTest ,
46
+ opts : & super :: GlobalTestOptions ,
47
+ edition : Edition ,
48
+ ) {
39
49
let ScrapedDocTest { filename, line, langstr, text, name, global_crate_attrs, .. } =
40
50
scraped_test;
41
51
@@ -45,7 +55,7 @@ impl ExtractedDocTests {
45
55
. edition ( edition)
46
56
. lang_str ( & langstr)
47
57
. build ( None ) ;
48
- let ( wrapper , _size) = doctest. generate_unique_doctest (
58
+ let ( wrapped , _size) = doctest. generate_unique_doctest (
49
59
& text,
50
60
langstr. test_harness ,
51
61
opts,
@@ -55,7 +65,7 @@ impl ExtractedDocTests {
55
65
file : filename. prefer_remapped_unconditionaly ( ) . to_string ( ) ,
56
66
line,
57
67
doctest_attributes : langstr. into ( ) ,
58
- doctest_code : match wrapper {
68
+ doctest_code : match wrapped {
59
69
DocTestWrapResult :: Valid { crate_level_code, wrapper, code } => Some ( DocTest {
60
70
crate_level : crate_level_code,
61
71
code,
@@ -71,6 +81,11 @@ impl ExtractedDocTests {
71
81
name,
72
82
} ) ;
73
83
}
84
+
85
+ #[ cfg( test) ]
86
+ pub ( crate ) fn doctests ( & self ) -> & [ ExtractedDocTest ] {
87
+ & self . doctests
88
+ }
74
89
}
75
90
76
91
#[ derive( Serialize ) ]
@@ -84,7 +99,12 @@ pub(crate) struct WrapperInfo {
84
99
pub ( crate ) struct DocTest {
85
100
crate_level : String ,
86
101
code : String ,
87
- wrapper : Option < WrapperInfo > ,
102
+ /// This field can be `None` if one of the following conditions is true:
103
+ ///
104
+ /// * The doctest's codeblock has the `test_harness` attribute.
105
+ /// * The doctest has a `main` function.
106
+ /// * The doctest has the `![no_std]` attribute.
107
+ pub ( crate ) wrapper : Option < WrapperInfo > ,
88
108
}
89
109
90
110
#[ derive( Serialize ) ]
@@ -94,7 +114,7 @@ pub(crate) struct ExtractedDocTest {
94
114
doctest_attributes : LangString ,
95
115
original_code : String ,
96
116
/// `None` if the code syntax is invalid.
97
- doctest_code : Option < DocTest > ,
117
+ pub ( crate ) doctest_code : Option < DocTest > ,
98
118
name : String ,
99
119
}
100
120
0 commit comments