ok/jj
1
0
Fork 0
forked from mirrors/jj

tests: move testutils from src/ to tests/

This commit is contained in:
Martin von Zweigbergk 2022-03-30 10:47:11 -07:00 committed by Martin von Zweigbergk
parent 47bdffed34
commit 710d51c45b
13 changed files with 33 additions and 32 deletions

View file

@ -24,6 +24,3 @@ pub mod graphlog;
pub mod template_parser; pub mod template_parser;
pub mod templater; pub mod templater;
pub mod ui; pub mod ui;
// TODO: make this a separate crate?
pub mod testutils;

View file

@ -15,8 +15,6 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use itertools::Itertools;
use regex::Regex;
use tempfile::TempDir; use tempfile::TempDir;
pub struct TestEnvironment { pub struct TestEnvironment {
@ -86,19 +84,3 @@ impl TestEnvironment {
pub fn get_stdout_string(assert: &assert_cmd::assert::Assert) -> String { pub fn get_stdout_string(assert: &assert_cmd::assert::Assert) -> String {
String::from_utf8(assert.get_output().stdout.clone()).unwrap() 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<String>) {
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)
}

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use jujutsu::testutils::TestEnvironment; use crate::common::TestEnvironment;
pub mod common;
#[test] #[test]
fn smoke_test() { fn smoke_test() {

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use jujutsu::testutils::TestEnvironment; use crate::common::TestEnvironment;
pub mod common;
#[test] #[test]
fn test_concurrent_operation_divergence() { fn test_concurrent_operation_divergence() {

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use jujutsu::testutils::TestEnvironment; use crate::common::TestEnvironment;
pub mod common;
#[test] #[test]
fn test_git_colocated() { fn test_git_colocated() {

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use jujutsu::testutils::{get_stdout_string, TestEnvironment}; use crate::common::{get_stdout_string, TestEnvironment};
pub mod common;
#[test] #[test]
fn test_git_push() { fn test_git_push() {

View file

@ -14,7 +14,9 @@
use std::io::Write; use std::io::Write;
use jujutsu::testutils::TestEnvironment; use crate::common::TestEnvironment;
pub mod common;
#[test] #[test]
fn test_gitignores() { fn test_gitignores() {

View file

@ -14,7 +14,9 @@
use std::io::Write; use std::io::Write;
use jujutsu::testutils::{get_stdout_string, TestEnvironment}; use crate::common::{get_stdout_string, TestEnvironment};
pub mod common;
#[test] #[test]
fn test_no_commit_working_copy() { fn test_no_commit_working_copy() {

View file

@ -14,7 +14,9 @@
use std::path::PathBuf; use std::path::PathBuf;
use jujutsu::testutils::TestEnvironment; use crate::common::TestEnvironment;
pub mod common;
fn init_git_repo(git_repo_path: &PathBuf) { fn init_git_repo(git_repo_path: &PathBuf) {
let git_repo = git2::Repository::init(&git_repo_path).unwrap(); let git_repo = git2::Repository::init(&git_repo_path).unwrap();

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use jujutsu::testutils::TestEnvironment; use common::TestEnvironment;
pub mod common;
#[test] #[test]
fn test_log_with_or_without_diff() { fn test_log_with_or_without_diff() {

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use jujutsu::testutils::{get_stdout_string, TestEnvironment}; use crate::common::{get_stdout_string, TestEnvironment};
pub mod common;
#[test] #[test]
fn test_new_with_message() { fn test_new_with_message() {

View file

@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use jujutsu::testutils::TestEnvironment; use crate::common::TestEnvironment;
pub mod common;
#[test] #[test]
fn test_undo_rewrite_with_child() { fn test_undo_rewrite_with_child() {

View file

@ -14,7 +14,9 @@
use std::path::PathBuf; use std::path::PathBuf;
use jujutsu::testutils::{get_stdout_string, TestEnvironment}; use crate::common::{get_stdout_string, TestEnvironment};
pub mod common;
#[test] #[test]
fn test_untrack() { fn test_untrack() {