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

Set MSRV to 1.70 #34

Merged
merged 9 commits into from
Mar 4, 2024
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
31 changes: 31 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,34 @@ jobs:
with:
command: test
args: --release --color=always

msrv:
name: Build an test with MSRV (1.65.0)
runs-on: ubuntu-latest
steps:
- name: Restore cached crates.io index
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo
- name: Checkout code
uses: actions/checkout@master
- name: Install MSRV toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.65.0
override: true
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --all-features --color=always
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --release --color=always

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
main:
* Fix support for Rust 1.65.

v0.3.13 - 2024-02-18:
* Suppress highlighting when diff contains consecutive changed lines.
* Make suppression of highlighting based on number of non-highlighted characters more conservative.
Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ name = "assert2"
description = "assert!(...) and check!(...) macros inspired by Catch2, now with diffs!"
version = "0.3.13"
license = "BSD-2-Clause"
authors = [
"Maarten de Vries <[email protected]>",
"Mara Bos <[email protected]>",
]
authors = ["Maarten de Vries <[email protected]>", "Mara Bos <[email protected]>"]

rust-version = "1.65"
edition = "2021"
Expand Down
33 changes: 32 additions & 1 deletion src/__assert2_impl/print/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Highlighter {
/// Write the data using the highlight ranges.
fn write_highlighted(&self, buffer: &mut String, data: &str) {
let not_highlighted = data.len() - self.total_highlighted;
if not_highlighted < self.total_highlighted.div_ceil(2) {
if not_highlighted < div_ceil(self.total_highlighted, 2) {
write!(buffer, "{}", self.normal.paint(data)).unwrap();
} else {
for (highlight, range) in self.ranges.iter().cloned() {
Expand All @@ -261,3 +261,34 @@ impl Highlighter {
}
}
}

fn div_ceil(a: usize, b: usize) -> usize {
if b == 0 {
a / b
} else {
let d = a / b;
let r = a % b;
if r > 0 {
d + 1
} else {
d
}
}
}

#[test]
fn test_div_ceil() {
use crate::assert;
assert!(div_ceil(0, 2) == 0);
assert!(div_ceil(1, 2) == 1);
assert!(div_ceil(2, 2) == 1);
assert!(div_ceil(3, 2) == 2);
assert!(div_ceil(4, 2) == 2);

assert!(div_ceil(20, 7) == 3);
assert!(div_ceil(21, 7) == 3);
assert!(div_ceil(22, 7) == 4);
assert!(div_ceil(27, 7) == 4);
assert!(div_ceil(28, 7) == 4);
assert!(div_ceil(29, 7) == 5);
}
4 changes: 2 additions & 2 deletions src/__assert2_impl/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use yansi::Paint;
use std::fmt::Write;

mod diff;
use diff::{MultiLineDiff, SingleLineDiff};
use self::diff::{MultiLineDiff, SingleLineDiff};

mod options;
use options::{AssertOptions, ExpansionFormat};
use self::options::{AssertOptions, ExpansionFormat};

pub struct FailedCheck<'a, T> {
pub macro_name: &'a str,
Expand Down
17 changes: 7 additions & 10 deletions src/__assert2_impl/print/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl AssertOptions {
yansi::Paint::disable()
}
return *style;
},
}
}
}
}
Expand All @@ -58,9 +58,7 @@ impl AssertOptions {
fn from_env() -> Self {
// If there is no valid `ASSERT2` environment variable, default to an empty string.
let format = std::env::var_os("ASSERT2");
let format = format.as_ref()
.and_then(|x| x.to_str())
.unwrap_or("");
let format = format.as_ref().and_then(|x| x.to_str()).unwrap_or("");

// Start with the defaults.
let mut output = Self {
Expand Down Expand Up @@ -117,8 +115,8 @@ impl ExpansionFormat {
pub fn expand_all<const N: usize>(self, values: [&dyn std::fmt::Debug; N]) -> [String; N] {
if !self.force_pretty() {
let expanded = values.map(|x| format!("{x:?}"));
if self.force_compact() || Self::is_compact_good(&expanded) {
return expanded
if self.force_compact() || Self::is_compact_good(&expanded) {
return expanded;
}
}
values.map(|x| format!("{x:#?}"))
Expand All @@ -138,7 +136,6 @@ impl ExpansionFormat {
}
true
}

}

/// Check if the clicolors spec thinks we should use colors.
Expand All @@ -159,11 +156,11 @@ fn should_color() -> bool {
}

#[allow(clippy::if_same_then_else)] // shut up clippy
if std::env::var_os("NO_COLOR").is_some_and(is_true) {
if std::env::var_os("NO_COLOR").map(is_true).unwrap_or_default() {
false
} else if std::env::var_os("CLICOLOR").is_some_and(is_false) {
} else if std::env::var_os("CLICOLOR").map(is_false).unwrap_or_default() {
false
} else if std::env::var_os("CLICOLOR_FORCE").is_some_and(is_true) {
} else if std::env::var_os("CLICOLOR_FORCE").map(is_true).unwrap_or_default() {
true
} else {
use is_terminal::IsTerminal;
Expand Down
Loading