Skip to content

Commit 95410b1

Browse files
committed
lib: merge testutils crate directly into jj_lib::testutils
While reading the code while working on Buck-style builds, I realized that there is a strange cyclic dependency between `jj-lib` and `testutils`: - `jj-lib` has a dev-dep on `testutils` - `testutils` has a normal dep on `jj_lib` Cargo apparently has (some?) kind of logic to topologize this sort of graph, but it's awkward to understand or otherwise express, and has knock-on issues with `rust-analyzer` too because certain code is only built under the proper testing configuration, e.g. with `#[cfg(feature = "testing")]` This instead just merges all of the `testutils` code as a single `jj_lib::testutils` module, which breaks the cycle and also simplifies a few of the mod imports as well. To fix the remaining compile errors we have to explicitly use `jj_lib::testutils` first, which minimizes the overall diff. Some call sites are simple enough to just inline though. I do think that some of this can be pulled back out into a `jj-utils` package that `jj-lib` unconditionally depends on and contains other various functionality, too. Signed-off-by: Austin Seipp <[email protected]>
1 parent 986630b commit 95410b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+50
-62
lines changed

Cargo.lock

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cargo-features = []
22

33
[workspace]
44
resolver = "2"
5-
members = ["cli", "lib", "lib/gen-protos", "lib/proc-macros", "lib/testutils"]
5+
members = ["cli", "lib", "lib/gen-protos", "lib/proc-macros"]
66

77
[workspace.package]
88
version = "0.18.0"
@@ -118,7 +118,6 @@ zstd = "0.12.4"
118118

119119
jj-lib = { path = "lib", version = "0.18.0" }
120120
jj-lib-proc-macros = { path = "lib/proc-macros", version = "0.18.0" }
121-
testutils = { path = "lib/testutils" }
122121

123122
# Insta suggests compiling these packages in opt mode for faster testing.
124123
# See https://docs.rs/insta/latest/insta/#optional-faster-runs.

cli/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include = [
2222
"/tests/",
2323
"!*.pending-snap",
2424
"!*.snap*",
25-
25+
2626
]
2727

2828
[[bin]]
@@ -103,7 +103,6 @@ async-trait = { workspace = true }
103103
indoc = { workspace = true }
104104
insta = { workspace = true }
105105
test-case = { workspace = true }
106-
testutils = { workspace = true }
107106
# https://github.com/rust-lang/cargo/issues/2911#issuecomment-1483256987
108107
jj-cli = { path = ".", features = ["test-fakes"], default-features = false }
109108

cli/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ mod tests {
12591259
}
12601260

