Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[CONTRACT_PATH]: [STATUS]
24 changes: 15 additions & 9 deletions tools/compact/src/bin/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{path::PathBuf, str::FromStr, sync::Arc};
use std::{collections::HashSet, path::PathBuf, str::FromStr, sync::Arc};

use anyhow::{Context as _, Result, anyhow, bail};
use axoupdater::AxoUpdater;
Expand Down Expand Up @@ -307,17 +307,20 @@ async fn format(cfg: &CommandLineArguments, command: &FormatCommand) -> Result<(

let bin = Arc::new(bin);
let check_mode = command.check;
let mut seen = HashSet::new();

for file_path in &command.files {
let path = PathBuf::from_str(file_path).unwrap();

if path.is_dir() {
for path in formatter::compact_files_excluding_gitignore(&path) {
let bin = Arc::clone(&bin);
if seen.insert(path.clone()) {
let bin = Arc::clone(&bin);

join_set.spawn(async move { format_file(&bin, check_mode, path).await });
join_set.spawn(async move { format_file(&bin, check_mode, path).await });
}
}
} else {
} else if seen.insert(path.clone()) {
let bin = Arc::clone(&bin);

join_set.spawn(async move { format_file(&bin, check_mode, path).await });
Expand Down Expand Up @@ -416,18 +419,21 @@ async fn fixup(cfg: &CommandLineArguments, command: &FixupCommand) -> Result<()>
let check_mode = command.check;
let update_uint_ranges = command.update_uint_ranges;
let vscode = command.vscode;
let mut seen = HashSet::new();

for file_path in &command.files {
let path = PathBuf::from_str(file_path).unwrap();

if path.is_dir() {
for path in fixup::compact_files_excluding_gitignore(&path) {
let bin = Arc::clone(&bin);
join_set.spawn(async move {
fixup_file(&bin, check_mode, path, update_uint_ranges, vscode).await
});
if seen.insert(path.clone()) {
let bin = Arc::clone(&bin);
join_set.spawn(async move {
fixup_file(&bin, check_mode, path, update_uint_ranges, vscode).await
});
}
}
} else {
} else if seen.insert(path.clone()) {
let bin = Arc::clone(&bin);
join_set.spawn(async move {
fixup_file(&bin, check_mode, path, update_uint_ranges, vscode).await
Expand Down
45 changes: 42 additions & 3 deletions tools/compact/tests/test_scenarios_four.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,11 @@ fn test_sc34_update_latest_format_verbose_same_file_twice() {
"--verbose",
],
None,
Some("./output/format/std_format_verbose_two_files.txt"),
Some("./output/format/std_format_verbose_one_file.txt"),
None,
&[
("[CONTRACT_PATH]", formated_contract_as_string),
("[STATUS]", "formatted"),
("[CONTRACT_PATH_TWO]", formated_contract_as_string),
("[STATUS_TWO]", "formatted"),
],
Some(0),
);
Expand Down Expand Up @@ -552,3 +550,44 @@ fn test_sc39_update_latest_format_check_unformatted_two_files() {
output_contract_two_as_string,
);
}

#[test]
fn test_sc40_update_latest_fixup_verbose_same_file_twice() {
let temp_dir = tempfile::tempdir().unwrap();
let temp_path = temp_dir.path();

run_command(
&["--directory", &format!("{}", temp_path.display()), "update"],
None,
Some("./output/update/std_default.txt"),
None,
&[
("[LATEST_COMPACTC_VERSION]", LATEST_COMPACTC_VERSION),
("[SYSTEM_VERSION]", get_version()),
],
None,
);

copy_file_to_dir("./contract/formatter/input/example_1.compact", temp_path).unwrap();
let contract = temp_path.join("example_1.compact");
let contract_as_string = contract.to_str().unwrap();

run_command_sorted(
&[
"--directory",
&format!("{}", temp_path.display()),
"fixup",
contract_as_string,
contract_as_string,
"--verbose",
],
None,
Some("./output/fixup/std_fixup_verbose_one_file.txt"),
None,
&[
("[CONTRACT_PATH]", contract_as_string),
("[STATUS]", "unchanged"),
],
Some(0),
);
}
Loading