homebrew-core/Formula/shadowenv.rb

55 lines
2.0 KiB
Ruby

class Shadowenv < Formula
desc "Reversible directory-local environment variable manipulations"
homepage "https://shopify.github.io/shadowenv/"
url "https://github.com/Shopify/shadowenv/archive/1.3.1.tar.gz"
sha256 "2ecb61475c75022a4cfe378e750b23fbf3c559452465bc399ea1369c18d9054b"
bottle do
cellar :any_skip_relocation
sha256 "6eb21077d08aa62b92b162a40c94f2b68c50deb3c8f0a38b68ce225f1d7af91c" => :catalina
sha256 "3e93b9b98ba2dcb84dcf19115c5650bd49241260bec2751e6e2843417024025d" => :mojave
sha256 "aff6c727929ab3a9de176a341f55997777318d65e0ef2c547baa981e32455e8d" => :high_sierra
end
depends_on "rust" => :build
def install
system "cargo", "install", "--locked", "--root", prefix, "--path", "."
man1.install "#{buildpath}/man/man1/shadowenv.1"
man5.install "#{buildpath}/man/man5/shadowlisp.5"
end
test do
expected_output = <<~EOM
EXAMPLE:
EXAMPLE2:b
EXAMPLE3:b
EXAMPLE_PATH:a:b:d
---
EXAMPLE:a
EXAMPLE2:
EXAMPLE3:a
EXAMPLE_PATH:c:d
EOM
environment = "export EXAMPLE2=b EXAMPLE3=b EXAMPLE_PATH=a:b:d;"
hash = "1256a7c3de15e864"
data = {
"scalars" => [
{ "name" => "EXAMPLE2", "original" => nil, "current" => "b" },
{ "name" => "EXAMPLE", "original" => "a", "current" => nil },
{ "name" => "EXAMPLE3", "original" => "a", "current" => "b" },
],
"lists" => [
{ "name" => "EXAMPLE_PATH", "additions" => ["b", "a"], "deletions" => ["c"] },
],
}
# Read ...'\"'\"'... on the next line as a ruby `...' + "'" + '...` but for bash
shadowenv_command = "#{bin}/shadowenv hook '\"'\"'#{hash}:#{data.to_json}'\"'\"' 2> /dev/null"
print_vars =
"echo EXAMPLE:$EXAMPLE; echo EXAMPLE2:$EXAMPLE2; echo EXAMPLE3:$EXAMPLE3; echo EXAMPLE_PATH:$EXAMPLE_PATH;"
assert_equal expected_output,
shell_output("bash -c '#{environment} #{print_vars} echo ---; eval \"$(#{shadowenv_command})\"; #{print_vars}'")
end
end