Add unit + integration tests for clipboard code paths #54

Closed
opened 2026-06-28 01:46:23 +00:00 by akinus · 2 comments
Owner

Goal

Add real unit and integration tests for the clipboard code so that cargo test actually exercises the platform-specific get_clipboard_content and set_clipboard_content functions, plus the env-var-driven code paths in src/main.rs. Currently the test suite has only placeholder stubs (assert!(true)).

What's missing

Looking at the current state:

  • src/clipboard/mod.rs has a single placeholder test that just asserts true.
  • src/clipboard/linux.rs, macos.rs, and windows.rs have no tests at all — the platform modules are completely untested.
  • src/main.rs has a few env-var tests but no tests for print_help, print_version actual output, the no-args clipboard-read path, or the command-and-copy-to-clipboard path.

Proposed scope

  1. src/clipboard/mod.rs: add a test that verifies the module's public surface compiles per-platform (already there, keep it).
  2. src/clipboard/linux.rs (and macos.rs, windows.rs): add #[cfg(test)] test modules that verify:
    • On Linux, when AKCLIP_GET_CMD / AKCLIP_SET_CMD are unset, the default wl-paste/wl-copy (or xclip) paths are tried.
    • On any platform, when AKCLIP_GET_CMD / AKCLIP_SET_CMD are set to a known-good command (e.g. cat for get, true for set), the env-var path is taken and the function returns Ok.
    • When AKCLIP_GET_CMD is set to a command that exits non-zero, the function returns Err.
  3. src/main.rs: add tests that verify
    • print_help() and print_version() produce non-empty output to stdout.
    • When invoked with no args and a mocked AKCLIP_GET_CMD=cat /dev/null, main exits 0 and prints empty stdout.
    • When invoked with no args and a mocked AKCLIP_GET_CMD=false, main exits non-zero and prints an error to stderr.

Constraints

  • All new tests must run successfully under cargo test --release.
  • Tests should be CI-friendly — i.e. they should not require an actual X11/Wayland display or pbcopy. They should rely on AKCLIP_GET_CMD / AKCLIP_SET_CMD env-var overrides to control behavior in tests.
  • Match the existing code style (tabs, no comments unless essential).
  • Do NOT edit AGENTS.md, .forgejo/workflows/*, or Formula/*.
  • Do NOT modify Cargo.toml version.

Acceptance

  • cargo test --release runs the new tests and they all pass.
  • The number of tests in the output increases from the current count (currently 5 tests).
  • The existing build (cargo build --release) continues to pass.
## Goal Add real unit and integration tests for the clipboard code so that `cargo test` actually exercises the platform-specific `get_clipboard_content` and `set_clipboard_content` functions, plus the env-var-driven code paths in `src/main.rs`. Currently the test suite has only placeholder stubs (`assert!(true)`). ## What's missing Looking at the current state: - `src/clipboard/mod.rs` has a single placeholder test that just asserts `true`. - `src/clipboard/linux.rs`, `macos.rs`, and `windows.rs` have **no tests at all** — the platform modules are completely untested. - `src/main.rs` has a few env-var tests but no tests for `print_help`, `print_version` actual output, the no-args clipboard-read path, or the command-and-copy-to-clipboard path. ## Proposed scope 1. **`src/clipboard/mod.rs`**: add a test that verifies the module's public surface compiles per-platform (already there, keep it). 2. **`src/clipboard/linux.rs`** (and `macos.rs`, `windows.rs`): add `#[cfg(test)]` test modules that verify: - On Linux, when `AKCLIP_GET_CMD` / `AKCLIP_SET_CMD` are unset, the default `wl-paste`/`wl-copy` (or `xclip`) paths are tried. - On any platform, when `AKCLIP_GET_CMD` / `AKCLIP_SET_CMD` are set to a known-good command (e.g. `cat` for get, `true` for set), the env-var path is taken and the function returns `Ok`. - When `AKCLIP_GET_CMD` is set to a command that exits non-zero, the function returns `Err`. 3. **`src/main.rs`**: add tests that verify - `print_help()` and `print_version()` produce non-empty output to stdout. - When invoked with no args and a mocked `AKCLIP_GET_CMD=cat /dev/null`, `main` exits 0 and prints empty stdout. - When invoked with no args and a mocked `AKCLIP_GET_CMD=false`, `main` exits non-zero and prints an error to stderr. ## Constraints - All new tests must run successfully under `cargo test --release`. - Tests should be **CI-friendly** — i.e. they should not require an actual X11/Wayland display or pbcopy. They should rely on `AKCLIP_GET_CMD` / `AKCLIP_SET_CMD` env-var overrides to control behavior in tests. - Match the existing code style (tabs, no comments unless essential). - Do NOT edit `AGENTS.md`, `.forgejo/workflows/*`, or `Formula/*`. - Do NOT modify `Cargo.toml` version. ## Acceptance - `cargo test --release` runs the new tests and they all pass. - The number of tests in the output increases from the current count (currently 5 tests). - The existing build (`cargo build --release`) continues to pass.

Auto-triage: skipping this issue.

Repository directory is empty (no source files exist), so there is no codebase to patch and an AI cannot auto-fix this.

If this is wrong, add the bug or enhancement label and re-comment, or open a PR manually.

Auto-triage: skipping this issue. Repository directory is empty (no source files exist), so there is no codebase to patch and an AI cannot auto-fix this. If this is wrong, add the `bug` or `enhancement` label and re-comment, or open a PR manually.

Auto-triage: skipping this issue.

Repository directory is empty (no source files exist), so there is no codebase to patch and an AI cannot auto-fix this.

If this is wrong, add the bug or enhancement label and re-comment, or open a PR manually.

Auto-triage: skipping this issue. Repository directory is empty (no source files exist), so there is no codebase to patch and an AI cannot auto-fix this. If this is wrong, add the `bug` or `enhancement` label and re-comment, or open a PR manually.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
akinus/akclip#54
No description provided.