Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/ci-shimforge-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Fork shimforge config tests
on:
push:
branches: ['shimforge-config-tests']
workflow_dispatch:
permissions:
contents: read
jobs:
verify:
if: github.repository == 'tanglearncode/zoxide'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.88.0
- name: Build the config tests at zoxide's MSRV, with the lockfile verified
run: cargo test --locked --bins config -- --list
- name: Run the config tests 20 times at 8 threads, nothing serialized
run: |
for attempt in $(seq 1 20); do
cargo test --locked --bins config -- --test-threads=8
done
echo 'config tests: 20 runs x 8 threads, no env mutation.' >> "$GITHUB_STEP_SUMMARY"
- name: Run the full test suite with the mocks present
run: cargo test --locked
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ color-print = "0.3.4"

[dev-dependencies]
assert_cmd = "2.0.0"
shimforge = "=0.1.1"
rstest = { version = "0.26.0", default-features = false }
rstest_reuse = "0.7.0"
tempfile = "3.15.0"
Expand Down
55 changes: 55 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,58 @@ pub fn maxage() -> Result<Rank> {
pub fn resolve_symlinks() -> bool {
env::var_os("_ZO_RESOLVE_SYMLINKS").is_some_and(|var| var == "1")
}

#[cfg(test)]
mod tests {
use std::ffi::OsString;

use shimforge::{Session, mock};

use super::*;

// Each test gets its own value for one variable, on its own thread. The
// process environment is never written, so these run in parallel with
// each other and with every other test in the suite.
fn env_var(session: &mut Session, name: &'static str, value: Option<&str>) {
let var_os = mock!(session, env::var_os::<&str>, fn(&str) -> Option<OsString>);
let value = value.map(OsString::from);
var_os.expect().with(move |var| *var == name).returns(value);
}

#[test]
fn maxage_defaults_when_unset() {
let mut session = Session::new();
env_var(&mut session, "_ZO_MAXAGE", None);
assert_eq!(maxage().unwrap(), 10_000.0);
}

#[test]
fn maxage_reads_the_variable() {
let mut session = Session::new();
env_var(&mut session, "_ZO_MAXAGE", Some("500"));
assert_eq!(maxage().unwrap(), 500.0);
}

#[test]
fn maxage_rejects_a_value_that_is_not_a_number() {
let mut session = Session::new();
env_var(&mut session, "_ZO_MAXAGE", Some("soon"));
let error = maxage().unwrap_err().to_string();
assert!(error.contains("unable to parse _ZO_MAXAGE"), "{error}");
}

#[test]
fn a_relative_data_dir_is_rejected() {
let mut session = Session::new();
env_var(&mut session, "_ZO_DATA_DIR", Some("relative/zoxide"));
let error = data_dir().unwrap_err().to_string();
assert!(error.contains("must be an absolute path"), "{error}");
}

#[test]
fn resolve_symlinks_is_opt_in() {
let mut session = Session::new();
env_var(&mut session, "_ZO_RESOLVE_SYMLINKS", Some("1"));
assert!(resolve_symlinks());
}
}
Loading