#![forbid(unsafe_code)]
#[path = "documentation_examples_tests/example_validation.rs"]
mod example_validation;
#[path = "documentation_examples_tests/links.rs"]
mod links;
#[path = "common/repo_access.rs"]
mod repo_access;
#[path = "documentation_examples_tests/shell_commands.rs"]
mod shell_commands;
#[path = "common/tested_examples.rs"]
mod tested_examples;
use std::collections::BTreeSet;
use repo_access::read_repo_file;
use tested_examples::{TestedExample, load_documents};
const DOCUMENTS: &[&str] = &[
"README.md",
"docs/users-guide.md",
"docs/v0-4-0-migration-guide.md",
];
const DOCUMENTED_RELEASE: &str = env!("CARGO_PKG_VERSION");
const CARGO_MANIFEST: &str = include_str!("../Cargo.toml");
const EXPECTED_EXAMPLE_IDS: &[&str] = &[
"guide-allocator",
"guide-client-call-streaming",
"guide-client-connect",
"guide-client-correlation",
"guide-client-error-mapping",
"guide-client-hooks",
"guide-client-lifecycle",
"guide-client-pool",
"guide-client-preamble",
"guide-client-send-streaming",
"guide-client-tracing",
"guide-client-typed-with",
"guide-connection-actor",
"guide-const-client",
"guide-const-config",
"guide-const-push-builder",
"guide-custom-envelope",
"guide-decode-eof",
"guide-dependencies",
"guide-first-server",
"guide-fragmentation-config",
"guide-fragmenter",
"guide-frame-codec",
"guide-lifecycle-hooks",
"guide-memory-budgets",
"guide-message-assembler",
"guide-message-assembly-state",
"guide-message-series",
"guide-middleware-from-fn",
"guide-middleware-transform",
"guide-middleware-versions",
"guide-prepared-app",
"guide-prometheus-dependency",
"guide-prometheus-recorder",
"guide-protocol-hooks",
"guide-push-queues",
"guide-recovery-hook",
"guide-request-body",
"guide-request-journey",
"guide-response-channel",
"guide-response-route",
"guide-response-route-stream",
"guide-response-stream",
"guide-routes",
"guide-run-client-example",
"guide-send-response",
"guide-server-configuration",
"guide-server-preamble",
"guide-server-push",
"guide-session-registry",
"guide-shared-state",
"guide-streaming-request-handler",
"guide-testing-dependencies",
"guide-testing-fixtures",
"guide-testing-observability",
"guide-testing-pair",
"guide-testing-partial-frames",
"guide-testing-reassembly",
"guide-testing-slow-io",
"guide-tracing-subscriber",
"migration-assembly-error-match",
"migration-before-send-order",
"migration-client-error-match",
"migration-copied-bytes-after",
"migration-copied-bytes-before",
"migration-dependencies",
"migration-extractors-after",
"migration-extractors-before",
"migration-fragmentation-config",
"migration-message-assembler-after",
"migration-message-assembler-before",
"migration-observability-dependencies",
"migration-pool-closed",
"migration-preamble-timeout",
"migration-prepared-app",
"migration-prepared-test-drivers",
"migration-protocol-error",
"migration-protocol-hooks-after",
"migration-protocol-hooks-before",
"migration-reassembler-new",
"migration-server-from-app",
"migration-server-lifecycle-harness",
"migration-streaming-request-route",
"readme-dependencies",
"readme-first-server",
"readme-new-project",
"readme-run-echo-client",
"readme-run-echo-server",
"readme-run-first-server",
];
fn read_document(path: &str) -> String {
read_repo_file(path).expect("a documented file should be readable")
}
fn load_documented_examples() -> Vec<TestedExample> {
let contents: Vec<_> = DOCUMENTS
.iter()
.map(|path| (*path, read_document(path)))
.collect();
let documents: Vec<_> = contents
.iter()
.map(|(path, text)| (*path, text.as_str()))
.collect();
load_documents(&documents).expect("documents should load")
}
fn parsed_manifest() -> toml::Table {
CARGO_MANIFEST
.parse()
.expect("Cargo.toml should parse as TOML")
}
#[test]
fn every_documented_fence_has_a_known_unique_identifier() {
let examples = load_documented_examples();
let actual: BTreeSet<_> = examples.iter().map(|example| example.id.as_str()).collect();
let expected: BTreeSet<_> = EXPECTED_EXAMPLE_IDS.iter().copied().collect();
assert_eq!(actual, expected, "documented example registry drifted");
}
#[test]
fn the_readme_links_the_badge_and_the_home_page_in_the_manifest() {
let manifest = parsed_manifest();
let homepage = manifest
.get("package")
.and_then(|package| package.get("homepage"))
.and_then(toml::Value::as_str)
.expect("Cargo.toml should declare a homepage");
let readme = read_document("README.md");
assert!(readme.contains(&format!("Website: <{homepage}>")));
assert!(
readme.contains(&format!("Wireframe v{DOCUMENTED_RELEASE}")),
"the README should describe the release this tree builds"
);
assert!(readme.contains("https://img.shields.io/crates/v/wireframe"));
assert!(readme.contains("https://crates.io/crates/wireframe"));
}