From 85f17ed74a048aa646df39946b2ae387cac170b2 Mon Sep 17 00:00:00 2001 From: Li Junchen Date: Sun, 29 Sep 2024 16:24:57 +0800 Subject: [PATCH] update tests --- crates/moon/tests/test_cases/mod.rs | 28 ++++++++++++++++++++++++++-- crates/moonutil/src/module.rs | 6 +++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index e47c66be..aabae4b0 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -20,8 +20,9 @@ use std::io::Write; use super::*; use expect_test::expect; -use moonutil::common::{ - get_cargo_pkg_version, CargoPathExt, TargetBackend, DEP_PATH, MOON_MOD_JSON, +use moonutil::{ + common::{get_cargo_pkg_version, CargoPathExt, TargetBackend, DEP_PATH, MOON_MOD_JSON}, + module::MoonModJSON, }; use serde::{Deserialize, Serialize}; use walkdir::WalkDir; @@ -6747,3 +6748,26 @@ fn test_moon_coverage() { expect!["Total: 3/6"], ); } + +#[test] +fn test_bad_version() { + let dir = TestDir::new("general.in"); + let content = std::fs::read_to_string(dir.join("moon.mod.json")).unwrap(); + let mut moon_mod: MoonModJSON = serde_json::from_str(&content).unwrap(); + moon_mod.version = Some("0.0".to_string()); + std::fs::write( + dir.join("moon.mod.json"), + serde_json::to_string(&moon_mod).unwrap(), + ) + .unwrap(); + check( + &get_err_stderr(&dir, ["check"]), + expect![[r#" + error: failed to load `$ROOT/moon.mod.json` + + Caused by: + 0: `version` bad format + 1: unexpected end of input while parsing minor version number + "#]], + ); +} diff --git a/crates/moonutil/src/module.rs b/crates/moonutil/src/module.rs index c9dae284..787d34a2 100644 --- a/crates/moonutil/src/module.rs +++ b/crates/moonutil/src/module.rs @@ -476,9 +476,9 @@ impl TryFrom for MoonMod { fn try_from(j: MoonModJSON) -> Result { let version = match &j.version { None => None, - Some(v) => Some( - Version::parse(v.as_str()).map_err(MoonModJSONFormatErrorKind::Version)?, - ), + Some(v) => { + Some(Version::parse(v.as_str()).map_err(MoonModJSONFormatErrorKind::Version)?) + } }; let deps = match j.deps {