Skip to content

Clean up rustdoc tests by moving them into one place #76223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ use rustc_span::Span;

use crate::html::escape::Escape;

#[cfg(test)]
mod tests;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Cfg {
/// Accepts all configurations.
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,3 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
);
}
}

#[cfg(test)]
mod tests;
5 changes: 1 addition & 4 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn write_header(out: &mut String, class: Option<&str>) {
.unwrap()
}

fn write_code(out: &mut String, src: &str) {
crate fn write_code(out: &mut String, src: &str) {
Classifier::new(src).highlight(&mut |highlight| {
match highlight {
Highlight::Token { text, class } => string(out, Escape(text), class),
Expand Down Expand Up @@ -343,6 +343,3 @@ fn string<T: Display>(out: &mut String, text: T, klass: Class) {
klass => write!(out, "<span class=\"{}\">{}</span>", klass.as_html(), text).unwrap(),
}
}

#[cfg(test)]
mod tests;
13 changes: 7 additions & 6 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ use crate::html::toc::TocBuilder;

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

#[cfg(test)]
mod tests;

fn opts() -> Options {
Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES | Options::ENABLE_STRIKETHROUGH
}
Expand Down Expand Up @@ -678,6 +675,10 @@ impl<'a, 'b> ExtraInfo<'a, 'b> {

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct LangString {
#[cfg(test)]
// Only making it public when running tests.
pub original: String,
#[cfg(not(test))]
original: String,
pub should_panic: bool,
pub no_run: bool,
Expand All @@ -698,7 +699,7 @@ pub enum Ignore {
}

impl LangString {
fn all_false() -> LangString {
pub fn all_false() -> LangString {
LangString {
original: String::new(),
should_panic: false,
Expand All @@ -713,15 +714,15 @@ impl LangString {
}
}

fn parse_without_check(
pub fn parse_without_check(
string: &str,
allow_error_code_check: ErrorCodes,
enable_per_target_ignores: bool,
) -> LangString {
Self::parse(string, allow_error_code_check, enable_per_target_ignores, None)
}

fn parse(
pub fn parse(
string: &str,
allow_error_code_check: ErrorCodes,
enable_per_target_ignores: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ crate mod highlight;
crate mod layout;
pub mod markdown;
pub mod render;
crate mod sources;
pub mod sources;
crate mod static_files;
crate mod toc;
pub mod toc;
3 changes: 0 additions & 3 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

pub mod cache;

#[cfg(test)]
mod tests;

use std::borrow::Cow;
use std::cell::{Cell, RefCell};
use std::cmp::Ordering;
Expand Down
15 changes: 6 additions & 9 deletions src/librustdoc/html/toc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Toc {
/// ### A
/// ## B
/// ```
entries: Vec<TocEntry>,
pub(crate) entries: Vec<TocEntry>,
}

impl Toc {
Expand All @@ -27,11 +27,11 @@ impl Toc {

#[derive(Debug, PartialEq)]
pub struct TocEntry {
level: u32,
sec_number: String,
name: String,
id: String,
children: Toc,
pub(crate) level: u32,
pub(crate) sec_number: String,
pub(crate) name: String,
pub(crate) id: String,
pub(crate) children: Toc,
}

/// Progressive construction of a table of contents.
Expand Down Expand Up @@ -183,6 +183,3 @@ impl Toc {
v
}
}

#[cfg(test)]
mod tests;
13 changes: 8 additions & 5 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern crate rustc_mir;
extern crate rustc_parse;
extern crate rustc_resolve;
extern crate rustc_session;
extern crate rustc_span as rustc_span;
extern crate rustc_span;
extern crate rustc_target;
extern crate rustc_trait_selection;
extern crate rustc_typeck;
Expand All @@ -57,21 +57,24 @@ use rustc_session::{early_error, early_warn};
#[macro_use]
mod externalfiles;

mod clean;
#[cfg(test)]
mod rustdoc_tests;

crate mod clean;
mod config;
mod core;
mod docfs;
mod doctree;
#[macro_use]
mod error;
mod doctest;
crate mod doctest;
mod fold;
crate mod formats;
pub mod html;
mod json;
mod markdown;
mod passes;
mod theme;
crate mod passes;
crate mod theme;
mod visit_ast;
mod visit_lib;

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use self::strip_private::STRIP_PRIVATE;
mod strip_priv_imports;
pub use self::strip_priv_imports::STRIP_PRIV_IMPORTS;

mod unindent_comments;
crate mod unindent_comments;
pub use self::unindent_comments::UNINDENT_COMMENTS;

mod propagate_doc_cfg;
Expand Down
7 changes: 2 additions & 5 deletions src/librustdoc/passes/unindent_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ use crate::core::DocContext;
use crate::fold::{self, DocFolder};
use crate::passes::Pass;

#[cfg(test)]
mod tests;

pub const UNINDENT_COMMENTS: Pass = Pass {
name: "unindent-comments",
run: unindent_comments,
description: "removes excess indentation on comments in order for markdown to like it",
};

pub fn unindent_comments(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate {
crate fn unindent_comments(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate {
CommentCleaner.fold_crate(krate)
}

Expand Down Expand Up @@ -46,7 +43,7 @@ fn unindent_fragments(docs: &mut Vec<DocFragment>) {
}
}

fn unindent(s: &str) -> String {
crate fn unindent(s: &str) -> String {
let lines = s.lines().collect::<Vec<&str>>();
let mut saw_first_line = false;
let mut saw_second_line = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::clean::cfg::Cfg;

use rustc_ast::attr;
use rustc_ast::Path;
use rustc_ast::{LitKind, MetaItem, MetaItemKind, NestedMetaItem, Path};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::with_default_session_globals;
use rustc_span::DUMMY_SP;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{make_test, TestOptions};
use rustc_span::edition::DEFAULT_EDITION;
use crate::doctest::{make_test, TestOptions};

#[test]
fn make_test_basic() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::write_code;
use expect_test::expect_file;
use crate::html::highlight::write_code;

#[test]
fn test_html_highlighting() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::plain_summary_line;
use super::{ErrorCodes, IdMap, Ignore, LangString, Markdown, MarkdownHtml};
use crate::html::markdown::plain_summary_line;
use crate::html::markdown::{ErrorCodes, IdMap, Ignore, LangString, Markdown, MarkdownHtml};
use rustc_span::edition::{Edition, DEFAULT_EDITION};
use std::cell::RefCell;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::html::render::compare_names;
use std::cmp::Ordering;

#[test]
fn test_compare_names() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Toc, TocBuilder, TocEntry};
use crate::html::toc::{Toc, TocBuilder, TocEntry};

#[test]
fn builder_smoke() {
Expand Down
16 changes: 16 additions & 0 deletions src/librustdoc/rustdoc_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[cfg(test)]
mod clean_cfg;
#[cfg(test)]
mod doctest;
#[cfg(test)]
mod html_highlight;
#[cfg(test)]
mod html_markdown;
#[cfg(test)]
mod html_render;
#[cfg(test)]
mod html_toc;
#[cfg(test)]
mod passes_unindent_comments;
#[cfg(test)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just cfg(test) the parent module instead of duplicating the cfgs?

mod theme;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use crate::passes::unindent_comments::*;

#[test]
fn should_unindent() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use crate::theme::*;

#[test]
fn test_comments_in_rules() {
Expand Down
13 changes: 5 additions & 8 deletions src/librustdoc/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use std::path::Path;

use rustc_errors::Handler;

#[cfg(test)]
mod tests;

#[derive(Debug, Clone, Eq)]
pub struct CssPath {
pub name: String,
Expand Down Expand Up @@ -43,14 +40,14 @@ impl Hash for CssPath {
}

impl CssPath {
fn new(name: String) -> CssPath {
pub fn new(name: String) -> CssPath {
CssPath { name, children: FxHashSet::default() }
}
}

/// All variants contain the position they occur.
#[derive(Debug, Clone, Copy)]
enum Events {
pub enum Events {
StartLineComment(usize),
StartComment(usize),
EndComment(usize),
Expand All @@ -59,7 +56,7 @@ enum Events {
}

impl Events {
fn get_pos(&self) -> usize {
pub fn get_pos(&self) -> usize {
match *self {
Events::StartLineComment(p)
| Events::StartComment(p)
Expand All @@ -69,7 +66,7 @@ impl Events {
}
}

fn is_comment(&self) -> bool {
pub fn is_comment(&self) -> bool {
match *self {
Events::StartLineComment(_) | Events::StartComment(_) | Events::EndComment(_) => true,
_ => false,
Expand All @@ -88,7 +85,7 @@ fn is_line_comment(pos: usize, v: &[u8], events: &[Events]) -> bool {
v[pos + 1] == b'/'
}

fn load_css_events(v: &[u8]) -> Vec<Events> {
pub fn load_css_events(v: &[u8]) -> Vec<Events> {
let mut pos = 0;
let mut events = Vec::with_capacity(100);

Expand Down