Skip to content

Commit

Permalink
Fix CI build, introduce justfile (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
paholg committed Feb 18, 2025
1 parent 4bccf7d commit 372a281
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 58 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:
target: x86_64
steps:
- uses: actions/checkout@v3
- if: matrix.rust == '1.37.0'
# Rust 1.37 doesn't like modern lock files :(
run: rm Cargo.lock
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
Expand Down Expand Up @@ -79,8 +82,8 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- run: cargo test --verbose --features "strict" ${{ matrix.mb_const_generics }}
- run: cargo doc --features "strict" ${{ matrix.mb_const_generics }}
- uses: extractions/setup-just@v2
- run: just test ${{ matrix.mb_const_generics }}

lint:
name: Lint
Expand All @@ -90,7 +93,5 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
- run: cargo fmt --all -- --check
- run: cargo clippy -- -D warnings
# Allow deprecated because we test the no_std feature.
- run: cargo clippy --all-features -- -D warnings -A deprecated
- uses: extractions/setup-just@v2
- run: just lint
67 changes: 39 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Run all CI checks except those that require different platforms
test-local: lint test
@just test --features const-generics

# Update lockfiles
up:
nix flake update
cargo update

# Run all lints
lint: fmt clippy clippy-all

# Check formatting
fmt:
cargo fmt --all -- --check

# Clippy
clippy:
cargo clippy -- -D warnings

# Clippy with all features
clippy-all:
# Allow deprecated because we test the no_std feature.
cargo clippy --all-features -- -D warnings -A deprecated

# Run test
test *args:
cargo test --verbose --features "strict" {{args}}
cargo doc --features "strict" {{args}}
24 changes: 17 additions & 7 deletions src/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,28 @@ impl BitXor<B1> for B1 {
}
}

#[cfg(tests)]
mod tests {
#[cfg(test)]
mod bit_op_tests {
use core::ops::{BitAnd, BitOr, BitXor, Not};

use crate::{B0, B1};

// macro for testing operation results. Uses `Same` to ensure the types are equal and
// not just the values they evaluate to.
macro_rules! test_bit_op {
($op:ident $Lhs:ident = $Answer:ident) => {{
type Test = <<$Lhs as $op>::Output as ::Same<$Answer>>::Output;
assert_eq!(<$Answer as Bit>::to_u8(), <Test as Bit>::to_u8());
type Test = <<$Lhs as $op>::Output as $crate::Same<$Answer>>::Output;
assert_eq!(
<$Answer as $crate::Bit>::to_u8(),
<Test as $crate::Bit>::to_u8()
);
}};
($Lhs:ident $op:ident $Rhs:ident = $Answer:ident) => {{
type Test = <<$Lhs as $op<$Rhs>>::Output as ::Same<$Answer>>::Output;
assert_eq!(<$Answer as Bit>::to_u8(), <Test as Bit>::to_u8());
type Test = <<$Lhs as $op<$Rhs>>::Output as $crate::Same<$Answer>>::Output;
assert_eq!(
<$Answer as $crate::Bit>::to_u8(),
<Test as $crate::Bit>::to_u8()
);
}};
}

Expand Down Expand Up @@ -318,7 +328,7 @@ impl Max<B1> for B1 {
}

#[cfg(test)]
mod tests {
mod bit_creation_tests {
#[test]
fn bit_creation() {
{
Expand Down
14 changes: 1 addition & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@
#![warn(missing_docs)]
#![cfg_attr(feature = "strict", deny(missing_docs))]
#![cfg_attr(feature = "strict", deny(warnings))]
#![cfg_attr(
feature = "cargo-clippy",
allow(
clippy::len_without_is_empty,
clippy::many_single_char_names,
clippy::new_without_default,
clippy::suspicious_arithmetic_impl,
clippy::type_complexity,
clippy::wrong_self_convention,
)
)]
#![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))]
#![doc(html_root_url = "https://docs.rs/typenum/1.17.0")]
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]

Expand Down Expand Up @@ -101,7 +89,7 @@ pub use crate::{
pub use consts::{
False, True, B0, B1,
U0, U1, U2, *,
N1, N2, Z0, P1, P2, *,
N1, N2, Z0, P1, P2,
};

#[cfg(feature = "const-generics")]
Expand Down
7 changes: 6 additions & 1 deletion src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub trait Trim {
pub type TrimOut<A> = <A as Trim>::Output;

/// Gets rid of all zeros until it hits a one.
// ONLY IMPLEMENT FOR INVERTED NUMBERS!
pub trait TrimTrailingZeros {
type Output;
Expand Down Expand Up @@ -395,6 +394,7 @@ use crate::{Equal, False, Greater, Less, True};
pub trait IsLessPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_less_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -426,6 +426,7 @@ impl<A, B> IsLessPrivate<B, Greater> for A {
pub trait IsEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -457,6 +458,7 @@ impl<A, B> IsEqualPrivate<B, Greater> for A {
pub trait IsGreaterPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_greater_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -488,6 +490,7 @@ impl<A, B> IsGreaterPrivate<B, Greater> for A {
pub trait IsLessOrEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_less_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -519,6 +522,7 @@ impl<A, B> IsLessOrEqualPrivate<B, Greater> for A {
pub trait IsNotEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_not_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down Expand Up @@ -550,6 +554,7 @@ impl<A, B> IsNotEqualPrivate<B, Greater> for A {
pub trait IsGreaterOrEqualPrivate<Rhs, Cmp> {
type Output: Bit;

#[allow(clippy::wrong_self_convention)]
fn is_greater_or_equal_private(self, _: Rhs, _: Cmp) -> Self::Output;
}

Expand Down
Loading

0 comments on commit 372a281

Please sign in to comment.