mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: Add git_commit module (#673)
This commit is contained in:
committed by
Matan Kushner
parent
5b440c0bb0
commit
c5a206e3cf
@@ -0,0 +1,68 @@
|
||||
use ansi_term::Color;
|
||||
use std::process::Command;
|
||||
use std::{io, str};
|
||||
|
||||
use crate::common::{self, TestCommand};
|
||||
|
||||
#[test]
|
||||
fn test_render_commit_hash() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
let mut git_output = Command::new("git")
|
||||
.args(&["rev-parse", "HEAD"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?
|
||||
.stdout;
|
||||
git_output.truncate(7);
|
||||
let expected_hash = str::from_utf8(&git_output).unwrap();
|
||||
|
||||
let output = common::render_module("git_commit")
|
||||
.use_config(toml::toml! {
|
||||
[git_commit]
|
||||
disabled = false
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(repo_dir)
|
||||
.output()?;
|
||||
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
let expected = Color::Green
|
||||
.bold()
|
||||
.paint(format!("({}) ", expected_hash))
|
||||
.to_string();
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_render_commit_hash_len_override() -> io::Result<()> {
|
||||
let repo_dir = common::create_fixture_repo()?;
|
||||
|
||||
let mut git_output = Command::new("git")
|
||||
.args(&["rev-parse", "HEAD"])
|
||||
.current_dir(repo_dir.as_path())
|
||||
.output()?
|
||||
.stdout;
|
||||
git_output.truncate(14);
|
||||
let expected_hash = str::from_utf8(&git_output).unwrap();
|
||||
|
||||
let output = common::render_module("git_commit")
|
||||
.use_config(toml::toml! {
|
||||
[git_commit]
|
||||
disabled = false
|
||||
commit_hash_length = 14
|
||||
})
|
||||
.arg("--path")
|
||||
.arg(repo_dir)
|
||||
.output()?;
|
||||
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
let expected = Color::Green
|
||||
.bold()
|
||||
.paint(format!("({}) ", expected_hash))
|
||||
.to_string();
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user