116 lines
6.6 KiB
Plaintext
116 lines
6.6 KiB
Plaintext
# Tests of blossom's parts: reading blossomfiles, the store's folders, output
|
|
# folders' names, versions, the digests packages carry, and commands as `-v`
|
|
# prints them.
|
|
import std::io;
|
|
import std::testing;
|
|
import blossom::models;
|
|
import blossom::management;
|
|
import blossom::pipeline;
|
|
|
|
# Reads a blossomfile's text, giving what's wrong, or empty text where nothing
|
|
# is.
|
|
def problem_in(text: strview): string {
|
|
val file := path::parse("/projects/tests/blossomfile") else (_) { return string::new(nothing {}); };
|
|
var overrides := vector::<models::setting>::new();
|
|
var read := models::read_project(text, &file, overrides.view(), "");
|
|
if read is error(&problem) {
|
|
return problem.describe();
|
|
}
|
|
return string::new(nothing {});
|
|
}
|
|
|
|
@test def digests_are_those_their_standards_give(t: &mut tester): void {
|
|
t.expects(pipeline::md5("") == "d41d8cd98f00b204e9800998ecf8427e");
|
|
t.expects(pipeline::md5("abc") == "900150983cd24fb0d6963f7d28e17f72");
|
|
t.expects(pipeline::md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890") == "57edf4a22be3c955ac49da2e2107b67a");
|
|
t.expects(pipeline::sha256("") == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
|
t.expects(pipeline::sha256("abc") == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
|
t.expects(pipeline::sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") == "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
|
|
t.expects(pipeline::crc32("123456789") == 0xCBF43926 && pipeline::crc32("") == 0);
|
|
}
|
|
|
|
@test def remotes_are_stored_by_their_host_path_and_ref(t: &mut tester): void {
|
|
t.expects(management::store_key("https://git.malunal.studio/malunal/json", "v1.0.0") == "git.malunal.studio/malunal/json@v1.0.0");
|
|
t.expects(management::store_key("https://me@host.com/a/b.git", "main") == "host.com/a/b@main");
|
|
t.expects(management::store_key("git@github.com:malunal/json.git", "main") == "github.com/malunal/json@main");
|
|
t.expects(management::store_key("file:///tmp/x/repo.git", "v2") == "file/tmp/x/repo@v2");
|
|
|
|
# Nothing leads out of the store.
|
|
t.expects(management::store_key("https://host/../../etc", "main") == "host/etc@main");
|
|
t.expects(management::store_key("https://host/a", "../../x") == "host/a@.._.._x");
|
|
}
|
|
|
|
@test def output_folders_are_named_by_identity_options_and_target(t: &mut tester): void {
|
|
var options := vector::<models::setting>::new();
|
|
options.append(models::setting { name = string::from("level", nothing {}), value = string::from("2", nothing {}) });
|
|
options.append(models::setting { name = string::from("debug", nothing {}), value = string::from("false", nothing {}) });
|
|
val first := models::output_key("malunal/hello@1.0.0", options.view(), "");
|
|
t.expects(first.length == 16);
|
|
|
|
# In any order, the same options name the same folder.
|
|
var reordered := vector::<models::setting>::new();
|
|
reordered.append(models::setting { name = string::from("debug", nothing {}), value = string::from("false", nothing {}) });
|
|
reordered.append(models::setting { name = string::from("level", nothing {}), value = string::from("2", nothing {}) });
|
|
t.expects(models::output_key("malunal/hello@1.0.0", reordered.view(), "") == first);
|
|
t.expects(models::output_key("malunal/hello@1.0.0", options.view(), "windows-x86_64") != first);
|
|
t.expects(models::output_key("malunal/hello@1.0.1", options.view(), "") != first);
|
|
t.expects(models::hex(0x0123456789abcdef) == "0123456789abcdef");
|
|
}
|
|
|
|
@test def versions_are_semantic(t: &mut tester): void {
|
|
for text in ["1.2.0", "0.0.1", "10.20.30", "1.2.0-alpha", "1.2.0-alpha.1", "1.2.0+build.5"] {
|
|
t.expects(models::is_version(text), text);
|
|
}
|
|
for text in ["1", "1.2", "1.2.x", "v1.2.0", "1.2.0-", "1..0", ""] {
|
|
t.expects(!models::is_version(text), text);
|
|
}
|
|
}
|
|
|
|
@test def blossomfiles_are_read_with_their_mistakes_found(t: &mut tester): void {
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\n").length == 0);
|
|
t.expects(problem_in("") == "/projects/tests/blossomfile: The blossomfile is empty: it needs `name`, `gpid`, and `semv`.");
|
|
t.expects(problem_in("name: a\ngpid: b\n") == "/projects/tests/blossomfile:1: `semv` is needed.");
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\nname: c\n") == "/projects/tests/blossomfile:4: `name` is written twice in the blossomfile.");
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\noptions:\n bin: x\n").view().find("`bin` is blossom's") is some);
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\nexports: [nope]\n").view().find("`nope` is exported, but it's no library") is some);
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\ntargets:\n- name: x.y\n type: library\n- name: x.y\n type: library\n").view().find("`x.y` names two targets.") is some);
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\ntargets:\n- name: 9lives\n type: library\n").view().find("names no module") is some);
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\ntargets:\n- name: p\n type: program\n").view().find("`p` needs `srcs`") is some);
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\nrequires:\n- ../x@v1\n- remote: ../y\n branch: v1\n").view().find("A folder takes no `branch`.") is some);
|
|
t.expects(problem_in("name: a\ngpid: b\nsemv: 1.0.0\ntargets:\n- name: l\n type: library\n srcs: [a.sakura]\n").view().find("A library takes no `srcs`") is some);
|
|
}
|
|
|
|
@test def requirements_are_read_short_and_as_blocks(t: &mut tester): void {
|
|
val file := path::parse("/projects/tests/blossomfile") else (_) { return; };
|
|
var overrides := vector::<models::setting>::new();
|
|
var read := models::read_project("""
|
|
name: a
|
|
gpid: b
|
|
semv: 1.0.0
|
|
requires:
|
|
- https://host/json@v1.0.0
|
|
- git@host:malunal/yaml
|
|
- ../shapes
|
|
- remote: https://host/args
|
|
options:
|
|
strict: true
|
|
""", &file, overrides.view(), "");
|
|
if read is not value(&made) {
|
|
t.expects(false);
|
|
return;
|
|
}
|
|
t.expects(made.requires.length == 4);
|
|
t.expects(made.requires[0].remote == "https://host/json" && made.requires[0].branch == "v1.0.0" && !made.requires[0].local);
|
|
t.expects(made.requires[1].remote == "git@host:malunal/yaml" && made.requires[1].branch == "main");
|
|
t.expects(made.requires[2].remote == "../shapes" && made.requires[2].local);
|
|
t.expects(made.requires[3].branch == "main" && made.requires[3].options.length == 1 && made.requires[3].options[0].value == "true");
|
|
}
|
|
|
|
@test def commands_are_printed_as_a_shell_takes_them(t: &mut tester): void {
|
|
var words := vector::<string>::new();
|
|
for each in ["sakura", "build", "--lib", "a::b=./x", "my file.sakura", "it's"] {
|
|
words.append(string::from(each, nothing {}));
|
|
}
|
|
t.expects(pipeline::spoken(words.view()) == "sakura build --lib a::b=./x 'my file.sakura' 'it'\\''s'");
|
|
}
|