Skip to content

Commit b10c81f

Browse files
committed
cargo fmt
1 parent 833af9b commit b10c81f

File tree

8 files changed

+64
-8
lines changed

8 files changed

+64
-8
lines changed

rust/src/changefile/changed_packages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use anyhow::Result;
22
use std::collections::HashSet;
33
use std::path::Path;
44

5-
use crate::log_info;
65
use crate::git::commands;
76
use crate::git::ensure_shared_history::ensure_shared_history;
7+
use crate::log_info;
88
use crate::monorepo::filter_ignored::filter_ignored_files;
99
use crate::types::change_info::{ChangeFileInfo, ChangeInfoMultiple};
1010
use crate::types::options::BeachballOptions;

rust/src/changefile/write_change_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use anyhow::Result;
22
use std::path::Path;
33

4-
use crate::log_info;
54
use crate::git::commands;
5+
use crate::log_info;
66
use crate::types::change_info::ChangeFileInfo;
77
use crate::types::options::BeachballOptions;
88

rust/src/commands/change.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use anyhow::{Result, bail};
22

3-
use crate::log_info;
43
use crate::changefile::changed_packages::get_changed_packages;
54
use crate::changefile::write_change_files::write_change_files;
65
use crate::git::commands::get_user_email;
6+
use crate::log_info;
77
use crate::types::change_info::{ChangeFileInfo, ChangeType};
88
use crate::types::options::ParsedOptions;
99
use crate::validation::validate::{ValidateOptions, ValidationResult, validate};

rust/src/monorepo/filter_ignored.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::log_info;
21
use super::path_included::match_with_base;
2+
use crate::log_info;
33

44
/// Filter out file paths that match any of the ignore patterns.
55
/// Uses matchBase: true behavior (patterns without '/' match against basename).

rust/src/validation/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use anyhow::Result;
22

3-
use crate::{log_error, log_info, log_warn};
43
use crate::changefile::change_types::get_disallowed_change_types;
54
use crate::changefile::changed_packages::get_changed_packages;
65
use crate::changefile::read_change_files::read_change_files;
@@ -14,6 +13,7 @@ use crate::types::options::ParsedOptions;
1413
use crate::types::package_info::{PackageGroups, PackageInfos, ScopedPackages};
1514
use crate::validation::are_change_files_deleted::are_change_files_deleted;
1615
use crate::validation::validators::*;
16+
use crate::{log_error, log_info, log_warn};
1717

