Skip to content

Commit

Permalink
Merge branch 'kevinmehall:master' into patch-unstable-vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
stevefan1999-personal committed Aug 24, 2023
2 parents a5b344c + c870876 commit 97995b5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ env:

jobs:
build:
name: Rust ${{matrix.rust}}
strategy:
fail-fast: false
matrix:
rust: [stable, 1.68.0]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
components: rustfmt
- name: Check bootstrap
run: ./bootstrap.sh && git diff --exit-code
- name: Run tests
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ keywords = ["peg", "parser", "parsing", "grammar"]
categories = ["parsing"]
readme = "README.md"
edition = "2018"
rust-version = "1.68.0" # if changed, also update .github/workflows/rust.yml

[dependencies]
peg-macros = { path = "./peg-macros", version = "= 0.8.1" }
Expand All @@ -22,6 +23,7 @@ arrayvec = "0.7.2"
assert_matches = "1.5.0"
smallvec = "1.10.0"
trybuild = "1.0.80"
version_check = "0.9"

[[test]]
name = "trybuild"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ pub fn main() {
[annotate-snippets]: https://crates.io/crates/annotate-snippets
[codespan-reporting]: https://crates.io/crates/codespan-reporting
[codemap-diagnostic]: https://crates.io/crates/codemap-diagnostic

## Development

The `rust-peg` grammar is written in `rust-peg`: `peg-macros/grammar.rustpeg`. To avoid the circular dependency, a precompiled grammar is checked in as `peg-macros/grammar.rs`. To regenerate this, run the `./bootstrap.sh` script.

There is a large test suite which uses [`trybuild`](https://crates.io/crates/trybuild) to support testing for compilation failure errors.
There is a large test suite which uses [`trybuild`](https://crates.io/crates/trybuild) to test both functionality (`tests/run-pass`) and error messages for incorrect grammars (`tests/compile-fail`). Because `rustc` error messages change, the `compile-fail` tests are only run on the minimum supported Rust version to avoid spurious failures.

Use `cargo test` to run the entire suite,
or `cargo test -- trybuild trybuild=lifetimes.rs` to test just the indicated file.
Add `--features trace` to trace these tests.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
//! ### Repeat ranges
//!
//! The repeat operators `*` and `**` can be followed by an optional range specification of the
//! form `<n>` (exact), `<n,>` (min), `<,m>` (max) or `<n,m>` (range), where `n` and `m` are either
//! form `<n>` (exact), `<n,>` (min-inclusive), `<,m>` (max-inclusive) or `<n,m>` (range-inclusive), where `n` and `m` are either
//! integers, or a Rust `usize` expression enclosed in `{}`.
//!
//! ### Precedence climbing
Expand Down
30 changes: 18 additions & 12 deletions tests/trybuild.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
extern crate trybuild;

fn main() {
let args: Vec<_> = std::env::args().collect();
let t = trybuild::TestCases::new();

let rust_ver = option_env!("TRAVIS_RUST_VERSION");
if rust_ver.is_none() {
println!(
"Note: compile-fail tests are normally only tested on the stable rust compiler in CI."
);
}
t.pass("tests/run-pass/*.rs");

let expected_rust_ver = env!("CARGO_PKG_RUST_VERSION");
let run_anyway = args.iter().any(|a| a == "--compile-fail");

if rust_ver.is_none() || rust_ver == Some("stable") {
let run_compile_fail = run_anyway || version_check::is_exact_version(expected_rust_ver).unwrap_or(true);
if run_compile_fail {
t.compile_fail("tests/compile-fail/*.rs");
} else {
println!("Skipping compile-fail tests.");
}

t.pass("tests/run-pass/*.rs");
// Trybuild runs the configured tests on drop
drop(t);

if !run_compile_fail {
eprintln!("!!! Skipped compile-fail tests !!!");
eprintln!("These tests are only checked on rust version {expected_rust_ver} because");
eprintln!("the error message text may change between compiler versions.");
eprintln!("");
eprintln!("Run `cargo +{expected_rust_ver} test` to run these tests.");
eprintln!("");
}
}

0 comments on commit 97995b5

Please sign in to comment.