class Shadowenv < Formula desc "Reversible directory-local environment variable manipulations" homepage "https://shopify.github.io/shadowenv/" url "https://github.com/Shopify/shadowenv/archive/1.1.0.tar.gz" sha256 "7b5b70c8395a2af1c2e6561f35fbeeedf2f356b868e3647950ee0de73694a112" bottle do cellar :any_skip_relocation sha256 "3fcca1d9cc12db3fd1551da2ebce5091e0dcb98c1b41ecb43d170361bfb4adb3" => :mojave sha256 "620d22d89c8e2867b0e5ea4c0ea0c1ad1645383908869d60e277cf59db79ad62" => :high_sierra sha256 "34b338e0f8fe27ed55fe97d5ea38df4c42323c00eadac9e6c2b0f30edd18c30f" => :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