204 lines
6.6 KiB
Plaintext
204 lines
6.6 KiB
Plaintext
# Tests of members: folders of a project holding blossomfiles of their own,
|
|
# which say whose members they are, read as one project with it, from its
|
|
# folder or a member's; a library's files, but its member's tests'; members
|
|
# that say nothing, or another project, or that no project lists; what a member
|
|
# requires, from its own folder; and a project requiring one of members.
|
|
import std::io;
|
|
import std::testing;
|
|
|
|
# Writes a project, `shop`, of two members: `shapes`, a library, `shop.shapes`,
|
|
# whose folder is the member's own, and its tests beside it in `tests`; and
|
|
# `app`, a program reading it.
|
|
def sandbox::shop(&this, folder: strview): void {
|
|
this.write($"{folder}/blossomfile".span, """
|
|
name: shop
|
|
gpid: tests
|
|
semv: 1.0.0
|
|
|
|
members:
|
|
- shapes
|
|
- ./app/
|
|
|
|
exports:
|
|
- shop.shapes
|
|
""");
|
|
this.write($"{folder}/shapes/blossomfile".span, """
|
|
member: shop
|
|
|
|
targets:
|
|
- name: shop.shapes
|
|
type: library
|
|
root: .
|
|
|
|
tests:
|
|
- name: shop.shapes.tests
|
|
type: program
|
|
deps: [shop.shapes]
|
|
""");
|
|
this.write($"{folder}/shapes/area.sakura".span, """
|
|
module shop::shapes;
|
|
|
|
pub def area(w: i64, h: i64): i64 { return w * h; }
|
|
""");
|
|
this.write($"{folder}/shapes/tests/main.sakura".span, """
|
|
import system;
|
|
import std::testing;
|
|
import shop::shapes;
|
|
|
|
def main(args: span<strview>): void { exit(tester::run(args)); }
|
|
|
|
@test def areas_multiply(t: &mut tester): void { t.expects(shapes::area(2, 5) == 10); }
|
|
""");
|
|
this.write($"{folder}/app/blossomfile".span, """
|
|
member: shop
|
|
|
|
targets:
|
|
- name: shop
|
|
type: program
|
|
deps: [std, shop.shapes]
|
|
srcs: [main.sakura]
|
|
""");
|
|
this.write($"{folder}/app/main.sakura".span, """
|
|
import std::io;
|
|
import shop::shapes;
|
|
|
|
def main(args: span<strview>): void {
|
|
io::println($"area {shapes::area(3, 4)}".span);
|
|
}
|
|
""");
|
|
}
|
|
|
|
@test def members_are_built_and_tested_as_one_project(t: &mut tester, box: sandbox): void {
|
|
box.shop("shop");
|
|
val tested := box.blossom("shop", ["test"]);
|
|
t.expects(tested.status == 0 && tested.says("[1/3] Checked shop.shapes") && tested.says("Built shop"), tested.output.span);
|
|
t.expects(tested.says("[3/3] Tested shop.shapes.tests (1 passed)") && tested.says("Tested tests/shop@1.0.0"), tested.output.span);
|
|
# The library's files are its member's, but those its tests list.
|
|
val checked := box.blossom("shop", ["check", "-v"]);
|
|
t.expects(checked.status == 0 && checked.says("area.sakura"), checked.output.span);
|
|
t.expects(!checked.says("tests/main.sakura") && !checked.says("tests\\main.sakura"), checked.output.span);
|
|
# Its program, of the member's file, runs as the project's.
|
|
val ran := box.blossom("shop", ["run"]);
|
|
t.expects(ran.status == 0 && ran.says("area 12"), ran.output.span);
|
|
}
|
|
|
|
@test def a_members_folder_keeps_to_the_member(t: &mut tester, box: sandbox): void {
|
|
box.shop("shop");
|
|
val tested := box.blossom("shop/shapes", ["test"]);
|
|
t.expects(tested.status == 0 && tested.says("[2/2] Tested shop.shapes.tests (1 passed)") && !tested.says("Built shop"), tested.output.span);
|
|
# Its outputs are the project's.
|
|
t.expects(box.has("shop/.blossom") && !box.has("shop/shapes/.blossom"));
|
|
# Its mistakes name it.
|
|
val none := box.blossom("shop/app", ["test"]);
|
|
t.expects(none.status == 2 && none.error.span.find("app of tests/shop@1.0.0 has no tests.") is some, none.error.span);
|
|
val ran := box.blossom("shop/app", ["run"]);
|
|
t.expects(ran.status == 0 && ran.says("area 12"), ran.output.span);
|
|
}
|
|
|
|
@test def members_say_whose_they_are(t: &mut tester, box: sandbox): void {
|
|
box.shop("shop");
|
|
box.write("shop/app/blossomfile", """
|
|
targets: []
|
|
""");
|
|
val unsaid := box.blossom("shop", ["build"]);
|
|
t.expects(unsaid.status == 2 && unsaid.error.span.find("`member` is needed.") is some, unsaid.error.span);
|
|
box.write("shop/app/blossomfile", """
|
|
member: market
|
|
""");
|
|
val other := box.blossom("shop", ["build"]);
|
|
t.expects(other.status == 2 && other.error.span.find("member of `market`, but `shop` lists it") is some, other.error.span);
|
|
# A member's blossomfile is never a project's of its own.
|
|
box.write("shop/app/blossomfile", """
|
|
member: shop
|
|
name: app
|
|
""");
|
|
val named := box.blossom("shop", ["build"]);
|
|
t.expects(named.status == 2 && named.error.span.find("`name` is no key of a member's blossomfile.") is some, named.error.span);
|
|
# One no project lists is read by no command.
|
|
box.shop("shop");
|
|
box.write("shop/loose/blossomfile", """
|
|
member: shop
|
|
""");
|
|
val loose := box.blossom("shop/loose", ["build"]);
|
|
t.expects(loose.status == 2 && loose.error.span.find("no blossomfile above it lists its folder in `members`") is some, loose.error.span);
|
|
# Members name their targets apart from each other.
|
|
box.write("shop/app/blossomfile", """
|
|
member: shop
|
|
|
|
targets:
|
|
- name: shop.shapes
|
|
type: library
|
|
""");
|
|
val twice := box.blossom("shop", ["build"]);
|
|
t.expects(twice.status == 2 && twice.error.span.find("`shop.shapes` names two targets") is some, twice.error.span);
|
|
}
|
|
|
|
@test def a_member_requires_from_its_own_folder(t: &mut tester, box: sandbox): void {
|
|
box.shop("shop");
|
|
box.write("extra/blossomfile", """
|
|
name: extra
|
|
gpid: tests
|
|
semv: 1.0.0
|
|
|
|
targets:
|
|
- name: extra.numbers
|
|
type: library
|
|
|
|
exports:
|
|
- extra.numbers
|
|
""");
|
|
box.write("extra/extra.numbers/twice.sakura", """
|
|
module extra::numbers;
|
|
|
|
pub def twice(n: i64): i64 { return n * 2; }
|
|
""");
|
|
box.write("shop/shapes/blossomfile", """
|
|
member: shop
|
|
|
|
requires:
|
|
- ../../extra
|
|
|
|
targets:
|
|
- name: shop.shapes
|
|
type: library
|
|
root: .
|
|
deps: [extra.numbers]
|
|
""");
|
|
box.write("shop/shapes/area.sakura", """
|
|
import extra::numbers;
|
|
module shop::shapes;
|
|
|
|
pub def area(w: i64, h: i64): i64 { return numbers::twice(w * h) / 2; }
|
|
""");
|
|
val built := box.blossom("shop", ["build"]);
|
|
t.expects(built.status == 0 && built.says("Built shop"), built.error.span);
|
|
}
|
|
|
|
@test def a_project_requiring_one_of_members_reads_their_libraries(t: &mut tester, box: sandbox): void {
|
|
box.shop("shop");
|
|
box.write("user/blossomfile", """
|
|
name: user
|
|
gpid: tests
|
|
semv: 1.0.0
|
|
|
|
requires:
|
|
- ../shop
|
|
|
|
targets:
|
|
- name: user
|
|
type: program
|
|
deps: [std, shop.shapes]
|
|
srcs: [main.sakura]
|
|
""");
|
|
box.write("user/main.sakura", """
|
|
import std::io;
|
|
import shop::shapes;
|
|
|
|
def main(args: span<strview>): void {
|
|
io::println($"used {shapes::area(2, 3)}".span);
|
|
}
|
|
""");
|
|
val built := box.blossom("user", ["run"]);
|
|
t.expects(built.status == 0 && built.says("used 6"), built.error.span);
|
|
}
|