You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 15, 2024. It is now read-only.
In main.rs, add a unit test for the cargo_dir function that checks that it panics if we have specified a new crate in the Cargo.toml file but have not yet run any command that would fetch that crate's source to our local filesystem.
Use the existing test marked should_panic for an example of how to make a test check that a function panics.
As I write this up, I'm seeing that it would be easier if a function to read the Cargo.toml contents was extracted from the cargo_dir function and, instead, cargo_dir took the contents of Cargo.toml as an argument. That would make it easier to pass different Cargo.toml contents in for a unit test, so that should be part of this issue and should be done before adding the test.
I'd accept a PR that adds this test even if it fails, or if it fails with a weird error message! I'm not sure if I've coded things in such a way as to reuse existing cargo knowledge or not. Eventually I'd like this to panic with a message like "This crate has not been fetched yet; please run cargo install" first.
Bonus points if you change the code to make the test pass!
The text was updated successfully, but these errors were encountered:
carols10cents
changed the title
Add tests for trying to open a crate that has not yet been downloaded
Add a test for trying to open a crate that has not yet been downloaded
Oct 4, 2015
In
main.rs
, add a unit test for thecargo_dir
function that checks that it panics if we have specified a new crate in theCargo.toml
file but have not yet run any command that would fetch that crate's source to our local filesystem.Use the existing test marked
should_panic
for an example of how to make a test check that a function panics.As I write this up, I'm seeing that it would be easier if a function to read the
Cargo.toml
contents was extracted from thecargo_dir
function and, instead,cargo_dir
took the contents ofCargo.toml
as an argument. That would make it easier to pass differentCargo.toml
contents in for a unit test, so that should be part of this issue and should be done before adding the test.I'd accept a PR that adds this test even if it fails, or if it fails with a weird error message! I'm not sure if I've coded things in such a way as to reuse existing cargo knowledge or not. Eventually I'd like this to panic with a message like "This crate has not been fetched yet; please run
cargo install
" first.Bonus points if you change the code to make the test pass!
The text was updated successfully, but these errors were encountered: