-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use util functions for reading from portal-spec-tests submo…
…dule
- Loading branch information
Showing
6 changed files
with
81 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
use std::{ | ||
fs::read_to_string, | ||
io, | ||
fs, io, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
pub const PORTAL_SPEC_TESTS_SUBMODULE_PATH: &str = "../../../portal-spec-tests"; | ||
pub const PORTAL_SPEC_TESTS_SUBMODULE_PATH: [&str; 2] = | ||
["../../portal-spec-tests", "../../../portal-spec-tests"]; | ||
|
||
/// Reads a file from a "portal-spec-tests" submodule. | ||
/// Returns a path to a file within "portal-spec-tests" submodule | ||
pub fn portal_spec_tests_file_path<P: AsRef<Path>>(path: P) -> PathBuf { | ||
for submodule_path in PORTAL_SPEC_TESTS_SUBMODULE_PATH { | ||
if fs::exists(submodule_path) | ||
.expect("we should be able to check whether submodule path exists") | ||
{ | ||
return PathBuf::from(submodule_path).join(path); | ||
} | ||
} | ||
|
||
panic!("Submodule directory not found!") | ||
} | ||
|
||
/// Reads text file from a "portal-spec-tests" submodule | ||
pub fn read_portal_spec_tests_file<P: AsRef<Path>>(path: P) -> io::Result<String> { | ||
read_to_string(PathBuf::from(PORTAL_SPEC_TESTS_SUBMODULE_PATH).join(path)) | ||
fs::read_to_string(portal_spec_tests_file_path(path)) | ||
} | ||
|
||
/// Reads binary file from a "portal-spec-tests" submodule | ||
pub fn read_portal_spec_tests_file_as_bytes<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { | ||
fs::read(portal_spec_tests_file_path(path)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters