class Shadowenv < Formula desc "Reversible directory-local environment variable manipulations" homepage "https://shopify.github.io/shadowenv/" url "https://github.com/Shopify/shadowenv/archive/1.2.1.tar.gz" sha256 "ce57ddc62f4b5772b11698c3fde6409c72fda2bb234edc19ac2bc3099a012496" bottle do cellar :any_skip_relocation sha256 "a29c4ec703e088e9c5030ae0ca9bad0a9dfd57ac7c8f616cd31658a0288e74b6" => :catalina sha256 "4c49d28a4409d10ebdde0974d943afdd99c26e79db903135c654709d6e470e8e" => :mojave sha256 "a78e9ad50488f2e07420c080378249f73758b65a604cc66f0e1db417a1c8e7ae" => :high_sierra sha256 "4a42c37a23a2b126ed1f5c5e22c8ff70082d04f557fd7a7f1d15a1ee6b38eede" => :sierra end depends_on "rust" => :build def install system "cargo", "install", "--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;" actual_output = shell_output("bash -c '#{environment} #{print_vars} echo ---; eval \"$(#{shadowenv_command})\"; #{print_vars}'") assert_equal expected_output, actual_output end end