Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr committed Nov 24, 2023
1 parent e84f7be commit a5d0672
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
11 changes: 8 additions & 3 deletions scarb/src/ops/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use tracing::{info, warn};

use crate::core::workspace::Workspace;
use crate::core::PackageId;
use crate::internal::fsx;
use crate::internal::serdex::toml_merge;

#[derive(Debug, Clone, ValueEnum)]
Expand Down Expand Up @@ -218,12 +219,16 @@ impl<'t> ParallelVisitor for PathFormatter<'t> {
return Continue;
}

let Ok(path) = fsx::canonicalize(path) else {
return Continue;
};

info!("Formatting file: {}.", path.display());

let success = match &self.opts.action {
FmtAction::Fix => format_file_in_place(self.fmt, self.opts, self.ws, path),
FmtAction::Check => check_file_formatting(self.fmt, self.opts, self.ws, path),
FmtAction::Emit(target) => emit_formatted_file(self.fmt, target, self.ws, path),
FmtAction::Fix => format_file_in_place(self.fmt, self.opts, self.ws, &path),
FmtAction::Check => check_file_formatting(self.fmt, self.opts, self.ws, &path),
FmtAction::Emit(target) => emit_formatted_file(self.fmt, target, self.ws, &path),
};

if !success {
Expand Down
56 changes: 41 additions & 15 deletions scarb/tests/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fs;
use std::path::PathBuf;

use assert_fs::prelude::*;
use assert_fs::TempDir;
Expand Down Expand Up @@ -72,9 +73,14 @@ fn simple_emit_invalid() {
.failure()
.stdout_matches(format!(
"{}:\n{}\n",
fsx::canonicalize(t.child("src/lib.cairo"))
.unwrap()
.display(),
fsx::canonicalize(
t.child("src/lib.cairo")
.path()
.components()
.collect::<PathBuf>()
)
.unwrap()
.display(),
SIMPLE_FORMATTED
));
let content = fs::read_to_string(t.child("src/lib.cairo")).unwrap();
Expand Down Expand Up @@ -340,9 +346,14 @@ fn workspace_emit_with_root() {
.failure()
.stdout_matches(format!(
"{}:\n{}\n",
fsx::canonicalize(t.child("src/lib.cairo"))
.unwrap()
.display(),
fsx::canonicalize(
t.child("src/lib.cairo")
.path()
.components()
.collect::<PathBuf>()
)
.unwrap()
.display(),
SIMPLE_FORMATTED
));

Expand All @@ -360,17 +371,32 @@ fn workspace_emit_with_root() {
.failure()
.stdout_matches(format!(
"{}:\n{}\n{}:\n{}\n{}:\n{}\n",
fsx::canonicalize(t.child("first/src/lib.cairo"))
.unwrap()
.display(),
fsx::canonicalize(
t.child("first/src/lib.cairo")
.path()
.components()
.collect::<PathBuf>()
)
.unwrap()
.display(),
SIMPLE_FORMATTED,
fsx::canonicalize(t.child("second/src/lib.cairo"))
.unwrap()
.display(),
fsx::canonicalize(
t.child("second/src/lib.cairo")
.path()
.components()
.collect::<PathBuf>()
)
.unwrap()
.display(),
SIMPLE_FORMATTED,
fsx::canonicalize(t.child("src/lib.cairo"))
.unwrap()
.display(),
fsx::canonicalize(
t.child("src/lib.cairo")
.path()
.components()
.collect::<PathBuf>()
)
.unwrap()
.display(),
SIMPLE_FORMATTED,
));

Expand Down

0 comments on commit a5d0672

Please sign in to comment.