From cc2d54ae2b5cf51069de29dfe4345065b4d695e1 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 5 Sep 2023 15:06:28 -0700 Subject: [PATCH] changes to testing framework --- compiler/compiler/src/compiler.rs | 1 - compiler/compiler/tests/compile.rs | 2 +- compiler/compiler/tests/execute.rs | 2 +- compiler/compiler/tests/utilities/mod.rs | 2 -- compiler/passes/src/common/symbol_table/mod.rs | 16 +++++++++++++++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/compiler/compiler/src/compiler.rs b/compiler/compiler/src/compiler.rs index ddc6e4e327..6aa5ee2ebd 100644 --- a/compiler/compiler/src/compiler.rs +++ b/compiler/compiler/src/compiler.rs @@ -312,7 +312,6 @@ impl<'a> Compiler<'a> { /// Writes the Symbol Table to a JSON file. fn write_symbol_table_to_json(&self, file_suffix: &str, symbol_table: &SymbolTable) -> Result<()> { symbol_table.to_json_file(self.output_directory.clone(), &format!("{}.{file_suffix}", self.program_name))?; - Ok(()) } } diff --git a/compiler/compiler/tests/compile.rs b/compiler/compiler/tests/compile.rs index e9b9973720..b5fcdd1a51 100644 --- a/compiler/compiler/tests/compile.rs +++ b/compiler/compiler/tests/compile.rs @@ -20,8 +20,8 @@ use utilities::{ get_build_options, get_cwd_option, hash_asts, - hash_symbol_tables, hash_content, + hash_symbol_tables, parse_program, setup_build_directory, BufferEmitter, diff --git a/compiler/compiler/tests/execute.rs b/compiler/compiler/tests/execute.rs index 1448bb5a29..ce0cf057c0 100644 --- a/compiler/compiler/tests/execute.rs +++ b/compiler/compiler/tests/execute.rs @@ -22,8 +22,8 @@ use utilities::{ get_build_options, get_cwd_option, hash_asts, - hash_symbol_tables, hash_content, + hash_symbol_tables, parse_program, setup_build_directory, Aleo, diff --git a/compiler/compiler/tests/utilities/mod.rs b/compiler/compiler/tests/utilities/mod.rs index 760fdac132..1b18e1c6f4 100644 --- a/compiler/compiler/tests/utilities/mod.rs +++ b/compiler/compiler/tests/utilities/mod.rs @@ -61,8 +61,6 @@ pub fn hash_symbol_tables() -> (String, String, String) { let type_checked_symbol_table = hash_file("/tmp/output/test.type_checked_symbol_table.json"); let unrolled_symbol_table = hash_file("/tmp/output/test.unrolled_symbol_table.json"); println!("hashed the st's"); - - (initial_symbol_table, type_checked_symbol_table, unrolled_symbol_table) } diff --git a/compiler/passes/src/common/symbol_table/mod.rs b/compiler/passes/src/common/symbol_table/mod.rs index 19c0491413..94239f8547 100644 --- a/compiler/passes/src/common/symbol_table/mod.rs +++ b/compiler/passes/src/common/symbol_table/mod.rs @@ -178,8 +178,22 @@ impl SymbolTable { /// Serializes the symbol table into a JSON string. pub fn to_json_string(&self) -> Result { - Ok(serde_json::to_string_pretty(&self).map_err(|e| AstError::failed_to_convert_symbol_table_to_json_string(&e))?) + Ok(serde_json::to_string_pretty(&self) + .map_err(|e| AstError::failed_to_convert_symbol_table_to_json_string(&e))?) } + /// Converts the symbol table into a JSON value + pub fn to_json_value(&self) -> Result { + Ok(serde_json::to_value(self).map_err(|e| AstError::failed_to_convert_symbol_table_to_json_value(&e))?) + } + // Serializes the symbol table into a JSON file. + pub fn to_json_file(&self, mut path: std::path::PathBuf, file_name: &str) -> Result<()> { + path.push(file_name); + let file = + std::fs::File::create(&path).map_err(|e| AstError::failed_to_create_symbol_table_json_file(&path, &e))?; + let writer = std::io::BufWriter::new(file); + Ok(serde_json::to_writer_pretty(writer, &self) + .map_err(|e| AstError::failed_to_write_symbol_table_to_json_file(&path, &e))?) + } }