plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
da2dabb
— Peter John
2026-11-10T23:12:53+05:30
determinism_test: a web build, and a module compiled by another path or from a copy of std
compiler/cli/tests/cli/determinism_test.rs
CHANGED
|
@@ -45,3 +45,55 @@ fn stdTestModulesCompileToTheSameBytesInSeparateProcesses() {
|
|
|
45
45
|
allSame(outs, file);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
/// Every file of a game's web build, from two processes; and a module that does not depend
|
|
50
|
+
/// on where the repository is, or on how the entry file is named: compiled by relative and
|
|
51
|
+
/// by absolute path, and in a copy of the repository's std somewhere else, it is the same
|
|
52
|
+
/// bytes. (Source files are named relative to the working folder, so one outside it would
|
|
53
|
+
/// be named by its absolute path: these all run from the folder holding `std`.)
|
|
54
|
+
#[test]
|
|
55
|
+
fn webBuildsAndModulesHoldNoPathOrTime() {
|
|
56
|
+
let dir = Scratch::new("det_paths");
|
|
57
|
+
let game = root().join("examples/games/orb_run.plum");
|
|
58
|
+
let sites: Vec<Vec<(String, Vec<u8>)>> = (0..2)
|
|
59
|
+
.map(|i| {
|
|
60
|
+
let site = dir.join(format!("site{i}"));
|
|
61
|
+
let st = Command::new(plumBin()).current_dir(root()).arg("build").arg(&game).arg("-o").arg(&site).output().unwrap();
|
|
62
|
+
assert!(st.status.success(), "{}", String::from_utf8_lossy(&st.stderr));
|
|
63
|
+
let mut files = Vec::new();
|
|
64
|
+
let mut dirs = vec![site.clone()];
|
|
65
|
+
while let Some(d) = dirs.pop() {
|
|
66
|
+
for e in std::fs::read_dir(&d).unwrap() {
|
|
67
|
+
let p = e.unwrap().path();
|
|
68
|
+
if p.is_dir() {
|
|
69
|
+
dirs.push(p);
|
|
70
|
+
} else {
|
|
71
|
+
files.push((p.strip_prefix(&site).unwrap().display().to_string(), std::fs::read(&p).unwrap()));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
files.sort();
|
|
76
|
+
files
|
|
77
|
+
})
|
|
78
|
+
.collect();
|
|
79
|
+
assert!(sites[0].iter().any(|(n, _)| n == "plum.wasm"), "{:?}", sites[0].iter().map(|f| &f.0).collect::<Vec<_>>());
|
|
80
|
+
assert!(sites[0] == sites[1], "two web builds of the same game differ");
|
|
81
|
+
|
|
82
|
+
// A copy of std, with the entry file, under the scratch folder.
|
|
83
|
+
let copy = dir.join("elsewhere");
|
|
84
|
+
std::fs::create_dir_all(©).unwrap();
|
|
85
|
+
assert!(Command::new("cp").arg("-R").arg(root().join("std")).arg(©).status().unwrap().success());
|
|
86
|
+
std::fs::copy(root().join("examples/strings.plum"), copy.join("strings.plum")).unwrap();
|
|
87
|
+
let compile = |cwd: &std::path::Path, file: &std::path::Path, lib: &std::path::Path, out: &str| {
|
|
88
|
+
let out = dir.join(out);
|
|
89
|
+
let st = Command::new(plumBin()).current_dir(cwd).arg("compile").arg(file).arg("--lib-path").arg(lib).arg("-o").arg(&out).output().unwrap();
|
|
90
|
+
assert!(st.status.success(), "{}", String::from_utf8_lossy(&st.stderr));
|
|
91
|
+
std::fs::read(&out).unwrap()
|
|
92
|
+
};
|
|
93
|
+
let relative = compile(&root(), std::path::Path::new("examples/strings.plum"), std::path::Path::new("."), "rel.wasm");
|
|
94
|
+
let moved0 = compile(©, ©.join("strings.plum"), ©, "moved0.wasm");
|
|
95
|
+
let absolute = compile(&root(), &root().join("examples/strings.plum"), &root(), "abs.wasm");
|
|
96
|
+
let moved = compile(©, std::path::Path::new("strings.plum"), std::path::Path::new("."), "moved.wasm");
|
|
97
|
+
assert!(relative == absolute, "a relative and an absolute entry path give other bytes");
|
|
98
|
+
assert!(relative == moved && moved == moved0, "std in another folder gives other bytes");
|
|
99
|
+
}
|