diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb index 9427fc0c5f424..aac8556f77e3a 100644 --- a/Library/Homebrew/cmd/outdated.rb +++ b/Library/Homebrew/cmd/outdated.rb @@ -65,7 +65,9 @@ def run formulae: json_info(formulae), casks: json_info(casks), } - puts JSON.pretty_generate(json) + # json v2.8.1 is inconsistent it how it renders empty arrays, + # so we use `[]` for consistency: + puts JSON.pretty_generate(json).gsub("[\n\n]", "[]") outdated = formulae + casks else diff --git a/Library/Homebrew/test/cmd/outdated_spec.rb b/Library/Homebrew/test/cmd/outdated_spec.rb index 94749286423c0..c2af5d43b9aa2 100644 --- a/Library/Homebrew/test/cmd/outdated_spec.rb +++ b/Library/Homebrew/test/cmd/outdated_spec.rb @@ -20,12 +20,9 @@ }], casks: [], }) - # json v2.8.1 is inconsistent it how it renders empty arrays, - # for now we allow multiple outputs: - alternate_json = expected_json.gsub("[]", "[\n\n]") expect { brew "outdated", "--json=v2" } - .to output(match(/\A(#{Regexp.escape(expected_json)}|#{Regexp.escape(alternate_json)})\n\z/)).to_stdout + .to output("#{expected_json}\n").to_stdout .and be_a_success end end