[x] Introduced missing tests for public API methods
:exclamation: Only the xdg::with_env internal method was being used in tests.
:heavy_check_mark: Added tests for xdg::new(), xdg::with_prefix(), and xdg::with_profile().
This prevent breaking changes to the public API.
[x] Introduced missing tests for fallback environment vars
:exclamation: Previously, there were no tests to cover if an XDG_* env var was missing
[x] Introduced missing tests for HOME environment var
:heavy_check_mark: Tests to make sure that HOME env var is honored
:heavy_check_mark: These tests spawn on their own thread to not override the main process's HOME env var.
This is important to ensure that the tests are consistent when running them in parallel.
This also results in faster tests.
[x] Removed unused HOME from make_env()
:exclamation: The existing tests were passing HOME to make_env for xdg::with_env
make_env is internal and does not affect the processes env vars
home was always set to the host's real HOME var
I discovered this by first creating the missing fallback environment vars tests
[x] Updated existing tests to use home override
Because xdg::with_env wasn't respecting make_env's attempts at override HOME in the other tests, the missing tests for HOME environment var added coverage for this area
With that extra coverage, it was safe to update the tests to use the new home override
This also prevents the need to spawn threads for overwriting the main test's HOME var
Abbreviated Coverage Reports
main Branch Test Coverage Report
```
$ cargo tarpaulin --out Html
2024-03-12T21:32:47.174649Z INFO cargo_tarpaulin::config: Creating config
2024-03-12T21:32:47.313183Z INFO cargo_tarpaulin: Running Tarpaulin
2024-03-12T21:32:47.313257Z INFO cargo_tarpaulin: Building project
2024-03-12T21:32:47.313278Z INFO cargo_tarpaulin::cargo: Cleaning project
Compiling xdg v2.5.2 (/home/jdalrymple/src/third-party/rust-xdg)
Finished test [unoptimized + debuginfo] target(s) in 1.96s
2024-03-12T21:33:00.019806Z INFO cargo_tarpaulin::process_handling::linux: Launching test
2024-03-12T21:33:00.019921Z INFO cargo_tarpaulin::process_handling: running /home/jdalrymple/.cache/cargo/target/debug/deps/xdg-130be4bb313f686f
running 10 tests
test base_directories::test::test_files_exists ... ok
test base_directories::test::test_profile ... ok
test base_directories::test::test_runtime_bad ... ok
test base_directories::test::test_symlinks ... ok
test base_directories::test::test_prefix ... ok
test base_directories::test::test_get_file ... ok
test base_directories::test::test_bad_environment ... ok
test base_directories::test::test_runtime_good ... ok
test base_directories::test::test_lists ... ok
test base_directories::test::test_good_environment ... ok
test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s
2024-03-12T21:33:01.369951Z INFO cargo_tarpaulin::report: Coverage Results:
|| Tested/Total Lines:
|| src/base_directories.rs: 178/301
||
59.14% coverage, 178/301 lines covered
```
home-dir Branch Test Coverage Report
```
$ cargo tarpaulin --out Html
2024-03-12T21:33:23.391096Z INFO cargo_tarpaulin::config: Creating config
2024-03-12T21:33:23.442409Z INFO cargo_tarpaulin: Running Tarpaulin
2024-03-12T21:33:23.442433Z INFO cargo_tarpaulin: Building project
2024-03-12T21:33:23.442443Z INFO cargo_tarpaulin::cargo: Cleaning project
Compiling xdg v2.5.2 (/home/jdalrymple/src/third-party/rust-xdg)
Finished test [unoptimized + debuginfo] target(s) in 2.15s
2024-03-12T21:33:25.773135Z INFO cargo_tarpaulin::process_handling::linux: Launching test
2024-03-12T21:33:25.773265Z INFO cargo_tarpaulin::process_handling: running /home/jdalrymple/.cache/cargo/target/debug/deps/xdg-130be4bb313f686f
running 18 tests
test base_directories::test::test_files_exists ... ok
test base_directories::test::test_profile ... ok
test base_directories::test::test_bad_environment ... ok
test base_directories::test::test_prefix ... ok
test base_directories::test::test_no_environment ... ok
test base_directories::test::test_home_environment ... ok
test base_directories::test::test_get_file ... ok
test base_directories::test::test_lists ... ok
test base_directories::test::test_good_environment ... ok
test base_directories::test::test_runtime_bad ... ok
test base_directories::test::test_symlinks ... ok
test base_directories::test::test_public_new ... ok
test base_directories::test::test_public_with_home ... ok
test base_directories::test::test_public_with_home_prefix ... ok
test base_directories::test::test_public_with_home_profile ... ok
test base_directories::test::test_public_with_prefix ... ok
test base_directories::test::test_runtime_good ... ok
test base_directories::test::test_public_with_profile ... ok
test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s
2024-03-12T21:33:27.056177Z INFO cargo_tarpaulin::report: Coverage Results:
|| Tested/Total Lines:
|| src/base_directories.rs: 198/310 +4.73%
||
63.87% coverage, 198/310 lines covered, +4.73% change in coverage
```
Fixes #68
Introduced new methods:
xdg::with_home("/custom/home")
xdg::with_home_prefix("/custom/home", "program-name")
xdg::with_home_profile("/custom/home", "program-name", "profile-name")
Tests Coverage:
xdg::with_home*()
methodsCoverage Summary
Notable New Coverage
Existing Tests: Fixes and Coverage Improvements
xdg::with_env
internal method was being used in tests.xdg::new()
,xdg::with_prefix()
, andxdg::with_profile()
.XDG_*
env var was missingHOME
environment varHOME
env var is honoredHOME
env var.HOME
frommake_env()
HOME
tomake_env
forxdg::with_env
make_env
is internal and does not affect the processes env varshome
was always set to the host's realHOME
varfallback environment vars
testsxdg::with_env
wasn't respectingmake_env
's attempts at overrideHOME
in the other tests, the missing tests forHOME
environment var added coverage for this areaHOME
varAbbreviated Coverage Reports
``` $ cargo tarpaulin --out Html 2024-03-12T21:32:47.174649Z INFO cargo_tarpaulin::config: Creating config 2024-03-12T21:32:47.313183Z INFO cargo_tarpaulin: Running Tarpaulin 2024-03-12T21:32:47.313257Z INFO cargo_tarpaulin: Building project 2024-03-12T21:32:47.313278Z INFO cargo_tarpaulin::cargo: Cleaning project Compiling xdg v2.5.2 (/home/jdalrymple/src/third-party/rust-xdg) Finished test [unoptimized + debuginfo] target(s) in 1.96s 2024-03-12T21:33:00.019806Z INFO cargo_tarpaulin::process_handling::linux: Launching test 2024-03-12T21:33:00.019921Z INFO cargo_tarpaulin::process_handling: running /home/jdalrymple/.cache/cargo/target/debug/deps/xdg-130be4bb313f686f running 10 tests test base_directories::test::test_files_exists ... ok test base_directories::test::test_profile ... ok test base_directories::test::test_runtime_bad ... ok test base_directories::test::test_symlinks ... ok test base_directories::test::test_prefix ... ok test base_directories::test::test_get_file ... ok test base_directories::test::test_bad_environment ... ok test base_directories::test::test_runtime_good ... ok test base_directories::test::test_lists ... ok test base_directories::test::test_good_environment ... ok test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s 2024-03-12T21:33:01.369951Z INFO cargo_tarpaulin::report: Coverage Results: || Tested/Total Lines: || src/base_directories.rs: 178/301 || 59.14% coverage, 178/301 lines covered ```main
Branch Test Coverage Report
``` $ cargo tarpaulin --out Html 2024-03-12T21:33:23.391096Z INFO cargo_tarpaulin::config: Creating config 2024-03-12T21:33:23.442409Z INFO cargo_tarpaulin: Running Tarpaulin 2024-03-12T21:33:23.442433Z INFO cargo_tarpaulin: Building project 2024-03-12T21:33:23.442443Z INFO cargo_tarpaulin::cargo: Cleaning project Compiling xdg v2.5.2 (/home/jdalrymple/src/third-party/rust-xdg) Finished test [unoptimized + debuginfo] target(s) in 2.15s 2024-03-12T21:33:25.773135Z INFO cargo_tarpaulin::process_handling::linux: Launching test 2024-03-12T21:33:25.773265Z INFO cargo_tarpaulin::process_handling: running /home/jdalrymple/.cache/cargo/target/debug/deps/xdg-130be4bb313f686f running 18 tests test base_directories::test::test_files_exists ... ok test base_directories::test::test_profile ... ok test base_directories::test::test_bad_environment ... ok test base_directories::test::test_prefix ... ok test base_directories::test::test_no_environment ... ok test base_directories::test::test_home_environment ... ok test base_directories::test::test_get_file ... ok test base_directories::test::test_lists ... ok test base_directories::test::test_good_environment ... ok test base_directories::test::test_runtime_bad ... ok test base_directories::test::test_symlinks ... ok test base_directories::test::test_public_new ... ok test base_directories::test::test_public_with_home ... ok test base_directories::test::test_public_with_home_prefix ... ok test base_directories::test::test_public_with_home_profile ... ok test base_directories::test::test_public_with_prefix ... ok test base_directories::test::test_runtime_good ... ok test base_directories::test::test_public_with_profile ... ok test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.06s 2024-03-12T21:33:27.056177Z INFO cargo_tarpaulin::report: Coverage Results: || Tested/Total Lines: || src/base_directories.rs: 198/310 +4.73% || 63.87% coverage, 198/310 lines covered, +4.73% change in coverage ```home-dir
Branch Test Coverage Report