Initial Commit
This commit is contained in:
28 files changed
+6914
No files matched your search
@@ -0,0 +1,150 @@
|
||||
# Tests of `test`, `install`, and `package`: tests passing, failing, run
|
||||
# natively, and suites and tests 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.span);
|
||||
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]}".span);
|
||||
exit(args[0].ends_with("bin") && args[1] == "second" ? 0 : 1);
|
||||
}
|
||||
""");
|
||||
val tested := box.blossom("hello", ["test", "--suite", "given"]);
|
||||
t.expects(tested.status == 0 && tested.says("[3/3] Tested given.tests") && !tested.says("hello.tests"), tested.output.span);
|
||||
t.expects(tested.says($"given {box.path_of("hello/.blossom")}".span));
|
||||
t.expects(box.blossom("hello", ["test", "--suite", "none"]).status == 2);
|
||||
}
|
||||
|
||||
@test def tests_are_chosen_by_name_within_the_suites_run(t: &mut tester, box: sandbox): void {
|
||||
box.hello("hello");
|
||||
# Each suite is given `--only cubes`, so it runs that test alone.
|
||||
val tested := box.blossom("hello", ["test", "--test", "cubes"]);
|
||||
t.expects(tested.status == 0 && tested.says("[ OK ] cubes_cube") && !tested.says("areas_multiply"), tested.output.span);
|
||||
t.expects(tested.says("[3/3] Tested hello.tests (1 passed)"), tested.output.span);
|
||||
# Within the suites chosen.
|
||||
val both := box.blossom("hello", ["test", "--suite", "hello", "--test", "areas"]);
|
||||
t.expects(both.status == 0 && both.says("[ OK ] areas_multiply") && !both.says("cubes_cube"), both.output.span);
|
||||
# A test named in no suite run is a mistake in the command, as a suite is.
|
||||
val none := box.blossom("hello", ["test", "--test", "spheres"]);
|
||||
t.expects(none.status == 2 && none.says("[3/3] Tested hello.tests (none named with `spheres`)"), none.output.span);
|
||||
t.expects(none.error.span.find("No test of tests/hello@1.0.0 is named with `spheres`.") is some, none.error.span);
|
||||
}
|
||||
|
||||
@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.span}/prefix".span]);
|
||||
t.expects(installed.status == 0 && installed.says("Installed tests/hello@1.0.0 (7 files)"), installed.error.span);
|
||||
val hello := program("hello");
|
||||
t.expects(box.has($"prefix/bin/{hello}".span), hello.span);
|
||||
for name in ["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.path_of($"prefix/bin/{hello}".span).span, ".", span::<strview>::blank());
|
||||
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.path_of("stage").span]);
|
||||
t.expects(staged.status == 0 && box.has($"stage/usr/local/bin/{hello}".span), staged.error.span);
|
||||
}
|
||||
|
||||
# A program for Linux shown as a desktop's program is installed with its icons
|
||||
# in the icon theme and its desktop entry; one for Windows holds them itself.
|
||||
@test def install_puts_a_desktop_entry_and_icons_beside_a_program_for_linux(t: &mut tester, box: sandbox): void {
|
||||
box.shown("shown");
|
||||
val installed := box.blossom("shown", ["install", "--target", "linux-x86_64", "--prefix", $"{box.at.span}/prefix".span]);
|
||||
t.expects(installed.status == 0 && installed.says("Installed tests/shown@2.1.0 (4 files)"), installed.error.span);
|
||||
t.expects(box.has("prefix/bin/shown"));
|
||||
t.expects(box.has("prefix/share/icons/hicolor/32x32/apps/shown.png"));
|
||||
t.expects(box.has("prefix/share/icons/hicolor/scalable/apps/shown.svg"));
|
||||
val entry := box.read("prefix/share/applications/shown.desktop");
|
||||
t.expects(entry.span.starts_with("[Desktop Entry]\nType=Application\nName=Shown Off\nExec="), entry.span);
|
||||
t.expects(entry.span.find("/prefix/bin/shown\nIcon=shown\nTerminal=false\nStartupWMClass=shown\n") is some, entry.span);
|
||||
t.expects(entry.span.find("\\") is none);
|
||||
|
||||
# In a console, it runs in a terminal.
|
||||
val console := box.blossom("shown", ["install", "--target", "linux-x86_64", "-o", "windowed=false", "--prefix", $"{box.at.span}/console".span]);
|
||||
t.expects(console.status == 0 && box.read("console/share/applications/shown.desktop").span.find("Terminal=true\n") is some, console.error.span);
|
||||
|
||||
# A package names it where the package installs it.
|
||||
val packaged := box.blossom("shown", ["package", "-f", "tar", "--target", "linux-x86_64"]);
|
||||
t.expects(packaged.status == 0, packaged.error.span);
|
||||
val dist := box.dist("shown");
|
||||
val stage := $"{dist.span.substr(0, dist.length - 4)}stage/share/applications/shown.desktop";
|
||||
val parsed := path::parse(stage.span) else (_) { return; };
|
||||
val staged := io::read_file(&parsed) else (_) {
|
||||
t.expects(false, stage.span);
|
||||
return;
|
||||
};
|
||||
t.expects(staged.span.find("Exec=/usr/bin/shown\n") is some, staged.span);
|
||||
|
||||
# For Windows, nothing's put beside it.
|
||||
val windows := box.blossom("shown", ["install", "--target", "windows-x86_64", "--prefix", $"{box.at.span}/windows".span]);
|
||||
t.expects(windows.status == 0 && box.has("windows/bin/shown.exe") && !box.has("windows/share"), windows.error.span);
|
||||
}
|
||||
|
||||
# A package for Linux, made on any system, compressed by the `gzip` on `PATH`.
|
||||
@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", "--target", "linux-x86_64"]);
|
||||
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.span);
|
||||
|
||||
val dist := box.dist("hello");
|
||||
val tar := box.path_of($"{dist}/hello-1.0.0-linux-x86_64.tar.gz".span);
|
||||
val listed := box.run("tar", "hello", ["-tzf", tar.span]);
|
||||
t.expects(lines_of(listed.output.span) == "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.span);
|
||||
val zip := box.read($"{dist}/hello-1.0.0-linux-x86_64.zip".span);
|
||||
t.expects(zip.span.starts_with("PK"));
|
||||
|
||||
# The same stage makes the same bytes.
|
||||
val first := box.read(tar.span);
|
||||
_ = box.blossom("hello", ["package", "-f", "tar,zip", "--target", "linux-x86_64"]);
|
||||
t.expects(first.length != 0 && box.read(tar.span) == first && box.read($"{dist}/hello-1.0.0-linux-x86_64.zip".span) == zip);
|
||||
|
||||
# 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"));
|
||||
}
|
||||
Reference in new issue
Block a user