Skip to content

Commit

Permalink
Public api test
Browse files Browse the repository at this point in the history
  • Loading branch information
WieslerAA committed May 10, 2024
1 parent c000481 commit 0ad4cea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ tokio = { version = "1.24.1", features = ["rt", "macros"] }
axum = { version = "0.7.4", features = ["macros"] }
async-trait = "0.1"
actix-web = "4.2.1"
rustup-toolchain = "0.1.6"
rustdoc-json = "0.9.0"
public-api = "0.33.1"
expect-test = "1.5.0"

# MSRV PINS
#
Expand Down
29 changes: 29 additions & 0 deletions tests/public_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[test]
fn public_api() {
// Install a compatible nightly toolchain if it is missing
rustup_toolchain::install(public_api::MINIMUM_NIGHTLY_RUST_VERSION).unwrap();

// Build rustdoc JSON
let rustdoc_json = rustdoc_json::Builder::default()
.toolchain(public_api::MINIMUM_NIGHTLY_RUST_VERSION)
.features(["runtime-tokio-hyper"])
.build()
.unwrap();

// Derive the public API from the rustdoc JSON
let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json)
.omit_auto_derived_impls(true)
.omit_blanket_impls(true)
.build()
.unwrap();

// Assert that the public API looks correct
let content = expect_test::expect_file!["public-api.txt"].data();

Check warning on line 21 in tests/public_api.rs

View workflow job for this annotation

GitHub Actions / format

Diff in /home/runner/work/async-stripe/async-stripe/tests/public_api.rs
// We do not use assert_eq here since it prints waaaay too much
if &content != &public_api.to_string() {
panic!(r#"Error: The API changed.
Use the following command if you want to commit these changes:
UPDATE_EXPECT=1 cargo test --features runtime-tokio-hyper"#);
}
}

0 comments on commit 0ad4cea

Please sign in to comment.