1818
#[derive(Default)]
1919
pub struct ValidateOptions {

rust/tests/change_test.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use beachball::types::change_info::{ChangeFileInfo, ChangeInfoMultiple, ChangeTy
66
use beachball::types::options::{BeachballOptions, CliOptions};
77
use common::change_files::get_change_files;
88
use common::repository_factory::RepositoryFactory;
9-
use common::{DEFAULT_BRANCH, DEFAULT_REMOTE_BRANCH};
9+
use common::{
10+
DEFAULT_BRANCH, DEFAULT_REMOTE_BRANCH, capture_logging, get_log_output, reset_logging,
11+
};
1012

1113
fn make_cli(message: &str, change_type: ChangeType) -> CliOptions {
1214
CliOptions {
@@ -31,10 +33,15 @@ fn does_not_create_change_files_when_no_changes() {
3133
let repo = factory.clone_repository();
3234
repo.checkout(&["-b", "no-changes-test", DEFAULT_BRANCH]);
3335

36+
capture_logging();
3437
let cli = make_cli("test change", ChangeType::Patch);
3538
let parsed = get_parsed_options_for_test(repo.root_path(), cli, make_repo_opts());
3639
assert!(change(&parsed).is_ok());
40+
let output = get_log_output();
41+
reset_logging();
42+
3743
assert!(get_change_files(&parsed.options).is_empty());
44+
assert!(output.contains("No change files are needed"));
3845
}
3946

4047
#[test]
@@ -83,8 +90,11 @@ fn creates_and_stages_a_change_file() {
8390
..make_cli("stage me please", ChangeType::Patch)
8491
};
8592

93+
capture_logging();
8694
let parsed = get_parsed_options_for_test(repo.root_path(), cli, repo_opts);
8795
assert!(change(&parsed).is_ok());
96+
let output = get_log_output();
97+
reset_logging();
8898

8999
// Verify file is staged (git status shows "A ")
90100
let status = repo.status();
@@ -100,6 +110,7 @@ fn creates_and_stages_a_change_file() {
100110
let change: ChangeFileInfo = serde_json::from_str(&contents).unwrap();
101111
assert_eq!(change.comment, "stage me please");
102112
assert_eq!(change.package_name, "foo");
113+
assert!(output.contains("git staged these change files:"));
103114
}
104115

105116
#[test]
@@ -109,9 +120,12 @@ fn creates_and_commits_a_change_file() {
109120
repo.checkout(&["-b", "commits-change-test", DEFAULT_BRANCH]);
110121
repo.commit_change("file.js");
111122

123+
capture_logging();
112124
let cli = make_cli("commit me please", ChangeType::Patch);
113125
let parsed = get_parsed_options_for_test(repo.root_path(), cli, make_repo_opts());
114126
assert!(change(&parsed).is_ok());
127+
let output = get_log_output();
128+
reset_logging();
115129

116130
// Verify clean git status (committed)
117131
let status = repo.status();
@@ -123,6 +137,7 @@ fn creates_and_commits_a_change_file() {
123137
let contents = std::fs::read_to_string(&files[0]).unwrap();
124138
let change: ChangeFileInfo = serde_json::from_str(&contents).unwrap();
125139
assert_eq!(change.comment, "commit me please");
140+
assert!(output.contains("git committed these change files:"));
126141
}
127142

128143
#[test]

rust/tests/changed_packages_test.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use beachball::options::get_options::get_parsed_options_for_test;
77
use beachball::types::options::{BeachballOptions, CliOptions};
88
use common::change_files::generate_change_files;
99
use common::repository_factory::RepositoryFactory;
10-
use common::{DEFAULT_BRANCH, DEFAULT_REMOTE_BRANCH};
10+
use common::{
11+
DEFAULT_BRANCH, DEFAULT_REMOTE_BRANCH, capture_logging, get_log_output, reset_logging,
12+
};
1113
use serde_json::json;
1214
use std::collections::HashMap;
1315

@@ -55,9 +57,18 @@ fn returns_package_name_when_changes_in_branch() {
5557
check_out_test_branch(&repo, "changes_in_branch");
5658
repo.commit_change("packages/foo/myFilename");
5759

58-
let (options, infos, scoped) = get_options_and_packages(&repo, None, None);
60+
let opts = BeachballOptions {
61+
verbose: true,
62+
..Default::default()
63+
};
64+
capture_logging();
65+
let (options, infos, scoped) = get_options_and_packages(&repo, Some(opts), None);
5966
let result = get_changed_packages(&options, &infos, &scoped).unwrap();
67+
let output = get_log_output();
68+
reset_logging();
69+
6070
assert_eq!(result, vec!["foo"]);
71+
assert!(output.contains("Checking for changes against"));
6172
}
6273

6374
#[test]
@@ -154,8 +165,13 @@ fn respects_ignore_patterns() {
154165
repo.write_file_content("yarn.lock", "changed");
155166
repo.git(&["add", "-A"]);
156167

168+
capture_logging();
157169
let result = get_changed_packages(&options, &infos, &scoped).unwrap();
170+
let output = get_log_output();
171+
reset_logging();
172+
158173
assert!(result.is_empty());
174+
assert!(output.contains("ignored by pattern"));
159175
}
160176

161177
// ===== Monorepo tests =====
@@ -191,8 +207,13 @@ fn excludes_packages_with_existing_change_files() {
191207
let (options, infos, scoped) = get_options_and_packages(&repo, Some(opts), None);
192208
generate_change_files(&["foo"], &options, &repo);
193209

210+
capture_logging();
194211
let result = get_changed_packages(&options, &infos, &scoped).unwrap();
212+
let output = get_log_output();
213+
reset_logging();
214+
195215
assert!(result.is_empty(), "Expected empty but got: {result:?}");
216+
assert!(output.contains("already has change files for these packages"));
196217

197218
// Change bar => bar is the only changed package returned
198219
repo.stage_change("packages/bar/test.js");
@@ -249,9 +270,15 @@ fn ignores_package_changes_as_appropriate() {
249270
..Default::default()
250271
};
251272

273+
capture_logging();
252274
let (options, infos, scoped) = get_options_and_packages(&repo, Some(opts), None);
253275
let result = get_changed_packages(&options, &infos, &scoped).unwrap();
276+
let output = get_log_output();
277+
reset_logging();
278+
254279
assert_eq!(result, vec!["publish-me"]);
280+
assert!(output.contains("is private"));
281+
assert!(output.contains("is out of scope"));
255282
}
256283

257284
#[test]

rust/tests/validate_test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use beachball::validation::validate::{ValidateOptions, ValidationError, validate
66
use common::DEFAULT_REMOTE_BRANCH;
77
use common::repository::Repository;
88
use common::repository_factory::RepositoryFactory;
9+
use common::{capture_logging, get_log_output, reset_logging};
910

1011
fn validate_wrapper(
1112
repo: &Repository,
@@ -26,16 +27,20 @@ fn succeeds_with_no_changes() {
2627
let repo = factory.clone_repository();
2728
repo.checkout(&["-b", "test"]);
2829

30+
capture_logging();
2931
let result = validate_wrapper(
3032
&repo,
3133
ValidateOptions {
3234
check_change_needed: true,
3335
..Default::default()
3436
},
3537
);
38+
let output = get_log_output();
39+
reset_logging();
3640

3741
assert!(result.is_ok());
3842
assert!(!result.unwrap().is_change_needed);
43+
assert!(output.contains("Validating options and change files..."));
3944
}
4045

4146
#[test]
@@ -45,16 +50,21 @@ fn exits_with_error_if_change_files_needed() {
4550
repo.checkout(&["-b", "test"]);
4651
repo.stage_change("packages/foo/test.js");
4752

53+
capture_logging();
4854
let result = validate_wrapper(
4955
&repo,
5056
ValidateOptions {
5157
check_change_needed: true,
5258
..Default::default()
5359
},
5460
);
61+
let output = get_log_output();
62+
reset_logging();
5563

5664
let err = result.expect_err("expected validation to fail");
5765
assert!(err.downcast_ref::<ValidationError>().is_some());
66+
assert!(output.contains("ERROR: Change files are needed!"));
67+
assert!(output.contains("Found changes in the following packages"));
5868
}
5969

6070
#[test]
@@ -64,6 +74,7 @@ fn returns_without_error_if_allow_missing_change_files() {
6474
repo.checkout(&["-b", "test"]);
6575
repo.stage_change("packages/foo/test.js");
6676

77+
capture_logging();
6778
let result = validate_wrapper(
6879
&repo,
6980
ValidateOptions {
@@ -72,7 +83,10 @@ fn returns_without_error_if_allow_missing_change_files() {
7283
..Default::default()
7384
},
7485
);
86+
let output = get_log_output();
87+
reset_logging();
7588

7689
assert!(result.is_ok());
7790
assert!(result.unwrap().is_change_needed);
91+
assert!(!output.contains("ERROR:"));
7892
}

0 commit comments

Comments
 (0)