Skip to content

Port findutils to use uutests #537

Open
@sylvestre

Description

@sylvestre

Currently, the tests are custom. we should move to our framework for consistency.

The doc is here:
https://docs.rs/uutests/0.0.30/uutests/

Some examples of usage:
https://github.com/uutils/coreutils/blob/main/tests/by-util/test_ls.rs
https://github.com/uutils/coreutils/blob/main/tests/by-util/test_cp.rs

To do it:
tests/common/mod.rs

diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index aa8de37..d69371b 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -8,3 +8,13 @@
 // in one test but not another can cause a dead code warning.
 #[allow(dead_code)]
 pub mod test_helpers;
+pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_find");
+
+// Use the ctor attribute to run this function before any tests
+#[ctor::ctor]
+fn init() {
+    unsafe {
+        // Necessary for uutests to be able to find the binary
+        std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY);
+    }
+}

Cargo.toml:

diff --git a/Cargo.toml b/Cargo.toml
index 6ed7124..43b09d0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,6 +19,9 @@ onig = { version = "6.4", default-features = false }
 uucore = { version = "0.0.30", features = ["entries", "fs", "fsext", "mode"] }
 nix = { version = "0.29", features = ["fs", "user"] }
 argmax = "0.3.1"
+uutests = { version = "0.0.30" }
+ctor = "0.4.1"
+
 
 [dev-dependencies]
 assert_cmd = "2"

And update:

  • tests/exec_unit_tests.rs
  • tests/find_cmd_tests.rs
  • tests/find_exec_tests.rs
  • tests/xargs_tests.rs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions