-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
231 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use anyhow::Result; | ||
use chrono::Utc; | ||
use std::process::{Command, Stdio}; | ||
|
||
pub fn git_init() -> Result<()> { | ||
let temp_dir = temp_testdir::TempDir::default().permanent(); | ||
println!("{:?}", &temp_dir.as_ref()); | ||
std::env::set_current_dir(temp_dir.as_ref())?; | ||
|
||
println!("on {:?}", std::env::current_dir()?); | ||
println!("git init"); | ||
|
||
Command::new("git") | ||
.arg("init") | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.output()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn git_commit(message: &str) -> Result<()> { | ||
let file_name = Utc::now().timestamp().to_string(); | ||
std::fs::write(file_name, "dummy")?; | ||
|
||
println!("git add ."); | ||
Command::new("git") | ||
.arg("add") | ||
.arg(".") | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.output()?; | ||
|
||
println!("git commit -m \"{}\"", message); | ||
Command::new("git") | ||
.arg("commit") | ||
.arg("-m") | ||
.arg(&format!("\"{}\"", message)) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.output()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn _git_tag(tag: &str) -> Result<()> { | ||
Command::new("tag") | ||
.arg(tag) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.output()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn create_empty_config() -> Result<()> { | ||
std::fs::File::create("coco.toml")?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use anyhow::Result; | ||
use assert_cmd::prelude::*; | ||
use std::process::Command; | ||
|
||
mod common; | ||
|
||
#[test] | ||
#[cfg(not(tarpaulin_include))] | ||
fn init_empty_repo_in_target_dir() -> Result<()> { | ||
let mut command = Command::cargo_bin("cog")?; | ||
|
||
command.arg("init").arg("test_repo"); | ||
|
||
let temp_dir = temp_testdir::TempDir::default(); | ||
std::env::set_current_dir(temp_dir.as_ref())?; | ||
|
||
command.assert().success(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(not(tarpaulin_include))] | ||
fn init_existing_repo() -> Result<()> { | ||
let temp_dir = temp_testdir::TempDir::default(); | ||
|
||
let mut command = Command::cargo_bin("cog")?; | ||
|
||
command.arg("init").arg("test_repo_existing"); | ||
|
||
// Create repo with commits | ||
let path = temp_dir.join("test_repo_existing"); | ||
std::fs::create_dir(&path)?; | ||
std::env::set_current_dir(&path)?; | ||
common::git_init()?; | ||
common::git_commit("chore: test commit")?; | ||
|
||
std::env::set_current_dir(temp_dir.as_ref())?; | ||
|
||
command.assert().success(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(not(tarpaulin_include))] | ||
fn fail_if_config_exist() -> Result<()> { | ||
let temp_dir = temp_testdir::TempDir::default(); | ||
|
||
let mut command = Command::cargo_bin("cog")?; | ||
|
||
command.arg("init").arg("test_repo_existing"); | ||
|
||
// Create repo with commits | ||
let path = temp_dir.join("test_repo_existing"); | ||
std::fs::create_dir(&path)?; | ||
std::fs::write(&path.join("coco.toml"), "[hooks]")?; | ||
std::env::set_current_dir(&path)?; | ||
common::git_init()?; | ||
common::git_commit("chore: test commit")?; | ||
|
||
std::env::set_current_dir(temp_dir.as_ref())?; | ||
|
||
command.assert().failure(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(not(tarpaulin_include))] | ||
fn init_current_dir_with_no_arg() -> Result<()> { | ||
let temp_dir = temp_testdir::TempDir::default(); | ||
let path = temp_dir.join("test_repo_no_args"); | ||
|
||
std::fs::create_dir(&path)?; | ||
let mut command = Command::cargo_bin("cog")?; | ||
|
||
command.arg("init"); | ||
|
||
std::env::set_current_dir(path)?; | ||
|
||
command.assert().success(); | ||
|
||
Ok(()) | ||
} |