Skip to content

Commit

Permalink
Merge pull request #202096 from Homebrew/jrnl-test
Browse files Browse the repository at this point in the history
jrnl: update test to drop `expect` dependency
  • Loading branch information
BrewTestBot authored Dec 22, 2024
2 parents d2de2f5 + 0cf0483 commit cc8d8d0
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions Formula/j/jrnl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class Jrnl < Formula
depends_on "libyaml"
depends_on "[email protected]"

uses_from_macos "expect" => :test

resource "colorama" do
url "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz"
sha256 "08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"
Expand Down Expand Up @@ -118,36 +116,30 @@ def install
end

test do
(testpath/"tests.sh").write <<~EXPECT
#!/usr/bin/env expect
set timeout 3
match_max 100000
spawn "#{bin}/jrnl" --encrypt
expect -exact "Enter password for journal 'default': "
sleep 0.5
send -- "homebrew\\r"
expect -exact "Enter password again: "
sleep 0.5
send -- "homebrew\\r"
expect -exact "Do you want to store the password in your keychain? \\[Y/n\\] "
send -- "n\\r"
expect -re "Journal encrypted to .*"
expect eof
EXPECT

# Write the journal
input = "#{testpath}/journal.txt\nn\nn"
assert_match "Journal 'default' created", pipe_output("#{bin}/jrnl My journal entry 2>&1", input, 0)
assert_predicate testpath/"journal.txt", :exist?
assert_path_exists testpath/"journal.txt"

# Read the journal
assert_match "#{testpath}/journal.txt", shell_output("#{bin}/jrnl --list 2>&1")

# Encrypt the journal. Needs a TTY to read password.
system "expect", "./tests.sh"
assert_predicate testpath/".config/jrnl/jrnl.yaml", :exist?
require "expect"
require "pty"
timeout = 3
PTY.spawn(bin/"jrnl", "--encrypt") do |r, w, pid|
refute_nil r.expect("Enter password for journal 'default': ", timeout), "Expected password input"
w.write "homebrew\r"
refute_nil r.expect("Enter password again: ", timeout), "Expected password confirmation input"
w.write "homebrew\r"
refute_nil r.expect("store the password in your keychain? [Y/n] ", timeout), "Expected keychain input"
w.write "n\r"
refute_nil r.expect("Journal encrypted to ", timeout), "Expected result output"
Process.wait pid
end

assert_path_exists testpath/".config/jrnl/jrnl.yaml"
assert_match "encrypt: true", (testpath/".config/jrnl/jrnl.yaml").read
end
end

0 comments on commit cc8d8d0

Please sign in to comment.