Skip to content

Commit

Permalink
Fix feature tests (#12)
Browse files Browse the repository at this point in the history
* Run feature tests only on purl crate

Using `--no-default-features` on the workspace does not work as expected
because the `purl_test` and `xtask` crates depend on certain features of
the `purl` crate. So with feature unification, the `purl` crate is built
with those features **enabled**.

To resolve this and simplify the tests, this patch switches the default
and minimal tests to only test the `purl` crate itself. The "Full" test
is left to test the entire workspace with code coverage.

This technically leaves open the possibility that `purl_test` or `xtask`
may not successfully build with default features... But since those are
test and development crates, I'm not actually concerned.

* Add missing feature guards

* Avoid `PackageType` in doctests

`PackageType` is only available with the `package-type` feature. So it's
best to avoid it in unrelated doctests. Otherwise, they will fail when
run without default features.
  • Loading branch information
kylewillmon authored Oct 31, 2023
1 parent 4d17bd8 commit fde807c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ jobs:
include:
- name: Minimal
runner: test
features: --no-default-features
args: -p purl --no-default-features
- name: Default
runner: test
features: ""
args: -p purl
- name: Full
runner: tarpaulin
features: --all-features
args: --all-features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -73,4 +73,4 @@ jobs:
rm tarpaulin.tar.gz
- name: Run tests
run: cargo ${{ matrix.runner }} ${{ matrix.features }}
run: cargo ${{ matrix.runner }} ${{ matrix.args }}
5 changes: 2 additions & 3 deletions purl/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use crate::{GenericPurl, ParseError, PurlParts, PurlShape, SmallString};
/// # Example
///
/// ```
/// // `PurlBuilder` is an alias for `GenericPurlBuilder<PackageType>`.
/// use purl::{PackageType, PurlBuilder};
/// use purl::GenericPurlBuilder;
///
/// // Use the builder if you want to set fields besides the type and name.
/// let purl = PurlBuilder::new(PackageType::Maven, "my-package")
/// let purl = GenericPurlBuilder::new(String::from("maven"), "my-package")
/// .with_namespace("my.company")
/// .build()
/// .unwrap();
Expand Down
10 changes: 7 additions & 3 deletions purl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use format::*;
pub use package_type::*;
pub use parse::*;
pub use qualifiers::Qualifiers;
#[cfg(feature = "smartstring")]
use smartstring::{LazyCompact, SmartString, SmartStringMode};

mod builder;
Expand Down Expand Up @@ -181,6 +182,7 @@ impl<'a> PurlShape for Cow<'a, str> {
/// Without type-specific functionality, it's possible to create PURLs that have
/// incorrect capitalization or are missing a required namespace or required
/// qualifiers.
#[cfg(feature = "smartstring")]
impl<M> PurlShape for SmartString<M>
where
M: SmartStringMode,
Expand Down Expand Up @@ -229,11 +231,13 @@ pub struct PurlParts {
/// # Example
///
/// ```
/// // `Purl` is an alias for `GenericPurl<PackageType>`.
/// use purl::{PackageType, Purl};
/// use purl::GenericPurl;
///
/// // Use the builder if you want to set fields besides the type and name.
/// let purl = Purl::builder(PackageType::Npm, "my-package").with_version("1.2.3").build().unwrap();
/// let purl = GenericPurl::builder(String::from("npm"), "my-package")
/// .with_version("1.2.3")
/// .build()
/// .unwrap();
///
/// assert_eq!("pkg:npm/[email protected]", &purl.to_string());
/// ```
Expand Down

0 comments on commit fde807c

Please sign in to comment.