Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: split cli/tests to separate crate, remove test-fakes feature (PoC) #4622

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ cargo-features = []

[workspace]
resolver = "2"
members = ["cli", "lib", "lib/gen-protos", "lib/proc-macros", "lib/testutils"]
members = [
"cli",
"cli/tests",
"lib",
"lib/gen-protos",
"lib/proc-macros",
"lib/tests",
"lib/testutils",
]

[workspace.package]
version = "0.23.0"
Expand Down Expand Up @@ -130,6 +138,7 @@ zstd = "0.12.4"
# put all inter-workspace libraries, i.e. those that use 'path = ...' here in
# their own (alphabetically sorted) block

jj-cli = { path = "cli", version = "0.23.0" }
jj-lib = { path = "lib", version = "0.23.0" }
jj-lib-proc-macros = { path = "lib/proc-macros", version = "0.23.0" }
testutils = { path = "lib/testutils" }
Expand Down
25 changes: 0 additions & 25 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ include = [
"/examples/",
"/src/",
"/docs/**",
"/testing/",
"/tests/",
"!*.pending-snap",
"!*.snap*",
"/tests/[email protected]"
Expand All @@ -30,24 +28,6 @@ include = [
name = "jj"
path = "src/main.rs"

[[bin]]
name = "fake-editor"
path = "testing/fake-editor.rs"
required-features = ["test-fakes"]

[[bin]]
name = "fake-diff-editor"
path = "testing/fake-diff-editor.rs"
required-features = ["test-fakes"]

[[bin]]
name = "fake-formatter"
path = "testing/fake-formatter.rs"
required-features = ["test-fakes"]

[[test]]
name = "runner"

[dependencies]
bstr = { workspace = true }
chrono = { workspace = true }
Expand Down Expand Up @@ -97,20 +77,15 @@ libc = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
assert_cmd = { workspace = true }
assert_matches = { workspace = true }
async-trait = { workspace = true }
insta = { workspace = true }
test-case = { workspace = true }
testutils = { workspace = true }
# https://github.com/rust-lang/cargo/issues/2911#issuecomment-1483256987
jj-cli = { path = ".", features = ["test-fakes"], default-features = false }

[features]
default = ["watchman"]
bench = ["dep:criterion"]
packaging = []
test-fakes = ["jj-lib/testing"]
vendored-openssl = ["git2/vendored-openssl", "jj-lib/vendored-openssl"]
watchman = ["jj-lib/watchman"]

Expand Down
60 changes: 60 additions & 0 deletions cli/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "jj-cli-tests"
description = "Integration tests for the jj-cli crate"
autotests = false
publish = false

version = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }

# FIXME: switch to custom main.rs and remove build.rs
build = "../build.rs"

[[bin]]
name = "jj"
path = "../src/main.rs"

# FIXME: move ../testing under .?
[[bin]]
name = "fake-diff-editor"
path = "../testing/fake-diff-editor.rs"

[[bin]]
name = "fake-editor"
path = "../testing/fake-editor.rs"

[[bin]]
name = "fake-formatter"
path = "../testing/fake-formatter.rs"

[[test]]
name = "runner"
path = "runner.rs"

[dependencies]
clap = { workspace = true }
itertools = { workspace = true }
jj-cli = { workspace = true }

[dev-dependencies]
assert_cmd = { workspace = true }
chrono = { workspace = true }
dunce = { workspace = true }
futures = { workspace = true }
git2 = { workspace = true }
indoc = { workspace = true }
insta = { workspace = true }
jj-lib = { workspace = true, features = ["testing"] }
regex = { workspace = true }
tempfile = { workspace = true }
test-case = { workspace = true }
testutils = { workspace = true }

[lints]
workspace = true
6 changes: 3 additions & 3 deletions cli/tests/runner.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::path::PathBuf;
use std::path::Path;

mod common;

#[test]
fn test_no_forgotten_test_files() {
let test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests");
testutils::assert_no_forgotten_test_files(&test_dir);
let test_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
testutils::assert_no_forgotten_test_files(test_dir);
}

mod test_abandon_command;
Expand Down
7 changes: 0 additions & 7 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ include = [
"/LICENSE",
"/benches/",
"/src/",
"/tests/",
"!*.pending-snap",
"!*.snap*",
]


[[test]]
name = "runner"

[[bench]]
name = "diff_bench"
harness = false
Expand Down Expand Up @@ -88,12 +84,9 @@ winreg = { workspace = true }
assert_matches = { workspace = true }
criterion = { workspace = true }
esl01-renderdag = { workspace = true }
indoc = { workspace = true }
insta = { workspace = true }
num_cpus = { workspace = true }
pretty_assertions = { workspace = true }
test-case = { workspace = true }
testutils = { workspace = true }
tokio = { workspace = true, features = ["full"] }

[features]
Expand Down
21 changes: 11 additions & 10 deletions lib/src/default_index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod tests {
use crate::object_id::HexPrefix;
use crate::object_id::ObjectId;
use crate::object_id::PrefixResolution;
use crate::tests::new_temp_dir;

/// Generator of unique 16-byte CommitId excluding root id
fn commit_id_generator() -> impl FnMut() -> CommitId {
Expand All @@ -80,7 +81,7 @@ mod tests {
#[test_case(false; "memory")]
#[test_case(true; "file")]
fn index_empty(on_disk: bool) {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mutable_segment = MutableIndexSegment::full(3, 16);
let index_segment: Box<DynIndexSegment> = if on_disk {
let saved_index = mutable_segment.save_in(temp_dir.path()).unwrap();
Expand All @@ -107,7 +108,7 @@ mod tests {
#[test_case(false; "memory")]
#[test_case(true; "file")]
fn index_root_commit(on_disk: bool) {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_change_id = change_id_generator();
let mut mutable_segment = MutableIndexSegment::full(3, 16);
let id_0 = CommitId::from_hex("000000");
Expand Down Expand Up @@ -159,7 +160,7 @@ mod tests {
#[test_case(true, false; "incremental in memory")]
#[test_case(true, true; "incremental on disk")]
fn index_multiple_commits(incremental: bool, on_disk: bool) {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_change_id = change_id_generator();
let mut mutable_segment = MutableIndexSegment::full(3, 16);
// 5
Expand Down Expand Up @@ -280,7 +281,7 @@ mod tests {
#[test_case(false; "in memory")]
#[test_case(true; "on disk")]
fn index_many_parents(on_disk: bool) {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_change_id = change_id_generator();
let mut mutable_segment = MutableIndexSegment::full(3, 16);
// 6
Expand Down Expand Up @@ -344,7 +345,7 @@ mod tests {

#[test]
fn resolve_commit_id_prefix() {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_change_id = change_id_generator();
let mut mutable_segment = MutableIndexSegment::full(3, 16);

Expand Down Expand Up @@ -416,7 +417,7 @@ mod tests {
#[test]
#[allow(clippy::redundant_clone)] // allow id_n.clone()
fn neighbor_commit_ids() {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_change_id = change_id_generator();
let mut mutable_segment = MutableIndexSegment::full(3, 16);

Expand Down Expand Up @@ -544,7 +545,7 @@ mod tests {

#[test]
fn shortest_unique_commit_id_prefix() {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_change_id = change_id_generator();
let mut mutable_segment = MutableIndexSegment::full(3, 16);

Expand Down Expand Up @@ -598,7 +599,7 @@ mod tests {

#[test]
fn resolve_change_id_prefix() {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_commit_id = commit_id_generator();
let local_positions_vec = |positions: &[u32]| -> SmallLocalPositionsVec {
positions.iter().copied().map(LocalPosition).collect()
Expand Down Expand Up @@ -768,7 +769,7 @@ mod tests {

#[test]
fn neighbor_change_ids() {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_commit_id = commit_id_generator();

let id_0 = ChangeId::from_hex("00000001");
Expand Down Expand Up @@ -914,7 +915,7 @@ mod tests {

#[test]
fn shortest_unique_change_id_prefix() {
let temp_dir = testutils::new_temp_dir();
let temp_dir = new_temp_dir();
let mut new_commit_id = commit_id_generator();

let id_0 = ChangeId::from_hex("00000001");
Expand Down
Loading