cpp-amalgamate 1.0.1

cpp-amalgamate recursively combines C++ source files and the headers they include into a single output file.
use crate::util;

use anyhow::Result;
use indoc::indoc;

#[test]
fn blacklist_filters() -> Result<()> {
    util::builder()
        .source_file(indoc! {"
            #include <a.hpp>
            #include <b.hpp>
        "})?
        .search_dir("-d", [("a.hpp", "// a.hpp\n"), ("b.hpp", "// b.hpp\n")])?
        .command()
        .args(["--filter", "**/b.hpp"])
        .assert()
        .success()
        .stdout(indoc! {"
            // a.hpp
            #include <b.hpp>
        "});
    Ok(())
}

#[test]
fn whilelist_filters() -> Result<()> {
    util::builder()
        .source_file(indoc! {"
            #include <a.hpp>
            #include <b.hpp>
        "})?
        .search_dir("-d", [("a.hpp", "// a.hpp\n"), ("b.hpp", "// b.hpp\n")])?
        .command()
        .args(["-f", "**", "-f", "!**/b.hpp"])
        .assert()
        .success()
        .stdout(indoc! {"
            #include <a.hpp>
            // b.hpp
        "});
    Ok(())
}

#[test]
fn quote_and_system_only_filters() -> Result<()> {
    util::builder()
        .source_file(indoc! {r#"
            #include <a.hpp>
            #include <b.hpp>
            #include "a.hpp"
            #include "b.hpp"
        "#})?
        .search_dir("-d", [("a.hpp", "// a.hpp\n"), ("b.hpp", "// b.hpp\n")])?
        .command()
        .args([
            "-f",
            "**",
            "--filter-quote",
            "!**/b.hpp",
            "--filter-system",
            "!**/a.hpp",
        ])
        .assert()
        .success()
        .stdout(indoc! {r#"
            // a.hpp
            #include <b.hpp>
            #include "a.hpp"
            // b.hpp
        "#});
    Ok(())
}

#[test]
fn filter_precedence() -> Result<()> {
    util::builder()
        .source_file("#include <a/b/c.hpp>")?
        .search_dir("-d", [("a/b/c.hpp", "arst")])?
        .command()
        .args(["-f", "**/a/**", "-f", "!**/a/b/**", "-f", "**/a/b/c.hpp"])
        .assert()
        .success()
        .stdout("#include <a/b/c.hpp>");
    Ok(())
}