Skip to content

Commit

Permalink
add target: wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
oligamiq committed Oct 3, 2024
1 parent cfe9912 commit 1afc36b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal
- name: Install Rust channel
run: rustup toolchain install ${{matrix.rust}} && rustup default ${{matrix.rust}}
- name: Install `cargo wasi`
run: cargo install cargo-wasi
- name: Install `wasmtime`
run: curl https://wasmtime.dev/install.sh -sSf | bash
- uses: actions/checkout@v4
- name: Run tests
run: cargo test --verbose
- name: Run `cargo wasi test`
run: cargo wasi test --verbose
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,20 @@ mod windows {
}
}
}

// For WASI, we can't check if a file is executable
// Since wasm and wasi
// is not supposed to add executables ideologically,
// specify them collectively
#[cfg(any(target_os = "wasi", target_family = "wasm"))]
mod wasm {
use std::path::Path;

use super::IsExecutable;

impl IsExecutable for Path {
fn is_executable(&self) -> bool {
false
}
}
}
24 changes: 24 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,31 @@ mod windows {
fn non_existent_correct_extension() {
assert!(!is_executable("./tests/non_existent.exe"));
}
}

#[cfg(any(target_os = "wasi", target_family = "wasm"))]
mod wasm {
use super::*;

#[test]
fn executable() {
assert!(!is_executable("./tests/i_am_executable"));
}

#[test]
fn executable_symlink() {
assert!(!is_executable("./tests/i_am_executable_and_symlink"));
}

#[test]
fn not_executable_symlink() {
assert!(!is_executable("./tests/i_am_not_executable_and_symlink"));
}

#[test]
fn not_executable_directory() {
assert!(!is_executable("."));
}
}

#[test]
Expand Down

0 comments on commit 1afc36b

Please sign in to comment.