Initial Commit
This commit is contained in:
27 files changed
+5400
No files matched your search
@@ -0,0 +1,144 @@
|
||||
# Tests of `build`, `check`, `run`, and `clean`: a program, a program with a
|
||||
# library of its own, the `sakurac` run where the config names none, building
|
||||
# only what changed, a check that fails, and building for Windows.
|
||||
import std::io;
|
||||
import std::process;
|
||||
import std::testing;
|
||||
|
||||
@test def a_program_is_built_then_run(t: &mut tester, box: sandbox): void {
|
||||
box.write("one/blossomfile", """
|
||||
name: one
|
||||
gpid: tests
|
||||
semv: 0.1.0
|
||||
|
||||
targets:
|
||||
- name: one
|
||||
type: program
|
||||
srcs: [main.sakura]
|
||||
""");
|
||||
box.write("one/main.sakura", """
|
||||
import std::io;
|
||||
|
||||
def main(args: span<strview>): void {
|
||||
io::println($"given {args.length}".view());
|
||||
}
|
||||
""");
|
||||
val built := box.blossom("one", ["build"]);
|
||||
t.expects(built.status == 0, built.error.view());
|
||||
t.expects(built.says("[1/1] Built one (.blossom/") && built.says("Built tests/one@0.1.0"));
|
||||
|
||||
# The executable is where blossom said.
|
||||
val output := built_path(built.output.view(), "one");
|
||||
val ran := box.run($"{box.at.view()}/one/{output}".view(), "one", ["a", "b"]);
|
||||
t.expects(ran.says("given 2"));
|
||||
|
||||
val again := box.blossom("one", ["run", "--", "x", "y", "z"]);
|
||||
t.expects(again.status == 0 && again.says("given 3"));
|
||||
}
|
||||
|
||||
@test def a_program_reads_a_library_of_its_project(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello");
|
||||
val built := box.blossom("hello", ["build"]);
|
||||
t.expects(built.status == 0, built.error.view());
|
||||
t.expects(built.says("[1/2] Checked hello.geometry") && built.says("[2/2] Built hello"));
|
||||
val ran := box.blossom("hello", ["run", "--", "1"]);
|
||||
t.expects(ran.says("area 12 cube 8 given 1"));
|
||||
|
||||
# `check` checks each target and writes nothing.
|
||||
box.hello("other");
|
||||
val checked := box.blossom("other", ["check"]);
|
||||
t.expects(checked.status == 0 && checked.says("[1/2] Checked hello") && checked.says("[2/2] Checked hello.geometry"));
|
||||
t.expects(!box.has("other/.blossom"));
|
||||
}
|
||||
|
||||
# Where the config names no `sakura`, blossom runs the first `sakurac` on
|
||||
# `PATH`, here a link to the tests' own, as none is beside it.
|
||||
@test def a_config_naming_no_sakura_runs_sakurac(t: &mut tester, box: sandbox): void {
|
||||
val sakura := process::variable("SAKURA") else { return; };
|
||||
box.write("config/blossom/config", "");
|
||||
box.hello("hello");
|
||||
val missing := box.blossom("hello", ["build"], "/usr/bin:/bin");
|
||||
t.expects(missing.status == 2 && missing.warns("No `sakurac` is found"), missing.error.view());
|
||||
|
||||
box.write("bin/.keep", "");
|
||||
val linked := box.run("ln", "bin", ["-s", sakura, "sakurac"]);
|
||||
t.expects(linked.status == 0, linked.error.view());
|
||||
val built := box.blossom("hello", ["build"], $"{box.at.view()}/bin:/usr/bin:/bin".view());
|
||||
t.expects(built.status == 0 && built.says("[2/2] Built hello"), built.error.view());
|
||||
}
|
||||
|
||||
@test def only_what_changed_is_built_again(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello");
|
||||
t.expects(box.blossom("hello", ["build"]).status == 0);
|
||||
|
||||
# Nothing changed: `sakura` isn't run.
|
||||
val again := box.blossom("hello", ["build", "-v"]);
|
||||
t.expects(again.says("[1/2] Up to date hello.geometry") && again.says("[2/2] Up to date hello"));
|
||||
t.expects(!again.says("sakura"));
|
||||
|
||||
# A file of the library: it's checked again, and the program built again.
|
||||
box.write("hello/hello.geometry/solids/solids.sakura", """
|
||||
module hello::geometry::solids;
|
||||
|
||||
pub def cube(side: i64): i64 { return side * side * side + 0; }
|
||||
""");
|
||||
val touched := box.blossom("hello", ["build"]);
|
||||
t.expects(touched.says("[1/2] Checked hello.geometry") && touched.says("[2/2] Built hello"));
|
||||
|
||||
# The program's own file: only it's built again.
|
||||
box.write("hello/main.sakura", box.read("hello/main.sakura").view());
|
||||
val program := box.blossom("hello", ["build"]);
|
||||
t.expects(program.says("[1/2] Up to date hello.geometry") && program.says("[2/2] Built hello"));
|
||||
|
||||
# Another option value builds in a folder of its own, and the first stays up
|
||||
# to date.
|
||||
val other := box.blossom("hello", ["build", "-o", "level=0"]);
|
||||
t.expects(other.says("[2/2] Built hello") && built_path(other.output.view(), "hello") != built_path(program.output.view(), "hello"));
|
||||
t.expects(box.blossom("hello", ["build"]).says("[2/2] Up to date hello"));
|
||||
|
||||
# Changing the blossomfile builds again.
|
||||
val text := box.read("hello/blossomfile");
|
||||
box.write("hello/blossomfile", $"{text.view()}\n".view());
|
||||
t.expects(box.blossom("hello", ["build"]).says("[2/2] Built hello"));
|
||||
|
||||
# `clean` removes this option set's outputs, and `--all` every set's.
|
||||
val cleaned := box.blossom("hello", ["clean"]);
|
||||
t.expects(cleaned.status == 0 && cleaned.says("Cleaned tests/hello@1.0.0"));
|
||||
t.expects(box.has("hello/.blossom") && box.blossom("hello", ["clean"]).says("Nothing to clean"));
|
||||
t.expects(box.blossom("hello", ["clean", "--all"]).status == 0 && !box.has("hello/.blossom"));
|
||||
}
|
||||
|
||||
@test def a_program_that_fails_to_check_fails_the_build(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello");
|
||||
box.write("hello/main.sakura", """
|
||||
def main(): void {
|
||||
val wrong: i64 = "text";
|
||||
}
|
||||
""");
|
||||
val built := box.blossom("hello", ["build"]);
|
||||
t.expects(built.status == 1 && built.says("Failed hello") && !built.says("Built tests/hello"));
|
||||
t.expects(built.error.view().find("main.sakura:2") is some, built.error.view());
|
||||
|
||||
# A library that fails to check skips the programs reading it.
|
||||
box.hello("broken");
|
||||
box.write("broken/hello.geometry/shapes.sakura", """
|
||||
module hello::geometry;
|
||||
|
||||
pub def area(w: i64, h: i64): i64 { return "no"; }
|
||||
""");
|
||||
val skipped := box.blossom("broken", ["build"]);
|
||||
t.expects(skipped.status == 1 && skipped.says("Failed hello.geometry") && skipped.says("Skipped hello"));
|
||||
|
||||
# `check` checks every target, so the program fails there too.
|
||||
val checked := box.blossom("broken", ["check"]);
|
||||
t.expects(checked.status == 1 && checked.says("Failed hello\n") && checked.says("Failed hello.geometry\n"), checked.output.view());
|
||||
}
|
||||
|
||||
@test def a_target_builds_an_executable_for_windows(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello");
|
||||
val built := box.blossom("hello", ["build", "--target", "windows-x86_64"]);
|
||||
t.expects(built.status == 0, built.error.view());
|
||||
val output := built_path(built.output.view(), "hello");
|
||||
t.expects(output.ends_with("/bin/hello.exe"), output);
|
||||
t.expects(box.read($"hello/{output}".view()).view().starts_with("MZ"));
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
# Tests of `test`, `install`, and `package`: tests passing, failing, run
|
||||
# natively, and chosen by name; installing into a prefix and under a folder;
|
||||
# and packages of tar and zip.
|
||||
import std::io;
|
||||
import std::testing;
|
||||
|
||||
@test def tests_run_and_say_how_many_passed(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello");
|
||||
val tested := box.blossom("hello", ["test"]);
|
||||
t.expects(tested.status == 0 && tested.says("[3/3] Tested hello.tests (2 passed)") && tested.says("[ OK ] cubes_cube"), tested.error.view());
|
||||
t.expects(tested.says("Tested tests/hello@1.0.0"));
|
||||
}
|
||||
|
||||
@test def a_test_that_fails_fails_the_command(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello");
|
||||
box.write("hello/tests/wrong.sakura", """
|
||||
import std::testing;
|
||||
|
||||
@test def nothing_is_something(t: &mut tester): void { t.expects(1 == 2); }
|
||||
""");
|
||||
val tested := box.blossom("hello", ["test"]);
|
||||
t.expects(tested.status == 1 && tested.says("Failed hello.tests") && !tested.says("Tested tests/hello"));
|
||||
}
|
||||
|
||||
@test def tests_run_natively_by_name_with_what_theyre_given(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello", """
|
||||
- name: given.tests
|
||||
type: program
|
||||
runs: native
|
||||
srcs: [given/main.sakura]
|
||||
args: ["${bin}", second]
|
||||
""");
|
||||
box.write("hello/given/main.sakura", """
|
||||
import std::io;
|
||||
import system;
|
||||
|
||||
def main(args: span<strview>): void {
|
||||
io::println($"given {args[0]} {args[1]}".view());
|
||||
exit(args[0].ends_with("/bin") && args[1] == "second" ? 0 : 1);
|
||||
}
|
||||
""");
|
||||
val tested := box.blossom("hello", ["test", "--only", "given"]);
|
||||
t.expects(tested.status == 0 && tested.says("[3/3] Tested given.tests") && !tested.says("hello.tests"), tested.output.view());
|
||||
t.expects(tested.says($"given {box.at.view()}/hello/.blossom/".view()));
|
||||
t.expects(box.blossom("hello", ["test", "--only", "none"]).status == 2);
|
||||
}
|
||||
|
||||
@test def install_puts_programs_libraries_and_steps_in_the_prefix(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello", """
|
||||
exports:
|
||||
- hello.geometry
|
||||
|
||||
install:
|
||||
- !include ./share
|
||||
- !include ./docs:share/doc/hello
|
||||
- !include ./notes.txt
|
||||
- !include ./notes.txt:etc/hello.txt
|
||||
""");
|
||||
box.write("hello/share/data.txt", "data\n");
|
||||
box.write("hello/docs/README.md", "# Hello\n");
|
||||
box.write("hello/notes.txt", "notes\n");
|
||||
val installed := box.blossom("hello", ["install", "--prefix", $"{box.at.view()}/prefix".view()]);
|
||||
t.expects(installed.status == 0 && installed.says("Installed tests/hello@1.0.0 (7 files)"), installed.error.view());
|
||||
for name in ["prefix/bin/hello", "prefix/share/data.txt", "prefix/share/doc/hello/README.md", "prefix/notes.txt", "prefix/etc/hello.txt",
|
||||
"prefix/share/sakura/hello.geometry/shapes.sakura", "prefix/share/sakura/hello.geometry/solids/solids.sakura"] {
|
||||
t.expects(box.has(name), name);
|
||||
}
|
||||
val ran := box.run($"{box.at.view()}/prefix/bin/hello".view(), ".", span::<strview>::empty());
|
||||
t.expects(ran.says("area 12"));
|
||||
|
||||
# Under a folder, as a package is staged.
|
||||
val staged := box.blossom("hello", ["install", "--prefix", "/usr/local", "--destdir", $"{box.at.view()}/stage".view()]);
|
||||
t.expects(staged.status == 0 && box.has("stage/usr/local/bin/hello"), staged.error.view());
|
||||
}
|
||||
|
||||
@test def packages_hold_what_installing_puts_in_the_prefix(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello", "install:\n- !include ./notes.txt\n");
|
||||
box.write("hello/notes.txt", "notes\n");
|
||||
val packaged := box.blossom("hello", ["package", "-f", "tar,zip"]);
|
||||
t.expects(packaged.status == 0 && packaged.says("hello-1.0.0-linux-x86_64.tar.gz") && packaged.says("hello-1.0.0-linux-x86_64.zip"), packaged.error.view());
|
||||
|
||||
val listed := box.run("sh", "hello", ["-c", "tar -tzf .blossom/*/dist/hello-1.0.0-linux-x86_64.tar.gz"]);
|
||||
t.expects(listed.output.view() == "hello-1.0.0-linux-x86_64/\nhello-1.0.0-linux-x86_64/bin/\nhello-1.0.0-linux-x86_64/bin/hello\nhello-1.0.0-linux-x86_64/notes.txt\n", listed.output.view());
|
||||
val zip := box.run("sh", "hello", ["-c", "head -c 2 .blossom/*/dist/hello-1.0.0-linux-x86_64.zip"]);
|
||||
t.expects(zip.output.view() == "PK");
|
||||
|
||||
# The same stage makes the same bytes.
|
||||
val first := box.run("sh", "hello", ["-c", "md5sum .blossom/*/dist/*"]);
|
||||
_ = box.blossom("hello", ["package", "-f", "tar,zip"]);
|
||||
val second := box.run("sh", "hello", ["-c", "md5sum .blossom/*/dist/*"]);
|
||||
t.expects(first.output.length != 0 && first.output == second.output);
|
||||
|
||||
# A system's package is refused for Windows before anything's built.
|
||||
val windows := box.blossom("hello", ["package", "-f", "deb", "--target", "windows-x86_64"]);
|
||||
t.expects(windows.status == 2 && windows.warns("deb packages are for Linux") && !windows.says("Built"));
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
# Tests of `libraries`, the `--lib` of each library a project holds or reads,
|
||||
# its folder absolute, in the order found, which names what the store is missing
|
||||
# rather than cloning it and refuses what a build refuses; and of `pull`, which
|
||||
# clones what a project requires, or what's named, or with `--update` clones it
|
||||
# again.
|
||||
import std::io;
|
||||
import std::testing;
|
||||
|
||||
@test def libraries_lists_what_a_project_holds_and_reads(t: &mut tester, box: sandbox): void {
|
||||
# Its own library, then what that reads, from a requirement given options;
|
||||
# and no `sakura` is needed, since none is run.
|
||||
box.shapes("shapes");
|
||||
box.write("app/blossomfile", """
|
||||
name: app
|
||||
gpid: tests
|
||||
semv: 1.0.0
|
||||
|
||||
requires:
|
||||
- remote: ../shapes
|
||||
options:
|
||||
flavor: fancy
|
||||
|
||||
targets:
|
||||
- name: app
|
||||
type: program
|
||||
deps: [std, app.parts]
|
||||
srcs: [main.sakura]
|
||||
|
||||
- name: app.parts
|
||||
type: library
|
||||
deps: [shapes.basic]
|
||||
|
||||
tests:
|
||||
- name: app.tests
|
||||
type: program
|
||||
deps: [app.parts, shapes.basic]
|
||||
""");
|
||||
box.write("config/blossom/config", "");
|
||||
val listed := box.blossom("app", ["libraries"], "/usr/bin:/bin");
|
||||
val want := $"--lib app::parts={box.at.view()}/app/app.parts\n--lib shapes::basic={box.at.view()}/shapes/fancy\n";
|
||||
t.expects(listed.status == 0 && listed.output == want, $"{listed.output.view()}{listed.error.view()}".view());
|
||||
|
||||
# Given another folder, it lists that project's.
|
||||
val other := box.blossom(".", ["libraries", "shapes"], "/usr/bin:/bin");
|
||||
t.expects(other.status == 0 && other.output == $"--lib shapes::basic={box.at.view()}/shapes/plain\n", other.output.view());
|
||||
}
|
||||
|
||||
@test def libraries_refuses_what_a_build_refuses(t: &mut tester, box: sandbox): void {
|
||||
box.shapes("hidden", false);
|
||||
box.app("private", "- ../hidden");
|
||||
val private := box.blossom("private", ["libraries"]);
|
||||
t.expects(private.status == 2 && private.output.length == 0, private.output.view());
|
||||
t.expects(private.warns("`shapes.basic`, which `app` reads, isn't exported by tests/shapes@1.0.0."), private.error.view());
|
||||
}
|
||||
|
||||
# Writes a project holding a library, `colors.basic`, and makes a bare git
|
||||
# repository of it, `colors.git`, as `remote` does.
|
||||
def sandbox::colors(&this): bool {
|
||||
this.write("colors/blossomfile", "name: colors\ngpid: tests\nsemv: 1.0.0\ntargets:\n- name: colors.basic\n type: library\nexports:\n- colors.basic\n");
|
||||
this.write("colors/colors.basic/basic.sakura", "module colors::basic;\n\npub def hue(): strview { return \"red\"; }\n");
|
||||
return this.remote("colors", "colors.git");
|
||||
}
|
||||
|
||||
@test def libraries_names_what_the_store_is_missing_and_clones_nothing(t: &mut tester, box: sandbox): void {
|
||||
box.shapes("source");
|
||||
t.expects(box.remote("source", "shapes.git"));
|
||||
box.app("app", $"- file://{box.at.view()}/shapes.git@v1.0.0".view());
|
||||
val listed := box.blossom("app", ["libraries"]);
|
||||
t.expects(listed.status == 0 && listed.output == $"--missing file://{box.at.view()}/shapes.git@v1.0.0\n", listed.output.view());
|
||||
t.expects(listed.warns("1 requirement isn't in the store") && !listed.says("Cloning"), listed.error.view());
|
||||
t.expects(!box.has($"cache/blossom/file{box.at.view()}/shapes@v1.0.0".view()));
|
||||
}
|
||||
|
||||
@test def pull_clones_what_a_project_requires_or_what_is_named(t: &mut tester, box: sandbox): void {
|
||||
box.shapes("source");
|
||||
t.expects(box.remote("source", "shapes.git") && box.colors());
|
||||
val shapes := $"file://{box.at.view()}/shapes.git@v1.0.0";
|
||||
val colors := $"file://{box.at.view()}/colors.git@v1.0.0";
|
||||
val store := $"{box.at.view()}/cache/blossom/file{box.at.view()}";
|
||||
box.write("app/blossomfile", $"name: app\ngpid: tests\nsemv: 1.0.0\nrequires:\n- {shapes.view()}\n- {colors.view()}\ntargets:\n- name: app.parts\n type: library\n deps: [shapes.basic, colors.basic]\n".view());
|
||||
|
||||
# One named by the last part of its path.
|
||||
val one := box.blossom("app", ["pull", "shapes"]);
|
||||
t.expects(one.status == 0 && one.says($"[1/1] Cloned {shapes.view()} ({store.view()}/shapes@v1.0.0)".view()), $"{one.output.view()}{one.error.view()}".view());
|
||||
t.expects(box.has($"cache/blossom/file{box.at.view()}/shapes@v1.0.0".view()) && !box.has($"cache/blossom/file{box.at.view()}/colors@v1.0.0".view()));
|
||||
val listed := box.blossom("app", ["libraries"]);
|
||||
t.expects(listed.output == $"--lib app::parts={box.at.view()}/app/app.parts\n--lib shapes::basic={store.view()}/shapes@v1.0.0/plain\n--missing {colors.view()}\n", listed.output.view());
|
||||
|
||||
# Everything, what's there already said to be.
|
||||
val all := box.blossom("app", ["pull"]);
|
||||
t.expects(all.status == 0 && all.says($"[1/2] Present {shapes.view()}".view()) && all.says($"[2/2] Cloned {colors.view()}".view()), all.output.view());
|
||||
t.expects(all.says("Pulled what tests/app@1.0.0 requires"));
|
||||
t.expects(box.blossom("app", ["libraries"]).output.view().find("--missing") is none);
|
||||
|
||||
# A name of nothing it requires.
|
||||
val none := box.blossom("app", ["pull", "sizes"]);
|
||||
t.expects(none.status == 2 && none.warns($"`sizes` is no requirement of tests/app@1.0.0: it requires `{shapes.view()}`, `{colors.view()}`.".view()), none.error.view());
|
||||
}
|
||||
|
||||
@test def pull_update_clones_a_branch_that_moved_again(t: &mut tester, box: sandbox): void {
|
||||
box.shapes("source");
|
||||
t.expects(box.remote("source", "shapes.git"));
|
||||
box.app("app", $"- file://{box.at.view()}/shapes.git".view());
|
||||
val stored := $"cache/blossom/file{box.at.view()}/shapes@main";
|
||||
t.expects(box.blossom("app", ["pull"]).says("Cloned"));
|
||||
|
||||
# The branch moves; a pull leaves the store's clone as it is.
|
||||
box.write("source/plain/basic.sakura", "module shapes::basic;\n\npub def side(): strview { return \"moved\"; }\n");
|
||||
val pushed := box.run("sh", "source", ["-c", $"git -c user.name=t -c user.email=t@t commit -q -am two && git push -q {box.at.view()}/shapes.git main".view()]);
|
||||
t.expects(pushed.status == 0, pushed.error.view());
|
||||
t.expects(box.blossom("app", ["pull"]).says("Present"));
|
||||
t.expects(box.read($"{stored.view()}/plain/basic.sakura".view()).view().find("plain") is some);
|
||||
|
||||
# With `--update`, it's cloned again, and nothing is left beside it.
|
||||
val updated := box.blossom("app", ["pull", "--update"]);
|
||||
t.expects(updated.status == 0 && updated.says("again") && updated.says("[1/1] Updated"), $"{updated.output.view()}{updated.error.view()}".view());
|
||||
t.expects(box.read($"{stored.view()}/plain/basic.sakura".view()).view().find("moved") is some);
|
||||
t.expects(!box.has($"{stored.view()}.old".view()) && !box.has($"{stored.view()}.partial".view()));
|
||||
val ran := box.blossom("app", ["run"]);
|
||||
t.expects(ran.status == 0 && ran.says("side moved"), ran.error.view());
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
# Runs blossom's tests of its commands. Each makes projects in a folder of its
|
||||
# own, runs the blossom it's given first on them, and compares what it says and
|
||||
# what it makes with what's expected. blossom's config in that folder names the
|
||||
# `sakura` that `SAKURA` names, where it's set, as `blossom test` sets it, which
|
||||
# finds the standard library as it does when it's run alone:
|
||||
#
|
||||
# blossom test --only blossom.commands
|
||||
#
|
||||
# or, from the root of the repository, with a blossom built:
|
||||
#
|
||||
# SAKURA=SAKURA sakura run tests/commands/*.sakura -- BLOSSOM
|
||||
#
|
||||
# Add `--only TEXT` after BLOSSOM to run those whose name holds the text, and
|
||||
# `--here` to run them in one program, as a debugger wants. They run `git`, `sh`,
|
||||
# and `tar`, so they run on Linux.
|
||||
import std::io;
|
||||
import std::process;
|
||||
import system;
|
||||
import std::testing;
|
||||
|
||||
def main(args: span<strview>): void {
|
||||
if args.length == 0 || args[0].starts_with("-") {
|
||||
io::println("blossom's tests are given the blossom they run first, as `-- .blossom/KEY/bin/blossom`.");
|
||||
exit(2);
|
||||
}
|
||||
if process::variable("SAKURA") is none {
|
||||
io::println("blossom's tests run the `sakura` that `SAKURA` names, as `blossom test` sets it.");
|
||||
exit(2);
|
||||
}
|
||||
blossom_at = args[0];
|
||||
exit(tester::run(args));
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
# 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".view(), blossomfile);
|
||||
this.write($"{folder}/main.sakura".view(), "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.view());
|
||||
}
|
||||
|
||||
@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.view());
|
||||
|
||||
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.view());
|
||||
}
|
||||
|
||||
@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.view());
|
||||
|
||||
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.view());
|
||||
|
||||
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.view());
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
# Tests of requirements: a folder beside the project, a remote cloned once into
|
||||
# the store, from a bare git repository in the test's folder, written short with
|
||||
# a ref and without, and as a block giving options, and what's refused: one
|
||||
# project with two sets of options, a library not exported, a name two
|
||||
# projects give, and a clone that fails.
|
||||
import std::io;
|
||||
import std::testing;
|
||||
|
||||
# Writes a project holding a library, `shapes.basic`, whose `side` gives the
|
||||
# text the option `flavor` names a folder of, `plain` unless given.
|
||||
def sandbox::shapes(&this, folder: strview, exported: bool = true): void {
|
||||
var exports := string::new(nothing {});
|
||||
if exported {
|
||||
exports.append("exports:\n- shapes.basic\n");
|
||||
}
|
||||
this.write($"{folder}/blossomfile".view(), $"""
|
||||
name: shapes
|
||||
gpid: tests
|
||||
semv: 1.0.0
|
||||
|
||||
options:
|
||||
flavor: plain
|
||||
|
||||
targets:
|
||||
- name: shapes.basic
|
||||
type: library
|
||||
root: ./$\{flavor\}
|
||||
|
||||
{exports.view()}
|
||||
""".view());
|
||||
this.write($"{folder}/plain/basic.sakura".view(), "module shapes::basic;\n\npub def side(): strview { return \"plain\"; }\n");
|
||||
this.write($"{folder}/fancy/basic.sakura".view(), "module shapes::basic;\n\npub def side(): strview { return \"fancy\"; }\n");
|
||||
}
|
||||
|
||||
# Writes a program, `app`, reading `shapes.basic`, which its blossomfile's
|
||||
# `requires` names.
|
||||
def sandbox::app(&this, folder: strview, requires: strview): void {
|
||||
this.write($"{folder}/blossomfile".view(), $"""
|
||||
name: app
|
||||
gpid: tests
|
||||
semv: 1.0.0
|
||||
|
||||
requires:
|
||||
{requires}
|
||||
|
||||
targets:
|
||||
- name: app
|
||||
type: program
|
||||
deps: [shapes.basic]
|
||||
srcs: [main.sakura]
|
||||
""".view());
|
||||
this.write($"{folder}/main.sakura".view(), """
|
||||
import std::io;
|
||||
import shapes::basic;
|
||||
|
||||
def main(): void {
|
||||
io::println($"side {basic::side()}".view());
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
# Makes a bare git repository of a project, as a remote is, with a commit on
|
||||
# `main` and a tag, `v1.0.0`.
|
||||
def sandbox::remote(&this, from: strview, bare: strview): bool {
|
||||
val made := this.run("sh", from, [
|
||||
"-c",
|
||||
$"git init -q -b main . && git add -A && git -c user.name=t -c user.email=t@t commit -q -m one && git tag v1.0.0 && git clone -q --bare . {this.at.view()}/{bare}".view()
|
||||
]);
|
||||
return made.status == 0;
|
||||
}
|
||||
|
||||
@test def a_folder_beside_the_project_is_required_by_its_path(t: &mut tester, box: sandbox): void {
|
||||
box.shapes("shapes");
|
||||
box.app("app", "- ../shapes");
|
||||
val ran := box.blossom("app", ["run"]);
|
||||
t.expects(ran.status == 0 && ran.says("side plain"), ran.error.view());
|
||||
}
|
||||
|
||||
@test def a_block_gives_a_requirement_values_for_its_options(t: &mut tester, box: sandbox): void {
|
||||
box.shapes("shapes");
|
||||
box.app("app", "- remote: ../shapes\n options:\n flavor: fancy");
|
||||
val ran := box.blossom("app", ["run"]);
|
||||
t.expects(ran.status == 0 && ran.says("side fancy"), ran.error.view());
|
||||
}
|
||||
|
||||
@test def a_remote_is_cloned_once_into_the_store(t: &mut tester, box: sandbox): void {
|
||||
box.shapes("source");
|
||||
t.expects(box.remote("source", "shapes.git"));
|
||||
box.app("app", $"- file://{box.at.view()}/shapes.git@v1.0.0".view());
|
||||
val first := box.blossom("app", ["build"]);
|
||||
t.expects(first.status == 0 && first.says("Cloning file://") && first.says("[1/1] Built app"), first.error.view());
|
||||
t.expects(box.has($"cache/blossom/file{box.at.view()}/shapes@v1.0.0/blossomfile".view()));
|
||||
|
||||
# Cloned, it's taken from the store.
|
||||
val second := box.blossom("app", ["build"]);
|
||||
t.expects(second.status == 0 && !second.says("Cloning"));
|
||||
|
||||
# Without a ref, `main` is cloned.
|
||||
box.app("main", $"- file://{box.at.view()}/shapes.git".view());
|
||||
val main := box.blossom("main", ["run"]);
|
||||
t.expects(main.status == 0 && main.says("side plain"), main.error.view());
|
||||
t.expects(box.has($"cache/blossom/file{box.at.view()}/shapes@main".view()));
|
||||
}
|
||||
|
||||
@test def a_clone_that_fails_says_why(t: &mut tester, box: sandbox): void {
|
||||
box.write("bin/git", "#!/bin/sh\necho 'fatal: the remote hung up' >&2\nexit 128\n");
|
||||
val git := box.at.join("bin/git");
|
||||
_ = io::set_permissions(&git, 0o755);
|
||||
box.app("app", "- https://example.com/shapes@v1.0.0");
|
||||
val built := box.blossom("app", ["build"], $"{box.at.view()}/bin:/usr/bin:/bin".view());
|
||||
t.expects(built.status == 1 && built.warns("fatal: the remote hung up") && built.warns("Cloning https://example.com/shapes@v1.0.0 failed."), built.error.view());
|
||||
t.expects(!box.has("cache/blossom/example.com/shapes@v1.0.0"));
|
||||
}
|
||||
|
||||
@test def requirements_that_dont_fit_are_refused(t: &mut tester, box: sandbox): void {
|
||||
# One project, with two sets of option values.
|
||||
box.shapes("shapes");
|
||||
box.write("other/blossomfile", "name: other\ngpid: tests\nsemv: 1.0.0\nrequires:\n- ../shapes\ntargets:\n- name: other.lib\n type: library\n deps: [shapes.basic]\n");
|
||||
box.app("app", "- ../other\n- remote: ../shapes\n options:\n flavor: fancy");
|
||||
val twice := box.blossom("app", ["build"]);
|
||||
t.expects(twice.status == 2 && twice.warns("tests/shapes@1.0.0 is required with two sets of option values"), twice.error.view());
|
||||
|
||||
# A library its project doesn't export.
|
||||
box.shapes("hidden", false);
|
||||
box.app("private", "- ../hidden");
|
||||
val private := box.blossom("private", ["build"]);
|
||||
t.expects(private.status == 2 && private.warns("`shapes.basic`, which `app` reads, isn't exported by tests/shapes@1.0.0."), private.error.view());
|
||||
|
||||
# One name, two projects.
|
||||
box.write("copy/blossomfile", "name: copy\ngpid: tests\nsemv: 1.0.0\ntargets:\n- name: shapes.basic\n type: library\n root: ./plain\nexports:\n- shapes.basic\n");
|
||||
box.write("copy/plain/basic.sakura", "module shapes::basic;\n\npub def side(): strview { return \"copy\"; }\n");
|
||||
box.app("both", "- ../shapes\n- ../copy");
|
||||
val clash := box.blossom("both", ["build"]);
|
||||
t.expects(clash.status == 2 && clash.warns("`shapes.basic` is a library of both"), clash.error.view());
|
||||
|
||||
# A library no project has.
|
||||
box.app("none", " []");
|
||||
t.expects(box.blossom("none", ["build"]).warns("`shapes.basic`, which `app` reads, is no library"));
|
||||
}
|
||||
|
||||
@test def a_requirement_reads_what_it_requires_only_where_its_libraries_need_it(t: &mut tester, box: sandbox): void {
|
||||
# What `shapes` requires for itself alone, which can't be fetched, isn't.
|
||||
box.shapes("shapes");
|
||||
val text := box.read("shapes/blossomfile");
|
||||
box.write("shapes/blossomfile", $"{text.view()}\nrequires:\n- https://example.invalid/never@v1.0.0\n".view());
|
||||
box.app("app", "- ../shapes");
|
||||
val ran := box.blossom("app", ["run"]);
|
||||
t.expects(ran.status == 0 && ran.says("side plain") && !ran.says("Cloning"), ran.error.view());
|
||||
|
||||
# A library reading one of what its project requires brings that along.
|
||||
box.shapes("inner");
|
||||
box.write("outer/blossomfile", """
|
||||
name: outer
|
||||
gpid: tests
|
||||
semv: 1.0.0
|
||||
|
||||
requires:
|
||||
- ../inner
|
||||
|
||||
targets:
|
||||
- name: outer.lib
|
||||
type: library
|
||||
deps: [shapes.basic]
|
||||
|
||||
exports:
|
||||
- outer.lib
|
||||
""");
|
||||
box.write("outer/outer.lib/lib.sakura", "import shapes::basic;\n\nmodule outer::lib;\n\npub def says(): strview { return basic::side(); }\n");
|
||||
box.write("user/blossomfile", "name: user\ngpid: tests\nsemv: 1.0.0\nrequires:\n- ../outer\ntargets:\n- name: user\n type: program\n deps: [outer.lib]\n srcs: [main.sakura]\n");
|
||||
box.write("user/main.sakura", "import std::io;\nimport outer::lib;\n\ndef main(): void { io::println($\"says {lib::says()}\".view()); }\n");
|
||||
val through := box.blossom("user", ["run"]);
|
||||
t.expects(through.status == 0 && through.says("says plain"), through.error.view());
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
# What blossom's tests of its commands share: the blossom they run, a folder of
|
||||
# each test's own, writing projects into it, and running blossom there.
|
||||
import std::io;
|
||||
import std::process;
|
||||
import system;
|
||||
import std::testing;
|
||||
|
||||
#! The blossom the tests run, which `main` is given first.
|
||||
var blossom_at: strview = "";
|
||||
|
||||
#! A folder of a test's own, holding the projects it makes, and blossom's
|
||||
#! config, in `config`, and store, in `cache`, removed with all it holds where
|
||||
#! the test returns.
|
||||
struct sandbox : fixture<sandbox>, owning {
|
||||
var at: path;
|
||||
}
|
||||
|
||||
def sandbox::setup(t: &mut tester): sandbox {
|
||||
for n in 0..10000 {
|
||||
var at := path::parse($"/tmp/blossom-tests-{n}".view()) else (_) { break; };
|
||||
if io::create_directory(&at) is error(_) {
|
||||
continue;
|
||||
}
|
||||
var made := sandbox { at = move(at) };
|
||||
var config := string::new(nothing {});
|
||||
if process::variable("SAKURA") is some(sakura) {
|
||||
config.append($"sakura: {sakura}\n".view());
|
||||
}
|
||||
made.write("config/blossom/config", config.view());
|
||||
return made;
|
||||
}
|
||||
system::abort();
|
||||
return sandbox {};
|
||||
}
|
||||
|
||||
def sandbox::close(&mut this): void {
|
||||
var remove := process::command::new("rm");
|
||||
remove.arguments(["-rf", this.at.view()]);
|
||||
_ = remove.run();
|
||||
}
|
||||
|
||||
#! Writes a file in the sandbox, making the folders above it.
|
||||
#! @param this The sandbox.
|
||||
#! @param name The file, relative to the sandbox.
|
||||
#! @param text What it holds.
|
||||
def sandbox::write(&this, name: strview, text: strview): void {
|
||||
val at := this.at.join(name);
|
||||
if at.parent() is some(&above) {
|
||||
_ = io::create_directories(above);
|
||||
}
|
||||
_ = io::write_file(&at, text);
|
||||
}
|
||||
|
||||
#! Reads a file of the sandbox.
|
||||
#! @param this The sandbox.
|
||||
#! @param name The file, relative to the sandbox.
|
||||
#! @returns What it holds, or empty text where it can't be read.
|
||||
def sandbox::read(&this, name: strview): string {
|
||||
val at := this.at.join(name);
|
||||
return io::read_file(&at) else (_) { return string::new(nothing {}); };
|
||||
}
|
||||
|
||||
#! Whether a file or folder is in the sandbox.
|
||||
#! @param this The sandbox.
|
||||
#! @param name Its path, relative to the sandbox.
|
||||
#! @returns Whether it is.
|
||||
def sandbox::has(&this, name: strview): bool {
|
||||
val at := this.at.join(name);
|
||||
return io::exists(&at);
|
||||
}
|
||||
|
||||
#! What a command said, and the status it ended with.
|
||||
struct said {
|
||||
var status: i32;
|
||||
var output: string;
|
||||
var error: string;
|
||||
}
|
||||
|
||||
#! Whether what a command wrote to its output holds some text.
|
||||
#! @param this What it said.
|
||||
#! @param text The text.
|
||||
#! @returns Whether it does.
|
||||
def said::says(&this, text: strview): bool {
|
||||
return this.output.view().find(text) is some;
|
||||
}
|
||||
|
||||
#! Whether what a command wrote to its error holds some text.
|
||||
#! @param this What it said.
|
||||
#! @param text The text.
|
||||
#! @returns Whether it does.
|
||||
def said::warns(&this, text: strview): bool {
|
||||
return this.error.view().find(text) is some;
|
||||
}
|
||||
|
||||
#! Runs blossom in a folder of the sandbox, its config and store the sandbox's.
|
||||
#! @param this The sandbox.
|
||||
#! @param folder The folder, relative to the sandbox.
|
||||
#! @param words What blossom is given.
|
||||
#! @param path What `PATH` is, or empty for the tests' own.
|
||||
#! @returns What it said.
|
||||
def sandbox::blossom(&this, folder: strview, words: span<strview>, path: strview = ""): said {
|
||||
return this.run(blossom_at, folder, words, path);
|
||||
}
|
||||
|
||||
#! Runs a program in a folder of the sandbox, as `blossom` does.
|
||||
#! @param this The sandbox.
|
||||
#! @param program The program.
|
||||
#! @param folder The folder, relative to the sandbox.
|
||||
#! @param words What it's given.
|
||||
#! @param path What `PATH` is, or empty for the tests' own.
|
||||
#! @returns What it said.
|
||||
def sandbox::run(&this, program: strview, folder: strview, words: span<strview>, path: strview = ""): said {
|
||||
var command := process::command::new(program);
|
||||
command.arguments(words);
|
||||
val at := this.at.join(folder);
|
||||
command.directory(&at);
|
||||
command.set_variable("XDG_CONFIG_HOME", $"{this.at.view()}/config".view());
|
||||
command.set_variable("XDG_CACHE_HOME", $"{this.at.view()}/cache".view());
|
||||
command.set_variable("SOURCE_DATE_EPOCH", "1700000000");
|
||||
if path.length != 0 {
|
||||
command.set_variable("PATH", path);
|
||||
}
|
||||
var got := command.capture() else (why) {
|
||||
return said { status = -1, output = string::new(nothing {}), error = $"`{program}` can't be run: {why}" };
|
||||
};
|
||||
var code: i32 = -1;
|
||||
if got.status is exited(exited) {
|
||||
code = exited;
|
||||
}
|
||||
return said { status = code, output = move(got.output), error = move(got.error) };
|
||||
}
|
||||
|
||||
#! The path a line of blossom's output gives in parentheses, as the program of
|
||||
#! `[2/2] Built hello (.blossom/KEY/bin/hello)`, relative to the project.
|
||||
#! @param text What blossom said.
|
||||
#! @param name The target.
|
||||
#! @returns The path, or empty text.
|
||||
def built_path(text: strview, name: strview): strview {
|
||||
val marker := $"Built {name} (";
|
||||
val at := text.find(marker.view()) else { return strview::empty(); };
|
||||
val from := at + marker.length;
|
||||
val rest := text.substr(from, text.length - from);
|
||||
val end := rest.find(")") else { return strview::empty(); };
|
||||
return rest.substr(0, end);
|
||||
}
|
||||
|
||||
#! Writes a project, `hello`, in a folder of the sandbox: a program reading a
|
||||
#! library of its own, `hello.geometry`, which holds a module within it, and
|
||||
#! tests of the library, as the plan's "Using it" has it.
|
||||
#! @param this The sandbox.
|
||||
#! @param folder The project's folder.
|
||||
#! @param more What's added to its blossomfile.
|
||||
def sandbox::hello(&this, folder: strview, more: strview = ""): void {
|
||||
this.write($"{folder}/blossomfile".view(), $"""
|
||||
name: hello
|
||||
gpid: tests
|
||||
semv: 1.0.0
|
||||
|
||||
options:
|
||||
level: 2
|
||||
|
||||
targets:
|
||||
- name: hello
|
||||
type: program
|
||||
level: $\{level\}
|
||||
deps: [std, hello.geometry]
|
||||
srcs: [main.sakura]
|
||||
|
||||
- name: hello.geometry
|
||||
type: library
|
||||
|
||||
tests:
|
||||
- name: hello.tests
|
||||
type: program
|
||||
deps: [hello.geometry]
|
||||
{more}
|
||||
""".view());
|
||||
this.write($"{folder}/main.sakura".view(), """
|
||||
import std::io;
|
||||
import hello::geometry;
|
||||
import hello::geometry::solids;
|
||||
|
||||
def main(args: span<strview>): void {
|
||||
io::println($"area {geometry::area(3, 4)} cube {solids::cube(2)} given {args.length}".view());
|
||||
}
|
||||
""");
|
||||
this.write($"{folder}/hello.geometry/shapes.sakura".view(), """
|
||||
module hello::geometry;
|
||||
|
||||
pub def area(w: i64, h: i64): i64 { return w * h; }
|
||||
""");
|
||||
this.write($"{folder}/hello.geometry/solids/solids.sakura".view(), """
|
||||
module hello::geometry::solids;
|
||||
|
||||
pub def cube(side: i64): i64 { return side * side * side; }
|
||||
""");
|
||||
this.write($"{folder}/tests/main.sakura".view(), """
|
||||
import system;
|
||||
import std::testing;
|
||||
import hello::geometry;
|
||||
import hello::geometry::solids;
|
||||
|
||||
def main(args: span<strview>): void { exit(tester::run(args)); }
|
||||
|
||||
@test def areas_multiply(t: &mut tester): void { t.expects(geometry::area(2, 5) == 10); }
|
||||
@test def cubes_cube(t: &mut tester): void { t.expects(solids::cube(3) == 27); }
|
||||
""");
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# Runs blossom's tests of its parts, which read its own files:
|
||||
#
|
||||
# blossom test --only blossom.units
|
||||
#
|
||||
# or, from the root of the repository, with the standard library beside it:
|
||||
#
|
||||
# sakurac run --lib std=../std
|
||||
# models/*.sakura management/*.sakura pipeline/*.sakura tests/units/*.sakura
|
||||
import system;
|
||||
import std::testing;
|
||||
|
||||
def main(args: span<strview>): void {
|
||||
exit(tester::run(args));
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
# 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'");
|
||||
}
|
||||
Reference in new issue
Block a user