Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure CI tests #353

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
on:
push:
branches:
- master
paths:
- '**.rs'
pull_request:
paths:
- '**.rs'
# `workflow_dispatch` allows CodSpeed to trigger backtest
# performance analysis in order to generate initial data.
workflow_dispatch:

name: Benchmark pull requests
jobs:
runBenchmark:
Expand All @@ -11,9 +20,17 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@stable
- uses: boa-dev/criterion-compare-action@v3
- name: Setup rust toolchain, cache and cargo-codspeed binary
uses: moonrepo/setup-rust@v0
with:
channel: stable
cache-target: release
bins: cargo-codspeed
- name: Build the benchmark target(s)
run: cargo codspeed build -p palette --features wide
- name: Run the benchmarks
uses: CodSpeedHQ/action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
branchName: ${{ github.base_ref }}
features: "wide"
run: cargo codspeed run
working-directory: palette # mimics how tests work, so the colors CSV can be found
token: ${{ secrets.CODSPEED_TOKEN }}
54 changes: 40 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,58 @@ on:
name: Continuous integration

jobs:
compile_and_test:
name: Compile and test
compile_and_test_msrv:
name: Compile and test MSRV
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
toolchain: [1.60.0, stable, beta, nightly]
runs-on: ${{ matrix.os }}
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
- uses: dtolnay/rust-toolchain@1.60.0
with:
toolchain: ${{ matrix.toolchain }}
targets: thumbv6m-none-eabi
components: clippy
- name: Minimal check
run: cargo check -v -p palette --no-default-features --features std
run: cargo clippy -v -p palette --no-default-features --features std
- name: find-crate check
run: cargo check -v -p palette --no-default-features --features "std find-crate"
run: cargo clippy -v -p palette --no-default-features --features "std find-crate"
- name: Default check
run: cargo check -v --workspace --exclude no_std_test
- run: cargo test -v
- name: Test features
run: cargo clippy -v --workspace --exclude no_std_test
- name: Test all features
run: cargo test -v -p palette --all-features
- name: Test each feature
shell: bash
working-directory: palette
run: bash ../scripts/test_features.sh
- name: "Test #[no_std]"
if: ${{ runner.os == 'Linux' && matrix.toolchain == 'nightly' }}
check_stable_beta_nightly:
name: Quick check
strategy:
matrix:
toolchain: [beta, stable, nightly]
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
components: clippy
- name: Check all features
run: cargo clippy -v -p palette --all-features
no_std:
name: "Test #[no_std]"
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
with:
targets: thumbv6m-none-eabi
- name: "Build with #[no_std]"
run: cargo build -v --package no_std_test --features nightly --target thumbv6m-none-eabi
miri:
name: Miri tests
Expand All @@ -61,7 +85,9 @@ jobs:
name: ci
if: success()
needs:
- compile_and_test
- compile_and_test_msrv
- check_stable_beta_nightly
- no_std
- miri
runs-on: ubuntu-latest
steps:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
pull_request:
branches:
- master
paths:
- '**.rs'
push:
branches:
- master
paths:
- '**.rs'

name: Test coverage

jobs:
coverage:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@nightly
- uses: taiki-e/install-action@cargo-llvm-cov
- name: Collect code coverage
run: cargo +nightly llvm-cov --all-features --workspace --exclude no_std_test --codecov --doctests --output-path codecov.json
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: codecov.json
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
],
"rust-analyzer.imports.granularity.enforce": true,
"rust-analyzer.imports.granularity.group": "crate",
"rust-analyzer.imports.group.enable": true
}
"rust-analyzer.imports.group.enable": true,
"rust-analyzer.check.command": "clippy"
}
1 change: 1 addition & 0 deletions palette/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ edition = "2018"
resolver = "2"
categories = ["graphics", "multimedia::images", "no-std"]
build = "build/main.rs"
rust-version = "1.60.0"

[features]
default = ["named_from_str", "std", "approx"]
Expand Down
2 changes: 1 addition & 1 deletion palette/benches/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn matrix(c: &mut Criterion) {
b.iter(|| matrix_inverse(*inverse))
});
group.bench_function("rgb_to_xyz_matrix", |b| {
b.iter(|| rgb_to_xyz_matrix::<encoding::Srgb, f32>())
b.iter(rgb_to_xyz_matrix::<encoding::Srgb, f32>)
});
}

