Files
fish-shell/src/stdx.rs
Johannes Altmanninger 525c9bbdcb Move Rust tests to implementation files
For historical reasons[^1], most of our Rust tests are in src/tests,
which
1. is unconventional (Rust unit tests are supposed to be either in the
   same module as the implementation, or in a child module).
   This makes them slightly harder to discover, navigate etc.
2. can't test private APIs (motivating some of the "exposed for
   testing" comments).

Fix this by moving tests to the corresponding implementation file.
Reviewed with

        git show $commit \
            --color-moved=dimmed-zebra \
            --color-moved-ws=allow-indentation-change

- Shared test-only code lives in
  src/tests/prelude.rs,
  src/builtins/string/test_helpers.rs
  src/universal_notifier/test_helpers.rs
  We might want to slim down the prelude in future.
- I put our two benchmarks below tests ("mod tests" followed by "mod bench").

Verified that "cargo +nightly bench --features=benchmark" still
compiles and runs.

[^1]: Separate files are idiomatic in most other languages; also
separate files makes it easy to ignore when navigating the call graph.
("rg --vimgrep | rg -v tests/").  Fortunately, rust-analyzer provides
a setting called references.excludeTests for textDocument/references,
the textDocument/prepareCallHierarchy family, and potentially
textDocument/documentHighlight (which can be used to find all
references in the current file).

Closes #11992
2025-11-01 12:42:55 +01:00

22 lines
688 B
Rust

/// This module contains tests that assert the functionality and behavior of the rust standard
/// library, to ensure we can safely use its abstractions to perform low-level operations.
#[cfg(test)]
mod tests {
use std::fs::File;
use std::os::fd::AsRawFd;
#[test]
fn test_fd_cloexec() {
// Just open a file. Any file.
let file = File::create("test_file_for_fd_cloexec").unwrap();
let fd = file.as_raw_fd();
unsafe {
assert_eq!(
libc::fcntl(fd, libc::F_GETFD) & libc::FD_CLOEXEC,
libc::FD_CLOEXEC
);
}
let _ = std::fs::remove_file("test_file_for_fd_cloexec");
}
}