From e988482a5a0418a03d1c6131413b200be8810548 Mon Sep 17 00:00:00 2001 From: Cosmic Horror Date: Tue, 22 Oct 2024 23:22:55 -0600 Subject: [PATCH] refactor: Add a `prelude` for internal tests --- src/__private_tests/mod.rs | 7 +++++++ src/lib.rs | 18 +++++++++++------- src/library.rs | 5 +++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/__private_tests/mod.rs b/src/__private_tests/mod.rs index 9df106d..bc3a003 100644 --- a/src/__private_tests/mod.rs +++ b/src/__private_tests/mod.rs @@ -9,3 +9,10 @@ mod wasm; pub type TestError = Box; pub type TestResult = Result<(), TestError>; + +pub mod prelude { + pub use super::{ + helpers::{expect_test_env, AppFile, SampleApp, TempLibrary, TempSteamDir}, + TestError, TestResult, + }; +} diff --git a/src/lib.rs b/src/lib.rs index 8aaefd3..9e9740d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,8 @@ //! # /* //! let steam_dir = steamlocate::SteamDir::locate()?; //! # */ -//! # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env(); +//! # use steamlocate::__private_tests::prelude::*; +//! # let temp_steam_dir = expect_test_env(); //! # let steam_dir = temp_steam_dir.steam_dir(); //! println!("Steam installation - {}", steam_dir.path().display()); //! // ^^ prints something like `Steam installation - C:\Program Files (x86)\Steam` @@ -40,7 +41,7 @@ //! assert_eq!(garrys_mod.name.as_ref().unwrap(), "Garry's Mod"); //! println!("{garrys_mod:#?}"); //! // ^^ prints something like vv -//! # Ok::<_, steamlocate::__private_tests::TestError>(()) +//! # Ok::<_, TestError>(()) //! ``` //! ```ignore //! App { @@ -61,7 +62,8 @@ //! # /* //! let steam_dir = steamlocate::SteamDir::locate()?; //! # */ -//! # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env(); +//! # use steamlocate::__private_tests::prelude::*; +//! # let temp_steam_dir = expect_test_env(); //! # let steam_dir = temp_steam_dir.steam_dir(); //! //! for library in steam_dir.libraries()? { @@ -73,7 +75,7 @@ //! println!(" App {} - {:?}", app.app_id, app.name); //! } //! } -//! # Ok::<_, steamlocate::__private_tests::TestError>(()) +//! # Ok::<_, TestError>(()) //! ``` //! //! On my laptop this prints @@ -149,7 +151,8 @@ pub struct ReadmeDoctests; /// # /* /// let steam_dir = SteamDir::locate()?; /// # */ -/// # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env(); +/// # use steamlocate::__private_tests::prelude::*; +/// # let temp_steam_dir = expect_test_env(); /// # let steam_dir = temp_steam_dir.steam_dir(); /// assert!(steam_dir.path().ends_with("Steam")); /// ``` @@ -180,7 +183,8 @@ impl SteamDir { /// /// # Example /// ``` - /// # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env(); + /// # use steamlocate::__private_tests::prelude::*; + /// # let temp_steam_dir = expect_test_env(); /// # let steam_dir = temp_steam_dir.steam_dir(); /// # /* /// let steam_dir = SteamDir::locate()?; @@ -189,7 +193,7 @@ impl SteamDir { /// let (warframe, library) = steam_dir.find_app(WARFRAME)?.unwrap(); /// assert_eq!(warframe.app_id, WARFRAME); /// assert!(library.app_ids().contains(&warframe.app_id)); - /// # Ok::<_, steamlocate::__private_tests::TestError>(()) + /// # Ok::<_, TestError>(()) /// ``` pub fn find_app(&self, app_id: u32) -> Result> { // Search for the `app_id` in each library diff --git a/src/library.rs b/src/library.rs index 3fdfaf4..6a1c582 100644 --- a/src/library.rs +++ b/src/library.rs @@ -162,14 +162,15 @@ impl Library { /// /// ``` /// # use std::path::Path; - /// # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env(); + /// # use steamlocate::__private_tests::prelude::*; + /// # let temp_steam_dir = expect_test_env(); /// # let steam_dir = temp_steam_dir.steam_dir(); /// const GRAVEYARD_KEEPER: u32 = 599_140; /// let (graveyard_keeper, library) = steam_dir.find_app(GRAVEYARD_KEEPER)?.unwrap(); /// let app_dir = library.resolve_app_dir(&graveyard_keeper); /// let expected_rel_path = Path::new("steamapps").join("common").join("Graveyard Keeper"); /// assert!(app_dir.ends_with(expected_rel_path)); - /// # Ok::<_, steamlocate::__private_tests::TestError>(()) + /// # Ok::<_, TestError>(()) /// ``` pub fn resolve_app_dir(&self, app: &App) -> PathBuf { self.path