Skip to content

Commit

Permalink
tests: apply clippy fixes
Browse files Browse the repository at this point in the history
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Jul 4, 2023
1 parent 8e6f19d commit 0ffdc58
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 45 deletions.
4 changes: 2 additions & 2 deletions tests/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ fn trees() -> Result<()> {
fn gardens() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
test_gardens(&config)
test_gardens(config)
}

#[test]
Expand Down Expand Up @@ -431,7 +431,7 @@ fn gardens_json() -> Result<()> {
);
let app_context = common::garden_context_from_string(&string)?;
let config = app_context.get_root_config();
test_gardens(&config)
test_gardens(config)
}

fn test_gardens(config: &garden::model::Configuration) -> Result<()> {
Expand Down
47 changes: 23 additions & 24 deletions tests/eval_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn tree_variable() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
let tree_name = garden::model::TreeName::from("git");
let result = garden::eval::tree_value(&app_context, &config, "${prefix}", &tree_name, None);
let result = garden::eval::tree_value(&app_context, config, "${prefix}", &tree_name, None);
assert_eq!(result, "/home/test/.local");

Ok(())
Expand All @@ -36,10 +36,10 @@ fn config_variable() -> Result<()> {
let config = app_context.get_root_config();
let tree_name = garden::model::TreeName::from("git");

let test = garden::eval::tree_value(&app_context, &config, "${test}", &tree_name, None);
let test = garden::eval::tree_value(&app_context, config, "${test}", &tree_name, None);
assert_eq!("TEST", test);

let local = garden::eval::tree_value(&app_context, &config, "${local}", &tree_name, None);
let local = garden::eval::tree_value(&app_context, config, "${local}", &tree_name, None);
assert_eq!("TEST/local", local);

Ok(())
Expand All @@ -52,7 +52,7 @@ fn tree_name() -> Result<()> {
let config = app_context.get_root_config();
let tree_name = garden::model::TreeName::from("git");
let expect = "git";
let actual = garden::eval::tree_value(&app_context, &config, "${TREE_NAME}", &tree_name, None);
let actual = garden::eval::tree_value(&app_context, config, "${TREE_NAME}", &tree_name, None);
assert_eq!(expect, actual);

Ok(())
Expand All @@ -65,7 +65,7 @@ fn tree_path() -> Result<()> {
let config = app_context.get_root_config();
let tree_name = garden::model::TreeName::from("git");
let expect = "/home/test/src/git";
let actual = garden::eval::tree_value(&app_context, &config, "${TREE_PATH}", &tree_name, None);
let actual = garden::eval::tree_value(&app_context, config, "${TREE_PATH}", &tree_name, None);
assert_eq!(expect, actual);

Ok(())
Expand All @@ -77,7 +77,7 @@ fn garden_path() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
let expect = "/home/test/src";
let actual = garden::eval::value(&app_context, &config, "${GARDEN_ROOT}");
let actual = garden::eval::value(&app_context, config, "${GARDEN_ROOT}");
assert_eq!(expect, actual);

Ok(())
Expand All @@ -89,7 +89,7 @@ fn exec_expression() -> Result<()> {
let config = app_context.get_root_config();

// Simple exec expression
let value = garden::eval::value(&app_context, &config, "$ echo test");
let value = garden::eval::value(&app_context, config, "$ echo test");
assert_eq!(value, "test");

// Exec expression found through variable indirection:
Expand All @@ -98,15 +98,15 @@ fn exec_expression() -> Result<()> {
// Evaluation of ${echo_cmd_exec} produces "$ ${echo_cmd}"
// which is further evaluated to "$ echo cmd" before getting
// run through a shell to produce the final result.
let value = garden::eval::value(&app_context, &config, "${echo_cmd_exec}");
let value = garden::eval::value(&app_context, config, "${echo_cmd_exec}");
assert_eq!(value, "cmd");

// Ensure that exec expressions are evaluated in the tree directory.
let context = garden::query::tree_context(&app_context, &config, "tmp", None)?;
let value = garden::eval::tree_value(&app_context, &config, "$ echo $PWD", &context.tree, None);
let context = garden::query::tree_context(&app_context, config, "tmp", None)?;
let value = garden::eval::tree_value(&app_context, config, "$ echo $PWD", &context.tree, None);
assert!(value == "/tmp" || value == "/private/tmp");

let value = garden::eval::tree_value(&app_context, &config, "$ pwd", &context.tree, None);
let value = garden::eval::tree_value(&app_context, config, "$ pwd", &context.tree, None);
assert!(value == "/tmp" || value == "/private/tmp");

Ok(())
Expand All @@ -117,8 +117,8 @@ fn exec_expression_in_tree_context() -> Result<()> {
let app_context =
garden::model::ApplicationContext::from_path_string("tests/data/garden.yaml")?;
let config = app_context.get_root_config();
let context = garden::query::tree_context(&app_context, &config, "trees/prebuilt", None)?;
let value = garden::eval::tree_value(&app_context, &config, "$ pwd", &context.tree, None);
let context = garden::query::tree_context(&app_context, config, "trees/prebuilt", None)?;
let value = garden::eval::tree_value(&app_context, config, "$ pwd", &context.tree, None);
assert!(value.ends_with("/trees/prebuilt"));

Ok(())
Expand All @@ -131,11 +131,11 @@ fn shell_variable_syntax() -> Result<()> {
let config = app_context.get_root_config();

// Simple exec expression
let value = garden::eval::value(&app_context, &config, "$ value=$(echo test); echo $value");
let value = garden::eval::value(&app_context, config, "$ value=$(echo test); echo $value");
assert_eq!(value, "test");

// Escaped ${braced} value
let value = garden::eval::value(&app_context, &config, "$ echo '$${value[@]:0:1}'");
let value = garden::eval::value(&app_context, config, "$ echo '$${value[@]:0:1}'");
assert_eq!(value, "${value[@]:0:1}");

Ok(())
Expand All @@ -152,7 +152,7 @@ fn multi_variable_with_tree() -> Result<()> {
assert_eq!("PATH", var.get_name());

let context = garden::model::TreeContext::new("cola", None, None, None);
let values = garden::eval::multi_variable(&app_context, &config, &mut var, &context);
let values = garden::eval::multi_variable(&app_context, config, &mut var, &context);
assert_eq!(
values,
[
Expand All @@ -175,7 +175,7 @@ fn multi_variable_with_garden() -> Result<()> {
assert_eq!("PATH", var.get_name());

let context = garden::model::TreeContext::new("cola", None, Some(string!("cola")), None);
let values = garden::eval::multi_variable(&app_context, &config, &mut var, &context);
let values = garden::eval::multi_variable(&app_context, config, &mut var, &context);
assert_eq!(
values,
[
Expand All @@ -193,7 +193,7 @@ fn garden_environment() -> Result<()> {
let config = app_context.get_root_config();
// cola tree(1) and cola garden(Some(0))
let context = garden::model::TreeContext::new("cola", None, Some(string!("cola")), None);
let values = garden::eval::environment(&app_context, &config, &context);
let values = garden::eval::environment(&app_context, config, &context);
assert_eq!(values.len(), 9);

let mut idx = 0;
Expand Down Expand Up @@ -269,7 +269,7 @@ fn group_environment() -> Result<()> {
let config = app_context.get_root_config();
// cola tree(1) + cola group(Some(0))
let context = garden::model::TreeContext::new("cola", None, None, Some(string!("cola")));
let values = garden::eval::environment(&app_context, &config, &context);
let values = garden::eval::environment(&app_context, config, &context);
assert_eq!(values.len(), 7);

let mut idx = 0;
Expand Down Expand Up @@ -332,8 +332,8 @@ fn group_environment() -> Result<()> {
fn environment_empty_value() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
let context = garden::query::tree_from_name(&config, "tmp", None, None).unwrap();
let values = garden::eval::environment(&app_context, &config, &context);
let context = garden::query::tree_from_name(config, "tmp", None, None).unwrap();
let values = garden::eval::environment(&app_context, config, &context);
assert_eq!(values.len(), 5);

let mut idx = 0;
Expand Down Expand Up @@ -416,11 +416,10 @@ fn environment_variables() -> Result<()> {
// Environment variables in tree scope
std::env::set_var("GARDEN_TEST_VALUE", "test");

let value = garden::eval::value(&app_context, &config, "${GARDEN_TEST_VALUE}");
let value = garden::eval::value(&app_context, config, "${GARDEN_TEST_VALUE}");
assert_eq!(value, "test");

let value =
garden::eval::tree_value(&app_context, &config, "${GARDEN_TEST_VALUE}", "git", None);
let value = garden::eval::tree_value(&app_context, config, "${GARDEN_TEST_VALUE}", "git", None);
assert_eq!(value, "test");

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions tests/plant_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn plant_empty_repo() -> Result<()> {
common::exec_garden(&["--chdir", &fixture.root(), "plant", "repo1", "repo2"])?;

// Load the configuration and assert that the remotes are configured.
let app_context = garden::model::ApplicationContext::from_path(pathbuf.clone())?;
let app_context = garden::model::ApplicationContext::from_path(pathbuf)?;
let cfg = app_context.get_root_config();
assert_eq!(2, cfg.trees.len());
assert_eq!("repo1", cfg.trees[0].get_name());
Expand Down Expand Up @@ -128,7 +128,7 @@ fn plant_bare_repo() -> Result<()> {

// Load the configuration and assert that the remotes are configured.
let pathbuf = fixture.pathbuf("garden.yaml");
let app_context = garden::model::ApplicationContext::from_path(pathbuf.clone())?;
let app_context = garden::model::ApplicationContext::from_path(pathbuf)?;
let cfg = app_context.get_root_config();
assert_eq!(1, cfg.trees.len());
assert_eq!("repos/example.git", cfg.trees[0].get_name());
Expand Down
4 changes: 2 additions & 2 deletions tests/query_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ fn tree_name_from_pathbuf() -> Result<()> {
)?;
let cfg = app_context.get_root_config();

let tree_name = garden::query::tree_name_from_path(&cfg, &fixture.worktree_pathbuf("dev"));
let tree_name = garden::query::tree_name_from_path(cfg, &fixture.worktree_pathbuf("dev"));
assert_eq!(tree_name, Some(string!("dev")));

let tree_name = garden::query::tree_name_from_path(&cfg, &fixture.worktree_pathbuf("default"));
let tree_name = garden::query::tree_name_from_path(cfg, &fixture.worktree_pathbuf("default"));
assert_eq!(tree_name, Some(string!("default")));

Ok(())
Expand Down
29 changes: 14 additions & 15 deletions tests/query_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use garden::string;
fn resolve_trees_default_query_finds_garden() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
let result = garden::query::resolve_trees(&app_context, &config, "cola");
let result = garden::query::resolve_trees(&app_context, config, "cola");
assert_eq!(3, result.len());
assert_eq!(Some(string!("cola")), result[0].garden);
assert_eq!("git", result[0].tree);
Expand All @@ -28,7 +28,7 @@ fn resolve_trees_default_query_finds_garden() -> Result<()> {
fn resolve_trees_tree_query_wildcard() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
let result = garden::query::resolve_trees(&app_context, &config, "@c*");
let result = garden::query::resolve_trees(&app_context, config, "@c*");
assert_eq!(1, result.len());
assert_eq!(None, result[0].garden);
assert_eq!(None, result[0].group);
Expand All @@ -41,7 +41,7 @@ fn resolve_trees_tree_query_wildcard() -> Result<()> {
fn resolve_trees_group_query() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
let result = garden::query::resolve_trees(&app_context, &config, "%rev*");
let result = garden::query::resolve_trees(&app_context, config, "%rev*");
assert_eq!(2, result.len());
assert_eq!(None, result[0].garden);
assert_eq!(Some(string!("reverse")), result[0].group);
Expand All @@ -58,7 +58,7 @@ fn resolve_trees_group_with_wildcards() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
// annex group
let result = garden::query::resolve_trees(&app_context, &config, "%annex");
let result = garden::query::resolve_trees(&app_context, config, "%annex");
assert_eq!(2, result.len());
// annex/data
assert_eq!(None, result[0].garden);
Expand All @@ -76,7 +76,7 @@ fn resolve_trees_group_with_wildcards() -> Result<()> {
fn trees_from_pattern() -> Result<()> {
let app_context = common::garden_context()?;
let config = app_context.get_root_config();
let result = garden::query::trees_from_pattern(&app_context, &config, "annex/*", None, None);
let result = garden::query::trees_from_pattern(&app_context, config, "annex/*", None, None);
assert_eq!(2, result.len());
assert_eq!(None, result[0].garden);
assert_eq!(None, result[0].group);
Expand All @@ -97,7 +97,7 @@ fn trees_from_group() -> Result<()> {
let annex_grp = config.groups.get("annex").context("Missing annex group")?;
assert_eq!("annex", annex_grp.get_name());

let result = garden::query::trees_from_group(&app_context, &config, None, annex_grp);
let result = garden::query::trees_from_group(&app_context, config, None, annex_grp);
assert_eq!(2, result.len());
assert_eq!(None, result[0].garden);
assert_eq!(Some(string!("annex")), result[0].group);
Expand All @@ -117,7 +117,7 @@ fn trees_from_garden() -> Result<()> {

// regular group, group uses wildcards
let annex_group = config.gardens.get("annex/group").context("annex/group")?;
let mut result = garden::query::trees_from_garden(&app_context, &config, annex_group);
let mut result = garden::query::trees_from_garden(&app_context, config, annex_group);
assert_eq!(2, result.len());

// annex/group
Expand All @@ -134,7 +134,7 @@ fn trees_from_garden() -> Result<()> {
.gardens
.get("annex/wildcard-groups")
.context("annex/wildcard-groups")?;
result = garden::query::trees_from_garden(&app_context, &config, annex_wild_groups);
result = garden::query::trees_from_garden(&app_context, config, annex_wild_groups);
assert_eq!(2, result.len());

// annex/Wildcard-groups
Expand All @@ -151,7 +151,7 @@ fn trees_from_garden() -> Result<()> {
.gardens
.get("annex/wildcard-trees")
.context("annex/wildcard-trees")?;
result = garden::query::trees_from_garden(&app_context, &config, annex_wild_trees);
result = garden::query::trees_from_garden(&app_context, config, annex_wild_trees);
assert_eq!(2, result.len());

assert_eq!(Some(string!("annex/wildcard-trees")), result[0].garden);
Expand All @@ -172,32 +172,31 @@ fn tree_query() -> Result<()> {

// Success: "cola" is in the "git" garden.
let tree_context_result =
garden::query::tree_context(&app_context, &config, "cola", Some("git"));
garden::query::tree_context(&app_context, config, "cola", Some("git"));
assert!(tree_context_result.is_ok());
let tree_context = tree_context_result.unwrap();
assert_eq!("cola", tree_context.tree);
assert_eq!(Some(string!("git")), tree_context.garden);

// Success: "cola" alone has a tree context with a None garden.
let tree_context_result = garden::query::tree_context(&app_context, &config, "cola", None);
let tree_context_result = garden::query::tree_context(&app_context, config, "cola", None);
assert!(tree_context_result.is_ok());
let tree_context = tree_context_result.unwrap();
assert_eq!("cola", tree_context.tree);
assert_eq!(None, tree_context.garden);

// "unknown" tarden is not a real garden.
let tree_context_result =
garden::query::tree_context(&app_context, &config, "cola", Some("unknown-garden"));
garden::query::tree_context(&app_context, config, "cola", Some("unknown-garden"));
assert!(tree_context_result.is_err());

// "tmp" is not in the "git" garden, and must raise an error.
let tree_context_result =
garden::query::tree_context(&app_context, &config, "tmp", Some("git"));
let tree_context_result = garden::query::tree_context(&app_context, config, "tmp", Some("git"));
assert!(tree_context_result.is_err());

// "unknown-tree" is not a real tree.
let tree_context_result =
garden::query::tree_context(&app_context, &config, "unknown-tree", None);
garden::query::tree_context(&app_context, config, "unknown-tree", None);
assert!(tree_context_result.is_err());

Ok(())
Expand Down

0 comments on commit 0ffdc58

Please sign in to comment.