Files
blossom/tests/commands/mistakes.sakura
T

93 lines
4.1 KiB
Plaintext
Raw Normal View History

2026-10-24 12:13:52 -05:00
# Tests of what blossom refuses, each with status 2 and a line saying what's
# wrong and where: a key written twice, keys and options it doesn't know, a
# step of `install` without a tag it knows, and a folder with no blossomfile.
import std::testing;
# Writes a project whose blossomfile is the text given, with a program to build.
def sandbox::project(&this, folder: strview, blossomfile: strview): void {
this.write($"{folder}/blossomfile".span, blossomfile);
this.write($"{folder}/main.sakura".span, "def main(): void {}\n");
}
@test def a_key_written_twice_is_refused_by_its_line(t: &mut tester, box: sandbox): void {
box.project("twice", """
name: twice
gpid: tests
semv: 1.0.0
requires:
- remote: https://example.com/one
branch: v1.0.0
remote: https://example.com/two
branch: v1.0.0
""");
val built := box.blossom("twice", ["build"]);
t.expects(built.status == 2 && built.warns("blossomfile:8: `remote` is written twice in a requirement."), built.error.span);
}
@test def keys_options_and_targets_blossom_doesnt_know_are_refused(t: &mut tester, box: sandbox): void {
box.project("keys", """
name: keys
gpid: tests
semv: 1.0.0
targets:
- name: keys
type: program
srcs: [main.sakura]
optlevel: 2
""");
t.expects(box.blossom("keys", ["build"]).warns("blossomfile:9: `optlevel` is no key of a target."));
box.project("options", """
name: options
gpid: tests
semv: 1.0.0
options:
level: 2
targets:
- name: options
type: program
level: ${nope}
srcs: [main.sakura]
""");
val unknown := box.blossom("options", ["build"]);
t.expects(unknown.status == 2 && unknown.warns("blossomfile:11: `${nope}` names no option declared before it."), unknown.error.span);
val bad := box.blossom("keys", ["build", "-o", "nope=1"]);
t.expects(bad.status == 2 && bad.warns("`nope`, given a value, names no option of tests/keys@1.0.0."));
t.expects(box.blossom("keys", ["build", "--target", "mars"]).status == 2);
t.expects(box.blossom("keys", ["frobnicate"]).status == 2);
t.expects(box.blossom("keys", ["build", "--no-such-option"]).status == 2);
box.project("version", "name: version\ngpid: tests\nsemv: one\n");
t.expects(box.blossom("version", ["build"]).warns("`one` is not a version"));
box.project("level", "name: level\ngpid: tests\nsemv: 1.0.0\ntargets:\n- name: level\n type: program\n level: 3\n srcs: [main.sakura]\n");
t.expects(box.blossom("level", ["build"]).warns("blossomfile:7: `level` is 0, 1, or 2, not `3`."));
box.project("missing", "name: missing\ngpid: tests\nsemv: 1.0.0\ntargets:\n- name: missing\n type: program\n srcs: [nothing.sakura, '*.c']\n");
val missing := box.blossom("missing", ["build"]);
t.expects(missing.status == 2 && missing.warns("`nothing.sakura`, in `missing`'s `srcs`, names no file."), missing.error.span);
}
@test def a_step_of_install_says_what_it_does_by_a_tag_blossom_knows(t: &mut tester, box: sandbox): void {
box.project("untagged", "name: untagged\ngpid: tests\nsemv: 1.0.0\ninstall:\n- ./share\n");
val untagged := box.blossom("untagged", ["install", "--prefix", "prefix"]);
t.expects(untagged.status == 2 && untagged.warns("blossomfile:5: A step of `install` says what it does with a tag"), untagged.error.span);
box.project("unknown", "name: unknown\ngpid: tests\nsemv: 1.0.0\ninstall:\n- !program ./share\n");
val unknown := box.blossom("unknown", ["install", "--prefix", "prefix"]);
t.expects(unknown.status == 2 && unknown.warns("`!program` is no step blossom knows"), unknown.error.span);
box.project("outside", "name: outside\ngpid: tests\nsemv: 1.0.0\ninstall:\n- !include ../elsewhere\n- !include ./a:/etc\n");
t.expects(box.blossom("outside", ["install", "--prefix", "prefix"]).warns("`../elsewhere` is outside the project"));
}
@test def a_folder_without_a_blossomfile_is_refused(t: &mut tester, box: sandbox): void {
box.write("empty/main.sakura", "def main(): void {}\n");
val built := box.blossom("empty", ["build"]);
t.expects(built.status == 2 && built.warns("holds no blossomfile"), built.error.span);
}