From 967a7a1862eb58c27e94cd59f91ff0627d6ccdad Mon Sep 17 00:00:00 2001 From: Andrea Kao Date: Wed, 10 Aug 2016 17:53:03 -0700 Subject: [PATCH 1/2] tests: refactor FormulaTextTests in test_cmd_audit --- Library/Homebrew/test/test_cmd_audit.rb | 52 +++++++++++-------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/Library/Homebrew/test/test_cmd_audit.rb b/Library/Homebrew/test/test_cmd_audit.rb index f9056d0da6..2da6d76e60 100644 --- a/Library/Homebrew/test/test_cmd_audit.rb +++ b/Library/Homebrew/test/test_cmd_audit.rb @@ -13,53 +13,45 @@ class FormulaTextTests < Homebrew::TestCase FileUtils.rm_rf @dir end - def formula_text(name, text) + def formula_text(name, body = nil, options = {}) path = Pathname.new "#{@dir}/#{name}.rb" - path.open("w") { |f| f.write text } + path.open("w") do |f| + f.write <<-EOS.undent + class #{Formulary.class_s(name)} < Formula + #{body} + end + #{options[:patch]} + EOS + end FormulaText.new path end def test_simple_valid_formula - ft = formula_text "valid", <<-EOS.undent - class Valid < Formula - url "http://www.example.com/valid-1.0.tar.gz" - end - EOS + ft = formula_text "valid", 'url "http://www.example.com/valid-1.0.tar.gz"' - refute ft.has_DATA?, "The formula doesn't have DATA" - refute ft.has_END?, "The formula doesn't have __END__" - assert ft.has_trailing_newline?, "The formula have a trailing newline" + refute ft.has_DATA?, "The formula should not have DATA" + refute ft.has_END?, "The formula should not have __END__" + assert ft.has_trailing_newline?, "The formula should have a trailing newline" - assert ft =~ /\burl\b/, "The formula match 'url'" - assert_nil ft.line_number(/desc/), "The formula doesn't match 'desc'" + assert ft =~ /\burl\b/, "The formula should match 'url'" + assert_nil ft.line_number(/desc/), "The formula should not match 'desc'" assert_equal 2, ft.line_number(/\burl\b/) end def test_trailing_newline - ft = formula_text "newline", "class Newline < Formula; end" - refute ft.has_trailing_newline?, "The formula doesn't have a trailing newline" + ft = formula_text "newline" + assert ft.has_trailing_newline?, "The formula must have a trailing newline" end def test_has_data - ft = formula_text "data", <<-EOS.undent - class Data < Formula - patch :DATA - end - EOS - - assert ft.has_DATA?, "The formula has DATA" + ft = formula_text "data", "patch :DATA" + assert ft.has_DATA?, "The formula must have DATA" end def test_has_end - ft = formula_text "end", <<-EOS.undent - class End < Formula - end - __END__ - a patch here - EOS - - assert ft.has_END?, "The formula has __END__" - assert_equal "class End < Formula\nend", ft.without_patch + ft = formula_text "end", "", :patch => "__END__\na patch here" + assert ft.has_END?, "The formula must have __END__" + assert_equal "class End < Formula\n \nend", ft.without_patch end end From 91b67bd41d3a6fa04d5dd438b667d9bcb7e414e9 Mon Sep 17 00:00:00 2001 From: Andrea Kao Date: Fri, 12 Aug 2016 15:21:27 -0700 Subject: [PATCH 2/2] tests: add assertion to test_simple_valid_formula --- Library/Homebrew/test/test_cmd_audit.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/test/test_cmd_audit.rb b/Library/Homebrew/test/test_cmd_audit.rb index 2da6d76e60..f3899e2d30 100644 --- a/Library/Homebrew/test/test_cmd_audit.rb +++ b/Library/Homebrew/test/test_cmd_audit.rb @@ -36,6 +36,7 @@ class FormulaTextTests < Homebrew::TestCase assert ft =~ /\burl\b/, "The formula should match 'url'" assert_nil ft.line_number(/desc/), "The formula should not match 'desc'" assert_equal 2, ft.line_number(/\burl\b/) + assert ft.include?("Valid"), "The formula should include \"Valid\"" end def test_trailing_newline