mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
write test output to filename specified by context
This commit is contained in:
parent
5efa131c65
commit
9a2fe61c6f
@ -153,7 +153,12 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
|
||||
/// Synthesizes the circuit for test functions with program input.
|
||||
pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(), CompilerError> {
|
||||
generate_test_constraints::<F, G>(self.program, input_pairs, &self.imported_programs)
|
||||
generate_test_constraints::<F, G>(
|
||||
self.program,
|
||||
input_pairs,
|
||||
&self.imported_programs,
|
||||
&self.output_directory,
|
||||
)
|
||||
}
|
||||
|
||||
/// Calls the internal generate_constraints method with arguments
|
||||
@ -205,6 +210,9 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compil
|
||||
|
||||
// Write results to file
|
||||
let output_file = OutputFile::new(&package_name);
|
||||
|
||||
log::info!("Writing to output registers...");
|
||||
|
||||
output_file.write(&output_directory, result.bytes()).unwrap();
|
||||
|
||||
Ok(())
|
||||
|
@ -8,6 +8,7 @@ use crate::{
|
||||
GroupType,
|
||||
ImportParser,
|
||||
OutputBytes,
|
||||
OutputFile,
|
||||
};
|
||||
use leo_typed::{Input, Program};
|
||||
|
||||
@ -17,6 +18,7 @@ use snarkos_models::{
|
||||
curves::{Field, PrimeField},
|
||||
gadgets::r1cs::{ConstraintSystem, TestConstraintSystem},
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn generate_constraints<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
@ -47,6 +49,7 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
||||
program: Program,
|
||||
input: InputPairs,
|
||||
imported_programs: &ImportParser,
|
||||
output_directory: &PathBuf,
|
||||
) -> Result<(), CompilerError> {
|
||||
let mut resolved_program = ConstrainedProgram::<F, G>::new();
|
||||
let program_name = program.get_name();
|
||||
@ -64,13 +67,20 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
||||
for (test_name, test) in tests.into_iter() {
|
||||
let cs = &mut TestConstraintSystem::<F>::new();
|
||||
let full_test_name = format!("{}::{}", program_name.clone(), test_name.to_string());
|
||||
let mut output_file_name = program_name.clone();
|
||||
|
||||
// get input file name from annotation or use test_name
|
||||
let input_pair = match test.input_file {
|
||||
Some(file_name) => match input.pairs.get(&file_name.name) {
|
||||
Some(pair) => pair.to_owned(),
|
||||
None => return Err(CompilerError::InvalidTestContext(file_name.name)),
|
||||
},
|
||||
Some(file_id) => {
|
||||
let file_name = file_id.name;
|
||||
|
||||
output_file_name = file_name.clone();
|
||||
|
||||
match input.pairs.get(&file_name) {
|
||||
Some(pair) => pair.to_owned(),
|
||||
None => return Err(CompilerError::InvalidTestContext(file_name)),
|
||||
}
|
||||
}
|
||||
None => default.ok_or(CompilerError::NoTestInput)?,
|
||||
};
|
||||
|
||||
@ -101,7 +111,13 @@ pub fn generate_test_constraints<F: Field + PrimeField, G: GroupType<F>>(
|
||||
cs.is_satisfied()
|
||||
);
|
||||
|
||||
// write result to file
|
||||
// write result to file
|
||||
let output = result?;
|
||||
let output_file = OutputFile::new(&output_file_name);
|
||||
|
||||
log::info!("\tWriting output to registers in `{}.out` ...", output_file_name);
|
||||
|
||||
output_file.write(output_directory, output.bytes()).unwrap();
|
||||
} else {
|
||||
log::error!("test {} errored: {}", full_test_name, result.unwrap_err());
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ impl OutputFile {
|
||||
// create output file
|
||||
let path = self.setup_file_path(path);
|
||||
let mut file = File::create(&path)?;
|
||||
log::info!("Writing to output registers...");
|
||||
|
||||
Ok(file.write_all(bytes)?)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
|
||||
use leo_package::{
|
||||
inputs::*,
|
||||
outputs::OUTPUTS_DIRECTORY_NAME,
|
||||
outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME},
|
||||
root::Manifest,
|
||||
source::{MainFile, MAIN_FILE_NAME, SOURCE_DIRECTORY_NAME},
|
||||
};
|
||||
@ -63,6 +63,9 @@ impl CLI for TestCommand {
|
||||
let mut output_directory = package_path.clone();
|
||||
output_directory.push(OUTPUTS_DIRECTORY_NAME);
|
||||
|
||||
// Create the output directory
|
||||
OutputsDirectory::create(&package_path)?;
|
||||
|
||||
// Parse the current main program file
|
||||
let program = Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(
|
||||
package_name.clone(),
|
||||
|
Loading…
Reference in New Issue
Block a user