From 710d51c45b828b71d6c2a2464681e6436923a0d9 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 30 Mar 2022 10:47:11 -0700 Subject: [PATCH] tests: move `testutils` from `src/` to `tests/` --- src/lib.rs | 3 --- src/testutils.rs => tests/common/mod.rs | 18 ------------------ tests/smoke_test.rs | 4 +++- tests/test_concurrent_operations.rs | 4 +++- tests/test_git_colocated.rs | 4 +++- tests/test_git_push.rs | 4 +++- tests/test_gitignores.rs | 4 +++- tests/test_global_opts.rs | 4 +++- tests/test_init_command.rs | 4 +++- tests/test_log_command.rs | 4 +++- tests/test_new.rs | 4 +++- tests/test_undo.rs | 4 +++- tests/test_untrack_command.rs | 4 +++- 13 files changed, 33 insertions(+), 32 deletions(-) rename src/testutils.rs => tests/common/mod.rs (84%) diff --git a/src/lib.rs b/src/lib.rs index dcf670bb7..6ea65f4e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,3 @@ pub mod graphlog; pub mod template_parser; pub mod templater; pub mod ui; - -// TODO: make this a separate crate? -pub mod testutils; diff --git a/src/testutils.rs b/tests/common/mod.rs similarity index 84% rename from src/testutils.rs rename to tests/common/mod.rs index 2b992b432..c452f18ad 100644 --- a/src/testutils.rs +++ b/tests/common/mod.rs @@ -15,8 +15,6 @@ use std::cell::RefCell; use std::path::{Path, PathBuf}; -use itertools::Itertools; -use regex::Regex; use tempfile::TempDir; pub struct TestEnvironment { @@ -86,19 +84,3 @@ impl TestEnvironment { pub fn get_stdout_string(assert: &assert_cmd::assert::Assert) -> String { String::from_utf8(assert.get_output().stdout.clone()).unwrap() } - -pub fn capture_matches( - assert: assert_cmd::assert::Assert, - pattern: &str, -) -> (assert_cmd::assert::Assert, Vec) { - let stdout_string = get_stdout_string(&assert); - let assert = assert.stdout(predicates::str::is_match(pattern).unwrap()); - let matches = Regex::new(pattern) - .unwrap() - .captures(&stdout_string) - .unwrap() - .iter() - .map(|m| m.unwrap().as_str().to_owned()) - .collect_vec(); - (assert, matches) -} diff --git a/tests/smoke_test.rs b/tests/smoke_test.rs index 2987cac6f..a5da9446e 100644 --- a/tests/smoke_test.rs +++ b/tests/smoke_test.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu::testutils::TestEnvironment; +use crate::common::TestEnvironment; + +pub mod common; #[test] fn smoke_test() { diff --git a/tests/test_concurrent_operations.rs b/tests/test_concurrent_operations.rs index 01f9dbc18..18861a798 100644 --- a/tests/test_concurrent_operations.rs +++ b/tests/test_concurrent_operations.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu::testutils::TestEnvironment; +use crate::common::TestEnvironment; + +pub mod common; #[test] fn test_concurrent_operation_divergence() { diff --git a/tests/test_git_colocated.rs b/tests/test_git_colocated.rs index 191143ddd..5b5c23a57 100644 --- a/tests/test_git_colocated.rs +++ b/tests/test_git_colocated.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu::testutils::TestEnvironment; +use crate::common::TestEnvironment; + +pub mod common; #[test] fn test_git_colocated() { diff --git a/tests/test_git_push.rs b/tests/test_git_push.rs index e6cd4024b..7d4a7307a 100644 --- a/tests/test_git_push.rs +++ b/tests/test_git_push.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu::testutils::{get_stdout_string, TestEnvironment}; +use crate::common::{get_stdout_string, TestEnvironment}; + +pub mod common; #[test] fn test_git_push() { diff --git a/tests/test_gitignores.rs b/tests/test_gitignores.rs index 67c28c724..9fc2da171 100644 --- a/tests/test_gitignores.rs +++ b/tests/test_gitignores.rs @@ -14,7 +14,9 @@ use std::io::Write; -use jujutsu::testutils::TestEnvironment; +use crate::common::TestEnvironment; + +pub mod common; #[test] fn test_gitignores() { diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index 676cf528a..628126902 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -14,7 +14,9 @@ use std::io::Write; -use jujutsu::testutils::{get_stdout_string, TestEnvironment}; +use crate::common::{get_stdout_string, TestEnvironment}; + +pub mod common; #[test] fn test_no_commit_working_copy() { diff --git a/tests/test_init_command.rs b/tests/test_init_command.rs index 9a2eee021..69defa1fd 100644 --- a/tests/test_init_command.rs +++ b/tests/test_init_command.rs @@ -14,7 +14,9 @@ use std::path::PathBuf; -use jujutsu::testutils::TestEnvironment; +use crate::common::TestEnvironment; + +pub mod common; fn init_git_repo(git_repo_path: &PathBuf) { let git_repo = git2::Repository::init(&git_repo_path).unwrap(); diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index 37139cef6..12717f7f1 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu::testutils::TestEnvironment; +use common::TestEnvironment; + +pub mod common; #[test] fn test_log_with_or_without_diff() { diff --git a/tests/test_new.rs b/tests/test_new.rs index 2f2ca9434..348e6ec63 100644 --- a/tests/test_new.rs +++ b/tests/test_new.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu::testutils::{get_stdout_string, TestEnvironment}; +use crate::common::{get_stdout_string, TestEnvironment}; + +pub mod common; #[test] fn test_new_with_message() { diff --git a/tests/test_undo.rs b/tests/test_undo.rs index ebbca166b..e76a051e3 100644 --- a/tests/test_undo.rs +++ b/tests/test_undo.rs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use jujutsu::testutils::TestEnvironment; +use crate::common::TestEnvironment; + +pub mod common; #[test] fn test_undo_rewrite_with_child() { diff --git a/tests/test_untrack_command.rs b/tests/test_untrack_command.rs index 4b40f7017..f0b08fbcb 100644 --- a/tests/test_untrack_command.rs +++ b/tests/test_untrack_command.rs @@ -14,7 +14,9 @@ use std::path::PathBuf; -use jujutsu::testutils::{get_stdout_string, TestEnvironment}; +use crate::common::{get_stdout_string, TestEnvironment}; + +pub mod common; #[test] fn test_untrack() {