122 lines
6.5 KiB
Plaintext
122 lines
6.5 KiB
Plaintext
# 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;
|
||
|
|
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());
|
||
|
|
}
|