From a3d2e47b84ca1d9243a873e7c4e977ea5cdd63a7 Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Sat, 10 Jun 2023 15:56:21 -0600 Subject: [PATCH 1/2] Run compile-fail tests only on designated version --- .github/workflows/rust.yml | 11 ++++++++++- Cargo.lock | 7 +++++++ Cargo.toml | 2 ++ README.md | 4 +++- tests/trybuild.rs | 30 ++++++++++++++++++------------ 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6feb105..2687d66 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 diff --git a/Cargo.lock b/Cargo.lock index bbf5526..ce921b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,7 @@ dependencies = [ "peg-macros", "peg-runtime", "trybuild", + "version_check", ] [[package]] @@ -144,6 +145,12 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 25302c4..88bdcaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } @@ -19,6 +20,7 @@ peg-runtime = { path = "./peg-runtime", version = "= 0.8.1" } [dev-dependencies] trybuild = "1.0.80" +version_check = "0.9" [[test]] name = "trybuild" diff --git a/README.md b/README.md index 15e1944..5ab36ac 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/tests/trybuild.rs b/tests/trybuild.rs index 0ee62a0..541fcba 100644 --- a/tests/trybuild.rs +++ b/tests/trybuild.rs @@ -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!(""); + } } From 676f0218ba39426a61af6e32b2f776d7252f62ee Mon Sep 17 00:00:00 2001 From: Flamenco Date: Wed, 5 Jul 2023 15:58:01 -0400 Subject: [PATCH 2/2] Update lib.rs Mention that range specifier is inclusive --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a1a9792..2405f11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -151,7 +151,7 @@ //! ### Repeat ranges //! //! The repeat operators `*` and `**` can be followed by an optional range specification of the -//! form `` (exact), `` (min), `<,m>` (max) or `` (range), where `n` and `m` are either +//! form `` (exact), `` (min-inclusive), `<,m>` (max-inclusive) or `` (range-inclusive), where `n` and `m` are either //! integers, or a Rust `usize` expression enclosed in `{}`. //! //! ### Precedence climbing