Skip to content

Commit

Permalink
Merge pull request #95 from Jules-Bertholet/bench-fuzz-ci
Browse files Browse the repository at this point in the history
Check benches and fuzz tests in CI
  • Loading branch information
Manishearth committed Mar 4, 2024
2 parents a6a221a + 2d713ab commit c49e96f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
- name: Build
run: cargo build --verbose
- name: Run tests with all features
Expand All @@ -49,7 +50,18 @@ jobs:
run: cargo fmt --all --check
- name: Check clippy
if: matrix.rust == 'stable'
run: cargo clippy --all-features --all --verbose
run: cargo clippy --all-features --lib --tests --examples --verbose
- name: Check benchmarks with clippy
if: matrix.rust == 'nightly'
run: cargo clippy --all-features --benches --verbose
- name: Check fuzz tests with clippy
if: matrix.rust == 'stable'
working-directory: fuzz
run: cargo clippy --all-features --all-targets --verbose
- name: Check fuzz tests formatting
if: matrix.rust == 'stable'
working-directory: fuzz
run: cargo fmt --all --check
msrv:
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 3 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::fs;
use test::Bencher;
use unicode_normalization::UnicodeNormalization;

const ASCII: &'static str = "all types of normalized";
const NFC: &'static str = "Introducci\u{00f3}n a Unicode.pdf";
const NFD: &'static str = "Introduccio\u{0301}n a Unicode.pdf";
const ASCII: &str = "all types of normalized";
const NFC: &str = "Introducci\u{00f3}n a Unicode.pdf";
const NFD: &str = "Introduccio\u{0301}n a Unicode.pdf";

#[bench]
fn bench_is_nfc_ascii(b: &mut Bencher) {
Expand Down
9 changes: 6 additions & 3 deletions fuzz/fuzz_targets/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#[macro_use]
extern crate libfuzzer_sys;

use std::str::Chars;
use std::cell::RefCell;
use std::rc::Rc;
use std::str::Chars;
use unicode_normalization::{char::canonical_combining_class, UnicodeNormalization};

const MAX_NONSTARTERS: u32 = 30;
Expand Down Expand Up @@ -43,8 +43,11 @@ impl<'a> Iterator for Counter<'a> {
fuzz_target!(|input: String| {
let stream_safe = input.chars().stream_safe().collect::<String>();

let mut value = Rc::new(RefCell::new(0));
let counter = Counter { iter: stream_safe.chars(), value: Rc::clone(&mut value) };
let value = Rc::new(RefCell::new(0));
let counter = Counter {
iter: stream_safe.chars(),
value: Rc::clone(&value),
};
for _ in counter.nfc() {
// Plus 1: The iterator may consume a starter that begins the next sequence.
assert!(*value.borrow() <= MAX_NONSTARTERS + 1);
Expand Down

0 comments on commit c49e96f

Please sign in to comment.