Initial Commit
This commit is contained in:
27 files changed
+6198
No files matched your search
@@ -0,0 +1,125 @@
|
||||
# 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"], box.search_path().span);
|
||||
val want := $"--lib app::parts={box.path_of("app/app.parts")}\n--lib shapes::basic={box.path_of("shapes/fancy")}\n";
|
||||
t.expects(listed.status == 0 && listed.output == want, $"{listed.output.span}{listed.error.span}".span);
|
||||
|
||||
# Given another folder, it lists that project's.
|
||||
val other := box.blossom(".", ["libraries", "shapes"], box.search_path().span);
|
||||
t.expects(other.status == 0 && other.output == $"--lib shapes::basic={box.path_of("shapes/plain")}\n", other.output.span);
|
||||
}
|
||||
|
||||
@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.span);
|
||||
t.expects(private.warns("`shapes.basic`, which `app` reads, isn't exported by tests/shapes@1.0.0."), private.error.span);
|
||||
}
|
||||
|
||||
# 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"));
|
||||
val shapes := $"{box.url("shapes.git")}@v1.0.0";
|
||||
box.app("app", $"- {shapes}".span);
|
||||
val listed := box.blossom("app", ["libraries"]);
|
||||
t.expects(listed.status == 0 && listed.output == $"--missing {shapes}\n", listed.output.span);
|
||||
t.expects(listed.warns("1 requirement isn't in the store") && !listed.says("Cloning"), listed.error.span);
|
||||
t.expects(box.stored("shapes@v1.0.0").length == 0);
|
||||
}
|
||||
|
||||
@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 := $"{box.url("shapes.git")}@v1.0.0";
|
||||
val colors := $"{box.url("colors.git")}@v1.0.0";
|
||||
box.write("app/blossomfile", $"name: app\ngpid: tests\nsemv: 1.0.0\nrequires:\n- {shapes.span}\n- {colors.span}\ntargets:\n- name: app.parts\n type: library\n deps: [shapes.basic, colors.basic]\n".span);
|
||||
|
||||
# One named by the last part of its path.
|
||||
val one := box.blossom("app", ["pull", "shapes"]);
|
||||
val stored := box.stored("shapes@v1.0.0");
|
||||
t.expects(one.status == 0 && stored.length != 0 && one.says($"[1/1] Cloned {shapes.span} ({stored})".span), $"{one.output.span}{one.error.span}".span);
|
||||
t.expects(box.stored("colors@v1.0.0").length == 0);
|
||||
val plain := box.path_of($"{stored}/plain".span);
|
||||
val listed := box.blossom("app", ["libraries"]);
|
||||
t.expects(listed.output == $"--lib app::parts={box.path_of("app/app.parts")}\n--lib shapes::basic={plain}\n--missing {colors.span}\n", listed.output.span);
|
||||
|
||||
# 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.span}".span) && all.says($"[2/2] Cloned {colors.span}".span), all.output.span);
|
||||
t.expects(all.says("Pulled what tests/app@1.0.0 requires"));
|
||||
t.expects(box.blossom("app", ["libraries"]).output.span.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.span}`, `{colors.span}`.".span), none.error.span);
|
||||
}
|
||||
|
||||
@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", $"- {box.url("shapes.git")}".span);
|
||||
t.expects(box.blossom("app", ["pull"]).says("Cloned"));
|
||||
val stored := box.stored("shapes@main");
|
||||
t.expects(stored.length != 0);
|
||||
|
||||
# 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 bare := box.path_of("shapes.git");
|
||||
t.expects(box.git("source", ["-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "-am", "two"])
|
||||
&& box.git("source", ["push", "-q", bare.span, "main"]));
|
||||
t.expects(box.blossom("app", ["pull"]).says("Present"));
|
||||
t.expects(box.read($"{stored.span}/plain/basic.sakura".span).span.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.span}{updated.error.span}".span);
|
||||
t.expects(box.read($"{stored.span}/plain/basic.sakura".span).span.find("moved") is some);
|
||||
t.expects(!box.has($"{stored.span}.old".span) && !box.has($"{stored.span}.partial".span));
|
||||
val ran := box.blossom("app", ["run"]);
|
||||
t.expects(ran.status == 0 && ran.says("side moved"), ran.error.span);
|
||||
}
|
||||
Reference in new issue
Block a user