|
| 1 | +class Replxx < Formula |
| 2 | + desc "Readline and libedit replacement" |
| 3 | + homepage "https://github.com/AmokHuginnsson/replxx" |
| 4 | + url "https://github.com/AmokHuginnsson/replxx/archive/refs/tags/release-0.0.4.tar.gz" |
| 5 | + sha256 "a22988b2184e1d256e2d111b5749e16ffb1accbf757c7b248226d73c426844c4" |
| 6 | + license all_of: ["BSD-3-Clause", "Unicode-TOU"] |
| 7 | + |
| 8 | + depends_on "cmake" => :build |
| 9 | + |
| 10 | + def install |
| 11 | + system "cmake", "-S", ".", "-B", "build", "-DBUILD_SHARED_LIBS=ON", *std_cmake_args |
| 12 | + system "cmake", "--build", "build" |
| 13 | + system "cmake", "--install", "build" |
| 14 | + |
| 15 | + pkgshare.install "examples" |
| 16 | + end |
| 17 | + |
| 18 | + test do |
| 19 | + cp_r pkgshare/"examples", testpath |
| 20 | + cd "examples" do |
| 21 | + system ENV.cc, "-c", "util.c", "-o", "util.o" |
| 22 | + system ENV.cc, "c-api.c", "util.o", "-L#{lib}", "-I#{include}", "-lreplxx", "-lm", "-o", "test" |
| 23 | + |
| 24 | + # `test` executable is an interactive program so we use Open3 to interact with it |
| 25 | + Open3.popen3("./test") do |stdin, stdout, stderr, _| |
| 26 | + sleep 2 |
| 27 | + assert_match "starting...", stdout.gets |
| 28 | + |
| 29 | + stdin.puts "hello" |
| 30 | + sleep 2 |
| 31 | + |
| 32 | + assert_match "thanks for the input: hello", stdout.gets |
| 33 | + |
| 34 | + stdin.close # simulate Ctrl+D by closing stdin |
| 35 | + |
| 36 | + assert_empty stderr.read |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | +end |
0 commit comments