Enable doctests

They are probably not terribly useful for us but let's see what happens.

Unfortunately cargo does not properly forward the combination of "RUSTFLAGS"
and "--target" that is currently required to build with ASan [1].  Hence doctests
will fail to link on ASan builds. Let's disable doctests when ASan is active.

[1]: https://github.com/rust-lang/cargo/issues/10666 et al
This commit is contained in:
Johannes Altmanninger 2024-01-13 01:26:28 +01:00
parent 07e3459fb0
commit 5512f44899
8 changed files with 16 additions and 20 deletions

View file

@ -52,7 +52,6 @@ rsconf = "0.1.1"
[lib] [lib]
crate-type = ["rlib"] crate-type = ["rlib"]
path = "fish-rust/src/lib.rs" path = "fish-rust/src/lib.rs"
doctest = false
[[bin]] [[bin]]
name = "fish" name = "fish"

View file

@ -146,6 +146,7 @@ foreach(PEXPECT ${PEXPECTS})
add_test_target("${PEXPECT}") add_test_target("${PEXPECT}")
endforeach(PEXPECT) endforeach(PEXPECT)
set(cargo_test_flags)
# Rust stuff. # Rust stuff.
if(DEFINED ASAN) if(DEFINED ASAN)
# Rust w/ -Zsanitizer=address requires explicitly specifying the --target triple or else linker # Rust w/ -Zsanitizer=address requires explicitly specifying the --target triple or else linker
@ -154,12 +155,13 @@ if(DEFINED ASAN)
message(FATAL_ERROR "ASAN requires defining the CMake variable Rust_CARGO_TARGET to the message(FATAL_ERROR "ASAN requires defining the CMake variable Rust_CARGO_TARGET to the
intended target triple") intended target triple")
endif() endif()
set(cargo_target_opt "--target" ${Rust_CARGO_TARGET}) list(APPEND cargo_test_flags "--target" ${Rust_CARGO_TARGET})
list(APPEND cargo_test_flags "--lib")
endif() endif()
add_test( add_test(
NAME "cargo-test" NAME "cargo-test"
COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package fish --target-dir ${rust_target_dir} ${cargo_target_opt} COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package fish --target-dir ${rust_target_dir} ${cargo_test_flags}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
) )
set_tests_properties("cargo-test" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE}) set_tests_properties("cargo-test" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
@ -167,7 +169,7 @@ add_test_target("cargo-test")
add_test( add_test(
NAME "cargo-test-widestring" NAME "cargo-test-widestring"
COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package widestring-suffix --target-dir ${rust_target_dir} ${cargo_target_opt} COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package widestring-suffix --target-dir ${rust_target_dir} ${cargo_test_flags}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
) )
add_test_target("cargo-test-widestring") add_test_target("cargo-test-widestring")

View file

@ -1800,8 +1800,9 @@ pub fn get_executable_path(argv0: impl AsRef<Path>) -> PathBuf {
/// ///
/// ```rust /// ```rust
/// use std::io::prelude::*; /// use std::io::prelude::*;
/// use fish::common::ScopeGuard;
/// ///
/// let file = std::fs::File::open("/dev/null"); /// let file = std::fs::File::create("/dev/null").unwrap();
/// // Create a scope guard to write to the file when the scope expires. /// // Create a scope guard to write to the file when the scope expires.
/// // To be able to still use the file, shadow `file` with the ScopeGuard itself. /// // To be able to still use the file, shadow `file` with the ScopeGuard itself.
/// let mut file = ScopeGuard::new(file, |file| file.write_all(b"goodbye\n").unwrap()); /// let mut file = ScopeGuard::new(file, |file| file.write_all(b"goodbye\n").unwrap());
@ -2000,7 +2001,10 @@ pub fn is_console_session() -> bool {
/// ///
/// # Examples /// # Examples
/// ///
/// ```rust /// ```ignore
/// use fish::wchar::prelude::*;
/// use fish::common::assert_sorted_by_name;
///
/// const COLORS: &[(&wstr, u32)] = &[ /// const COLORS: &[(&wstr, u32)] = &[
/// // must be in alphabetical order /// // must be in alphabetical order
/// (L!("blue"), 0x0000ff), /// (L!("blue"), 0x0000ff),

View file

@ -2215,17 +2215,13 @@ pub fn append_completion(
/// The command 'gcc -o' requires that a file follows it, so the `requires_param` mode is suitable. /// The command 'gcc -o' requires that a file follows it, so the `requires_param` mode is suitable.
/// This can be done using the following line: /// This can be done using the following line:
/// ///
/// ```
/// complete -c gcc -s o -r /// complete -c gcc -s o -r
/// ```
/// ///
/// The command 'grep -d' required that one of the strings 'read', 'skip' or 'recurse' is used. As /// The command 'grep -d' required that one of the strings 'read', 'skip' or 'recurse' is used. As
/// such, it is suitable to specify that a completion requires one of them. This can be done using /// such, it is suitable to specify that a completion requires one of them. This can be done using
/// the following line: /// the following line:
/// ///
/// ```
/// complete -c grep -s d -x -a "read skip recurse" /// complete -c grep -s d -x -a "read skip recurse"
/// ```
/// ///
/// - `cmd`: Command to complete. /// - `cmd`: Command to complete.
/// - `cmd_is_path`: If `true`, cmd will be interpreted as the absolute /// - `cmd_is_path`: If `true`, cmd will be interpreted as the absolute

View file

@ -475,7 +475,7 @@ impl<'s> State<'s> {
}; };
} }
/// ``` /// ```text
/// <base> = <constant> | /// <base> = <constant> |
/// <function-0> {"(" ")"} | /// <function-0> {"(" ")"} |
/// <function-1> <power> | /// <function-1> <power> |
@ -641,9 +641,7 @@ impl<'s> State<'s> {
} }
} }
/// ```
/// <power> = {("-" | "+")} <base> /// <power> = {("-" | "+")} <base>
/// ```
fn power(&mut self) -> f64 { fn power(&mut self) -> f64 {
let mut sign = 1.0; let mut sign = 1.0;
while let Token::Infix(op) = self.current { while let Token::Infix(op) = self.current {
@ -660,9 +658,7 @@ impl<'s> State<'s> {
sign * self.base() sign * self.base()
} }
/// ```
/// <factor> = <power> {"^" <power>} /// <factor> = <power> {"^" <power>}
/// ```
fn factor(&mut self) -> f64 { fn factor(&mut self) -> f64 {
let mut ret = self.power(); let mut ret = self.power();
@ -674,9 +670,7 @@ impl<'s> State<'s> {
ret ret
} }
/// ```
/// <term> = <factor> {("*" | "/" | "%") <factor>} /// <term> = <factor> {("*" | "/" | "%") <factor>}
/// ```
fn term(&mut self) -> f64 { fn term(&mut self) -> f64 {
let mut ret = self.factor(); let mut ret = self.factor();
while let Token::Infix(op @ (Operator::Mul | Operator::Div | Operator::Rem)) = self.current while let Token::Infix(op @ (Operator::Mul | Operator::Div | Operator::Rem)) = self.current
@ -695,9 +689,7 @@ impl<'s> State<'s> {
ret ret
} }
/// ```
/// <expr> = <term> {("+" | "-") <term>} /// <expr> = <term> {("+" | "-") <term>}
/// ```
fn expr(&mut self) -> f64 { fn expr(&mut self) -> f64 {
let mut ret = self.term(); let mut ret = self.term();
while let Token::Infix(op @ (Operator::Add | Operator::Sub)) = self.current { while let Token::Infix(op @ (Operator::Add | Operator::Sub)) = self.current {

View file

@ -876,6 +876,7 @@ impl TryFrom<&wstr> for PipeOrRedir {
/// Examples of supported syntaxes. /// Examples of supported syntaxes.
/// Note we are only responsible for parsing the redirection part, not 'cmd' or 'file'. /// Note we are only responsible for parsing the redirection part, not 'cmd' or 'file'.
/// ///
/// ```text
/// cmd | cmd normal pipe /// cmd | cmd normal pipe
/// cmd &| cmd normal pipe plus stderr-merge /// cmd &| cmd normal pipe plus stderr-merge
/// cmd >| cmd pipe with explicit fd /// cmd >| cmd pipe with explicit fd
@ -893,6 +894,7 @@ impl TryFrom<&wstr> for PipeOrRedir {
/// cmd &> file redirection with stderr merge /// cmd &> file redirection with stderr merge
/// cmd ^ file caret (stderr) redirection, perhaps disabled via feature flags /// cmd ^ file caret (stderr) redirection, perhaps disabled via feature flags
/// cmd ^^ file caret (stderr) redirection, perhaps disabled via feature flags /// cmd ^^ file caret (stderr) redirection, perhaps disabled via feature flags
/// ```
fn try_from(buff: &wstr) -> Result<PipeOrRedir, ()> { fn try_from(buff: &wstr) -> Result<PipeOrRedir, ()> {
// Extract a range of leading fd. // Extract a range of leading fd.
let mut cursor = buff.chars().take_while(|c| c.is_ascii_digit()).count(); let mut cursor = buff.chars().take_while(|c| c.is_ascii_digit()).count();

View file

@ -238,6 +238,7 @@ fn wcsfilecmp_leading_digits(a: &wstr, b: &wstr) -> (Ordering, usize, usize) {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use fish::util::find_subslice;
/// let haystack = b"ABC ABCDAB ABCDABCDABDE"; /// let haystack = b"ABC ABCDAB ABCDABCDABDE";
/// ///
/// assert_eq!(find_subslice(b"ABCDABD", haystack), Some(15)); /// assert_eq!(find_subslice(b"ABCDABD", haystack), Some(15));

View file

@ -32,7 +32,7 @@ pub use L;
/// A proc-macro for creating wide string literals using an L *suffix*. /// A proc-macro for creating wide string literals using an L *suffix*.
/// Example usage: /// Example usage:
/// ``` /// ```ignore
/// #[widestrs] /// #[widestrs]
/// pub fn func() { /// pub fn func() {
/// let s = "hello"L; // type &'static wstr /// let s = "hello"L; // type &'static wstr