Merge pull request #207012 from Homebrew/bump-tailwindcss-4.0.5
[Homebrew/homebrew-core.git] / Formula / t / tinycdb.rb
blob01e53a63948a478e64bab56ca0c2f09d6aec1954
1 class Tinycdb < Formula
2   desc "Create and read constant databases"
3   homepage "https://www.corpit.ru/mjt/tinycdb.html"
4   url "https://www.corpit.ru/mjt/tinycdb/tinycdb-0.81.tar.gz"
5   sha256 "469de2d445bf54880f652f4b6dc95c7cdf6f5502c35524a45b2122d70d47ebc2"
6   license :public_domain
7   revision 1
9   livecheck do
10     url :homepage
11     regex(/href=.*?tinycdb[._-]v?(\d+(?:\.\d+)+)\.t/i)
12   end
14   bottle do
15     sha256 cellar: :any,                 arm64_sequoia: "680cfcfc325b233fe7340563af3250740568b8a3689fae20f477e108ed673a8e"
16     sha256 cellar: :any,                 arm64_sonoma:  "345b0faa2f7c6d23974d5c2428eb7961fbf0934a5064e39f1d957469c6ca491c"
17     sha256 cellar: :any,                 arm64_ventura: "29a4f84b5a7f2f4eeb6301260a9dd6dc063428a9550bb646b526c3cca3d96565"
18     sha256 cellar: :any,                 sonoma:        "00517e16683f21a47b6f985fd00927be4fca3c501aa34e445008aad1f9bbf7ea"
19     sha256 cellar: :any,                 ventura:       "c803d0c447413f5d29e43172e75c6a6ac54f6b23b2c85c469e1d0a2930932b95"
20     sha256 cellar: :any_skip_relocation, x86_64_linux:  "e936f20c0ba2216f0ead62448ee2793eb96181c32bb381b9f3207e34e3ce46b5"
21   end
23   def libcdb_soversion
24     # This value is used only on macOS.
25     # If the test block fails only on Linux, then this value likely needs updating.
26     "1"
27   end
29   def install
30     system "make"
31     system "make", "install", "prefix=#{prefix}", "mandir=#{man}"
33     shared_flags = ["prefix=#{prefix}"]
34     shared_flags += if OS.mac?
35       %W[
36         SHAREDLIB=#{shared_library("$(LIBBASE)", libcdb_soversion)}
37         SOLIB=#{shared_library("$(LIBBASE)")}
38         LDFLAGS_SONAME=-Wl,-install_name,$(prefix)/
39         LDFLAGS_VSCRIPT=
40         LIBMAP=
41       ]
42     end.to_a
44     system "make", *shared_flags, "shared"
45     system "make", *shared_flags, "install-sharedlib"
46   end
48   test do
49     (testpath/"test.c").write <<~C
50       #include <stdio.h>
51       #include <fcntl.h>
52       #include <cdb.h>
54       int main() {
55         struct cdb_make cdbm;
56         int fd;
57         char *key = "test",
58              *val = "homebrew";
59         unsigned klen = 4,
60                  vlen = 8;
62         fd = open("#{testpath}/db", O_RDWR|O_CREAT);
64         cdb_make_start(&cdbm, fd);
65         cdb_make_add(&cdbm, key, klen, val, vlen);
66         cdb_make_exists(&cdbm, key, klen);
67         cdb_make_finish(&cdbm);
68         return 0;
69       }
70     C
71     system ENV.cc, "test.c", "-L#{lib}", "-lcdb", "-o", "test"
72     system "./test"
73     return unless OS.linux?
75     # Let's test whether our hard-coded `libcdb_soversion` is correct, since we don't override this on Linux.
76     # If this test fails, the the value in the `libcdb_soversion` needs updating.
77     versioned_libcdb_candidates = lib.glob(shared_library("libcdb", "*")).reject { |so| so.to_s.end_with?(".so") }
78     assert_equal versioned_libcdb_candidates.count, 1, "expected only one versioned `libcdb`!"
80     versioned_libcdb = versioned_libcdb_candidates.first.basename.to_s
81     soversion = versioned_libcdb[/\.(\d+)$/, 1]
82     assert_equal libcdb_soversion, soversion
83   end
84 end