Skip to content

Commit

Permalink
refactor: Add a prelude for internal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Oct 23, 2024
1 parent a51c0e1 commit e988482
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/__private_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ mod wasm;

pub type TestError = Box<dyn std::error::Error>;
pub type TestResult = Result<(), TestError>;

pub mod prelude {
pub use super::{
helpers::{expect_test_env, AppFile, SampleApp, TempLibrary, TempSteamDir},
TestError, TestResult,
};
}
18 changes: 11 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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 {
Expand All @@ -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()? {
Expand All @@ -73,7 +75,7 @@
//! println!(" App {} - {:?}", app.app_id, app.name);
//! }
//! }
//! # Ok::<_, steamlocate::__private_tests::TestError>(())
//! # Ok::<_, TestError>(())
//! ```
//!
//! On my laptop this prints
Expand Down Expand Up @@ -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"));
/// ```
Expand Down Expand Up @@ -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()?;
Expand All @@ -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<Option<(App, Library)>> {
// Search for the `app_id` in each library
Expand Down
5 changes: 3 additions & 2 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e988482

Please sign in to comment.