From 476b360eb8f6492f891ab5edacfe3c7c08f934c6 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sat, 4 May 2024 20:49:49 -0500 Subject: [PATCH] Remove rust test dependency on cmake output The test_history_formats test was reading from build/tests/ which is an artifact of the cmake test runner. The source code tests should not depend on the cmake test harness at all, so this is changed to read from the original test source in the ./tests/ directory instead. --- src/tests/history.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/tests/history.rs b/src/tests/history.rs index 8b27f418a..f5448b4c9 100644 --- a/src/tests/history.rs +++ b/src/tests/history.rs @@ -1,13 +1,11 @@ -use crate::common::{is_windows_subsystem_for_linux, str2wcstring, wcs2osstring}; +use crate::common::{is_windows_subsystem_for_linux, str2wcstring, wcs2osstring, wcs2string}; use crate::env::{EnvMode, EnvStack}; -use crate::fds::wopen_cloexec; use crate::history::{self, History, HistoryItem, HistorySearch, PathList, SearchDirection}; use crate::path::path_get_data; use crate::tests::prelude::*; use crate::tests::string_escape::ESCAPE_TEST_CHAR; use crate::wchar::prelude::*; use crate::wcstringutil::{string_prefixes_string, string_prefixes_string_case_insensitive}; -use nix::{fcntl::OFlag, sys::stat::Mode}; use rand::random; use std::collections::VecDeque; use std::ffi::CString; @@ -560,7 +558,9 @@ fn test_history_path_detection() { fn install_sample_history(name: &wstr) { let path = path_get_data().expect("Failed to get data directory"); std::fs::copy( - wcs2osstring(&(L!("tests/").to_owned() + &name[..])), + env!("CARGO_MANIFEST_DIR").to_owned() + + "/tests/" + + std::str::from_utf8(&wcs2string(&name[..])).unwrap(), wcs2osstring(&(path + L!("/") + &name[..] + L!("_history"))), ) .unwrap(); @@ -598,12 +598,9 @@ fn test_history_formats() { "echo foo".into(), ]; let test_history_imported_from_bash = History::with_name(L!("bash_import")); - let file = wopen_cloexec( - L!("tests/history_sample_bash"), - OFlag::O_RDONLY, - Mode::empty(), - ) - .unwrap(); + let file = + std::fs::File::open(env!("CARGO_MANIFEST_DIR").to_owned() + "/tests/history_sample_bash") + .unwrap(); test_history_imported_from_bash.populate_from_bash(BufReader::new(file)); assert_eq!(test_history_imported_from_bash.get_history(), expected); test_history_imported_from_bash.clear();