xdoc-rs 0.1.1

Declarative XML engine for Rust
Documentation
use std::fs;
use std::path::PathBuf;
use std::process::Command;

#[test]
fn compile_pass() {
    let tests = trybuild::TestCases::new();
    tests.pass("tests/compile/pass/*.rs");
}

#[test]
fn compile_fail() {
    let tests = trybuild::TestCases::new();
    tests.compile_fail("tests/compile/fail/*.rs");
}

#[test]
fn compile_pass_with_renamed_xdoc_dependency() {
    let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let fixture_dir = manifest_dir.join("target/compile-renamed-xdoc");
    let src_dir = fixture_dir.join("src");

    if fixture_dir.exists() {
        fs::remove_dir_all(&fixture_dir).expect("remove previous renamed dependency fixture");
    }
    fs::create_dir_all(&src_dir).expect("create renamed dependency fixture");

    fs::write(
        fixture_dir.join("Cargo.toml"),
        format!(
            r#"[package]
name = "compile-renamed-xdoc"
version = "0.0.0"
edition = "2021"

[dependencies]
xml_runtime = {{ package = "xdoc-rs", path = "{}" }}

[workspace]
"#,
            manifest_dir.display()
        ),
    )
    .expect("write renamed dependency fixture manifest");

    fs::write(
        src_dir.join("main.rs"),
        r##"use xml_runtime::core::XmlResult;
use xml_runtime::macros::xml;

fn main() -> XmlResult<()> {
    let document = xml! {
        <Root>
            <Child code="A">value</Child>
        </Root>
    }?
    .into_document()?;
    let output = xml_runtime::writer::to_string_compact(&document)?;
    assert_eq!(output, r#"<Root><Child code="A">value</Child></Root>"#);
    Ok(())
}
"##,
    )
    .expect("write renamed dependency fixture main");

    let status = Command::new("cargo")
        .arg("run")
        .arg("--manifest-path")
        .arg(fixture_dir.join("Cargo.toml"))
        .status()
        .expect("run renamed dependency fixture");

    assert!(status.success(), "renamed dependency fixture failed");
}