summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Rodarmor <casey@rodarmor.com>2024-01-18 18:48:03 -0800
committerCasey Rodarmor <casey@rodarmor.com>2024-01-18 18:48:03 -0800
commitd7722839bad0937558fca8fe0f0c15f01168c25b (patch)
tree91e64b934b5758cc2a11633409eb48e90f9bf736
parentea1bd6aa207f050b9a8d7a09d990fdb7630c83be (diff)
More teststree
-rw-r--r--src/subcommand.rs58
-rw-r--r--tests/lib.rs1
-rw-r--r--tests/tree.rs103
3 files changed, 148 insertions, 14 deletions
diff --git a/src/subcommand.rs b/src/subcommand.rs
index c90a90af..91bea0ef 100644
--- a/src/subcommand.rs
+++ b/src/subcommand.rs
@@ -83,7 +83,7 @@ impl Subcommand {
List => Self::list(config, 0, justfile),
Show { ref name } => Self::show(config, name, justfile)?,
Summary => Self::summary(config, justfile),
- Tree => Self::tree(justfile),
+ Tree => Self::tree(0, justfile),
Variables => Self::variables(justfile),
Changelog | Completions { .. } | Edit | Init | Run { .. } => unreachable!(),
}
@@ -571,27 +571,57 @@ impl Subcommand {
}
}
- fn tree(justfile: &Justfile) {
- for (i, (name, recipe)) in justfile.recipes.iter().enumerate() {
- if recipe.is_public() {
- if i == justfile.recipes.len() - 1 {
+ fn tree(depth: usize, justfile: &Justfile) {
+ let recipes = justfile
+ .recipes
+ .values()
+ .filter(|recipe| recipe.is_public())
+ .map(|recipe| recipe.as_ref())
+ .collect::<Vec<&Recipe>>();
+
+ for (i, recipe) in recipes.iter().enumerate() {
+ let last_recipe = i == recipes.len() - 1;
+
+ print!("{}", " ".repeat(depth));
+
+ if last_recipe {
+ print!("└── ");
+ } else {
+ print!("├── ");
+ }
+
+ println!("{}", recipe.name());
+
+ for (i, dependency) in recipe.dependencies.iter().enumerate() {
+ let last_dependency = i == recipe.dependencies.len() - 1;
+
+ if last_recipe {
+ print!(" ");
+ } else {
+ print!("│ ");
+ }
+
+ if last_dependency {
print!("└── ");
} else {
print!("├── ");
}
- println!("{name}");
+ println!("{}", dependency.recipe.name());
+ }
+ }
- for (i, dependency) in recipe.dependencies.iter().enumerate() {
- if i == recipe.dependencies.len() - 1 {
- print!("│ └── ");
- } else {
- print!("│ ├── ");
- }
+ for (i, (name, module)) in justfile.modules.iter().enumerate() {
+ let last_module = i == justfile.modules.len() - 1;
- println!("{}", dependency.recipe.name());
- }
+ if last_module {
+ print!("└── ");
+ } else {
+ print!("├── ");
}
+
+ println!("{name}");
+ Self::tree(depth + 1, module);
}
}
diff --git a/tests/lib.rs b/tests/lib.rs
index a9f3c344..83a8f462 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -91,6 +91,7 @@ mod string;
mod subsequents;
mod summary;
mod tempdir;
+mod tree;
mod undefined_variables;
mod unstable;
#[cfg(target_family = "windows")]
diff --git a/tests/tree.rs b/tests/tree.rs
new file mode 100644
index 00000000..0644d58a
--- /dev/null
+++ b/tests/tree.rs
@@ -0,0 +1,103 @@
+use super::*;
+
+#[test]
+fn single_recipe() {
+ Test::new()
+ .justfile("foo:")
+ .arg("--tree")
+ .stdout(
+ "
+ └── foo
+ ",
+ )
+ .run();
+}
+
+#[test]
+fn multiple_recipes() {
+ Test::new()
+ .justfile(
+ "
+ foo:
+ bar:
+ baz:
+ ",
+ )
+ .arg("--tree")
+ .stdout(
+ "
+ ├── bar
+ ├── baz
+ └── foo
+ ",
+ )
+ .run();
+}
+
+#[test]
+fn dependencies() {
+ Test::new()
+ .justfile(
+ "
+ foo: bar baz
+ bar: baz
+ baz:
+ ",
+ )
+ .arg("--tree")
+ .stdout(
+ "
+ ├── bar
+ │ └── baz
+ ├── baz
+ └── foo
+ ├── bar
+ └── baz
+ ",
+ )
+ .run();
+}
+
+#[test]
+fn submodule() {
+ Test::new()
+ .justfile(
+ "
+ mod foo
+ ",
+ )
+ .write("foo.just", "bar:")
+ .test_round_trip(false)
+ .args(["--tree", "--unstable"])
+ .stdout(
+ "
+ └── foo
+ └── bar
+ ",
+ )
+ .run();
+}
+
+#[test]
+fn multiple_submodules() {
+ Test::new()
+ .justfile(
+ "
+ mod foo
+ mod baz
+ ",
+ )
+ .write("foo.just", "bar:")
+ .write("baz.just", "qux:")
+ .test_round_trip(false)
+ .args(["--tree", "--unstable"])
+ .stdout(
+ "
+ ├── baz
+ │ └── qux
+ └── foo
+ └── bar
+ ",
+ )
+ .run();
+}