diff --git a/Formula/b/beakerlib.rb b/Formula/b/beakerlib.rb new file mode 100644 index 00000000000000..5767c08dca88b8 --- /dev/null +++ b/Formula/b/beakerlib.rb @@ -0,0 +1,39 @@ +class Beakerlib < Formula + desc "Shell-level integration testing library" + homepage "https://github.com/beakerlib/beakerlib" + url "https://github.com/beakerlib/beakerlib/archive/refs/tags/1.29.3.tar.gz" + sha256 "f792b86bac8be1a4593dd096c32c1a061102c802c6f5760259a5753b13f6caa1" + license "GPL-2.0-only" + + on_macos do + # Fix `readlink` + depends_on "coreutils" + depends_on "gnu-getopt" + end + + def install + system "make", "DD=#{prefix}", "install" + (prefix.glob "**/*.sh").each do |f| + inreplace f, "readlink", "#{Formula["coreutils"].opt_bin}/greadlink", false if OS.mac? + inreplace f, "getopt", "#{Formula["gnu-getopt"].opt_bin}/getopt", false if OS.mac? + end + end + + test do + (testpath/"test.sh").write <<~EOS + #!/usr/bin/env bash + source #{share}/beakerlib/beakerlib.sh || exit 1 + rlJournalStart + rlPhaseStartTest + rlPass "All works" + rlPhaseEnd + rlJournalEnd + EOS + expected_journal = /\[\s*PASS\s*\]\s*::\s*All works/ + ENV["BEAKERLIB_DIR"] = testpath + system "bash", "#{testpath}/test.sh" + assert_match expected_journal, File.read(testpath/"journal.txt") + assert_match "TESTRESULT_STATE=complete", File.read(testpath/"TestResults") + assert_match "TESTRESULT_RESULT_STRING=PASS", File.read(testpath/"TestResults") + end +end