treeflow 0.2.0

CLI tool for simplified Git worktree management to speed up switching contexts when working collaboratively.
Documentation
#[cfg(test)]
mod utils;

#[cfg(test)]
mod init_tests {
    use crate::utils::treeflow_command::TreeflowCommand;
    use assert_cmd::Command;
    use predicates::prelude::predicate;
    use tempdir::TempDir;
    use test_case::test_case;

    #[test_case(true)]
    #[test_case(false)]
    fn init_bash_is_valid(enable_shorthands: bool) {
        let config_dir = TempDir::new("config_dir").expect("should be able to create temp config dir");

        let stdout = TreeflowCommand::new(config_dir.path().to_path_buf())
            .init("bash", enable_shorthands)
            .cmd()
            .assert()
            .success()
            .stdout(predicate::str::starts_with("#!/usr/bin/env sh"))
            .get_output()
            .stdout
            .clone();

        let init_script = String::from_utf8(stdout).expect("should be valid UTF-8");

        if enable_shorthands {
            assert!(init_script.contains("# Static aliases"), "Script should contain static aliases comment when shorthands are enabled");
        } else {
            assert!(!init_script.contains("# Static aliases"), "Script should not contain static aliases comment when shorthands are disabled");
        }

        Command::new("bash")
            .args(["-c", &format!("complete() {{ :; }}\n_complete_alias() {{ :; }}\n{}", init_script)]) // Mock the complete function for non-interactive Bash
            .assert()
            .success()
            .stdout(predicate::str::is_empty())
            .stderr(predicate::str::is_empty());
    }

    #[test_case(true)]
    #[test_case(false)]
    fn init_zsh_is_valid(enable_shorthands: bool) {
        // Check if zsh is available on the machine
        Command::new("zsh")
            .arg("--version")
            .assert()
            .success();

        let config_dir = TempDir::new("config_dir").expect("should be able to create temp config dir");

        let stdout = TreeflowCommand::new(config_dir.path().to_path_buf())
            .init("zsh", enable_shorthands)
            .cmd()
            .assert()
            .success()
            .stdout(predicate::str::starts_with("#!/usr/bin/env zsh"))
            .get_output()
            .stdout
            .clone();

        let init_script = String::from_utf8(stdout).expect("should be valid UTF-8");

        if enable_shorthands {
            assert!(init_script.contains("# Static aliases"), "Script should contain static aliases comment when shorthands are enabled");
        } else {
            assert!(!init_script.contains("# Static aliases"), "Script should not contain static aliases comment when shorthands are disabled");
        }

        // Validate the script syntax by running it with a mocked complete() function
        Command::new("zsh")
            .args(["-c", &format!("complete() {{ :; }}\n_complete_alias() {{ :; }}\ncompdef() {{ :; }}\n{}", init_script)]) // Mock the complete function and zsh-specific compdef for non-interactive zsh
            .assert()
            .success()
            .stdout(predicate::str::is_empty())
            .stderr(predicate::str::is_empty());
    }
}