# 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): 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::::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")); }