| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  | require "testing_env" | 
					
						
							|  |  |  | require "tab" | 
					
						
							| 
									
										
										
										
											2014-06-29 21:49:34 -05:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | class TabTests < Homebrew::TestCase | 
					
						
							|  |  |  |   def setup | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     @used = Options.create(%w[--with-foo --without-bar]) | 
					
						
							|  |  |  |     @unused = Options.create(%w[--with-baz --without-qux]) | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-14 18:55:47 +08:00
										 |  |  |     @tab = Tab.new("used_options"         => @used.as_flags, | 
					
						
							|  |  |  |                    "unused_options"       => @unused.as_flags, | 
					
						
							|  |  |  |                    "built_as_bottle"      => false, | 
					
						
							|  |  |  |                    "poured_from_bottle"   => true, | 
					
						
							|  |  |  |                    "time"                 => nil, | 
					
						
							|  |  |  |                    "source_modified_time" => 0, | 
					
						
							|  |  |  |                    "HEAD"                 => TEST_SHA1, | 
					
						
							|  |  |  |                    "compiler"             => "clang", | 
					
						
							|  |  |  |                    "stdlib"               => "libcxx", | 
					
						
							|  |  |  |                    "source"               => { | 
					
						
							| 
									
										
										
										
											2016-02-26 19:43:49 +08:00
										 |  |  |                      "tap" => "homebrew/core", | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |                      "path" => nil, | 
					
						
							|  |  |  |                      "spec" => "stable" | 
					
						
							|  |  |  |                    }) | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_defaults | 
					
						
							| 
									
										
										
										
											2015-02-21 12:15:39 -05:00
										 |  |  |     tab = Tab.empty | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |     assert_empty tab.unused_options | 
					
						
							|  |  |  |     assert_empty tab.used_options | 
					
						
							| 
									
										
										
										
											2014-08-08 23:31:55 -05:00
										 |  |  |     refute_predicate tab, :built_as_bottle | 
					
						
							|  |  |  |     refute_predicate tab, :poured_from_bottle | 
					
						
							| 
									
										
										
										
											2015-03-13 00:41:10 -04:00
										 |  |  |     assert_nil tab.tap | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |     assert_nil tab.time | 
					
						
							|  |  |  |     assert_nil tab.HEAD | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     assert_equal DevelopmentTools.default_compiler, tab.cxxstdlib.compiler | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |     assert_nil tab.cxxstdlib.type | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_include? | 
					
						
							|  |  |  |     assert_includes @tab, "with-foo" | 
					
						
							|  |  |  |     assert_includes @tab, "without-bar" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_with? | 
					
						
							|  |  |  |     assert @tab.with?("foo") | 
					
						
							|  |  |  |     assert @tab.with?("qux") | 
					
						
							|  |  |  |     refute @tab.with?("bar") | 
					
						
							|  |  |  |     refute @tab.with?("baz") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_universal? | 
					
						
							| 
									
										
										
										
											2014-08-07 17:39:55 -05:00
										 |  |  |     tab = Tab.new(:used_options => %w[--universal]) | 
					
						
							|  |  |  |     assert_predicate tab, :universal? | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_cxxstdlib | 
					
						
							|  |  |  |     assert_equal :clang, @tab.cxxstdlib.compiler | 
					
						
							|  |  |  |     assert_equal :libcxx, @tab.cxxstdlib.type | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_other_attributes | 
					
						
							|  |  |  |     assert_equal TEST_SHA1, @tab.HEAD | 
					
						
							| 
									
										
										
										
											2016-02-26 19:43:49 +08:00
										 |  |  |     assert_equal "homebrew/core", @tab.tap.name | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |     assert_nil @tab.time | 
					
						
							|  |  |  |     refute_predicate @tab, :built_as_bottle | 
					
						
							|  |  |  |     assert_predicate @tab, :poured_from_bottle | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 16:14:26 +08:00
										 |  |  |   def test_from_old_version_file | 
					
						
							|  |  |  |     path = Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt_old.json") | 
					
						
							|  |  |  |     tab = Tab.from_file(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal @used.sort, tab.used_options.sort | 
					
						
							|  |  |  |     assert_equal @unused.sort, tab.unused_options.sort | 
					
						
							|  |  |  |     refute_predicate tab, :built_as_bottle | 
					
						
							|  |  |  |     assert_predicate tab, :poured_from_bottle | 
					
						
							| 
									
										
										
										
											2016-02-26 19:43:49 +08:00
										 |  |  |     assert_equal "homebrew/core", tab.tap.name | 
					
						
							| 
									
										
										
										
											2015-07-31 16:14:26 +08:00
										 |  |  |     assert_equal :stable, tab.spec | 
					
						
							|  |  |  |     refute_nil tab.time | 
					
						
							|  |  |  |     assert_equal TEST_SHA1, tab.HEAD | 
					
						
							|  |  |  |     assert_equal :clang, tab.cxxstdlib.compiler | 
					
						
							|  |  |  |     assert_equal :libcxx, tab.cxxstdlib.type | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |   def test_from_file | 
					
						
							|  |  |  |     path = Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt.json") | 
					
						
							|  |  |  |     tab = Tab.from_file(path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-30 08:54:47 -05:00
										 |  |  |     assert_equal @used.sort, tab.used_options.sort | 
					
						
							|  |  |  |     assert_equal @unused.sort, tab.unused_options.sort | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |     refute_predicate tab, :built_as_bottle | 
					
						
							|  |  |  |     assert_predicate tab, :poured_from_bottle | 
					
						
							| 
									
										
										
										
											2016-02-26 19:43:49 +08:00
										 |  |  |     assert_equal "homebrew/core", tab.tap.name | 
					
						
							| 
									
										
										
										
											2015-07-31 16:14:26 +08:00
										 |  |  |     assert_equal :stable, tab.spec | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  |     refute_nil tab.time | 
					
						
							|  |  |  |     assert_equal TEST_SHA1, tab.HEAD | 
					
						
							|  |  |  |     assert_equal :clang, tab.cxxstdlib.compiler | 
					
						
							|  |  |  |     assert_equal :libcxx, tab.cxxstdlib.type | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-06-29 22:18:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_to_json | 
					
						
							| 
									
										
										
										
											2014-06-30 08:54:47 -05:00
										 |  |  |     tab = Tab.new(Utils::JSON.load(@tab.to_json)) | 
					
						
							|  |  |  |     assert_equal @tab.used_options.sort, tab.used_options.sort | 
					
						
							|  |  |  |     assert_equal @tab.unused_options.sort, tab.unused_options.sort | 
					
						
							|  |  |  |     assert_equal @tab.built_as_bottle, tab.built_as_bottle | 
					
						
							|  |  |  |     assert_equal @tab.poured_from_bottle, tab.poured_from_bottle | 
					
						
							| 
									
										
										
										
											2015-03-13 00:41:10 -04:00
										 |  |  |     assert_equal @tab.tap, tab.tap | 
					
						
							| 
									
										
										
										
											2015-07-31 16:14:26 +08:00
										 |  |  |     assert_equal @tab.spec, tab.spec | 
					
						
							| 
									
										
										
										
											2014-06-30 08:54:47 -05:00
										 |  |  |     assert_equal @tab.time, tab.time | 
					
						
							|  |  |  |     assert_equal @tab.HEAD, tab.HEAD | 
					
						
							|  |  |  |     assert_equal @tab.compiler, tab.compiler | 
					
						
							|  |  |  |     assert_equal @tab.stdlib, tab.stdlib | 
					
						
							| 
									
										
										
										
											2014-06-29 22:18:44 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-10-16 13:01:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def test_remap_deprecated_options | 
					
						
							|  |  |  |     deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")] | 
					
						
							|  |  |  |     remapped_options = Tab.remap_deprecated_options(deprecated_options, @tab.used_options) | 
					
						
							|  |  |  |     assert_includes remapped_options, Option.new("without-bar") | 
					
						
							|  |  |  |     assert_includes remapped_options, Option.new("with-foo-new") | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-06-29 00:55:56 -05:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2014-06-29 21:49:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | class TabLoadingTests < Homebrew::TestCase | 
					
						
							|  |  |  |   def setup | 
					
						
							|  |  |  |     @f = formula { url "foo-1.0" } | 
					
						
							|  |  |  |     @f.prefix.mkpath | 
					
						
							|  |  |  |     @path = @f.prefix.join(Tab::FILENAME) | 
					
						
							|  |  |  |     @path.write Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt.json").read | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def teardown | 
					
						
							|  |  |  |     @f.rack.rmtree | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_for_keg | 
					
						
							|  |  |  |     tab = Tab.for_keg(@f.prefix) | 
					
						
							|  |  |  |     assert_equal @path, tab.tabfile | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_for_keg_nonexistent_path | 
					
						
							|  |  |  |     @path.unlink | 
					
						
							|  |  |  |     tab = Tab.for_keg(@f.prefix) | 
					
						
							|  |  |  |     assert_nil tab.tabfile | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_for_formula | 
					
						
							|  |  |  |     tab = Tab.for_formula(@f) | 
					
						
							|  |  |  |     assert_equal @path, tab.tabfile | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_for_formula_nonexistent_path | 
					
						
							|  |  |  |     @path.unlink | 
					
						
							|  |  |  |     tab = Tab.for_formula(@f) | 
					
						
							|  |  |  |     assert_nil tab.tabfile | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_for_formula_multiple_kegs | 
					
						
							|  |  |  |     f2 = formula { url "foo-2.0" } | 
					
						
							|  |  |  |     f2.prefix.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal @f.rack, f2.rack | 
					
						
							| 
									
										
										
										
											2015-11-29 15:41:42 +08:00
										 |  |  |     assert_equal 2, @f.installed_prefixes.length | 
					
						
							| 
									
										
										
										
											2014-06-29 21:49:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     tab = Tab.for_formula(@f) | 
					
						
							|  |  |  |     assert_equal @path, tab.tabfile | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def test_for_formula_outdated_keg | 
					
						
							|  |  |  |     f2 = formula { url "foo-2.0" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_equal @f.rack, f2.rack | 
					
						
							| 
									
										
										
										
											2015-11-29 15:41:42 +08:00
										 |  |  |     assert_equal 1, @f.installed_prefixes.length | 
					
						
							| 
									
										
										
										
											2014-06-29 21:49:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     tab = Tab.for_formula(f2) | 
					
						
							|  |  |  |     assert_equal @path, tab.tabfile | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |