Repository: ilai-deutel/kibi (language: rust)

Issue:
Fix tests on WASI platform
Currently, tests fail on WASI, likely due to https://github.com/WebAssembly/WASI/issues/306:

```bash
$ cargo wasi test
running 9 tests
test config::tests::ini_processing_error_propagation ... Error: failed to run main module `.../target/wasm32-wasi/debug/deps/kibi-0e014d2d22062c7e.wasm`

Caused by:
    0: failed to invoke command default
    1: wasm trap: wasm `unreachable` instruction executed
       wasm backtrace:
           0: 0xaf1d7 - <unknown>!__rust_start_panic
           1: 0x8a2d3 - <unknown>!rust_panic
           2: 0x410bc - <unknown>!std::panicking::rust_panic_with_hook::h5cd357190ec2dc27
           3: 0xace7d - <unknown>!std::panicking::begin_panic::{{closure}}::h2b921c6015217a8c
           4: 0xaea75 - <unknown>!std::sys_common::backtrace::__rust_end_short_backtrace::h7804c064a89e5468
           5: 0xad127 - <unknown>!std::panicking::begin_panic::h74bbbdc216a2be15
           6: 0xaed39 - <unknown>!std::sys::wasi::os::temp_dir::h7c1705b1d80bf88f
           7: 0xaf0c4 - <unknown>!std::env::temp_dir::h8de49376550872b5
           8: 0xa3189 - <unknown>!tempfile::Builder::tempdir::he99c51adad158d09
           9: 0xa0aa1 - <unknown>!tempfile::dir::TempDir::new::h467eed705bdbfad5
          10: 0x64c6b - <unknown>!kibi::config::tests::ini_processing_helper::h04a043013200609f
          11: 0x43ad2 - <unknown>!kibi::config::tests::ini_processing_error_propagation::hd9e29b0360fe1c0e
          12: 0xaa1be - <unknown>!kibi::config::tests::ini_processing_error_propagation::{{closure}}::hd20dc0108869c254
          13: 0xab2e1 - <unknown>!core::ops::function::FnOnce::call_once::h470aa8b99eb85c41
          14: 0xaf0b7 - <unknown>!test::__rust_begin_short_backtrace::hdb236f9e8ab372e2
          15: 0xaf032 - <unknown>!core::ops::function::FnOnce::call_once{{vtable.shim}}::h46e94de7b5f8562e
          16: 0x20873 - <unknown>!test::run_test::run_test_inner::hb0fda869795a04b5
          17: 0x1f050 - <unknown>!test::run_test::h5e16ffceb7355d13
          18: 0x4765 - <unknown>!test::console::run_tests_console::hbd9d6e4ac7994c7e
          19: 0x21c76 - <unknown>!test::test_main::ha1139bbdf0c18c77
          20: 0x7fb9b - <unknown>!test::test_main_static::h88b81b227e6e27db
          21: 0xae6bf - <unknown>!kibi::main::hcb06a8996b2c438e
          22: 0xaa3cc - <unknown>!core::ops::function::FnOnce::call_once::hb9394b846f8ebed8
          23: 0xa9ac3 - <unknown>!std::sys_common::backtrace::__rust_begin_short_backtrace::ha02a7b57bbe40130
          24: 0xa6e84 - <unknown>!std::rt::lang_start::{{closure}}::h3ed9764642bc7713
          25: 0x728f3 - <unknown>!std::rt::lang_start_internal::h114e06638993fc12
          26: 0x92ab7 - <unknown>!std::rt::lang_start::hefbdca51d9ded6ce
          27: 0xae610 - <unknown>!__original_main
          28: 0xae96a - <unknown>!_start
          29: 0xaf0a3 - <unknown>!_start.command_export
       note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable to may show more debugging information
```


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 004e6ad..bf96481 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -36,6 +36,10 @@ jobs:
           - os: windows-latest
             target: i686-pc-windows-msvc
 
+          # WASI
+          - os: ubuntu-latest
+            target: wasm32-wasi
+
           # MSRV (Linux)
           - os: ubuntu-latest
             target: x86_64-unknown-linux-gnu
@@ -48,6 +52,10 @@ jobs:
           - os: windows-latest
             target: x86_64-pc-windows-gnu
             toolchain: 1.64.0
