Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix release.toml version check #126

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion twoliter/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions twoliter/src/test/data/Release-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.0.0"
1 change: 1 addition & 0 deletions twoliter/src/test/data/Release-2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "2.0.0"