Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more test in report/compiler.rs and Default trait for CompilerInput #19

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const SOLIDITY: &str = "Solidity";
const YUL: &str = "Yul";

/// Input type `solc` expects
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
mattsse marked this conversation as resolved.
Show resolved Hide resolved
pub struct CompilerInput {
pub language: String,
pub sources: Sources,
Expand Down
52 changes: 52 additions & 0 deletions src/report/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ fn get_file_name(path: impl Into<PathBuf>, v: &Version) -> PathBuf {
#[cfg(test)]
mod tests {
use super::*;
use semver::Version;
use std::fs;
use tempfile::tempdir;

#[test]
fn can_set_file_name() {
Expand Down Expand Up @@ -208,4 +211,53 @@ mod tests {
);
std::env::remove_var("foundry_compilers_LOG");
}

#[test]
fn fails_on_invalid_format() {
let result: Result<Target, _> = "invalid_format".parse();
assert!(result.is_err());
}

#[test]
fn fails_on_bad_name() {
let result: Result<Target, _> = "bad=in.json".parse();
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
assert!(result.is_err());
if let Err(e) = result {
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
assert_eq!(e.to_string(), "bad=in.json");
}
}
mattsse marked this conversation as resolved.
Show resolved Hide resolved

#[test]
fn check_no_write_when_no_target() {
let reporter = SolcCompilerIoReporter::default();
let version = Version::parse("0.8.10").unwrap();
let input = CompilerInput::default();
let output = CompilerOutput::default();

reporter.log_compiler_input(&input, &version);
reporter.log_compiler_output(&output, &version);
}

#[test]
fn serialize_and_write_to_file() {
let dir = tempdir().unwrap();
let input_path = dir.path().join("input.json");
let output_path = dir.path().join("output.json");
let version = Version::parse("0.8.10").unwrap();
let target = Target { dest_input: input_path.clone(), dest_output: output_path.clone() };

let input = CompilerInput::default();
let output = CompilerOutput::default();

target.write_input(&input, &version);
target.write_output(&output, &version);

let input_content = fs::read_to_string(get_file_name(&input_path, &version)).unwrap();
let output_content = fs::read_to_string(get_file_name(&output_path, &version)).unwrap();

assert!(!input_content.is_empty());
assert!(!output_content.is_empty());

dir.close().unwrap();
}
}