+          # MSRV (WASI)
+          - os: ubuntu-latest
+            target: wasm32-wasi
+            toolchain: 1.64.0
 
           # Nightly (Linux)
           - os: ubuntu-latest
@@ -64,6 +72,11 @@ jobs:
             target: x86_64-pc-windows-gnu
             toolchain: nightly
             coverage: true
+          # Nightly (WASI)
+          - os: ubuntu-latest
+            target: wasm32-wasi
+            toolchain: nightly
+            coverage: true
 
     runs-on: ${{ matrix.os }}
 
@@ -107,30 +120,6 @@ jobs:
           fail_ci_if_error: false
           verbose: true
 
-  wasi:
-    name: wasi
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        toolchain:
-          - stable
-          - 1.64.0  # MSRV
-          - nightly
-    env:
-      CARGO_TERM_COLOR: always
-    steps:
-      - uses: actions/checkout@v4
-      - name: Install Rust toolchain
-        uses: actions-rs/toolchain@v1
-        with:
-          toolchain: ${{ matrix.toolchain }}
-          target: wasm32-wasi
-          override: true
-      - name: Install WASI
-        run: cargo install cargo-wasi
-      - name: Run build on wasm32-wasi
-        run: cargo wasi build
-
   static_checks:
     strategy:
       matrix:
diff --git a/README.md b/README.md
index 662a361..6c3f8c2 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
 [![Lines of code](https://img.shields.io/github/actions/workflow/status/ilai-deutel/kibi/loc.yml?label=LOC%E2%89%A41024)](#)
 [![Crate](https://img.shields.io/crates/v/kibi.svg)](https://crates.io/crates/kibi)
 [![Minimum rustc version](https://img.shields.io/badge/rustc-1.64+-blue.svg?logo=rust)](https://www.rust-lang.org/)
-[![Platform](https://img.shields.io/badge/platform-Linux%20%7C%20macOS%20%7C%20Windows%2010-blue)](#)
+[![Platform](https://img.shields.io/badge/platform-Linux%20|%20macOS%20|%20Windows%2010%20|%20WASI-blue)](#)
 [![Packaging status](https://repology.org/badge/tiny-repos/kibi.svg)](https://repology.org/project/kibi/versions)
 [![Dependency Status](https://deps.rs/repo/github/ilai-deutel/kibi/status.svg)](https://deps.rs/repo/github/ilai-deutel/kibi)
 [![License](https://img.shields.io/crates/l/kibi?color=blue)](#license)
@@ -20,8 +20,8 @@ A configurable text editor with UTF-8 support, incremental search, syntax
 highlighting, line numbers and more, written in less than 1024
 lines<sup>[1](#counted-with)</sup> of Rust with minimal dependencies.
 
-Kibi is compatible with Linux, macOS, and Windows
-10<sup>[2](#windows-version)</sup>.
+Kibi is compatible with Linux, macOS, Windows
+10<sup>[2](#windows-version)</sup>, and WASI.
 
 This project is inspired by [`kilo`](https://github.com/antirez/kilo), a text
 editor written in C.
diff --git a/rustfmt.toml b/rustfmt.toml
index c26397d..f44e2af 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,6 +1,6 @@
 brace_style = "PreferSameLine"
 condense_wildcard_suffixes = true
-fn_args_layout = "Compressed"
+fn_params_layout = "Compressed"
 fn_single_line = true
 inline_attribute_width = 50
 use_field_init_shorthand = true
diff --git a/src/config.rs b/src/config.rs
index 2235f0f..e5cf818 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -100,6 +100,7 @@ pub fn parse_values<T: FromStr<Err = E>, E: Display>(value: &str) -> Result<Vec<
 }
 
 #[cfg(test)]
+#[cfg(not(target_family = "wasm"))] // No filesystem on wasm
 mod tests {
     use std::ffi::{OsStr, OsString};
     use std::{env, fs};
diff --git a/src/syntax.rs b/src/syntax.rs
index 15a4e6c..65dc106 100644
--- a/src/syntax.rs
+++ b/src/syntax.rs
@@ -93,6 +93,7 @@ impl Conf {
 }
 
 #[cfg(test)]
+#[cfg(not(target_family = "wasm"))] // No filesystem on wasm
 mod tests {
     use std::collections::HashSet;
     use std::fs;


Test patch: