| 
									
										
										
										
											2013-09-05 18:50:42 -05:00
										 |  |  | require 'testing_env' | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  | require 'build_options' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | class BuildOptionsTests < Homebrew::TestCase | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2013-09-05 18:50:42 -05:00
										 |  |  |     args = %w{--with-foo --with-bar --without-qux} | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  |     @build = BuildOptions.new(args) | 
					
						
							|  |  |  |     @build.add("with-foo") | 
					
						
							|  |  |  |     @build.add("with-bar") | 
					
						
							|  |  |  |     @build.add("without-baz") | 
					
						
							|  |  |  |     @build.add("without-qux") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_as_flags | 
					
						
							|  |  |  |     assert_equal %w{--with-foo --with-bar --without-baz --without-qux}.sort, | 
					
						
							|  |  |  |       @build.as_flags.sort | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_has_option? | 
					
						
							|  |  |  |     assert @build.has_option?("with-foo") | 
					
						
							|  |  |  |     assert !@build.has_option?("with-qux") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_include | 
					
						
							| 
									
										
										
										
											2014-06-11 13:03:06 -05:00
										 |  |  |     assert_includes @build, "with-foo" | 
					
						
							|  |  |  |     refute_includes @build, "with-qux" | 
					
						
							|  |  |  |     refute_includes @build, "--with-foo" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:26 -06:00
										 |  |  |   def test_with_without | 
					
						
							|  |  |  |     assert @build.with?("foo") | 
					
						
							|  |  |  |     assert @build.with?("bar") | 
					
						
							|  |  |  |     assert @build.with?("baz") | 
					
						
							|  |  |  |     assert @build.without?("qux") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  |   def test_used_options | 
					
						
							| 
									
										
										
										
											2014-06-11 13:03:06 -05:00
										 |  |  |     assert_includes @build.used_options, "--with-foo" | 
					
						
							|  |  |  |     assert_includes @build.used_options, "--with-bar" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_unused_options | 
					
						
							| 
									
										
										
										
											2014-06-11 13:03:06 -05:00
										 |  |  |     assert_includes @build.unused_options, "--without-baz" | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-21 10:33:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_implicit_options | 
					
						
							| 
									
										
										
										
											2013-06-13 15:52:23 +02:00
										 |  |  |     # --without-baz is not explicitly specified on the command line (i.e. args) | 
					
						
							| 
									
										
										
										
											2013-01-21 10:33:56 +01:00
										 |  |  |     # therefore --with-baz should be implicitly assumed: | 
					
						
							| 
									
										
										
										
											2014-06-11 13:03:06 -05:00
										 |  |  |     assert_includes @build.implicit_options, "--with-baz" | 
					
						
							| 
									
										
										
										
											2013-01-21 10:33:56 +01:00
										 |  |  |     # But all these should not be in the implict_options: | 
					
						
							| 
									
										
										
										
											2014-06-11 13:03:06 -05:00
										 |  |  |     refute_includes @build.implicit_options, "--without-baz" | 
					
						
							|  |  |  |     refute_includes @build.implicit_options, "--with-bar" | 
					
						
							|  |  |  |     refute_includes @build.implicit_options, "--without-bar" | 
					
						
							|  |  |  |     refute_includes @build.implicit_options, "--with-qux" | 
					
						
							| 
									
										
										
										
											2013-01-21 10:33:56 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-06-13 15:52:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_opposite_of | 
					
						
							| 
									
										
										
										
											2014-06-11 13:05:10 -05:00
										 |  |  |     assert_equal Option.new("without-foo"), @build.opposite_of(Option.new("with-foo")) | 
					
						
							|  |  |  |     assert_equal Option.new("with-foo"), @build.opposite_of("without-foo") | 
					
						
							|  |  |  |     assert_equal Option.new("disable-spam"), @build.opposite_of(Option.new("enable-spam")) | 
					
						
							|  |  |  |     assert_equal Option.new("enable-beer"), @build.opposite_of("disable-beer") | 
					
						
							| 
									
										
										
										
											2013-06-13 15:52:23 +02:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2013-09-05 18:50:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_actually_recognizes_implicit_options | 
					
						
							|  |  |  |     assert @build.has_opposite_of?("--with-baz") | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-14 17:03:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_copies_do_not_share_underlying_options | 
					
						
							|  |  |  |     orig = BuildOptions.new [] | 
					
						
							|  |  |  |     copy = orig.dup | 
					
						
							|  |  |  |     copy.add 'foo' | 
					
						
							|  |  |  |     assert_empty orig | 
					
						
							|  |  |  |     assert_equal 1, copy.count | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_copies_do_not_share_underlying_args | 
					
						
							|  |  |  |     orig = BuildOptions.new [] | 
					
						
							|  |  |  |     copy = orig.dup | 
					
						
							|  |  |  |     copy.args << Option.new('foo') | 
					
						
							|  |  |  |     assert_empty orig.args | 
					
						
							|  |  |  |     assert_equal 1, copy.args.count | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:24 -06:00
										 |  |  | end |