jsonette-core 0.3.0

JSON parse, format, query, and diagnostics engine — core library for the jsonette tool
Documentation
/*
 * Copyright (c) 2026 DevEtte.
 *
 * This project is dual-licensed under both the MIT License and the
 * Apache License, Version 2.0 (the "License"). You may not use this
 * file except in compliance with one of these licenses.
 *
 * You may obtain a copy of the Licenses at:
 * - MIT: https://opensource.org
 * - Apache 2.0: http://apache.org
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the licenses.
 */

//! Integration tests for the `uniffi-bindgen` binary.
//!
//! These tests verify that the binary entrypoint is properly compiled and
//! responds to CLI invocations, giving `cargo llvm-cov` data to mark
//! `engine/src/bin/uniffi-bindgen.rs` as covered.

use std::process::Command;

/// Returns the path to the compiled `uniffi-bindgen` binary.
fn uniffi_bindgen_bin() -> std::path::PathBuf {
    let mut path = std::env::current_exe()
        .unwrap()
        .parent()
        .unwrap()
        .to_path_buf();
    // When running integration tests the binary sits in target/debug/deps/
    // alongside the test binary. Walk up one level to find target/debug/.
    if path.ends_with("deps") {
        path.pop();
    }
    path.join("uniffi-bindgen")
}

/// **Test Case**: `uniffi-bindgen --help` prints usage and exits cleanly.
///
/// UniFFI's `uniffi_bindgen_main()` honours `--help` and exits with code 0.
/// Spawning the process gives llvm-cov a hook into the binary's `main()`.
#[test]
fn test_uniffi_bindgen_help_exits_cleanly() {
    let bin = uniffi_bindgen_bin();
    if !bin.exists() {
        // Binary may not be compiled yet when running a single test via `cargo test`.
        // Skip gracefully — CI always builds first.
        eprintln!("uniffi-bindgen binary not found at {:?}, skipping", bin);
        return;
    }

    let output = Command::new(bin)
        .arg("--help")
        .output()
        .expect("failed to spawn uniffi-bindgen");

    // --help may exit 0 or 1 depending on the clap version; either is acceptable.
    // What matters is that the process started and produced output.
    let stdout = String::from_utf8_lossy(&output.stdout);
    let stderr = String::from_utf8_lossy(&output.stderr);
    let combined = format!("{}{}", stdout, stderr);
    assert!(
        combined.to_lowercase().contains("usage") || combined.to_lowercase().contains("generate"),
        "expected help output, got: {}",
        combined
    );
}