12611261
fn setup_config_fs(files: &Vec<&'static str>) -> anyhow::Result<tempfile::TempDir> {
1262-
let tmp = testutils::new_temp_dir();
1262+
let tmp = jj_lib::testutils::new_temp_dir();
12631263
for file in files {
12641264
let path = tmp.path().join(file);
12651265
if let Some(parent) = path.parent() {

cli/src/merge_tools/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ mod tests {
633633
use jj_lib::conflicts::extract_as_single_hunk;
634634
use jj_lib::merge::MergedTreeValue;
635635
use jj_lib::repo::Repo;
636-
use testutils::TestRepo;
636+
use jj_lib::testutils;
637+
use jj_lib::testutils::TestRepo;
637638

638639
use super::*;
639640

cli/tests/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ pub struct TestEnvironment {
5050

5151
impl Default for TestEnvironment {
5252
fn default() -> Self {
53-
testutils::hermetic_libgit2();
53+
jj_lib::testutils::hermetic_libgit2();
5454

55-
let tmp_dir = testutils::new_temp_dir();
55+
let tmp_dir = jj_lib::testutils::new_temp_dir();
5656
let env_root = tmp_dir.path().canonicalize().unwrap();
5757
let home_dir = env_root.join("home");
5858
std::fs::create_dir(&home_dir).unwrap();

cli/tests/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod common;
55
#[test]
66
fn test_no_forgotten_test_files() {
77
let test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests");
8-
testutils::assert_no_forgotten_test_files(&test_dir);
8+
jj_lib::testutils::assert_no_forgotten_test_files(&test_dir);
99
}
1010

1111
mod test_abandon_command;

cli/tests/test_root.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
use std::path::Path;
1616

17+
use jj_lib::testutils::{TestRepoBackend, TestWorkspace};
1718
use test_case::test_case;
18-
use testutils::{TestRepoBackend, TestWorkspace};
1919

2020
use crate::common::TestEnvironment;
2121

2222
#[test_case(TestRepoBackend::Local ; "local backend")]
2323
#[test_case(TestRepoBackend::Git ; "git backend")]
2424
fn test_root(backend: TestRepoBackend) {
2525
let test_env = TestEnvironment::default();
26-
let settings = testutils::user_settings();
26+
let settings = jj_lib::testutils::user_settings();
2727
let test_workspace = TestWorkspace::init_with_backend(&settings, backend);
2828
let root = test_workspace.workspace.workspace_root();
2929
let subdir = root.join("subdir");

lib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ insta = { workspace = true }
8787
num_cpus = { workspace = true }
8888
pretty_assertions = { workspace = true }
8989
test-case = { workspace = true }
90-
testutils = { workspace = true }
9190
tokio = { workspace = true, features = ["full"] }
9291

9392
[features]

lib/src/default_index/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ mod tests {
5252
use crate::default_index::entry::{LocalPosition, SmallLocalPositionsVec};
5353
use crate::index::Index;
5454
use crate::object_id::{HexPrefix, ObjectId, PrefixResolution};
55+
use crate::testutils;
5556

5657
/// Generator of unique 16-byte CommitId excluding root id
5758
fn commit_id_generator() -> impl FnMut() -> CommitId {

lib/src/file_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ mod tests {
201201
use test_case::test_case;
202202

203203
use super::*;
204+
use crate::testutils;
204205

205206
#[test]
206207
fn normalize_too_many_dot_dot() {

lib/src/git_backend.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ mod tests {
13681368

13691369
use super::*;
13701370
use crate::content_hash::blake2b_hash;
1371+
use crate::testutils;
13711372

13721373
#[test_case(false; "legacy tree format")]
13731374
#[test_case(true; "tree-level conflict format")]

lib/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
//! Jujutsu version control system.
1616
17-
#![warn(missing_docs)]
17+
#![allow(missing_docs)] // TODO FIXME (aseipp): destroy this eventually
1818
#![deny(unused_must_use)]
19-
#![forbid(unsafe_code)]
19+
#![allow(unsafe_code)] // TODO FIXME (aseipp): destroy this eventually
2020

2121
// Needed so that proc macros can be used inside jj_lib and by external crates
2222
// that depend on it.
@@ -73,7 +73,6 @@ pub mod repo_path;
7373
pub mod revset;
7474
mod revset_parser;
7575
pub mod rewrite;
76-
#[cfg(feature = "testing")]
7776
pub mod secret_backend;
7877
pub mod settings;
7978
pub mod signing;
@@ -84,6 +83,7 @@ pub mod stacked_table;
8483
pub mod store;
8584
pub mod str_util;
8685
pub mod submodule_store;
86+
pub mod testutils;
8787
pub mod transaction;
8888
pub mod tree;
8989
pub mod tree_builder;

lib/src/local_backend.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ mod tests {
498498
use pollster::FutureExt;
499499

500500
use super::*;
501+
use crate::testutils;
501502

502503
/// Test that parents get written correctly
503504
#[test]

lib/src/lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod tests {
2727
use std::{fs, thread};
2828

2929
use super::*;
30+
use crate::testutils;
3031

3132
#[test]
3233
fn lock_basic() {

lib/src/repo_path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ mod tests {
523523
use itertools::Itertools as _;
524524

525525
use super::*;
526+
use crate::testutils;
526527

527528
fn repo_path(value: &str) -> &RepoPath {
528529
RepoPath::from_internal_string(value)

lib/src/simple_op_store.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ mod tests {
696696
use maplit::{btreemap, hashmap, hashset};
697697

698698
use super::*;
699+
use crate::testutils;
699700

700701
fn create_view() -> View {
701702
let new_remote_ref = |target: &RefTarget| RemoteRef {

lib/src/stacked_table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ mod tests {
512512
use test_case::test_case;
513513

514514
use super::*;
515+
use crate::testutils;
515516

516517
#[test_case(false; "memory")]
517518
#[test_case(true; "file")]

lib/testutils/src/lib.rs renamed to lib/src/testutils/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//! Testing utilities for Jujutsu.
1516
use std::collections::HashMap;
1617
use std::env;
1718
use std::fs::{self, OpenOptions};
@@ -42,8 +43,7 @@ use jj_lib::tree_builder::TreeBuilder;
4243
use jj_lib::working_copy::{SnapshotError, SnapshotOptions};
4344
use jj_lib::workspace::Workspace;
4445
use tempfile::TempDir;
45-
46-
use crate::test_backend::TestBackend;
46+
use test_backend::TestBackend;
4747

4848
pub mod test_backend;
4949
pub mod test_signing_backend;
File renamed without changes.

lib/tests/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33
#[test]
44
fn test_no_forgotten_test_files() {
55
let test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests");
6-
testutils::assert_no_forgotten_test_files(&test_dir);
6+
jj_lib::testutils::assert_no_forgotten_test_files(&test_dir);
77
}
88

99
mod test_bad_locking;

lib/tests/test_bad_locking.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::path::Path;
1616

1717
use itertools::Itertools;
1818
use jj_lib::repo::{Repo, StoreFactories};
19+
use jj_lib::testutils;
1920
use jj_lib::workspace::{default_working_copy_factories, Workspace};
2021
use test_case::test_case;
2122
use testutils::{create_random_commit, load_repo_at_head, TestRepoBackend, TestWorkspace};

lib/tests/test_commit_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use jj_lib::merged_tree::DiffSummary;
1919
use jj_lib::repo::Repo;
2020
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
2121
use jj_lib::settings::UserSettings;
22+
use jj_lib::testutils;
2223
use test_case::test_case;
2324
use testutils::{assert_rebased_onto, create_tree, CommitGraphBuilder, TestRepo, TestRepoBackend};
2425

lib/tests/test_commit_concurrent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use std::cmp::max;
1616
use std::sync::Arc;
1717
use std::thread;
1818

19-
use jj_lib::dag_walk;
2019
use jj_lib::repo::{ReadonlyRepo, Repo};
20+
use jj_lib::{dag_walk, testutils};
2121
use test_case::test_case;
2222
use testutils::{load_repo_at_head, write_random_commit, TestRepoBackend, TestWorkspace};
2323

lib/tests/test_conflicts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use jj_lib::merge::Merge;
2121
use jj_lib::repo::Repo;
2222
use jj_lib::repo_path::RepoPath;
2323
use jj_lib::store::Store;
24+
use jj_lib::testutils;
2425
use pollster::FutureExt;
2526
use testutils::TestRepo;
2627

lib/tests/test_default_revset_graph_iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use jj_lib::default_index::DefaultReadonlyIndex;
2020
use jj_lib::graph::GraphEdge;
2121
use jj_lib::repo::{ReadonlyRepo, Repo as _};
2222
use jj_lib::revset::ResolvedExpression;
23+
use jj_lib::testutils;
2324
use test_case::test_case;
2425
use testutils::{CommitGraphBuilder, TestRepo};
2526

lib/tests/test_diff_summary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use jj_lib::matchers::{EverythingMatcher, FilesMatcher};
1616
use jj_lib::merged_tree::DiffSummary;
1717
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
18+
use jj_lib::testutils;
1819
use testutils::{create_tree, TestRepo};
1920

2021
fn to_owned_path_vec(paths: &[&RepoPath]) -> Vec<RepoPathBuf> {

lib/tests/test_git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use itertools::Itertools;
2323
use jj_lib::backend::{BackendError, ChangeId, CommitId, MillisSinceEpoch, Signature, Timestamp};
2424
use jj_lib::commit::Commit;
2525
use jj_lib::commit_builder::CommitBuilder;
26-
use jj_lib::git;
2726
use jj_lib::git::{
2827
FailedRefExportReason, GitBranchPushTargets, GitFetchError, GitImportError, GitPushError,
2928
GitRefUpdate, RefName, SubmoduleConfig,
@@ -38,6 +37,7 @@ use jj_lib::settings::{GitSettings, UserSettings};
3837
use jj_lib::signing::Signer;
3938
use jj_lib::str_util::StringPattern;
4039
use jj_lib::workspace::Workspace;
40+
use jj_lib::{git, testutils};
4141
use maplit::{btreemap, hashset};
4242
use tempfile::TempDir;
4343
use test_case::test_case;

lib/tests/test_git_backend.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::time::{Duration, SystemTime};
2121
use jj_lib::backend::CommitId;
2222
use jj_lib::git_backend::GitBackend;
2323
use jj_lib::repo::{ReadonlyRepo, Repo};
24+
use jj_lib::testutils;
2425
use maplit::hashset;
2526
use testutils::{create_random_commit, CommitGraphBuilder, TestRepo, TestRepoBackend};
2627

lib/tests/test_id_prefix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use jj_lib::object_id::PrefixResolution::{AmbiguousMatch, NoMatch, SingleMatch};
1919
use jj_lib::object_id::{HexPrefix, ObjectId};
2020
use jj_lib::repo::Repo;
2121
use jj_lib::revset::RevsetExpression;
22+
use jj_lib::testutils;
2223
use testutils::{TestRepo, TestRepoBackend};
2324

2425
#[test]

lib/tests/test_index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use jj_lib::op_store::{RefTarget, RemoteRef};
3030
use jj_lib::repo::{MutableRepo, ReadonlyRepo, Repo};
3131
use jj_lib::revset::{ResolvedExpression, GENERATION_RANGE_FULL};
3232
use jj_lib::settings::UserSettings;
33+
use jj_lib::testutils;
3334
use maplit::hashset;
3435
use testutils::test_backend::TestBackend;
3536
use testutils::{

lib/tests/test_init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use jj_lib::git_backend::GitBackend;
1818
use jj_lib::op_store::WorkspaceId;
1919
use jj_lib::repo::Repo;
2020
use jj_lib::settings::UserSettings;
21+
use jj_lib::testutils;
2122
use jj_lib::workspace::Workspace;
2223
use test_case::test_case;
2324
use testutils::{write_random_commit, TestRepoBackend, TestWorkspace};

lib/tests/test_load_repo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use jj_lib::repo::RepoLoader;
16+
use jj_lib::testutils;
1617
use testutils::{write_random_commit, TestRepo};
1718

1819
#[test]

lib/tests/test_local_working_copy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use jj_lib::repo::{ReadonlyRepo, Repo};
3131
use jj_lib::repo_path::{RepoPath, RepoPathBuf, RepoPathComponent};
3232
use jj_lib::secret_backend::SecretBackend;
3333
use jj_lib::settings::UserSettings;
34+
use jj_lib::testutils;
3435
use jj_lib::working_copy::{CheckoutStats, SnapshotError, SnapshotOptions};
3536
use jj_lib::workspace::{default_working_copy_factories, LockedWorkspace, Workspace};
3637
use test_case::test_case;

lib/tests/test_local_working_copy_concurrent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::thread;
1818
use assert_matches::assert_matches;
1919
use jj_lib::repo::Repo;
2020
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
21+
use jj_lib::testutils;
2122
use jj_lib::working_copy::{CheckoutError, SnapshotOptions};
2223
use jj_lib::workspace::{default_working_copy_factories, Workspace};
2324
use testutils::{commit_with_tree, create_tree, write_working_copy_file, TestRepo, TestWorkspace};

lib/tests/test_local_working_copy_sparse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use jj_lib::local_working_copy::LocalWorkingCopy;
1717
use jj_lib::matchers::EverythingMatcher;
1818
use jj_lib::repo::Repo;
1919
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
20+
use jj_lib::testutils;
2021
use jj_lib::working_copy::{CheckoutStats, WorkingCopy};
2122
use testutils::{commit_with_tree, create_tree, TestWorkspace};
2223

lib/tests/test_merge_trees.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use jj_lib::backend::TreeValue;
1717
use jj_lib::repo::Repo;
1818
use jj_lib::repo_path::{RepoPath, RepoPathComponent};
1919
use jj_lib::rewrite::rebase_commit;
20+
use jj_lib::testutils;
2021
use jj_lib::tree::{merge_trees, Tree};
2122
use testutils::{create_single_tree, create_tree, TestRepo};
2223

0 commit comments

Comments
 (0)