Skip to content

Commit

Permalink
Webassembly gha test.
Browse files Browse the repository at this point in the history
Add GHA test target wasm32-unknown-unknown.
Switch from `use std::*` to qualified `std::` calls.
  • Loading branch information
notpeter committed Apr 22, 2024
1 parent 4673d39 commit a35695f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ jobs:
run: cargo build --locked --all-targets --verbose
- name: Run tests
run: cargo test --locked --all-targets --verbose

build-and-test-wasm:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
- name: Report cargo version
run: cargo --version
- name: Report rustc version
run: rustc --version
- name: Build
run: cargo build --locked --target wasm32-unknown-unknown --verbose
- name: Run tests
run: cargo test --locked --target wasm32-unknown-unknown --verbose
17 changes: 7 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
//! }
//! ```
use std::env;
use std::path::PathBuf;

#[cfg(unix)]
/// Returns the path of the current user’s home directory if known.
///
Expand All @@ -39,27 +36,27 @@ use std::path::PathBuf;
///
/// This function returns `None` when the environment variable is set but empty.
/// Those implementations return the empty string `""` instead.
pub fn env_home_dir() -> Option<PathBuf> {
let home = env::var("HOME");
pub fn env_home_dir() -> Option<std::path::PathBuf> {
let home = std::env::var("HOME");
match home {
Ok(val) if !val.is_empty() => Some(PathBuf::from(val)),
Ok(val) if !val.is_empty() => Some(std::path::PathBuf::from(val)),
_ => None,
}
}

#[cfg(windows)]
/// Returns the path of the current user’s home directory if known.
pub fn env_home_dir() -> Option<PathBuf> {
let home = env::var("USERPROFILE");
pub fn env_home_dir() -> Option<std::path::PathBuf> {
let home = std::env::var("USERPROFILE");
match home {
Ok(val) if !val.is_empty() => Some(PathBuf::from(val)),
Ok(val) if !val.is_empty() => Some(std::path::PathBuf::from(val)),
_ => None,
}
}

#[cfg(all(not(windows), not(unix)))]
/// Returns the path of the current user’s home directory if known.
pub fn env_home_dir() -> Option<PathBuf> {
pub fn env_home_dir() -> Option<std::path::PathBuf> {
None
}

Expand Down

0 comments on commit a35695f

Please sign in to comment.