From 59a0c1e1b5604ab198e9694df030cd855b5ccbd6 Mon Sep 17 00:00:00 2001 From: Samuel John Date: Thu, 13 Jun 2013 15:52:23 +0200 Subject: Improve python tests for brew bots Allow `build.with?` and similar methods to be used during the test phase. The BuildOptions (`build`) are initialized with the `Tab.used_options` unless explicitly overwritten on the command line. So basically `build.with?` works in `def install` and in `test do` as one would naively expect. (For the test, gramatically it should be `built.with?` but who cares) If a formula was installed `--with-python`, now the tests are also run `--with-python`. This enables us to use the `python do ... end` in a meaningful manner. Using `python do ... end` blocks for the tests, because the bot.brew.sh has system python per default and we need to set the PYTHONPATH for the test. Potentially to different values for Python 2.x and 3.x. --- Library/Homebrew/test/test_build_options.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'Library/Homebrew/test') diff --git a/Library/Homebrew/test/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb index cc5fd01d7..9e2a9e06f 100644 --- a/Library/Homebrew/test/test_build_options.rb +++ b/Library/Homebrew/test/test_build_options.rb @@ -1,9 +1,9 @@ -require 'testing_env' + require 'testing_env' require 'build_options' class BuildOptionsTests < Test::Unit::TestCase def setup - args = %w{--with-foo --with-bar --without-qux} + args = %w{--with-foo --with-bar --without-qux} # args fake the command line @build = BuildOptions.new(args) @build.add("with-foo") @build.add("with-bar") @@ -44,7 +44,7 @@ class BuildOptionsTests < Test::Unit::TestCase end def test_implicit_options - # --without-baz is not explicitly specified on the command line + # --without-baz is not explicitly specified on the command line (i.e. args) # therefore --with-baz should be implicitly assumed: assert @build.implicit_options.include?("--with-baz") # But all these should not be in the implict_options: @@ -53,4 +53,18 @@ class BuildOptionsTests < Test::Unit::TestCase assert !@build.implicit_options.include?("--without-bar") assert !@build.implicit_options.include?("--with-qux") end + + def test_opposite_of + assert @build.opposite_of(Option.new("with-foo")) == Option.new("without-foo") + assert @build.opposite_of("without-foo") == Option.new("with-foo") + assert @build.opposite_of(Option.new("enable-spam")) == Option.new("disable-spam") + assert @build.opposite_of("disable-beer") == Option.new("enable-beer") + end + + def test_has_opposite_of? + assert @build.has_opposite_of?("--without-foo") + assert @build.has_opposite_of?(Option.new("--with-qux")) + assert !@build.has_opposite_of?("--without-qux") + assert !@build.has_opposite_of?("--without-nonexisting") + end end -- cgit v1.2.3