Skip to content

Commit 4b2234a

Browse files
committed
feat: tests (untested)
1 parent 40a6139 commit 4b2234a

File tree

5 files changed

+96
-4
lines changed

5 files changed

+96
-4
lines changed

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "bin_patch_gen"
33
version = "0.1.0"
44
edition = "2021"
5+
build = "build.rs"
56

67
[dependencies]
78
serde = { version = "1.0.214", features = ["derive"] }
@@ -25,3 +26,4 @@ hex = "0.4.3"
2526
clap = { version = "4.5.21", features = ["derive"] }
2627
qbsdiff = "1.4.2"
2728
bzip2 = "0.4.4"
29+
paste = "1.0.15"

build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println!("cargo:rerun-if-changed=build.rs");
3+
println!("cargo:rustc-env=RUST_TEST_THREADS=1");
4+
}

config.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
java_8_home = ""
2-
java_16_home = ""
3-
java_17_home = ""
4-
java_21_home = ""
1+
java_8_home = "/usr/lib/jvm/java-8-openjdk/"
2+
java_16_home = "/usr/lib/jvm/java-17-openjdk/"
3+
java_17_home = "/usr/lib/jvm/java-17-openjdk/"
4+
java_21_home = "/usr/lib/jvm/java-21-temurin/"
55

src/tests.rs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use crate::{
2+
config::PatchedVersionMeta,
3+
download_url, run,
4+
util::{sha1, TimeFormatter},
5+
};
6+
use std::{env::current_dir, io::Result, path::PathBuf};
7+
use tokio::test;
8+
use tracing_subscriber::fmt::format;
9+
10+
fn run_dir() -> Result<PathBuf> {
11+
let run_dir = if current_dir()?.ends_with("run") {
12+
current_dir()?.join("tests")
13+
} else {
14+
current_dir()?.join("run/tests")
15+
};
16+
17+
Ok(run_dir)
18+
}
19+
20+
async fn test_version(version: String) -> Result<()> {
21+
println!();
22+
23+
let fmt = format()
24+
.with_file(true)
25+
.with_line_number(true)
26+
.with_timer(TimeFormatter);
27+
let _ = tracing_subscriber::fmt().event_format(fmt).try_init();
28+
29+
let run_dir = run_dir().expect("failed retrieving run directory");
30+
31+
run(vec![version.clone()], run_dir.clone(), true)
32+
.await
33+
.expect("failed running patch gen");
34+
35+
let patched_meta = PatchedVersionMeta::read(&run_dir.join(format!("{version}.json")))
36+
.expect("failed reading patched meta");
37+
let patch = &run_dir.join(format!("{version}.patch"));
38+
let vanilla_jar_path = &run_dir.join(format!("{version}-vanilla.jar"));
39+
let spigot_jar_path = &run_dir.join(format!("{version}-patched.jar"));
40+
41+
download_url(patched_meta.vanilla_download_url, vanilla_jar_path)
42+
.await
43+
.expect("failed downloading vanilla");
44+
45+
assert_eq!(
46+
sha1(vanilla_jar_path).expect("failed hashing vanilla jar"),
47+
patched_meta.vanilla_jar_hash
48+
);
49+
assert_eq!(
50+
sha1(patch).expect("failed hashing patch"),
51+
patched_meta.patch_hash
52+
);
53+
54+
crate::patch(vanilla_jar_path, spigot_jar_path, patch)
55+
.await
56+
.expect("failed patching");
57+
58+
assert_eq!(
59+
sha1(spigot_jar_path).expect("failed hashing spigot jar"),
60+
patched_meta.patched_jar_hash
61+
);
62+
63+
Ok(())
64+
}
65+
66+
macro_rules! tests {
67+
($($version:literal),+) => {
68+
$(
69+
paste::paste! {
70+
#[test]
71+
async fn [<test_ $version>]() {
72+
test_version(stringify!($version).to_owned().replace("_", ".")).await.unwrap();
73+
}
74+
}
75+
)+
76+
};
77+
}
78+
79+
tests!(1_21_3, 1_10, 1_17, 1_8);

0 commit comments

Comments
 (0)