From ca36d0602257891e2e559bb5aa922537dc513175 Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 11 Dec 2020 13:31:13 -0500 Subject: [PATCH] undeprecate parse_program_from_string and add test --- compiler/src/compiler.rs | 3 --- compiler/tests/compiler/main.leo | 3 +++ compiler/tests/compiler/mod.rs | 46 ++++++++++++++++++++++++++++++++ compiler/tests/mod.rs | 1 + 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 compiler/tests/compiler/main.leo create mode 100644 compiler/tests/compiler/mod.rs diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 0726fc756b..51e85d1d0f 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -229,9 +229,6 @@ impl> Compiler { /// Equivalent to parse_and_check_program but uses the given program_string instead of a main /// file path. /// - /// Used for testing only. - /// - #[deprecated(note = "Please use the 'parse_program' method instead.")] pub fn parse_program_from_string(&mut self, program_string: &str) -> Result<(), CompilerError> { // Use the given bytes to construct the abstract syntax tree. let ast = Grammar::new(&self.main_file_path, &program_string).map_err(|mut e| { diff --git a/compiler/tests/compiler/main.leo b/compiler/tests/compiler/main.leo new file mode 100644 index 0000000000..f5ddfb4e7f --- /dev/null +++ b/compiler/tests/compiler/main.leo @@ -0,0 +1,3 @@ +function main() { + let a: u32 = 1 + 2; +} \ No newline at end of file diff --git a/compiler/tests/compiler/mod.rs b/compiler/tests/compiler/mod.rs new file mode 100644 index 0000000000..8daa6a9270 --- /dev/null +++ b/compiler/tests/compiler/mod.rs @@ -0,0 +1,46 @@ +// Copyright (C) 2019-2020 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use crate::{assert_satisfied, get_output, parse_program, EdwardsTestCompiler}; + +use std::{env::current_dir, path::PathBuf}; + +static MAIN_FILE_NAME: &str = "tests/compiler/main.leo"; + +// Compiler tests rely on knowledge of local directories. They should be run locally only. + +#[test] +#[ignore] +fn test_parse_program_from_string() { + // Parse program from string with compiler. + let program_string = include_str!("main.leo"); + let mut compiler_no_path = EdwardsTestCompiler::new("".to_string(), PathBuf::new(), PathBuf::new()); + + compiler_no_path.parse_program_from_string(program_string).unwrap(); + + // Parse program from file path with compiler. + let mut local = current_dir().unwrap(); + local.push(MAIN_FILE_NAME); + + let compiler_with_path = + EdwardsTestCompiler::parse_program_without_input("".to_string(), local, PathBuf::new()).unwrap(); + + // Compare output bytes. + let expected_output = get_output(compiler_no_path); + let actual_output = get_output(compiler_with_path); + + assert_eq!(expected_output, actual_output); +} diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 434a19ff16..52e50e9188 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -21,6 +21,7 @@ pub mod address; pub mod array; pub mod boolean; pub mod circuits; +pub mod compiler; pub mod console; pub mod core; pub mod definition;