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!
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!