Debian Codegraph @

third_party/rust/serde_with/tests/version_numbers.rs

raw
1 //! Test Cases
2
3 use version_sync::{assert_contains_regex, assert_html_root_url_updated};
4
5 #[test]
6 fn test_changelog() {
7 assert_contains_regex!("CHANGELOG.md", r"## \[{version}\]");
8 }
9
10 #[test]
11 fn test_html_root_url() {
12 assert_html_root_url_updated!("src/lib.rs");
13 }
14
15 #[test]
16 fn test_serde_with_macros_dependency() {
17 version_sync::assert_contains_regex!(
18 "../serde_with/Cargo.toml",
19 r#"^serde_with_macros = .*? version = "={version}""#
20 );
21 version_sync::assert_contains_regex!("../Cargo.toml", r#"^version = "{version}""#);
22 }
23
24 /// Check that all docs.rs links point to the current version
25 ///
26 /// Parse all docs.rs links in `*.rs` and `*.md` files and check that they point to the current version.
27 /// If a link should point to latest version this can be done by using `latest` in the version.
28 /// The `*` version specifier is not allowed.
29 ///
30 /// Arguably this should be part of version-sync. There is an open issue for this feature:
31 /// <https://github.com/mgeisler/version-sync/issues/72>
32 #[test]
33 fn test_docs_rs_url_point_to_current_version() -> Result<(), Box<dyn std::error::Error>> {
34 let pkg_name = env!("CARGO_PKG_NAME");
35 let pkg_version = env!("CARGO_PKG_VERSION");
36
37 let re = regex::Regex::new(&format!(
38 "https?://docs.rs/{pkg_name}/((\\d[^/]+|\\*|latest))/"
39 ))?;
40 let mut error = false;
41
42 for entry in glob::glob("**/*.rs")?.chain(glob::glob("**/README.md")?) {
43 let entry = entry?;
44 let content = std::fs::read_to_string(&entry)?;
45 for (line_number, line) in content.split('\n').enumerate() {
46 for capture in re.captures_iter(line) {
47 match capture
48 .get(1)
49 .expect("Will exist if regex matches")
50 .as_str()
51 {
52 "latest" => {}
53 version if version != pkg_version => {
54 error = true;
55 println!(
56 "{}:{} pkg_version is {} but found URL {}",
57 entry.display(),
58 line_number + 1,
59 pkg_version,
60 capture.get(0).expect("Group 0 always exists").as_str()
61 );
62 }
63 _ => {}
64 }
65 }
66 }
67 }
68
69 if error {
70 panic!("Found wrong URLs in file(s)");
71 } else {
72 Ok(())
73 }
74 }