diff --git a/twoliter/src/project.rs b/twoliter/src/project.rs index b81e7a7b3..f9530546a 100644 --- a/twoliter/src/project.rs +++ b/twoliter/src/project.rs @@ -226,7 +226,8 @@ impl UnvalidatedProject { return Ok(()); } } - .to_string(); + .as_str() + .context("The version in Release.toml is not a string")?; ensure!( version == self.release_version, "The version found in Release.toml, '{version}', does not match the release-version \ @@ -328,4 +329,63 @@ mod test { project.toolchain("aarch64").unwrap().to_string() ); } + + #[tokio::test] + async fn test_release_toml_check_error() { + let tempdir = TempDir::new().unwrap(); + let p = tempdir.path(); + let from = data_dir(); + let twoliter_toml_from = from.join("Twoliter-1.toml"); + let twoliter_toml_to = p.join("Twoliter.toml"); + let release_toml_from = from.join("Release-2.toml"); + let release_toml_to = p.join("Release.toml"); + fs::copy(&twoliter_toml_from, &twoliter_toml_to) + .await + .expect(&format!( + "Unable to copy {} to {}", + twoliter_toml_from.display(), + twoliter_toml_to.display() + )); + fs::copy(&release_toml_from, &release_toml_to) + .await + .expect(&format!( + "Unable to copy {} to {}", + release_toml_from.display(), + release_toml_to.display() + )); + let result = Project::find_and_load(&p).await; + assert!( + result.is_err(), + "Expected the loading of the project to fail because of a mismatched version in \ + Release.toml, but the project loaded without an error." + ); + } + + #[tokio::test] + async fn test_release_toml_check_ok() { + let tempdir = TempDir::new().unwrap(); + let p = tempdir.path(); + let from = data_dir(); + let twoliter_toml_from = from.join("Twoliter-1.toml"); + let twoliter_toml_to = p.join("Twoliter.toml"); + let release_toml_from = from.join("Release-1.toml"); + let release_toml_to = p.join("Release.toml"); + fs::copy(&twoliter_toml_from, &twoliter_toml_to) + .await + .expect(&format!( + "Unable to copy {} to {}", + twoliter_toml_from.display(), + twoliter_toml_to.display() + )); + fs::copy(&release_toml_from, &release_toml_to) + .await + .expect(&format!( + "Unable to copy {} to {}", + release_toml_from.display(), + release_toml_to.display() + )); + + // The project should load because Release.toml and Twoliter.toml versions match. + Project::find_and_load(&p).await.unwrap(); + } } diff --git a/twoliter/src/test/data/Release-1.toml b/twoliter/src/test/data/Release-1.toml new file mode 100644 index 000000000..11a716ec1 --- /dev/null +++ b/twoliter/src/test/data/Release-1.toml @@ -0,0 +1 @@ +version = "1.0.0" diff --git a/twoliter/src/test/data/Release-2.toml b/twoliter/src/test/data/Release-2.toml new file mode 100644 index 000000000..1b236407f --- /dev/null +++ b/twoliter/src/test/data/Release-2.toml @@ -0,0 +1 @@ +version = "2.0.0"