Make test_init() return a scope guard

To be used in the next commit.
This commit is contained in:
Johannes Altmanninger 2024-03-24 11:55:03 +01:00
parent ecdc9ce1dd
commit 3cfa09d1bd
25 changed files with 62 additions and 62 deletions

View File

@ -269,7 +269,7 @@ pub fn abbrs_match(token: &wstr, position: Position) -> Vec<Replacer> {
#[test]
#[serial]
fn rename_abbrs() {
test_init();
let _cleanup = test_init();
use crate::abbrs::{Abbreviation, Position};
use crate::wchar::prelude::*;

View File

@ -4012,7 +4012,7 @@ fn keyword_for_token(tok: TokenType, token: &wstr) -> ParseKeyword {
#[test]
#[serial]
fn test_ast_parse() {
test_init();
let _cleanup = test_init();
let src = L!("echo");
let ast = Ast::parse(src, ParseTreeFlags::empty(), None);
assert!(!ast.any_error);

View File

@ -319,7 +319,7 @@ impl AutoloadFileCache {
#[test]
#[serial]
fn test_autoload() {
test_init();
let _cleanup = test_init();
use crate::common::{charptr2wcstring, wcs2zstring};
use crate::fds::wopen_cloexec;
use crate::wutil::sprintf;

View File

@ -5,7 +5,7 @@ use crate::wchar::prelude::*;
#[test]
#[serial]
fn test_string() {
test_init();
let _cleanup = test_init();
use crate::builtins::shared::{STATUS_CMD_ERROR, STATUS_CMD_OK, STATUS_INVALID_ARGS};
use crate::builtins::string::string;
use crate::common::escape;
@ -15,7 +15,7 @@ fn test_string() {
use crate::tests::prelude::*;
use crate::wchar::prelude::*;
test_init();
let _cleanup = test_init();
// avoid 1.3k L!()'s
macro_rules! test_cases {

View File

@ -169,7 +169,7 @@ fn test_test() {
#[test]
#[serial]
fn test_test_builtin() {
test_init();
let _cleanup = test_init();
test_test_brackets();
test_test();
}

View File

@ -310,7 +310,7 @@ pub fn make_fd_blocking(fd: RawFd) -> Result<(), io::Error> {
#[test]
#[serial]
fn test_pipes() {
test_init();
let _cleanup = test_init();
// Here we just test that each pipe has CLOEXEC set and is in the high range.
// Note pipe creation may fail due to fd exhaustion; don't fail in that case.
let mut pipes = vec![];

View File

@ -1830,7 +1830,7 @@ const var_err_len: usize = 16;
#[test]
#[serial]
fn test_parse_util_cmdsubst_extent() {
test_init();
let _cleanup = test_init();
const a: &wstr = L!("echo (echo (echo hi");
assert_eq!(parse_util_cmdsubst_extent(a, 0), 0..a.len());
assert_eq!(parse_util_cmdsubst_extent(a, 1), 0..a.len());
@ -1849,7 +1849,7 @@ fn test_parse_util_cmdsubst_extent() {
#[test]
#[serial]
fn test_parse_util_slice_length() {
test_init();
let _cleanup = test_init();
assert_eq!(parse_util_slice_length(L!("[2]")), Some(3));
assert_eq!(parse_util_slice_length(L!("[12]")), Some(4));
assert_eq!(parse_util_slice_length(L!("[\"foo\"]")), Some(7));
@ -1859,7 +1859,7 @@ fn test_parse_util_slice_length() {
#[test]
#[serial]
fn test_escape_quotes() {
test_init();
let _cleanup = test_init();
macro_rules! validate {
($cmd:expr, $quote:expr, $no_tilde:expr, $expected:expr) => {
assert_eq!(
@ -1902,7 +1902,7 @@ fn test_escape_quotes() {
#[test]
#[serial]
fn test_indents() {
test_init();
let _cleanup = test_init();
// A struct which is either text or a new indent.
struct Segment {
// The indent to set

View File

@ -9,7 +9,7 @@ use crate::wchar::prelude::*;
#[test]
#[serial]
fn test_abbreviations() {
test_init();
let _cleanup = test_init();
{
let mut abbrs = abbrs_get_set();
abbrs.add(Abbreviation::new(

View File

@ -25,7 +25,7 @@ fn comma_join(lst: Vec<WString>) -> WString {
#[test]
#[serial]
fn test_complete() {
test_init();
let _cleanup = test_init();
let vars = PwdEnvironment {
parent: TestEnvironment {
vars: HashMap::from([
@ -433,7 +433,7 @@ fn test_complete() {
#[test]
#[serial]
fn test_autosuggest_suggest_special() {
test_init();
let _cleanup = test_init();
macro_rules! perform_one_autosuggestion_cd_test {
($command:literal, $expected:literal, $vars:expr) => {
let mut comps = complete(
@ -596,7 +596,7 @@ fn test_autosuggest_suggest_special() {
#[test]
#[serial]
fn test_autosuggestion_ignores() {
test_init();
let _cleanup = test_init();
// Testing scenarios that should produce no autosuggestions
macro_rules! perform_one_autosuggestion_should_ignore_test {
($command:literal) => {

View File

@ -15,7 +15,7 @@ use crate::wchar::prelude::*;
#[test]
#[serial]
fn test_debounce() {
test_init();
let _cleanup = test_init();
// Run 8 functions using a condition variable.
// Only the first and last should run.
let db = Debounce::new(Duration::from_secs(0));
@ -88,7 +88,7 @@ fn test_debounce() {
#[test]
#[serial]
fn test_debounce_timeout() {
test_init();
let _cleanup = test_init();
// Verify that debounce doesn't wait forever.
// Use a shared_ptr so we don't have to join our threads.
let timeout = Duration::from_millis(500);

View File

@ -91,7 +91,7 @@ fn test_timezone_env_vars() {
#[test]
#[serial]
fn test_env_vars() {
test_init();
let _cleanup = test_init();
test_timezone_env_vars();
// TODO: Add tests for the locale and ncurses vars.
@ -110,7 +110,7 @@ fn test_env_vars() {
#[test]
#[serial]
fn test_env_snapshot() {
test_init();
let _cleanup = test_init();
std::fs::create_dir_all("test/fish_env_snapshot_test/").unwrap();
pushd("test/fish_env_snapshot_test/");
let vars = Parser::principal_parser().vars();

View File

@ -14,7 +14,7 @@ const UVARS_PER_THREAD: usize = 8;
const UVARS_TEST_PATH: &wstr = L!("test/fish_uvars_test/varsfile.txt");
fn test_universal_helper(x: usize) {
test_init();
let _cleanup = test_init();
let mut callbacks = CallbackDataList::new();
let mut uvars = EnvUniversal::new();
uvars.initialize_at_path(&mut callbacks, UVARS_TEST_PATH.to_owned());
@ -39,7 +39,7 @@ fn test_universal_helper(x: usize) {
#[test]
#[serial]
fn test_universal() {
test_init();
let _cleanup = test_init();
let _ = std::fs::remove_dir_all("test/fish_uvars_test/");
std::fs::create_dir_all("test/fish_uvars_test/").unwrap();
@ -78,7 +78,7 @@ fn test_universal() {
#[test]
#[serial]
fn test_universal_output() {
test_init();
let _cleanup = test_init();
let flag_export = EnvVarFlags::EXPORT;
let flag_pathvar = EnvVarFlags::PATHVAR;
@ -127,7 +127,7 @@ fn test_universal_output() {
#[test]
#[serial]
fn test_universal_parsing() {
test_init();
let _cleanup = test_init();
let input = concat!(
"# This file contains fish universal variable definitions.\n",
"# VERSION: 3.0\n",
@ -179,7 +179,7 @@ fn test_universal_parsing() {
#[test]
#[serial]
fn test_universal_parsing_legacy() {
test_init();
let _cleanup = test_init();
let input = concat!(
"# This file contains fish universal variable definitions.\n",
"SET varA:ValA1\\x1eValA2\n",
@ -208,7 +208,7 @@ fn test_universal_parsing_legacy() {
#[test]
#[serial]
fn test_universal_callbacks() {
test_init();
let _cleanup = test_init();
std::fs::create_dir_all("test/fish_uvars_test/").unwrap();
let mut callbacks = CallbackDataList::new();
let mut uvars1 = EnvUniversal::new();
@ -265,7 +265,7 @@ fn test_universal_callbacks() {
#[test]
#[serial]
fn test_universal_formats() {
test_init();
let _cleanup = test_init();
macro_rules! validate {
( $version_line:literal, $expected_format:expr ) => {
assert_eq!(
@ -287,7 +287,7 @@ fn test_universal_formats() {
#[test]
#[serial]
fn test_universal_ok_to_save() {
test_init();
let _cleanup = test_init();
// Ensure we don't try to save after reading from a newer fish.
std::fs::create_dir_all("test/fish_uvars_test/").unwrap();
let contents = b"# VERSION: 99999.99\n";

View File

@ -65,7 +65,7 @@ fn expand_test_impl(
#[test]
#[serial]
fn test_expand() {
test_init();
let _cleanup = test_init();
/// Perform parameter expansion and test if the output equals the zero-terminated parameter list /// supplied.
///
/// \param in the string to expand
@ -349,7 +349,7 @@ fn test_expand() {
#[test]
#[serial]
fn test_expand_overflow() {
test_init();
let _cleanup = test_init();
// Testing overflowing expansions
// Ensure that we have sane limits on number of expansions - see #7497.
@ -386,7 +386,7 @@ fn test_expand_overflow() {
#[test]
#[serial]
fn test_abbreviations() {
test_init();
let _cleanup = test_init();
// Testing abbreviations
with_abbrs_mut(|abbrset| {

View File

@ -109,7 +109,7 @@ impl ItemMaker {
#[test]
#[serial]
fn fd_monitor_items() {
test_init();
let _cleanup = test_init();
let monitor = FdMonitor::new();
// Items which will never receive data or be called.

View File

@ -24,7 +24,7 @@ fn get_overlong_path() -> String {
#[test]
#[serial]
fn test_is_potential_path() {
test_init();
let _cleanup = test_init();
// Directories
std::fs::create_dir_all("test/is_potential_path_test/alpha/").unwrap();
std::fs::create_dir_all("test/is_potential_path_test/beta/").unwrap();
@ -160,7 +160,7 @@ fn test_is_potential_path() {
#[test]
#[serial]
fn test_highlighting() {
test_init();
let _cleanup = test_init();
// Testing syntax highlighting
pushd("test/fish_highlight_test/");
let _popd = ScopeGuard::new((), |_| popd());

View File

@ -43,7 +43,7 @@ fn random_string() -> WString {
#[test]
#[serial]
fn test_history() {
test_init();
let _cleanup = test_init();
macro_rules! test_history_matches {
($search:expr, $expected:expr) => {
let expected: Vec<&wstr> = $expected;
@ -226,7 +226,7 @@ fn generate_history_lines(item_count: usize, idx: usize) -> Vec<WString> {
}
fn test_history_races_pound_on_history(item_count: usize, idx: usize) {
test_init();
let _cleanup = test_init();
// Called in child thread to modify history.
let hist = History::new(L!("race_test"));
let hist_lines = generate_history_lines(item_count, idx);
@ -239,7 +239,7 @@ fn test_history_races_pound_on_history(item_count: usize, idx: usize) {
#[test]
#[serial]
fn test_history_races() {
test_init();
let _cleanup = test_init();
// This always fails under WSL
if is_windows_subsystem_for_linux() {
return;
@ -340,7 +340,7 @@ fn test_history_races() {
#[test]
#[serial]
fn test_history_merge() {
test_init();
let _cleanup = test_init();
// In a single fish process, only one history is allowed to exist with the given name But it's
// common to have multiple history instances with the same name active in different processes,
// e.g. when you have multiple shells open. We try to get that right and merge all their history
@ -449,7 +449,7 @@ fn test_history_merge() {
#[test]
#[serial]
fn test_history_path_detection() {
test_init();
let _cleanup = test_init();
// Regression test for #7582.
let tmpdirbuff = CString::new("/tmp/fish_test_history.XXXXXX").unwrap();
let tmpdir = unsafe { libc::mkdtemp(tmpdirbuff.into_raw()) };
@ -565,7 +565,7 @@ fn install_sample_history(name: &wstr) {
#[test]
#[serial]
fn test_history_formats() {
test_init();
let _cleanup = test_init();
// Test inferring and reading legacy and bash history formats.
let name = L!("history_sample_fish_2_0");
install_sample_history(name);

View File

@ -8,7 +8,7 @@ use std::sync::Arc;
#[test]
#[serial]
fn test_input() {
test_init();
let _cleanup = test_init();
use crate::env::EnvStack;
let parser = Parser::new(Arc::pin(EnvStack::new()), false);
let mut input = Inputter::new(parser, libc::STDIN_FILENO);

View File

@ -9,7 +9,7 @@ use crate::wcstringutil::StringFuzzyMatch;
#[test]
#[serial]
fn test_pager_navigation() {
test_init();
let _cleanup = test_init();
// Generate 19 strings of width 10. There's 2 spaces between completions, and our term size is
// 80; these can therefore fit into 6 columns (6 * 12 - 2 = 70) or 5 columns (58) but not 7
// columns (7 * 12 - 2 = 82).
@ -99,7 +99,7 @@ fn test_pager_navigation() {
#[test]
#[serial]
fn test_pager_layout() {
test_init();
let _cleanup = test_init();
// These tests are woefully incomplete
// They only test the truncation logic for a single completion

View File

@ -12,7 +12,7 @@ use crate::wchar::prelude::*;
#[test]
#[serial]
fn test_error_messages() {
test_init();
let _cleanup = test_init();
// Given a format string, returns a list of non-empty strings separated by format specifiers. The
// format specifiers themselves are omitted.
fn separate_by_format_specifiers(format: &wstr) -> Vec<&wstr> {

View File

@ -21,7 +21,7 @@ use std::time::Duration;
#[test]
#[serial]
fn test_parser() {
test_init();
let _cleanup = test_init();
macro_rules! detect_errors {
($src:literal) => {
parse_util_detect_errors(L!($src), None, true /* accept incomplete */)
@ -303,7 +303,7 @@ fn test_parser() {
#[test]
#[serial]
fn test_new_parser_correctness() {
test_init();
let _cleanup = test_init();
macro_rules! validate {
($src:expr, $ok:expr) => {
let ast = Ast::parse(L!($src), ParseTreeFlags::default(), None);
@ -333,7 +333,7 @@ fn test_new_parser_correctness() {
#[test]
#[serial]
fn test_new_parser_correctness_by_fuzzing() {
test_init();
let _cleanup = test_init();
let fuzzes = [
L!("if"),
L!("else"),
@ -395,7 +395,7 @@ fn test_new_parser_correctness_by_fuzzing() {
#[test]
#[serial]
fn test_new_parser_ll2() {
test_init();
let _cleanup = test_init();
// Parse a statement, returning the command, args (joined by spaces), and the decoration. Returns
// true if successful.
fn test_1_parse_ll2(src: &wstr) -> Option<(WString, WString, StatementDecoration)> {
@ -516,7 +516,7 @@ fn test_new_parser_ll2() {
#[test]
#[serial]
fn test_new_parser_ad_hoc() {
test_init();
let _cleanup = test_init();
// Very ad-hoc tests for issues encountered.
// Ensure that 'case' terminates a job list.
@ -577,7 +577,7 @@ fn test_new_parser_ad_hoc() {
#[test]
#[serial]
fn test_new_parser_errors() {
test_init();
let _cleanup = test_init();
macro_rules! validate {
($src:expr, $expected_code:expr) => {
let mut errors = vec![];
@ -611,7 +611,7 @@ fn test_new_parser_errors() {
#[test]
#[serial]
fn test_eval_recursion_detection() {
test_init();
let _cleanup = test_init();
// Ensure that we don't crash on infinite self recursion and mutual recursion. These must use
// the principal parser because we cannot yet execute jobs on other parsers.
let parser = Parser::principal_parser().shared();
@ -632,7 +632,7 @@ fn test_eval_recursion_detection() {
#[test]
#[serial]
fn test_eval_illegal_exit_code() {
test_init();
let _cleanup = test_init();
macro_rules! validate {
($cmd:expr, $result:expr) => {
let parser = Parser::principal_parser();
@ -664,7 +664,7 @@ fn test_eval_illegal_exit_code() {
#[test]
#[serial]
fn test_eval_empty_function_name() {
test_init();
let _cleanup = test_init();
let parser = Parser::principal_parser().shared();
parser.eval(
L!("function '' ; echo fail; exit 42 ; end ; ''"),
@ -675,7 +675,7 @@ fn test_eval_empty_function_name() {
#[test]
#[serial]
fn test_expand_argument_list() {
test_init();
let _cleanup = test_init();
let parser = Parser::principal_parser().shared();
let comps: Vec<WString> = Parser::expand_argument_list(
L!("alpha 'beta gamma' delta"),
@ -717,7 +717,7 @@ fn test_1_cancellation(src: &wstr) {
#[test]
#[serial]
fn test_cancellation() {
test_init();
let _cleanup = test_init();
reader_push(Parser::principal_parser(), L!(""), ReaderConfig::default());
let _pop = ScopeGuard::new((), |()| reader_pop());

View File

@ -7,7 +7,7 @@ use crate::wcstringutil::join_strings;
#[test]
#[serial]
fn test_complete() {
test_init();
let _cleanup = test_init();
let mut lc = LayoutCache::new();
assert_eq!(lc.escape_code_length(L!("")), 0);
assert_eq!(lc.escape_code_length(L!("abcd")), 0);
@ -42,7 +42,7 @@ fn test_complete() {
#[test]
#[serial]
fn test_layout_cache() {
test_init();
let _cleanup = test_init();
let mut seqs = LayoutCache::new();
// Verify escape code cache.
@ -116,7 +116,7 @@ fn test_layout_cache() {
#[test]
#[serial]
fn test_prompt_truncation() {
test_init();
let _cleanup = test_init();
let mut cache = LayoutCache::new();
let mut trunc = WString::new();

View File

@ -9,7 +9,7 @@ use std::sync::Mutex;
#[test]
#[serial]
fn test_termsize() {
test_init();
let _cleanup = test_init();
let env_global = EnvMode::GLOBAL;
let parser = Parser::principal_parser();
let vars = parser.vars();

View File

@ -8,7 +8,7 @@ use std::sync::{
#[test]
#[serial]
fn test_topic_monitor() {
test_init();
let _cleanup = test_init();
let monitor = topic_monitor_t::default();
let gens = GenerationsList::new();
let t = topic_t::sigchld;
@ -34,7 +34,7 @@ fn test_topic_monitor() {
#[test]
#[serial]
fn test_topic_monitor_torture() {
test_init();
let _cleanup = test_init();
let monitor = Arc::new(topic_monitor_t::default());
const THREAD_COUNT: usize = 64;
let t1 = topic_t::sigchld;

View File

@ -168,7 +168,7 @@ pub use wgettext_maybe_fmt;
#[test]
#[serial]
fn test_untranslated() {
test_init();
let _cleanup = test_init();
let s: &'static wstr = wgettext!("abc");
assert_eq!(s, "abc");
let s2: &'static wstr = wgettext!("static");

View File

@ -59,7 +59,7 @@ fn test_wdirname_wbasename() {
#[test]
#[serial]
fn test_wwrite_to_fd() {
test_init();
let _cleanup = test_init();
let (_fd, filename) =
fish_mkstemp_cloexec(CString::new("/tmp/fish_test_wwrite.XXXXXX").unwrap()).unwrap();
let sizes = [1, 2, 3, 5, 13, 23, 64, 128, 255, 4096, 4096 * 2];