From 17bded576fa3605f55375f02f12b292cc8ed05ef Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:20:35 +0100 Subject: [PATCH] Run tests in CI. (#148) It doesn't matter too much when I'm the only one contributing code, but that's quickly changing! --- .github/workflows/docs.yml | 36 ++++++++++++ .../cookbook/project/Cargo.lock | 21 +++---- .../buffered_body/project/Cargo.lock | 21 +++---- .../request_data/json/project/Cargo.lock | 21 +++---- .../request_data/path/project/Cargo.lock | 21 +++---- .../request_data/query/project/Cargo.lock | 21 +++---- .../query_params/project/Cargo.lock | 21 +++---- .../request_target/project/Cargo.lock | 21 +++---- .../route_params/project/Cargo.lock | 21 +++---- doc_examples/quickstart/05-error.snap | 2 +- doc_examples/quickstart/07-error.snap | 2 +- doc_examples/quickstart/demo-bp_binary.snap | 7 ++- libs/Cargo.lock | 21 +++---- libs/pavex_cli/tests/ui_tests.rs | 14 ++++- libs/pavex_cli_client/Cargo.toml | 3 +- .../pavex_cli_client/src/commands/generate.rs | 57 ++++++++++++++++--- libs/pavex_test_runner/src/lib.rs | 37 ++++++------ .../template/{{crate_name}}/src/bin/bp.rs | 7 ++- 18 files changed, 230 insertions(+), 124 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d92ce6d4d..34a79022b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -53,6 +53,42 @@ jobs: name: tutorial_generator path: doc_examples/tutorial_generator/target/debug/tutorial_generator + tests: + runs-on: ubuntu-latest + needs: + - build_pavex_cli + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust stable toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1.6.0 + with: + rustflags: "" + - name: Install Rust nightly toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: nightly + components: rust-docs-json + rustflags: "" + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + with: + workspaces: "./libs -> ./target" + key: "tests" + - name: Download pavex CLI artifact + uses: actions/download-artifact@v4 + with: + name: pavex_cli + path: ~/.cargo/bin + - name: Mark as executable + run: chmod +x ~/.cargo/bin/pavex + - name: Run tests + run: | + cd libs + cargo test --no-run + cargo test --workspace --exclude="pavex_cli" + PAVEX_TEST_CLI_PATH="pavex" cargo test --package pavex_cli + is_up_to_date: runs-on: ubuntu-latest needs: diff --git a/doc_examples/guide/dependency_injection/cookbook/project/Cargo.lock b/doc_examples/guide/dependency_injection/cookbook/project/Cargo.lock index 30ac35319..4a18b5bc0 100644 --- a/doc_examples/guide/dependency_injection/cookbook/project/Cargo.lock +++ b/doc_examples/guide/dependency_injection/cookbook/project/Cargo.lock @@ -424,6 +424,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -455,18 +456,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -576,9 +577,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -587,18 +588,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/guide/request_data/buffered_body/project/Cargo.lock b/doc_examples/guide/request_data/buffered_body/project/Cargo.lock index 612c727fa..3f495f721 100644 --- a/doc_examples/guide/request_data/buffered_body/project/Cargo.lock +++ b/doc_examples/guide/request_data/buffered_body/project/Cargo.lock @@ -425,6 +425,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -456,18 +457,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -577,9 +578,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -588,18 +589,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/guide/request_data/json/project/Cargo.lock b/doc_examples/guide/request_data/json/project/Cargo.lock index a4fcaa780..fe6a87442 100644 --- a/doc_examples/guide/request_data/json/project/Cargo.lock +++ b/doc_examples/guide/request_data/json/project/Cargo.lock @@ -425,6 +425,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -456,18 +457,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -577,9 +578,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -588,18 +589,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/guide/request_data/path/project/Cargo.lock b/doc_examples/guide/request_data/path/project/Cargo.lock index 5e096317a..054998fa7 100644 --- a/doc_examples/guide/request_data/path/project/Cargo.lock +++ b/doc_examples/guide/request_data/path/project/Cargo.lock @@ -425,6 +425,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -456,18 +457,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -577,9 +578,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -588,18 +589,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/guide/request_data/query/project/Cargo.lock b/doc_examples/guide/request_data/query/project/Cargo.lock index 671814c46..527d96fd0 100644 --- a/doc_examples/guide/request_data/query/project/Cargo.lock +++ b/doc_examples/guide/request_data/query/project/Cargo.lock @@ -403,6 +403,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -434,9 +435,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -465,9 +466,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -577,9 +578,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -588,18 +589,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/guide/request_data/query_params/project/Cargo.lock b/doc_examples/guide/request_data/query_params/project/Cargo.lock index 9eb45e8e8..5295887d8 100644 --- a/doc_examples/guide/request_data/query_params/project/Cargo.lock +++ b/doc_examples/guide/request_data/query_params/project/Cargo.lock @@ -403,6 +403,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -434,9 +435,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -465,9 +466,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -577,9 +578,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -588,18 +589,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/guide/request_data/request_target/project/Cargo.lock b/doc_examples/guide/request_data/request_target/project/Cargo.lock index 0093eca7b..560bbd053 100644 --- a/doc_examples/guide/request_data/request_target/project/Cargo.lock +++ b/doc_examples/guide/request_data/request_target/project/Cargo.lock @@ -403,6 +403,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -434,18 +435,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -555,9 +556,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -587,18 +588,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/guide/request_data/route_params/project/Cargo.lock b/doc_examples/guide/request_data/route_params/project/Cargo.lock index 809a84584..633d1adbf 100644 --- a/doc_examples/guide/request_data/route_params/project/Cargo.lock +++ b/doc_examples/guide/request_data/route_params/project/Cargo.lock @@ -403,6 +403,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -434,18 +435,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -577,9 +578,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.42" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d0a2c048d661a1a59fcd7355baa232f7ed34e0ee4df2eef3c1c1c0d3852d8" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -588,18 +589,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/doc_examples/quickstart/05-error.snap b/doc_examples/quickstart/05-error.snap index ac1b53ccd..e671825c2 100644 --- a/doc_examples/quickstart/05-error.snap +++ b/doc_examples/quickstart/05-error.snap @@ -19,5 +19,5 @@ │ ╰──── │  help: Register a constructor for `demo::user_agent::UserAgent` -Error: `pavex_cli` exited with a non-zero status code: 1 +The invocation of `pavex_cli` exited with a non-zero status code: 1 error: Failed to run `bp`, the code generator for package `demo_server_sdk` diff --git a/doc_examples/quickstart/07-error.snap b/doc_examples/quickstart/07-error.snap index 0570d6ad1..e60fdd034 100644 --- a/doc_examples/quickstart/07-error.snap +++ b/doc_examples/quickstart/07-error.snap @@ -12,5 +12,5 @@ │ ╰──── │  help: Add an error handler via `.error_handler` -Error: `pavex_cli` exited with a non-zero status code: 1 +The invocation of `pavex_cli` exited with a non-zero status code: 1 error: Failed to run `bp`, the code generator for package `demo_server_sdk` diff --git a/doc_examples/quickstart/demo-bp_binary.snap b/doc_examples/quickstart/demo-bp_binary.snap index f249f7534..b2dcc40f8 100644 --- a/doc_examples/quickstart/demo-bp_binary.snap +++ b/doc_examples/quickstart/demo-bp_binary.snap @@ -11,9 +11,10 @@ use std::error::Error; /// the application. fn main() -> Result<(), Box> { let generated_dir = generated_pkg_manifest_path()?.parent().unwrap().into(); - Client::new() - .generate(blueprint(), generated_dir) - .execute()?; + if let Err(e) = Client::new().generate(blueprint(), generated_dir).execute() { + eprintln!("{e}"); + std::process::exit(1); + } Ok(()) } ``` \ No newline at end of file diff --git a/libs/Cargo.lock b/libs/Cargo.lock index 90f05f046..3b36350d3 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -2101,6 +2101,7 @@ version = "0.1.0" dependencies = [ "anyhow", "pavex", + "thiserror", ] [[package]] @@ -2319,9 +2320,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.72" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a293318316cf6478ec1ad2a21c49390a8d5b5eae9fab736467d93fbc0edc29c5" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -2343,9 +2344,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2943,9 +2944,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.43" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -3067,18 +3068,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2cd5904763bad08ad5513ddbb12cf2ae273ca53fa9f68e843e236ec6dfccc09" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.53" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcf4a824cce0aeacd6f38ae6f24234c8e80d68632338ebaa1443b5df9e29e19" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", diff --git a/libs/pavex_cli/tests/ui_tests.rs b/libs/pavex_cli/tests/ui_tests.rs index a87158a0d..ad0aefc5a 100644 --- a/libs/pavex_cli/tests/ui_tests.rs +++ b/libs/pavex_cli/tests/ui_tests.rs @@ -6,5 +6,17 @@ fn main() -> Result<(), Box> { let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap(); let test_data_folder = manifest_dir.join("tests").join("ui_tests"); let test_runtime_folder = manifest_dir.parent().unwrap().join("ui_test_envs"); - run_tests(test_data_folder, test_runtime_folder)?.exit(); + let cli_path = get_cli_path()?; + run_tests(cli_path, test_data_folder, test_runtime_folder)?.exit(); +} + +fn get_cli_path() -> Result> { + if let Ok(path) = std::env::var("PAVEX_TEST_CLI_PATH") { + return Ok(PathBuf::from_str(&path)?); + } + + let profile = std::env::var("PAVEX_TEST_CLI_PROFILE").unwrap_or("debug".to_string()); + let manifest_dir = PathBuf::from_str(env!("CARGO_MANIFEST_DIR"))?; + let target_dir = manifest_dir.parent().unwrap().join("target"); + Ok(target_dir.join(profile).join("pavex")) } diff --git a/libs/pavex_cli_client/Cargo.toml b/libs/pavex_cli_client/Cargo.toml index c53cfe4ae..9882ae526 100644 --- a/libs/pavex_cli_client/Cargo.toml +++ b/libs/pavex_cli_client/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] anyhow = "1" -pavex = { path = "../pavex" } \ No newline at end of file +pavex = { path = "../pavex" } +thiserror = "1.0.56" \ No newline at end of file diff --git a/libs/pavex_cli_client/src/commands/generate.rs b/libs/pavex_cli_client/src/commands/generate.rs index c3dc33291..5fd104114 100644 --- a/libs/pavex_cli_client/src/commands/generate.rs +++ b/libs/pavex_cli_client/src/commands/generate.rs @@ -1,7 +1,5 @@ use std::{path::PathBuf, process::Command}; -use anyhow::Context; - use pavex::blueprint::Blueprint; /// The configuration for `pavex`'s `generate` command. @@ -32,16 +30,19 @@ impl GenerateBuilder { /// It won't return until `pavex` has finished running. /// /// If `pavex` exits with a non-zero status code, this will return an error. - pub fn execute(self) -> Result<(), anyhow::Error> { - let mut cmd = self.command()?; + pub fn execute(self) -> Result<(), GenerateError> { + let mut cmd = self + .command() + .map_err(GenerateError::BlueprintPersistenceError)?; let status = cmd .status() - .context("Failed to invoke `pavex_cli [...] generate [...]`")?; + .map_err(InvocationError) + .map_err(GenerateError::InvocationError)?; if !status.success() { if let Some(code) = status.code() { - anyhow::bail!("`pavex_cli` exited with a non-zero status code: {}", code); + return Err(GenerateError::NonZeroExitCode(NonZeroExitCode { code })); } else { - anyhow::bail!("`pavex_cli` was terminated by a signal"); + return Err(GenerateError::SignalTermination(SignalTermination {})); } } Ok(()) @@ -53,10 +54,12 @@ impl GenerateBuilder { /// /// This method can be useful if you need to customize the command before running it. /// If that's not your usecase, consider using [`GenerateBuilder::execute`] instead. - pub fn command(mut self) -> Result { + pub fn command(mut self) -> Result { // TODO: Pass the blueprint via `stdin` instead of writing it to a file. let bp_path = self.output_directory.join("blueprint.ron"); - self.blueprint.persist(&bp_path)?; + self.blueprint + .persist(&bp_path) + .map_err(|source| BlueprintPersistenceError { source })?; self.cmd .arg("generate") @@ -84,3 +87,39 @@ impl GenerateBuilder { self } } + +#[derive(Debug, thiserror::Error)] +#[non_exhaustive] +pub enum GenerateError { + #[error(transparent)] + InvocationError(InvocationError), + #[error(transparent)] + SignalTermination(SignalTermination), + #[error(transparent)] + NonZeroExitCode(NonZeroExitCode), + #[error(transparent)] + BlueprintPersistenceError(BlueprintPersistenceError), +} + +#[derive(Debug, thiserror::Error)] +#[error("Failed to invoke `pavex_cli [...] generate [...]`")] +pub struct InvocationError(#[source] std::io::Error); + +#[derive(Debug, thiserror::Error)] +#[non_exhaustive] +#[error("The invocation of `pavex_cli` was terminated by a signal")] +pub struct SignalTermination {} + +#[derive(Debug, thiserror::Error)] +#[non_exhaustive] +#[error("The invocation of `pavex_cli` exited with a non-zero status code: {code}")] +pub struct NonZeroExitCode { + pub code: i32, +} + +#[derive(Debug, thiserror::Error)] +#[error("Failed to persist the blueprint to a file")] +pub struct BlueprintPersistenceError { + #[source] + source: anyhow::Error, +} diff --git a/libs/pavex_test_runner/src/lib.rs b/libs/pavex_test_runner/src/lib.rs index 61a2a7b88..dd227d0a4 100644 --- a/libs/pavex_test_runner/src/lib.rs +++ b/libs/pavex_test_runner/src/lib.rs @@ -57,12 +57,12 @@ pub fn get_test_name(ui_tests_folder: &Path, ui_test_folder: &Path) -> String { /// Our custom test runner is built on top of `libtest_mimic`, which gives us /// [compatibility out-of-the-box](https://nexte.st/book/custom-test-harnesses.html) with `cargo-nextest`. pub fn run_tests( + cli_path: PathBuf, definition_directory: PathBuf, runtime_directory: PathBuf, ) -> Result { let arguments = libtest_mimic::Arguments::from_args(); - let cli_profile = std::env::var("PAVEX_TEST_CLI_PROFILE").unwrap_or("debug".to_string()); let target_directory_pool = TargetDirectoryPool::new(None, &runtime_directory); let mut tests = Vec::new(); @@ -77,10 +77,10 @@ pub fn run_tests( .load_configuration() .expect("Failed to load test configuration"); let is_ignored = test_configuration.ignore; - let profile = cli_profile.clone(); + let cli = cli_path.clone(); let pool = target_directory_pool.clone(); let test = libtest_mimic::Trial::test(name.clone(), move || { - run_test(test_data, test_configuration, profile, pool) + run_test(test_data, test_configuration, cli, pool) }) .with_ignored_flag(is_ignored); tests.push(test); @@ -211,7 +211,7 @@ impl TestData { fn seed_test_filesystem( &self, test_config: &TestConfig, - cli_profile: &str, + cli: &Path, target_dir: &Path, ) -> Result { Self::remove_target_junk(target_dir).context("Failed to clean up target directory")?; @@ -384,12 +384,9 @@ impl TestData { toml::to_string(&cargo_toml)?.as_bytes(), )?; - // - Use sccache to avoid rebuilding the same dependencies - // over and over again. // - Use the new sparse registry to speed up registry operations. let mut cargo_config = toml! { [build] - rustc-wrapper = "sccache" incremental = false [registries.crates-io] @@ -409,19 +406,27 @@ impl TestData { let main_rs = format!( r#"use app::blueprint; use pavex_cli_client::{{Client, client::Color}}; +use pavex_cli_client::commands::generate::GenerateError; fn main() -> Result<(), Box> {{ - if Client::new() + let outcome = Client::new() .color(Color::Always) - .pavex_cli_path("../../../../../libs/target/{cli_profile}/pavex".into()) + .pavex_cli_path("{}".into()) .generate(blueprint(), "generated_app".into()) .diagnostics_path("diagnostics.dot".into()) - .execute().is_err() {{ - std::process::exit(1); + .execute(); + match outcome {{ + Ok(_) => {{}}, + Err(GenerateError::NonZeroExitCode(_)) => {{ std::process::exit(1); }} + Err(e) => {{ + eprintln!("Failed to invoke `pavex generate`.\n{{:?}}", e); + std::process::exit(1); + }} }} Ok(()) }} -"# +"#, + cli.to_str().unwrap() ); persist_if_changed(&source_directory.join("main.rs"), main_rs.as_bytes())?; Ok(if has_tests { @@ -467,10 +472,10 @@ enum ShouldRunTests { fn run_test( test: TestData, config: TestConfig, - cli_profile: String, + cli: PathBuf, target_dir_pool: TargetDirectoryPool, ) -> Result<(), Failed> { - match _run_test(&config, &test, &cli_profile, &target_dir_pool) { + match _run_test(&config, &test, &cli, &target_dir_pool) { Ok(TestOutcome { outcome: Err(mut msg), codegen_output, @@ -514,12 +519,12 @@ fn run_test( fn _run_test( test_config: &TestConfig, test: &TestData, - cli_profile: &str, + cli: &Path, target_dir_pool: &TargetDirectoryPool, ) -> Result { let target_dir = target_dir_pool.pull(); let should_run_tests = test - .seed_test_filesystem(test_config, cli_profile, &target_dir) + .seed_test_filesystem(test_config, cli, &target_dir) .context("Failed to seed the filesystem for the test runtime folder")?; let output = std::process::Command::new("cargo") diff --git a/template/template/{{crate_name}}/src/bin/bp.rs b/template/template/{{crate_name}}/src/bin/bp.rs index 677e4b0d4..05227a3b3 100644 --- a/template/template/{{crate_name}}/src/bin/bp.rs +++ b/template/template/{{crate_name}}/src/bin/bp.rs @@ -10,8 +10,11 @@ use std::error::Error; /// the application. fn main() -> Result<(), Box> { let generated_dir = generated_pkg_manifest_path()?.parent().unwrap().into(); - Client::new() + if let Err(e) = Client::new() .generate(blueprint(), generated_dir) - .execute()?; + .execute() { + eprintln!("{e}"); + std::process::exit(1); + } Ok(()) }