Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace use of lazy_static_include_bytes in tests with std::fs::read #6729

Merged
merged 2 commits into from
May 1, 2022
Merged

replace use of lazy_static_include_bytes in tests with std::fs::read #6729

merged 2 commits into from
May 1, 2022

Conversation

abhijeetbhagat
Copy link
Contributor

@abhijeetbhagat abhijeetbhagat commented Apr 30, 2022

Replace use of lazy_static_include_bytes in tests with std::fs::read

Since we don’t need to include test data files in test binaries,
prefer reading the files via std::fs::read rather than using
lazy_static_include_bytes. In release builds the latter results in
the file being read at compilation which is a waste of time.

Fixes: #6665

@abhijeetbhagat abhijeetbhagat requested a review from a team as a code owner April 30, 2022 17:46
Copy link
Contributor

@mina86 mina86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m afraid we may need to take CARGO_MANIFEST_DIR into consideration.
This works when run over cargo test (because cargo test will change
to the manifest directory before executing the test) but when the test
is run directly it fails:

$ ./target/debug/deps/nearcore-92e4a7e0c6bc4d0d -- test_config_from_file

running 1 test
test config::test_config_from_file ... FAILED

failures:

---- config::test_config_from_file stdout ----
thread 'config::test_config_from_file' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', nearcore/src/config.rs:1496:73
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This doesn’t happen with the previous code.

std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("...")

should solve that issue.

By the way, could you also take a look at Cargo.toml files and remove
lazy-static-include dependencies which this change makes unnecessary.

nearcore/src/config.rs Outdated Show resolved Hide resolved
@mina86 mina86 merged commit 960c8eb into near:master May 1, 2022
EdvardD pushed a commit that referenced this pull request May 6, 2022
…6729)

Replace use of `lazy_static_include_bytes` in tests with `std::fs::read`

Since we don’t need to include test data files in test binaries,
prefer reading the files via `std::fs::read` rather than using
`lazy_static_include_bytes`.  In release builds the latter results in
the file being read at compilation which is a waste of time.

Fixes: #6665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace use of lazy_static_include_bytes in tests with std::fs::read
2 participants