Expand Down
13 changes: 6 additions & 7 deletions palette/examples/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
&mut image,
x,
y,
0 * ALPHA_STEPS + alpha_step,
alpha_step,
tile_width,
tile_height,
foreground,
Expand All @@ -56,7 +56,7 @@ fn main() {
&mut image,
x,
y,
1 * ALPHA_STEPS + alpha_step,
ALPHA_STEPS + alpha_step,
tile_width,
tile_height,
Xyza::from_color(foreground),
Expand All @@ -72,6 +72,7 @@ fn main() {
}
}

#[allow(clippy::too_many_arguments)]
fn draw_composed_pixels<C>(
image: &mut image::RgbaImage,
x: u32,
Expand Down Expand Up @@ -106,11 +107,9 @@ fn draw_composed_pixels<C>(
}
}

fn compose<C>(
fg: Alpha<C, f32>,
bg: Alpha<C, f32>,
function: fn(Alpha<C, f32>, Alpha<C, f32>) -> Alpha<C, f32>,
) -> image::Rgba<u8>
type ComposeFn<C> = fn(Alpha<C, f32>, Alpha<C, f32>) -> Alpha<C, f32>;

fn compose<C>(fg: Alpha<C, f32>, bg: Alpha<C, f32>, function: ComposeFn<C>) -> image::Rgba<u8>
where
Alpha<C, f32>: Blend + IntoColor<LinSrgba>,
{
Expand Down
6 changes: 3 additions & 3 deletions palette/examples/color_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ fn blit_shades(color: LinSrgb<f32>, mut canvas: SubImage<&mut RgbImage>) {
let primary = Srgb::from_linear(color).into();

//Generate one lighter and two darker versions of the color
let light = Srgb::from_linear(color.lighten(0.1).into()).into();
let dark1 = Srgb::from_linear(color.darken(0.1).into()).into();
let dark2 = Srgb::from_linear(color.darken(0.2).into()).into();
let light = Srgb::from_linear(color.lighten(0.1)).into();
let dark1 = Srgb::from_linear(color.darken(0.1)).into();
let dark2 = Srgb::from_linear(color.darken(0.2)).into();

for x in 0..width {
for y in 0..height {
Expand Down
5 changes: 3 additions & 2 deletions palette/examples/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() {
&mut image,
x,
y,
0 * ALPHA_STEPS + alpha_step,
alpha_step,
tile_width,
tile_height,
foreground.into(),
Expand All @@ -67,7 +67,7 @@ fn main() {
&mut image,
x,
y,
1 * ALPHA_STEPS + alpha_step,
ALPHA_STEPS + alpha_step,
tile_width,
tile_height,
Xyza::from_color(foreground).into(),
Expand Down Expand Up @@ -127,6 +127,7 @@ fn main() {
}
}

#[allow(clippy::too_many_arguments)]
fn draw_composed_pixels<C>(
image: &mut image::RgbaImage,
x: u32,
Expand Down
2 changes: 1 addition & 1 deletion palette/examples/readme_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn display_colors(filename: &str, displays: &[DisplayType]) {

let mut image = RgbImage::new(WIDTH, displays.len() as u32 * row_height);

for (i, display) in displays.into_iter().enumerate() {
for (i, display) in displays.iter().enumerate() {
let image = image.sub_image(0, i as u32 * row_height, WIDTH, row_height);
match *display {
DisplayType::Discrete(colors) => {
Expand Down
1 change: 1 addition & 0 deletions palette/src/alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use self::alpha::*;
#[doc(no_inline)]
pub use crate::blend::PreAlpha; // Cross-link for visibility.

#[allow(clippy::module_inception)]
mod alpha;

/// A trait for color types that can have or be given transparency (alpha channel).
Expand Down
1 change: 1 addition & 0 deletions palette/src/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub use self::{
pre_alpha::PreAlpha,
};

#[allow(clippy::module_inception)]
mod blend;
mod blend_with;
mod compose;
Expand Down
4 changes: 2 additions & 2 deletions palette/src/blend/equations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ where
.apply_to(source.clone(), destination.clone());

(
alpha_src_param.mul_constant(source.alpha.clone()),
alpha_dst_param.mul_constant(destination.alpha.clone()),
alpha_src_param.mul_constant(source.alpha),
alpha_dst_param.mul_constant(destination.alpha),
)
};

Expand Down
2 changes: 1 addition & 1 deletion palette/src/cast/from_into_components_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ where
}
}

impl<'a, T, C> TryComponentsInto<C> for T
impl<T, C> TryComponentsInto<C> for T
where
C: TryFromComponents<T>,
{
Expand Down
11 changes: 6 additions & 5 deletions palette/src/color_difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,12 @@ mod test {
assert!(c1.has_enhanced_contrast_text(white));
assert!(c1.has_enhanced_contrast_large_text(white));
assert!(c1.has_min_contrast_graphics(white));
assert!(c1.has_min_contrast_text(black) == false);
assert!(c1.has_min_contrast_large_text(black) == false);
assert!(c1.has_enhanced_contrast_text(black) == false);
assert!(c1.has_enhanced_contrast_large_text(black) == false);
assert!(c1.has_min_contrast_graphics(black) == false);

assert!(!c1.has_min_contrast_text(black));
assert!(!c1.has_min_contrast_large_text(black));
assert!(!c1.has_enhanced_contrast_text(black));
assert!(!c1.has_enhanced_contrast_large_text(black));
assert!(!c1.has_min_contrast_graphics(black));

let c1 = Srgb::from_str("#066").unwrap().into_format();

Expand Down
20 changes: 9 additions & 11 deletions palette/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,17 @@
//! }
//! }
//!
//! fn main() {
//! // Start with an Xyz100 color.
//! let xyz = Xyz100 {
//! x: 59,
//! y: 75,
//! z: 42,
//! };
//! // Start with an Xyz100 color.
//! let xyz = Xyz100 {
//! x: 59,
//! y: 75,
//! z: 42,
//! };
//!
//! // Convert the color to sRGB.
//! let rgb: Srgb = xyz.into_color();
//! // Convert the color to sRGB.
//! let rgb: Srgb = xyz.into_color();
//!
//! assert_eq!(rgb.into_format(), Srgb::new(196u8, 238, 154));
//! }
//! assert_eq!(rgb.into_format(), Srgb::new(196u8, 238, 154));
//! ```
//!
//! With generic components:
Expand Down
3 changes: 2 additions & 1 deletion palette/src/convert/from_into_color_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ where
///
/// This reuses the memory space, and the returned scope guard will restore
/// the converted colors to their original type when it's dropped.
#[allow(clippy::wrong_self_convention)]
#[must_use]
fn into_color_mut(&mut self) -> FromColorMutGuard<T, Self>;
}
Expand Down Expand Up @@ -308,7 +309,7 @@ where
.and_then(|mut guard| guard.current.take());

if let Some(restored) = restored {
return restored;
restored
} else {
unreachable!()
}
Expand Down
1 change: 1 addition & 0 deletions palette/src/convert/from_into_color_unclamped_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ where
///
/// This reuses the memory space, and the returned scope guard will restore
/// the converted colors to their original type when it's dropped.
#[allow(clippy::wrong_self_convention)]
#[must_use]
fn into_color_unclamped_mut(&mut self) -> FromColorUnclampedMutGuard<T, Self>;
}
Expand Down
2 changes: 0 additions & 2 deletions palette/src/convert/try_from_into_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub trait TryFromColor<T>: Sized {
/// }
/// };
/// ```
#[must_use]
fn try_from_color(t: T) -> Result<Self, OutOfBounds<Self>>;
}

Expand Down Expand Up @@ -105,7 +104,6 @@ pub trait TryIntoColor<T>: Sized {
/// }
/// };
/// ```
#[must_use]
fn try_into_color(self) -> Result<T, OutOfBounds<T>>;
}

Expand Down
Loading
Loading