Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunchen committed Sep 29, 2024
1 parent aefa652 commit 85f17ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
28 changes: 26 additions & 2 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
"#]],
);
}
6 changes: 3 additions & 3 deletions crates/moonutil/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ impl TryFrom<MoonModJSON> for MoonMod {
fn try_from(j: MoonModJSON) -> Result<Self, Self::Error> {
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 {
Expand Down

0 comments on commit 85f17ed

Please sign in to comment.