Files
swaitsandClaude 7568bca7b0 build(notices): a crate's own licence file where the generator gave a placeholder
MIT, BSD and ISC ask that the copyright notice itself travel with a copy,
not only the licence's words. For 70 of the crates the program links,
cargo-about could give only the licence's standard text, whose copyright
line is a placeholder ("Copyright (c) <year> <copyright holders>"):
the crate's own licence file is a compound one it cannot match (chrono
and libm put two licences in one file, aws-lc's is 316 lines of several,
the windows crates indent theirs), or the crate was packaged with no
licence file at all (egui, objc2, wasmi and 32 more).

scripts/notices-packaged.py reads cargo-about's output, finds every
section with such a placeholder, and adds a part to the file: the licence
files those crates were packaged with, whole, each distinct text once
under the crates that carry it, and for the 35 packaged with none the
repository their manifest names. It reads the crates where cargo has them
(cargo metadata, locked and offline), so the text still depends on
Cargo.lock alone; two runs are byte-identical. The file grows from 551 KB
to 707 KB. The test for `wanderbooks licenses` now asks for a copyright
line that only a compound file holds.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-09 22:00:44 -07:00

81 lines
2.3 KiB
Rust

//! `wanderbooks licenses`: the third-party notices are part of the binary
//! and print as plain text, and the mode behaves like every other one.
use std::process::Command;
fn wanderbooks() -> Command {
Command::new(env!("CARGO_BIN_EXE_wanderbooks"))
}
#[test]
fn licenses_prints_the_notices_and_nothing_on_stderr() {
let out = wanderbooks().arg("licenses").output().unwrap();
assert_eq!(out.status.code(), Some(0), "{out:?}");
assert!(
out.stderr.is_empty(),
"{:?}",
String::from_utf8_lossy(&out.stderr)
);
let text = String::from_utf8(out.stdout).unwrap();
assert!(
text.starts_with("wanderbooks "),
"the version line comes first: {:?}",
&text[..text.len().min(80)]
);
for needle in [
"MIT OR Apache-2.0",
"Apache License",
"SIL OPEN FONT LICENSE",
"rust_decimal",
"egui",
"rusqlite",
"Inter Project Authors",
"Bitstream",
// A crate whose own licence file cargo-about cannot match (two
// licences in one file) still travels with its copyright line.
"LICENCE FILES AS PACKAGED",
"Kang Seonghoon",
"Packaged with no licence file",
] {
assert!(text.contains(needle), "{needle:?} is not in the notices");
}
}
#[test]
fn the_printed_notices_are_the_file_at_the_repository_root() {
let notices = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../THIRD-PARTY-NOTICES.txt"
));
let out = wanderbooks().arg("licenses").output().unwrap();
let done = out
.stdout
.windows(2)
.position(|w| w == b"\n\n")
.expect("the header line and an empty line");
assert_eq!(&out.stdout[done + 2..], notices);
}
#[test]
fn licenses_takes_no_arguments() {
let out = wanderbooks().args(["licenses", "extra"]).output().unwrap();
assert_eq!(out.status.code(), Some(2), "{out:?}");
assert!(
String::from_utf8_lossy(&out.stderr).contains("usage: wanderbooks licenses"),
"{out:?}"
);
}
#[test]
fn licenses_comes_first_like_every_mode() {
let out = wanderbooks()
.args(["--root", "x", "licenses"])
.output()
.unwrap();
assert_eq!(out.status.code(), Some(2), "{out:?}");
assert!(
String::from_utf8_lossy(&out.stderr).contains("must come first"),
"{out:?}"
);
}