Skip to content

Commit

Permalink
Fix wasm32 in general (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev authored Dec 23, 2023
1 parent 4c777a7 commit 6c8e433
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@ jobs:
env:
RUSTDOCFLAGS: -Dwarnings
run: cargo doc --all --no-deps

wasm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install wasm-pack
uses: taiki-e/install-action@wasm-pack
- name: Run wasm tests (`--no-default-features`)
run: wasm-pack test --node --no-default-features
- name: Run wasm tests (`--all-features`)
run: wasm-pack test --node --all-features
15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ categories = ["os", "hardware-support", "filesystem", "accessibility"]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

# TODO: test more features in CI

[features]
default = ["locate"]
locate = ["locate_backend"]
Expand All @@ -34,3 +32,16 @@ locate_backend = { package = "dirs", version = "5", optional = true }

[dev-dependencies]
insta = { version = "1.34.0", features = ["ron"] }
wasm-bindgen-test = "0.3.39"

[[example]]
name = "appmanifest"
required-features = ["locate"]

[[example]]
name = "overview"
required-features = ["locate"]

[[example]]
name = "shortcuts"
required-features = ["locate"]
9 changes: 9 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl fmt::Display for Error {
impl std::error::Error for Error {}

impl Error {
#[cfg(feature = "locate")]
pub(crate) fn locate(locate: LocateError) -> Self {
Self::FailedLocate(locate)
}
Expand Down Expand Up @@ -110,6 +111,7 @@ impl fmt::Display for LocateError {

#[derive(Clone, Debug)]
pub struct BackendError {
#[cfg(feature = "locate")]
#[allow(dead_code)] // Only used for displaying currently
inner: BackendErrorInner,
}
Expand All @@ -126,11 +128,18 @@ impl fmt::Display for BackendError {
BackendErrorInner::NoHome => f.write_str("Unable to locate the user's $HOME"),
}
}
#[cfg(not(feature = "locate"))]
{
// "Use" the unused value
let _ = f;
unreachable!("This should never be constructed!");
}
}
}

// TODO: move all this conditional junk into different modules, so that I don't have to keep
// repeating it everywhere
// TODO: ^^
#[derive(Clone, Debug)]
#[cfg(all(feature = "locate", target_os = "windows"))]
struct BackendErrorInner(std::sync::Arc<io::Error>);
Expand Down
2 changes: 2 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub mod helpers;
#[cfg(test)]
mod legacy;
mod temp;
#[cfg(test)]
mod wasm;

pub type TestError = Box<dyn std::error::Error>;
pub type TestResult = Result<(), TestError>;
10 changes: 10 additions & 0 deletions src/tests/wasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use wasm_bindgen_test::wasm_bindgen_test;

#[wasm_bindgen_test]
#[cfg_attr(not(feature = "locate"), ignore = "Needs `locate` feature")]
fn locate() {
#[cfg(not(feature = "locate"))]
unreachable!("Don't run ignored tests silly");
#[cfg(feature = "locate")]
let _ = crate::SteamDir::locate().unwrap_err();
}

0 comments on commit 6c8e433

Please sign in to comment.