Skip to content

Commit

Permalink
tests: split cli/tests to separate crate, remove test-fakes feature (…
Browse files Browse the repository at this point in the history
…PoC)

The goal is to remove the crate-cycle: `jj-cli --(dev)--> jj-cli`. Since there's
no way to express binary dependency in Cargo.toml, all binaries which the tests
depend on should have to be built within the same crate.

I put Cargo.toml in cli/tests so the directory structure looks familiar.

One big caveat: since we build a separate "jj" binary for tests, the production
"jj" binary is no longer covered by these tests. We might want to leave a couple
of tests in jj-cli to ensure that the real "jj" binary works.
  • Loading branch information
yuja committed Oct 11, 2024
1 parent c656878 commit 7e5f12e
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 32 deletions.
24 changes: 21 additions & 3 deletions Cargo.lock

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

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ 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/testutils",
]

[workspace.package]
version = "0.22.0"
Expand Down Expand Up @@ -129,6 +136,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.22.0" }
jj-lib = { path = "lib", version = "0.22.0" }
jj-lib-proc-macros = { path = "lib/proc-macros", version = "0.22.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 @@ -18,8 +18,6 @@ include = [
"/build.rs",
"/examples/",
"/src/",
"/testing/",
"/tests/",
"!*.pending-snap",
"!*.snap*",
"/tests/[email protected]"
Expand All @@ -29,24 +27,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 @@ -96,20 +76,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-editor"
path = "../testing/fake-editor.rs"

[[bin]]
name = "fake-diff-editor"
path = "../testing/fake-diff-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

0 comments on commit 7e5f12e

Please sign in to comment.