diff --git a/Cargo.toml b/Cargo.toml index f552fca5a..1c7d267f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 # diff --git a/tests/public_api.rs b/tests/public_api.rs new file mode 100644 index 000000000..cf149d01c --- /dev/null +++ b/tests/public_api.rs @@ -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(); + // 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"#); + } +} \ No newline at end of file