From 2a616eb13d0a301ed4c377e8025c5f281bbf153d Mon Sep 17 00:00:00 2001 From: Protryon Date: Sun, 7 Mar 2021 10:17:33 -0800 Subject: [PATCH] absolute path for parser tests --- parser/src/test.rs | 13 ++++++++++--- parser/tests/serialization/expected_leo_ast.json | 16 ++++++++-------- parser/tests/serialization/json.rs | 14 +++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/parser/src/test.rs b/parser/src/test.rs index 1014d83e85..ad123ca63d 100644 --- a/parser/src/test.rs +++ b/parser/src/test.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{fs, path::Path}; +use std::{ + fs, + path::{Path, PathBuf}, +}; use crate::SyntaxError; @@ -42,7 +45,9 @@ pub fn parser_pass_tests() { let mut pass = 0; let mut fail = vec![]; let mut tests = vec![]; - find_tests("../tests/pass/parse/", &mut tests); + let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + test_dir.push("../tests/pass/parse/"); + find_tests(&test_dir, &mut tests); for (path, content) in tests.into_iter() { match crate::parse(&path, &content) { Ok(_) => { @@ -73,7 +78,9 @@ pub fn parser_fail_tests() { let mut pass = 0; let mut fail = vec![]; let mut tests = vec![]; - find_tests("../tests/fail/parse/", &mut tests); + let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + test_dir.push("../tests/fail/parse/"); + find_tests(&test_dir, &mut tests); for (path, content) in tests.into_iter() { match crate::parse(&path, &content) { Ok(_) => { diff --git a/parser/tests/serialization/expected_leo_ast.json b/parser/tests/serialization/expected_leo_ast.json index 9535cdd016..cedf6db8a0 100644 --- a/parser/tests/serialization/expected_leo_ast.json +++ b/parser/tests/serialization/expected_leo_ast.json @@ -4,9 +4,9 @@ "imports": [], "circuits": {}, "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"./tests/serialization/main.leo\\\"}\"}": { + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"test\\\"}\"}": { "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"./tests/serialization/main.leo\\\"}\"}", + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"test\\\"}\"}", "input": [], "output": null, "block": { @@ -24,7 +24,7 @@ "line_stop": 2, "col_start": 12, "col_stop": 13, - "path": "./tests/serialization/main.leo" + "path": "test" } ] } @@ -38,7 +38,7 @@ "line_stop": 2, "col_start": 16, "col_stop": 17, - "path": "./tests/serialization/main.leo" + "path": "test" } ] } @@ -49,7 +49,7 @@ "line_stop": 2, "col_start": 12, "col_stop": 17, - "path": "./tests/serialization/main.leo" + "path": "test" } } }, @@ -58,7 +58,7 @@ "line_stop": 2, "col_start": 5, "col_stop": 17, - "path": "./tests/serialization/main.leo" + "path": "test" } } } @@ -68,7 +68,7 @@ "line_stop": 3, "col_start": 17, "col_stop": 2, - "path": "./tests/serialization/main.leo" + "path": "test" } }, "span": { @@ -76,7 +76,7 @@ "line_stop": 3, "col_start": 1, "col_stop": 2, - "path": "./tests/serialization/main.leo" + "path": "test" } } } diff --git a/parser/tests/serialization/json.rs b/parser/tests/serialization/json.rs index cf1c01f66b..9e62f65072 100644 --- a/parser/tests/serialization/json.rs +++ b/parser/tests/serialization/json.rs @@ -25,7 +25,7 @@ fn to_ast(program_filepath: &Path) -> Result { let program_string = std::fs::read_to_string(program_filepath).expect("failed to open test"); // Parses the Leo file and constructs a leo ast. - leo_parser::parse_ast(&program_filepath.to_str().unwrap(), &program_string) + leo_parser::parse_ast("test", &program_string) } #[test] @@ -33,7 +33,8 @@ fn to_ast(program_filepath: &Path) -> Result { fn test_serialize() { // Construct an ast from the given test file. let ast = { - let program_filepath = PathBuf::from("./tests/serialization/main.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -52,7 +53,8 @@ fn test_serialize() { fn test_deserialize() { // Load the expected ast. let expected_ast = { - let program_filepath = PathBuf::from("./tests/serialization/main.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -68,7 +70,8 @@ fn test_deserialize() { fn test_serialize_deserialize_serialize() { // Construct an ast from the given test file. let ast = { - let program_filepath = PathBuf::from("./tests/serialization/main.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -88,7 +91,8 @@ fn test_serialize_deserialize_serialize() { #[test] fn test_generic_parser_error() { let error_result = { - let program_filepath = PathBuf::from("./tests/serialization/parser_error.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/parser_error.leo"); to_ast(&program_filepath) }