Skip to content

doctest should not be opt-in #117529

Open
Open
@loynoir

Description

@loynoir

BUG

compile_fail should not be ignored on test function.

Actual

compile_fail is ignored on test function.

$ cargo test && echo OK
...
OK
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    /// ```compile_fail
    /// let mut x = 5;
    /// x += 2;
    /// ```
    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

Expected

compile_fail should not be ignored on test function.

Same as on non-test function.

$ cargo test
...
Test compiled successfully, but it's marked `compile_fail`.
...
/// ```compile_fail
/// let mut x = 5;
/// x += 2;
/// ```
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

Version

  • rustc 1.73.0 (cc66ad4 2023-10-03)

  • cargo 1.73.0 (9c4383fb5 2023-08-26)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions