Skip to content

Commit

Permalink
Rename our hidden internal test module
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Jul 3, 2024
1 parent 5b2f75d commit 28f2bb9
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/tests/helpers.rs → src/__private_tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Some test helpers for setting up isolated dummy steam installations.
// TODO: add a test with an env var flag that runs against your real local steam installation?

use std::{
collections::BTreeMap,
convert::{TryFrom, TryInto},
Expand All @@ -10,9 +8,9 @@ use std::{
};

use crate::{
tests::{temp::TempDir, TestError},
SteamDir,
};
use super::{temp::TempDir, TestError};

use serde::Serialize;

Expand Down Expand Up @@ -305,7 +303,7 @@ impl SampleApp {
#[cfg(test)]
mod test {
use super::*;
use crate::tests::TestResult;
use crate::__private_tests::TestResult;

#[test]
fn sanity() -> TestResult {
Expand Down
8 changes: 4 additions & 4 deletions src/tests/legacy.rs → src/__private_tests/legacy.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
tests::{
helpers::{expect_test_env, SampleApp},
TestResult,
},
Error,
};
use super::{
helpers::{expect_test_env, SampleApp},
TestResult,
};

static GMOD_ID: u32 = SampleApp::GarrysMod.id();

Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions src/tests/temp.rs → src/__private_tests/temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::{collections, env, fs, hash, path};

use crate::tests::TestError;
use super::TestError;

#[derive(Debug)]
pub struct TempDir(Option<path::PathBuf>);
Expand All @@ -15,7 +15,6 @@ impl TempDir {
let mut dir = env::temp_dir();
let random_name = format!("steamlocate-test-{:x}", random_seed());
dir.push(random_name);
// TODO: could retry on failure
fs::create_dir_all(&dir)?;
Ok(Self(Some(dir)))
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/tests.rs → src/__private_tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::tests::{
use super::{
helpers::{SampleApp, TempSteamDir},
TestResult,
};
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! # /*
//! let steam_dir = steamlocate::SteamDir::locate()?;
//! # */
//! # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
//! # let temp_steam_dir = steamlocate::__private_tests::helpers::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 +40,7 @@
//! assert_eq!(garrys_mod.name.as_ref().unwrap(), "Garry's Mod");
//! println!("{garrys_mod:#?}");
//! // ^^ prints something like vv
//! # Ok::<_, steamlocate::tests::TestError>(())
//! # Ok::<_, steamlocate::__private_tests::TestError>(())
//! ```
//! ```ignore
//! App {
Expand All @@ -61,7 +61,7 @@
//! # /*
//! let steam_dir = steamlocate::SteamDir::locate()?;
//! # */
//! # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
//! # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env();
//! # let steam_dir = temp_steam_dir.steam_dir();
//!
//! for library in steam_dir.libraries()? {
Expand All @@ -73,7 +73,7 @@
//! println!(" App {} - {:?}", app.app_id, app.name);
//! }
//! }
//! # Ok::<_, steamlocate::tests::TestError>(())
//! # Ok::<_, steamlocate::__private_tests::TestError>(())
//! ```
//!
//! On my laptop this prints
Expand Down Expand Up @@ -106,7 +106,7 @@ pub mod shortcut;
// NOTE: exposed publicly, so that we can use them in doctests
/// Not part of the public API >:V
#[doc(hidden)]
pub mod tests; // TODO: rename this since it may leak out in compiler error messages
pub mod __private_tests;

use std::collections::HashMap;
use std::fs;
Expand Down Expand Up @@ -149,7 +149,7 @@ pub struct ReadmeDoctests;
/// # /*
/// let steam_dir = SteamDir::locate()?;
/// # */
/// # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
/// # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env();
/// # let steam_dir = temp_steam_dir.steam_dir();
/// assert!(steam_dir.path().ends_with("Steam"));
/// ```
Expand Down Expand Up @@ -180,7 +180,7 @@ impl SteamDir {
///
/// # Example
/// ```
/// # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
/// # let temp_steam_dir = steamlocate::__private_tests::helpers::expect_test_env();
/// # let steam_dir = temp_steam_dir.steam_dir();
/// # /*
/// let steam_dir = SteamDir::locate()?;
Expand All @@ -189,7 +189,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::tests::TestError>(())
/// # Ok::<_, steamlocate::__private_tests::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: 2 additions & 3 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl Library {
&self.path
}

// TODO: if this was sorted then we could locate single apps faster
pub fn app_ids(&self) -> &[u32] {
&self.apps
}
Expand Down Expand Up @@ -163,14 +162,14 @@ impl Library {
///
/// ```
/// # use std::path::Path;
/// # let temp_steam_dir = steamlocate::tests::helpers::expect_test_env();
/// # let temp_steam_dir = steamlocate::__private_tests::helpers::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::tests::TestError>(())
/// # Ok::<_, steamlocate::__private_tests::TestError>(())
/// ```
pub fn resolve_app_dir(&self, app: &App) -> PathBuf {
self.path
Expand Down

0 comments on commit 28f2bb9

Please sign in to comment.