EmbarkStudios / cargo-about

📜 Cargo plugin to generate list of all licenses for a crate 🦀
http://embark.rs
Apache License 2.0
545 stars 32 forks source link

Add cli tests for init and generate subcommands #191

Closed dylanholmes closed 2 years ago

dylanholmes commented 2 years ago

Checklist

Description of Changes

Adding cli tests for the init and generate subcommands using the approach suggested by @Jake-Shadle in his comment on issue #18. The tests construct local packages to test the logic so they don't rely on any network connectivity to run.

I've left some TODO comments in some of the generate tests, where I thought that the error messaging or output could be improved. Please take a look, and let me know if you think they are non-issues and I should remove the comments or if I should create a real issue.

I haven't written any rust docs for the test utilities, since they are not part of any public API; let me know if you'd like me to add some. (Didn't want to put in the work if not necessary)

I'm relatively new to rust, so I'd really appreciate any constructive feedback!

Output of cargo test:

   Compiling cargo-about v0.5.1 (/Users/dylanhol/Downloads/cargo-about)
    Finished test [unoptimized + debuginfo] target(s) in 3.23s
     Running unittests src/lib.rs (target/debug/deps/cargo_about-6c876e50d5d489cd)

running 3 tests
test licenses::fetch::test::fetches_bitbucket ... ignored, online
test licenses::fetch::test::fetches_github ... ignored, online
test licenses::fetch::test::fetches_gitlab ... ignored, online

test result: ok. 0 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests src/cargo-about/main.rs (target/debug/deps/cargo_about-90fdeeef43f15ac6)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/all.rs (target/debug/deps/all-6b7aede08bbeaea8)

running 28 tests
test cli::generate::fails_when_templates_arg_missing ... ok
test cli::generate::fails_when_manifest_absent ... ok
test cli::generate::fails_when_manifest_invalid ... ok
test cli::generate::fails_when_missing_accepted_field ... ok
test cli::generate::fails_when_template_file_missing ... ok
test cli::generate::fails_when_license_field_valid_and_accepted_field_empty ... ok
test cli::generate::reports_all_licenses_when_dependency_has_different_license_and_text ... ok
test cli::generate::reports_a_license_when_license_field_valid ... ok
test cli::generate::reports_no_licenses_when_license_field_unknown ... ok
test cli::generate::reports_custom_spdx_license_text_when_manifest_has_license_file_field_with_spdx_text ... ok
test cli::generate::fails_when_dependency_has_non_accepted_license_field ... ok
test cli::generate::fails_back_to_default_about_config_when_absent ... ok
test cli::init::fails_when_manifest_absent ... ok
test cli::init::fails_when_manifest_empty ... ok
test cli::generate::reports_all_licenses_when_dependency_has_same_spdx_license_and_different_text ... ok
test cli::generate::reports_custom_spdx_license_file_when_spdx_license_file_has_std_naming_but_not_specifed_in_manifest ... ok
test cli::init::does_not_overwrite_by_default ... ok
test cli::init::overwrites_config_and_template_when_overwrite_specified ... ok
test cli::init::overwrites_config_only_when_no_handlebars_and_overwrite_specified ... ok
test cli::init::writes_config_and_template_by_default ... ok
test cli::init::writes_config_only_when_no_handlebars_specifed ... ok
test cli::generate::reports_no_licenses_when_license_file_field_but_no_file ... ok
test cli::generate::reports_no_licenses_when_manifest_has_license_file_field_with_non_spdx_text ... ok
test cli::generate::reports_no_licenses_when_license_file_field_but_file_empty ... ok
test cli::generate::reports_no_licenses_when_no_license_and_accepted_field_empty ... ok
test cli::generate::reports_no_licenses_when_manifest_has_license_file_field_with_spdx_license_text_and_non_std_filename ... ok
test cli::generate::reports_one_license_when_when_dependency_has_same_spdx_license_and_text ... ok
test cli::generate::reports_no_licenses_when_no_licenses ... ok

test result: ok. 28 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 4.53s

   Doc-tests cargo-about

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Related Issues

Jake-Shadle commented 2 years ago

Thanks for the PR! It's rather large so will take a bit to review but hopefully can do that before the end of the week.