Skip to content

Commit

Permalink
test: add test for shell-hook command
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jan 16, 2024
1 parent af8b692 commit 5c65ccf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub async fn execute_command(command: Command) -> miette::Result<()> {
Command::Auth(cmd) => auth::execute(cmd).await,
Command::Install(cmd) => install::execute(cmd).await,
Command::Shell(cmd) => shell::execute(cmd).await,
Command::ShellHook => shell_hook::execute().await,
Command::ShellHook => shell_hook::execute(),
Command::Task(cmd) => task::execute(cmd),
Command::Info(cmd) => info::execute(cmd).await,
Command::Upload(cmd) => upload::execute(cmd).await,
Expand Down
24 changes: 21 additions & 3 deletions src/cli/shell_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use rattler_shell::{

use crate::prefix::Prefix;

/// Prints the activation script to the stdout.
pub async fn execute() -> miette::Result<()> {
/// Generates the activation script.
fn generate_activation_script() -> miette::Result<String> {
let prefix = Prefix::new(PathBuf::new())?;
let shell: ShellEnum = if cfg!(windows) {
rattler_shell::shell::CmdExe.into()
Expand Down Expand Up @@ -41,7 +41,25 @@ pub async fn execute() -> miette::Result<()> {
result.script
};

println!("{script}");
Ok(script)
}

/// Prints the activation script to the stdout.
pub fn execute() -> miette::Result<()> {
let script = generate_activation_script()?;
println!("{script}");
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
pub fn test_shell_hook() {
let script = generate_activation_script().unwrap();
assert!(script.starts_with("#!/bin/sh"));
assert!(script.contains("export PATH="));
assert!(script.contains("export CONDA_PREFIX="));
}
}

0 comments on commit 5c65ccf

Please sign in to comment.