Skip to content

Commit 5512f44

Browse files
committed
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]: rust-lang/cargo#10666 et al
1 parent 07e3459 commit 5512f44

File tree

8 files changed

+16
-20
lines changed

8 files changed

+16
-20
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ rsconf = "0.1.1"
5252
[lib]
5353
crate-type = ["rlib"]
5454
path = "fish-rust/src/lib.rs"
55-
doctest = false
5655

5756
[[bin]]
5857
name = "fish"

cmake/Tests.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ foreach(PEXPECT ${PEXPECTS})
146146
add_test_target("${PEXPECT}")
147147
endforeach(PEXPECT)
148148

149+
set(cargo_test_flags)
149150
# Rust stuff.
150151
if(DEFINED ASAN)
151152
# Rust w/ -Zsanitizer=address requires explicitly specifying the --target triple or else linker
@@ -154,20 +155,21 @@ if(DEFINED ASAN)
154155
message(FATAL_ERROR "ASAN requires defining the CMake variable Rust_CARGO_TARGET to the
155156
intended target triple")
156157
endif()
157-
set(cargo_target_opt "--target" ${Rust_CARGO_TARGET})
158+
list(APPEND cargo_test_flags "--target" ${Rust_CARGO_TARGET})
159+
list(APPEND cargo_test_flags "--lib")
158160
endif()
159161

160162
add_test(
161163
NAME "cargo-test"
162-
COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package fish --target-dir ${rust_target_dir} ${cargo_target_opt}
164+
COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package fish --target-dir ${rust_target_dir} ${cargo_test_flags}
163165
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
164166
)
165167
set_tests_properties("cargo-test" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
166168
add_test_target("cargo-test")
167169

168170
add_test(
169171
NAME "cargo-test-widestring"
170-
COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package widestring-suffix --target-dir ${rust_target_dir} ${cargo_target_opt}
172+
COMMAND env ${VARS_FOR_CARGO} cargo test ${CARGO_FLAGS} --package widestring-suffix --target-dir ${rust_target_dir} ${cargo_test_flags}
171173
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
172174
)
173175
add_test_target("cargo-test-widestring")

fish-rust/src/common.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,8 +1800,9 @@ pub fn get_executable_path(argv0: impl AsRef<Path>) -> PathBuf {
18001800
///
18011801
/// ```rust
18021802
/// use std::io::prelude::*;
1803+
/// use fish::common::ScopeGuard;
18031804
///
1804-
/// let file = std::fs::File::open("/dev/null");
1805+
/// let file = std::fs::File::create("/dev/null").unwrap();
18051806
/// // Create a scope guard to write to the file when the scope expires.
18061807
/// // To be able to still use the file, shadow `file` with the ScopeGuard itself.
18071808
/// let mut file = ScopeGuard::new(file, |file| file.write_all(b"goodbye\n").unwrap());
@@ -2000,7 +2001,10 @@ pub fn is_console_session() -> bool {
20002001
///
20012002
/// # Examples
20022003
///
2003-
/// ```rust
2004+
/// ```ignore
2005+
/// use fish::wchar::prelude::*;
2006+
/// use fish::common::assert_sorted_by_name;
2007+
///
20042008
/// const COLORS: &[(&wstr, u32)] = &[
20052009
/// // must be in alphabetical order
20062010
/// (L!("blue"), 0x0000ff),

fish-rust/src/complete.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,17 +2215,13 @@ pub fn append_completion(
22152215
/// The command 'gcc -o' requires that a file follows it, so the `requires_param` mode is suitable.
22162216
/// This can be done using the following line:
22172217
///
2218-
/// ```
22192218
/// complete -c gcc -s o -r
2220-
/// ```
22212219
///
22222220
/// The command 'grep -d' required that one of the strings 'read', 'skip' or 'recurse' is used. As
22232221
/// such, it is suitable to specify that a completion requires one of them. This can be done using
22242222
/// the following line:
22252223
///
2226-
/// ```
22272224
/// complete -c grep -s d -x -a "read skip recurse"
2228-
/// ```
22292225
///
22302226
/// - `cmd`: Command to complete.
22312227
/// - `cmd_is_path`: If `true`, cmd will be interpreted as the absolute

fish-rust/src/tinyexpr.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl<'s> State<'s> {
475475
};
476476
}
477477

478-
/// ```
478+
/// ```text
479479
/// <base> = <constant> |
480480
/// <function-0> {"(" ")"} |
481481
/// <function-1> <power> |
@@ -641,9 +641,7 @@ impl<'s> State<'s> {
641641
}
642642
}
643643

644-
/// ```
645644
/// <power> = {("-" | "+")} <base>
646-
/// ```
647645
fn power(&mut self) -> f64 {
648646
let mut sign = 1.0;
649647
while let Token::Infix(op) = self.current {
@@ -660,9 +658,7 @@ impl<'s> State<'s> {
660658
sign * self.base()
661659
}
662660

663-
/// ```
664661
/// <factor> = <power> {"^" <power>}
665-
/// ```
666662
fn factor(&mut self) -> f64 {
667663
let mut ret = self.power();
668664

@@ -674,9 +670,7 @@ impl<'s> State<'s> {
674670
ret
675671
}
676672

677-
/// ```
678673
/// <term> = <factor> {("*" | "/" | "%") <factor>}
679-
/// ```
680674
fn term(&mut self) -> f64 {
681675
let mut ret = self.factor();
682676
while let Token::Infix(op @ (Operator::Mul | Operator::Div | Operator::Rem)) = self.current
@@ -695,9 +689,7 @@ impl<'s> State<'s> {
695689
ret
696690
}
697691

698-
/// ```
699692
/// <expr> = <term> {("+" | "-") <term>}
700-
/// ```
701693
fn expr(&mut self) -> f64 {
702694
let mut ret = self.term();
703695
while let Token::Infix(op @ (Operator::Add | Operator::Sub)) = self.current {

fish-rust/src/tokenizer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ impl TryFrom<&wstr> for PipeOrRedir {
876876
/// Examples of supported syntaxes.
877877
/// Note we are only responsible for parsing the redirection part, not 'cmd' or 'file'.
878878
///
879+
/// ```text
879880
/// cmd | cmd normal pipe
880881
/// cmd &| cmd normal pipe plus stderr-merge
881882
/// cmd >| cmd pipe with explicit fd
@@ -893,6 +894,7 @@ impl TryFrom<&wstr> for PipeOrRedir {
893894
/// cmd &> file redirection with stderr merge
894895
/// cmd ^ file caret (stderr) redirection, perhaps disabled via feature flags
895896
/// cmd ^^ file caret (stderr) redirection, perhaps disabled via feature flags
897+
/// ```
896898
fn try_from(buff: &wstr) -> Result<PipeOrRedir, ()> {
897899
// Extract a range of leading fd.
898900
let mut cursor = buff.chars().take_while(|c| c.is_ascii_digit()).count();

fish-rust/src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ fn wcsfilecmp_leading_digits(a: &wstr, b: &wstr) -> (Ordering, usize, usize) {
238238
/// # Examples
239239
///
240240
/// ```
241+
/// use fish::util::find_subslice;
241242
/// let haystack = b"ABC ABCDAB ABCDABCDABDE";
242243
///
243244
/// assert_eq!(find_subslice(b"ABCDABD", haystack), Some(15));

fish-rust/src/wchar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub use L;
3232

3333
/// A proc-macro for creating wide string literals using an L *suffix*.
3434
/// Example usage:
35-
/// ```
35+
/// ```ignore
3636
/// #[widestrs]
3737
/// pub fn func() {
3838
/// let s = "hello"L; // type &'static wstr

0 commit comments

Comments
 (0)