chore(build): preparing for CI
This commit is contained in:
@@ -127,44 +127,51 @@ impl JjExecutor for JjLib {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::process::Command;
|
||||
|
||||
/// Initialize a jj repository in the given directory using `jj git init`
|
||||
fn init_jj_repo(dir: &Path) -> std::io::Result<()> {
|
||||
let output = Command::new("jj")
|
||||
.args(["git", "init"])
|
||||
.current_dir(dir)
|
||||
.output()?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(std::io::Error::other(format!(
|
||||
"jj git init failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
/// Initialize a jj repository in the given directory using jj-lib directly
|
||||
async fn init_jj_repo(dir: &Path) -> Result<(), String> {
|
||||
let settings = JjLib::load_settings().map_err(|e| e.to_string())?;
|
||||
Workspace::init_internal_git(&settings, dir)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(|e| format!("Failed to init jj repo: {e}"))
|
||||
}
|
||||
|
||||
/// Get the current commit description from a jj repository
|
||||
fn get_commit_description(dir: &Path) -> std::io::Result<String> {
|
||||
let output = Command::new("jj")
|
||||
.args(["log", "-r", "@", "--no-graph", "-T", "description"])
|
||||
.current_dir(dir)
|
||||
.output()?;
|
||||
/// Get the current commit description from a jj repository using jj-lib
|
||||
async fn get_commit_description(dir: &Path) -> Result<String, String> {
|
||||
let settings = JjLib::load_settings().map_err(|e| e.to_string())?;
|
||||
let store_factories = StoreFactories::default();
|
||||
let wc_factories = default_working_copy_factories();
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(std::io::Error::other(format!(
|
||||
"jj log failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
)));
|
||||
}
|
||||
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
|
||||
let workspace = Workspace::load(&settings, dir, &store_factories, &wc_factories)
|
||||
.map_err(|e| format!("Failed to load workspace: {e}"))?;
|
||||
|
||||
let repo = workspace
|
||||
.repo_loader()
|
||||
.load_at_head()
|
||||
.await
|
||||
.map_err(|e| format!("Failed to load repo: {e}"))?;
|
||||
|
||||
let wc_commit_id = repo
|
||||
.view()
|
||||
.get_wc_commit_id(WorkspaceName::DEFAULT)
|
||||
.ok_or_else(|| "No working copy commit found".to_string())?
|
||||
.clone();
|
||||
|
||||
let wc_commit = repo
|
||||
.store()
|
||||
.get_commit(&wc_commit_id)
|
||||
.map_err(|e| format!("Failed to get commit: {e}"))?;
|
||||
|
||||
Ok(wc_commit.description().trim_end().to_string())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn is_repository_returns_true_inside_jj_repo() {
|
||||
let temp_dir = assert_fs::TempDir::new().unwrap();
|
||||
init_jj_repo(temp_dir.path()).expect("Failed to init jj repo");
|
||||
init_jj_repo(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to init jj repo");
|
||||
|
||||
let executor = JjLib::with_working_dir(temp_dir.path());
|
||||
let result = executor.is_repository().await;
|
||||
@@ -187,7 +194,9 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn describe_updates_commit_description() {
|
||||
let temp_dir = assert_fs::TempDir::new().unwrap();
|
||||
init_jj_repo(temp_dir.path()).expect("Failed to init jj repo");
|
||||
init_jj_repo(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to init jj repo");
|
||||
|
||||
let test_message = "test: initial commit";
|
||||
let executor = JjLib::with_working_dir(temp_dir.path());
|
||||
@@ -195,14 +204,18 @@ mod tests {
|
||||
let result = executor.describe(test_message).await;
|
||||
assert!(result.is_ok(), "describe failed: {result:?}");
|
||||
|
||||
let actual = get_commit_description(temp_dir.path()).expect("Failed to get description");
|
||||
let actual = get_commit_description(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to get description");
|
||||
assert_eq!(actual, test_message);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn describe_handles_special_characters() {
|
||||
let temp_dir = assert_fs::TempDir::new().unwrap();
|
||||
init_jj_repo(temp_dir.path()).expect("Failed to init jj repo");
|
||||
init_jj_repo(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to init jj repo");
|
||||
|
||||
let test_message = "feat: add feature with special chars !@#$%^&*()";
|
||||
let executor = JjLib::with_working_dir(temp_dir.path());
|
||||
@@ -210,14 +223,18 @@ mod tests {
|
||||
let result = executor.describe(test_message).await;
|
||||
assert!(result.is_ok());
|
||||
|
||||
let actual = get_commit_description(temp_dir.path()).expect("Failed to get description");
|
||||
let actual = get_commit_description(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to get description");
|
||||
assert_eq!(actual, test_message);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn describe_handles_unicode() {
|
||||
let temp_dir = assert_fs::TempDir::new().unwrap();
|
||||
init_jj_repo(temp_dir.path()).expect("Failed to init jj repo");
|
||||
init_jj_repo(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to init jj repo");
|
||||
|
||||
let test_message = "docs: add unicode support 🎉 🚀";
|
||||
let executor = JjLib::with_working_dir(temp_dir.path());
|
||||
@@ -225,14 +242,18 @@ mod tests {
|
||||
let result = executor.describe(test_message).await;
|
||||
assert!(result.is_ok());
|
||||
|
||||
let actual = get_commit_description(temp_dir.path()).expect("Failed to get description");
|
||||
let actual = get_commit_description(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to get description");
|
||||
assert_eq!(actual, test_message);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn describe_handles_multiline_message() {
|
||||
let temp_dir = assert_fs::TempDir::new().unwrap();
|
||||
init_jj_repo(temp_dir.path()).expect("Failed to init jj repo");
|
||||
init_jj_repo(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to init jj repo");
|
||||
|
||||
let test_message = "feat: add feature\n\nThis is a multiline\ndescription";
|
||||
let executor = JjLib::with_working_dir(temp_dir.path());
|
||||
@@ -240,7 +261,9 @@ mod tests {
|
||||
let result = executor.describe(test_message).await;
|
||||
assert!(result.is_ok());
|
||||
|
||||
let actual = get_commit_description(temp_dir.path()).expect("Failed to get description");
|
||||
let actual = get_commit_description(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to get description");
|
||||
assert_eq!(actual, test_message);
|
||||
}
|
||||
|
||||
@@ -258,7 +281,9 @@ mod tests {
|
||||
#[tokio::test]
|
||||
async fn describe_can_be_called_multiple_times() {
|
||||
let temp_dir = assert_fs::TempDir::new().unwrap();
|
||||
init_jj_repo(temp_dir.path()).expect("Failed to init jj repo");
|
||||
init_jj_repo(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to init jj repo");
|
||||
|
||||
let executor = JjLib::with_working_dir(temp_dir.path());
|
||||
|
||||
@@ -266,16 +291,18 @@ mod tests {
|
||||
.describe("feat: first commit")
|
||||
.await
|
||||
.expect("First describe failed");
|
||||
let desc1 =
|
||||
get_commit_description(temp_dir.path()).expect("Failed to get first description");
|
||||
let desc1 = get_commit_description(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to get first description");
|
||||
assert_eq!(desc1, "feat: first commit");
|
||||
|
||||
executor
|
||||
.describe("feat: updated commit")
|
||||
.await
|
||||
.expect("Second describe failed");
|
||||
let desc2 =
|
||||
get_commit_description(temp_dir.path()).expect("Failed to get second description");
|
||||
let desc2 = get_commit_description(temp_dir.path())
|
||||
.await
|
||||
.expect("Failed to get second description");
|
||||
assert_eq!(desc2, "feat: updated commit");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,4 @@ pub use crate::{
|
||||
///
|
||||
/// Enable with `--features test-utils` (e.g. `cargo test --features test-utils`).
|
||||
#[cfg(feature = "test-utils")]
|
||||
pub use crate::{
|
||||
jj::mock::MockJjExecutor,
|
||||
prompts::mock::MockPrompts,
|
||||
};
|
||||
pub use crate::{jj::mock::MockJjExecutor, prompts::mock::MockPrompts};
|
||||
|
||||
Reference in New Issue
Block a user