Skip to content

Commit

Permalink
sanctuary fixes
Browse files Browse the repository at this point in the history
- reset git state before running tests
- fix a bunch of nits with string/error reporting in CI
- trim null terminators from input files
  • Loading branch information
OmarTawfik committed Feb 26, 2024
1 parent 5c42e0e commit 162ad7b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions crates/solidity/testing/sanctuary/src/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl DataSet {
}

pub fn checkout_directory(&self, directory: &str) -> Result<&Vec<SourceFile>> {
Command::new("git")
.arg("reset")
.flag("--hard")
.current_dir(&self.repo_dir)
.run()?;

let relative_path = format!("contracts/{network}/{directory}", network = self.network);

Command::new("git")
Expand Down
6 changes: 5 additions & 1 deletion crates/solidity/testing/sanctuary/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::cmp;

use console::Color;
use indicatif::ProgressBar;
use infra_utils::github::GitHub;

use crate::reporting::Reporter;

Expand Down Expand Up @@ -82,7 +83,10 @@ impl Events {
self.all_directories.inc(1);

self.reporter.hide();
self.reporter.print_full_report();

GitHub::collapse_group("Statistics:", || {
self.reporter.print_full_report();
});
}

pub fn test(&self, outcome: TestOutcome) {
Expand Down
6 changes: 2 additions & 4 deletions crates/solidity/testing/sanctuary/src/reporting.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::io::Write;
use std::time::Duration;

use console::{style, Color, Term};
Expand Down Expand Up @@ -67,9 +66,8 @@ impl Reporter {

self.parent.set_draw_target(ProgressDrawTarget::hidden());

std::io::stdout()
.write_all(&buffer.contents_formatted()[..])
.unwrap();
let contents = String::from_utf8(buffer.contents_formatted()).unwrap();
println!("{contents}");
}

pub fn add_blank(&mut self) {
Expand Down
2 changes: 2 additions & 0 deletions crates/solidity/testing/sanctuary/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub fn run_test(file: &SourceFile, events: &Events) -> Result<()> {
let source = file
.path
.read_to_string()?
// Some files are null terminated, remove the null character:
.trim_end_matches('\0')
// Remove unicode character inserted by sanctuary (illegal in Solidity):
.replace("[email protected]", "[email-protected]");

Expand Down

0 comments on commit 162ad7b

Please sign in to comment.