brew/Library/Homebrew/test/test_fails_with.rb
Misty De Meo 5537abbe51 Adjust fails_with syntax for non-Apple compilers
The old version worked like this:

fails_with :gcc => '4.8.1'

That wasn't really flexible enough, and made it harder to distinguish
different releases in the same GCC series. Since no one was really
using it yet, this adjusts the syntax to be more similar to the
Apple compilers:

fails_with :gcc => '4.8' do
  release '4.8.1'
end

Like with Apple compilers, omitting `release` blacklists the entire
series.

This also unifies the `build` and `version` attributes and accessors,
and exposes them under both names.
2013-12-03 22:42:49 -08:00

67 lines
1.3 KiB
Ruby

require 'testing_env'
require 'test/testball'
class FailsWithTests < Test::Unit::TestCase
class Double < Compiler
attr_accessor :name, :version
end
def assert_fails_with(cc)
assert @f.new.fails_with?(cc)
end
def assert_does_not_fail_with(cc)
assert !@f.new.fails_with?(cc)
end
def fails_with(*args, &block)
@f.send(:fails_with, *args, &block)
end
def build_cc(sym, build, version=nil)
cc = Double.new
cc.name = sym
cc.version = version || build
cc
end
def setup
@f = Class.new(TestBall)
end
def test_fails_with_symbol
fails_with :clang
cc = build_cc(:clang, 425)
assert_fails_with cc
end
def test_fails_with_build
fails_with(:clang) { build 211 }
cc = build_cc(:clang, 318)
assert_does_not_fail_with cc
end
def test_fails_with_block_without_build
fails_with(:clang) { }
cc = build_cc(:clang, 425)
assert_fails_with cc
end
def test_non_apple_gcc_version
fails_with(:gcc => '4.8')
cc = build_cc("gcc-4.8", nil, "4.8.1")
assert_fails_with cc
end
def test_multiple_failures
fails_with(:llvm)
fails_with(:clang)
gcc = build_cc(:gcc, 5666)
llvm = build_cc(:llvm, 2336)
clang = build_cc(:clang, 425)
assert_fails_with llvm
assert_fails_with clang
assert_does_not_fail_with gcc
end
end