Skip to content

Commit 7ff4f37

Browse files
committed
Add test to check version in CITATION.cff is up to date
1 parent 4a45879 commit 7ff4f37

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/citation_cff.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Check the CITATION.cff file
2+
use anyhow::{Context, Result};
3+
use std::fs;
4+
use yaml_rust2::{Yaml, YamlLoader};
5+
6+
fn get_version_from_citation_cff() -> Result<String> {
7+
let citation = fs::read_to_string("CITATION.cff")?;
8+
let yaml = YamlLoader::load_from_str(&citation)?;
9+
let yaml = yaml
10+
.iter()
11+
.next()
12+
.context("Empty YAML file")?
13+
.as_hash()
14+
.context("Not YAML object")?;
15+
let version = yaml
16+
.get(&Yaml::from_str("version"))
17+
.context("version key not found")?
18+
.as_str()
19+
.context("version should be string")?;
20+
21+
Ok(version.to_string())
22+
}
23+
24+
#[test]
25+
fn test_citation_cff_version() {
26+
assert_eq!(
27+
env!("CARGO_PKG_VERSION"),
28+
get_version_from_citation_cff().unwrap(),
29+
"Software version in Cargo.toml and CITATION.cff must match. If you are making a new \
30+
release, please also update the CITATION.cff file."
31+
)
32+
}

0 commit comments

Comments
 (0)