Skip to content

Commit

Permalink
Fix broken doctests that never ran when the crate was a dylib
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
  • Loading branch information
rydrman committed Apr 9, 2022
1 parent fd25431 commit f90a632
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 33 deletions.
8 changes: 5 additions & 3 deletions src/api/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ mod ident_test;
/// and should only be used for testing.
///
/// ```
/// ident!("my-pkg/1.0.0")
/// # #[macro_use] extern crate spk;
/// # fn main() {
/// ident!("my-pkg/1.0.0");
/// # }
/// ```
#[macro_export]
macro_rules! ident {
($ident:literal) => {
crate::api::parse_ident($ident).unwrap()
$crate::api::parse_ident($ident).unwrap()
};
}

Expand Down Expand Up @@ -136,7 +139,6 @@ impl Ident {
}
}
}

}

impl TryFrom<&str> for Ident {
Expand Down
3 changes: 2 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub use python::init_module;
pub use test_spec::{TestSpec, TestStage};
pub use validation::{default_validators, ValidationSpec, Validator};
pub use version::{
parse_version, InvalidVersionError, TagSet, Version, TAG_SEP, TAG_SET_SEP, VERSION_SEP,
parse_tag_set, parse_version, InvalidVersionError, TagSet, Version, TAG_SEP, TAG_SET_SEP,
VERSION_SEP,
};
pub use version_range::{
parse_version_range, CompatRange, ExactVersion, ExcludedVersion, GreaterThanOrEqualToRange,
Expand Down
13 changes: 12 additions & 1 deletion src/api/option_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ pub const DIGEST_SIZE: usize = 8;

type Digest = [char; DIGEST_SIZE];

/// Create a set of options from a simple mapping.
///
/// ```
/// # #[macro_use] extern crate spk;
/// # fn main() {
/// option_map!{
/// "debug" => "on",
/// "python.abi" => "cp37m"
/// };
/// # }
/// ```
#[macro_export]
macro_rules! option_map {
($($k:expr => $v:expr),* $(,)?) => {{
use crate::api::OptionMap;
use $crate::api::OptionMap;
#[allow(unused_mut)]
let mut opts = OptionMap::default();
$(opts.insert($k.into(), $v.into());)*
Expand Down
4 changes: 2 additions & 2 deletions src/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ impl<'de> Deserialize<'de> for RangeIdent {
/// Parse a package identifier which specifies a range of versions.
///
/// ```
/// parse_ident_range("maya/~2020.0").unwrap()
/// parse_ident_range("maya/^2020.0").unwrap()
/// spk::api::parse_ident_range("maya/~2020.0").unwrap();
/// spk::api::parse_ident_range("maya/^2020.0").unwrap();
/// ```
pub fn parse_ident_range<S: AsRef<str>>(source: S) -> Result<RangeIdent> {
let mut parts = source.as_ref().split('/');
Expand Down
7 changes: 5 additions & 2 deletions src/api/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ mod spec_test;
/// cannot be deserialized into a spec.
///
/// ```
/// let spec = spec!({
/// # #[macro_use] extern crate spk;
/// # fn main() {
/// spec!({
/// "pkg": "my-pkg/1.0.0",
/// "build": {
/// "options": [
/// {"pkg": "dependency"}
/// ]
/// }
/// });
/// # }
/// ```
#[macro_export]
macro_rules! spec {
($($spec:tt)+) => {{
let value = serde_json::json!($($spec)+);
let spec: crate::api::Spec = serde_json::from_value(value).unwrap();
let spec: $crate::api::Spec = serde_json::from_value(value).unwrap();
spec
}};
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ impl pyo3::mapping::PyMappingProtocol for TagSet {
/// Parse the given string as a set of version tags.
///
/// ```
/// let tag_set = parse_tag_set("release.tags,alpha.1").unwrap();
/// assert_eq!(tag_set.get("alpha"), Some(1));
/// let tag_set = spk::api::parse_tag_set("dev.4,alpha.1").unwrap();
/// assert_eq!(tag_set.get("alpha"), Some(&1));
/// ```
pub fn parse_tag_set<S: AsRef<str>>(tags: S) -> crate::Result<TagSet> {
let tags = tags.as_ref();
Expand Down
23 changes: 5 additions & 18 deletions src/build/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ pub enum BuildSource {

/// Builds a binary package.
///
/// ```
/// BinaryPackageBuilder
/// .from_spec(api.Spec.from_dict({
/// ```no_run
/// spk::build::BinaryPackageBuilder::from_spec(spk::spec!({
/// "pkg": "my-pkg",
/// "build": {"script": "echo hello, world"},
/// }))
/// .with_option("debug", "true")
/// .with_source(".")
/// .build()
/// .unwrap()
/// .unwrap();
/// ```
#[pyclass]
#[derive(Clone)]
Expand Down Expand Up @@ -691,27 +689,16 @@ pub fn component_marker_path(pkg: &api::Ident, name: &api::Component) -> Relativ
}

/// Expand a path to a list of itself and all of its parents
///
/// ```
/// use relative_path::RelativePathBuf;
/// let path = RelativePathBuf::from("some/deep/path")
/// let hierarchy = path_and_parents(path);
/// assert_eq!(hierarchy, vec![
/// RelativePathBuf::from("some/deep/path"),
/// RelativePathBuf::from("some/deep"),
/// RelativePathBuf::from("some"),
/// ]);
/// ```
fn path_and_parents(mut path: RelativePathBuf) -> Vec<RelativePathBuf> {
let mut hierarchy = Vec::new();
loop {
let parent = path.parent().map(ToOwned::to_owned);
hierarchy.push(path);
match parent {
None => break,
Some(parent) => {
Some(parent) if !parent.as_str().is_empty() => {
path = parent;
}
_ => break,
}
}
hierarchy
Expand Down
15 changes: 15 additions & 0 deletions src/build/binary_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,18 @@ fn test_build_add_startup_files(tmpdir: tempdir::TempDir) {

assert_eq!(tcsh_value.as_slice(), b"1.7:true:append\n");
}

#[rstest]
fn test_path_and_parents() {
use relative_path::RelativePathBuf;
let path = RelativePathBuf::from("some/deep/path");
let hierarchy = super::path_and_parents(path);
assert_eq!(
hierarchy,
vec![
RelativePathBuf::from("some/deep/path"),
RelativePathBuf::from("some/deep"),
RelativePathBuf::from("some"),
]
);
}
10 changes: 6 additions & 4 deletions src/build/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ impl CollectionError {

/// Builds a source package.
///
/// ```
/// SourcePackageBuilder
/// .from_spec(api.Spec.from_dict({
/// ```no_run
/// # #[macro_use] extern crate spk;
/// # fn main() {
/// spk::build::SourcePackageBuilder::from_spec(spk::spec!({
/// "pkg": "my-pkg",
/// }))
/// .build()
/// .unwrap()
/// .unwrap();
/// # }
/// ```
#[pyclass]
pub struct SourcePackageBuilder {
Expand Down

0 comments on commit f90a632

Please sign in to comment.