| 
									
										
										
										
											2018-03-25 13:18:23 +05:30
										 |  |  | #:  * `tests` [`--verbose`] [`--coverage`] [`--generic`] [`--no-compat`] [`--only=`<test_script>[`:`<line_number>]] [`--seed=`<seed>] [`--online`] [`--official-cmd-taps`]: | 
					
						
							| 
									
										
										
										
											2017-03-05 21:45:15 -05:00
										 |  |  | #:    Run Homebrew's unit and integration tests. If provided, | 
					
						
							|  |  |  | #:    `--only=`<test_script> runs only <test_script>_spec.rb, and `--seed` | 
					
						
							|  |  |  | #:    randomizes tests with the provided value instead of a random seed. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-04-02 10:14:21 +01:00
										 |  |  | #:    If `--verbose` (or `-v`) is passed, print the command that runs the tests. | 
					
						
							| 
									
										
										
										
											2017-03-05 21:45:15 -05:00
										 |  |  | #: | 
					
						
							|  |  |  | #:    If `--coverage` is passed, also generate code coverage reports. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--generic` is passed, only run OS-agnostic tests. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--no-compat` is passed, do not load the compatibility layer when | 
					
						
							|  |  |  | #:    running tests. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-06-07 16:25:07 +01:00
										 |  |  | #:    If `--online` is passed, include tests that use the GitHub API and tests | 
					
						
							|  |  |  | #:    that use any of the taps for official external commands. | 
					
						
							| 
									
										
										
										
											2016-06-26 23:00:10 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:18:23 +05:30
										 |  |  | require "cli_parser" | 
					
						
							| 
									
										
										
										
											2016-01-18 15:33:59 +01:00
										 |  |  | require "fileutils" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 16:44:11 -05:00
										 |  |  |   def tests | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     Homebrew::CLI::Parser.parse do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:18:23 +05:30
										 |  |  |       switch "--no-compat" | 
					
						
							|  |  |  |       switch "--generic" | 
					
						
							|  |  |  |       switch "--coverage" | 
					
						
							|  |  |  |       switch "--online" | 
					
						
							| 
									
										
										
										
											2018-04-01 16:47:30 +05:30
										 |  |  |       switch :debug | 
					
						
							|  |  |  |       switch :verbose | 
					
						
							| 
									
										
										
										
											2018-04-14 19:04:24 +05:30
										 |  |  |       flag   "--only=" | 
					
						
							|  |  |  |       flag   "--seed=" | 
					
						
							| 
									
										
										
										
											2018-03-25 17:48:22 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-03-25 13:18:23 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-21 08:57:39 +02:00
										 |  |  |     HOMEBREW_LIBRARY_PATH.cd do | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |       ENV.delete("HOMEBREW_VERBOSE") | 
					
						
							|  |  |  |       ENV.delete("VERBOSE") | 
					
						
							| 
									
										
										
										
											2017-02-10 21:21:57 +01:00
										 |  |  |       ENV.delete("HOMEBREW_CASK_OPTS") | 
					
						
							| 
									
										
										
										
											2017-03-21 09:31:09 -05:00
										 |  |  |       ENV.delete("HOMEBREW_TEMP") | 
					
						
							| 
									
										
										
										
											2018-06-06 13:13:45 +02:00
										 |  |  |       ENV.delete("HOMEBREW_NO_GITHUB_API") | 
					
						
							| 
									
										
										
										
											2018-06-07 17:38:47 +02:00
										 |  |  |       ENV.delete("HOMEBREW_NO_EMOJI") | 
					
						
							| 
									
										
										
										
											2016-07-04 18:26:44 +01:00
										 |  |  |       ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" | 
					
						
							| 
									
										
										
										
											2016-09-10 09:50:40 +01:00
										 |  |  |       ENV["HOMEBREW_DEVELOPER"] = "1" | 
					
						
							| 
									
										
										
										
											2018-03-25 13:18:23 +05:30
										 |  |  |       ENV["HOMEBREW_NO_COMPAT"] = "1" if args.no_compat? | 
					
						
							|  |  |  |       ENV["HOMEBREW_TEST_GENERIC_OS"] = "1" if args.generic? | 
					
						
							| 
									
										
										
										
											2018-06-06 13:13:45 +02:00
										 |  |  |       ENV["HOMEBREW_TEST_ONLINE"] = "1" if args.online? | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:18:23 +05:30
										 |  |  |       if args.coverage? | 
					
						
							| 
									
										
										
										
											2016-01-18 15:33:59 +01:00
										 |  |  |         ENV["HOMEBREW_TESTS_COVERAGE"] = "1" | 
					
						
							| 
									
										
										
										
											2016-09-19 23:00:58 +01:00
										 |  |  |         FileUtils.rm_f "test/coverage/.resultset.json" | 
					
						
							| 
									
										
										
										
											2016-01-18 15:33:59 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-12-23 00:34:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-07 17:28:39 +01:00
										 |  |  |       ENV["BUNDLE_GEMFILE"] = "#{HOMEBREW_LIBRARY_PATH}/test/Gemfile" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-04 14:54:09 +01:00
										 |  |  |       # Override author/committer as global settings might be invalid and thus | 
					
						
							|  |  |  |       # will cause silent failure during the setup of dummy Git repositories. | 
					
						
							|  |  |  |       %w[AUTHOR COMMITTER].each do |role| | 
					
						
							|  |  |  |         ENV["GIT_#{role}_NAME"] = "brew tests" | 
					
						
							|  |  |  |         ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" | 
					
						
							| 
									
										
										
										
											2017-01-22 20:54:37 +00:00
										 |  |  |         ENV["GIT_#{role}_DATE"]  = "Sun Jan 22 19:59:13 2017 +0000" | 
					
						
							| 
									
										
										
										
											2016-01-04 14:54:09 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-13 17:15:03 +01:00
										 |  |  |       Homebrew.install_gem_setup_path! "bundler" | 
					
						
							| 
									
										
										
										
											2017-05-29 18:24:52 +01:00
										 |  |  |       system "bundle", "install" unless quiet_system("bundle", "check") | 
					
						
							| 
									
										
										
										
											2015-12-23 00:34:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |       parallel = true | 
					
						
							| 
									
										
										
										
											2016-09-20 14:57:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:18:23 +05:30
										 |  |  |       files = if args.only | 
					
						
							|  |  |  |         test_name, line = args.only.split(":", 2) | 
					
						
							| 
									
										
										
										
											2016-09-20 14:57:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |         if line.nil? | 
					
						
							|  |  |  |           Dir.glob("test/{#{test_name},#{test_name}/**/*}_spec.rb") | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           parallel = false | 
					
						
							|  |  |  |           ["test/#{test_name}_spec.rb:#{line}"] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         Dir.glob("test/**/*_spec.rb").reject { |p| p =~ %r{^test/vendor/bundle/} } | 
					
						
							| 
									
										
										
										
											2016-01-20 07:06:09 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-09-20 14:57:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-08 08:38:25 +01:00
										 |  |  |       opts = if ENV["CI"] | 
					
						
							|  |  |  |         %w[
 | 
					
						
							|  |  |  |           --combine-stderr | 
					
						
							|  |  |  |           --serialize-stdout | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         %w[
 | 
					
						
							|  |  |  |           --nice | 
					
						
							|  |  |  |         ] | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-02-10 21:21:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-15 09:14:44 +00:00
										 |  |  |       # Generate seed ourselves and output later to avoid multiple different | 
					
						
							|  |  |  |       # seeds being output when running parallel tests. | 
					
						
							| 
									
										
										
										
											2018-06-06 23:34:19 -04:00
										 |  |  |       seed = args.seed || rand(0xFFFF).to_i | 
					
						
							| 
									
										
										
										
											2017-12-15 09:14:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |       bundle_args = ["-I", HOMEBREW_LIBRARY_PATH/"test"] | 
					
						
							|  |  |  |       bundle_args += %W[
 | 
					
						
							| 
									
										
										
										
											2017-12-15 09:14:44 +00:00
										 |  |  |         --seed #{seed} | 
					
						
							| 
									
										
										
										
											2017-05-08 08:38:25 +01:00
										 |  |  |         --color | 
					
						
							|  |  |  |         --require spec_helper | 
					
						
							| 
									
										
										
										
											2017-12-15 09:14:44 +00:00
										 |  |  |         --format NoSeedProgressFormatter | 
					
						
							| 
									
										
										
										
											2017-05-08 08:38:25 +01:00
										 |  |  |         --format ParallelTests::RSpec::RuntimeLogger | 
					
						
							| 
									
										
										
										
											2017-05-28 16:59:53 +01:00
										 |  |  |         --out #{HOMEBREW_CACHE}/tests/parallel_runtime_rspec.log | 
					
						
							| 
									
										
										
										
											2017-02-10 21:21:57 +01:00
										 |  |  |       ] | 
					
						
							| 
									
										
										
										
											2017-02-21 21:55:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |       unless OS.mac? | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |         bundle_args << "--tag" << "~needs_macos" | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |         files = files.reject { |p| p =~ %r{^test/(os/mac|cask)(/.*|_spec\.rb)$} } | 
					
						
							| 
									
										
										
										
											2015-07-22 16:04:59 +08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 20:45:48 -08:00
										 |  |  |       unless OS.linux? | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |         bundle_args << "--tag" << "~needs_linux" | 
					
						
							| 
									
										
										
										
											2017-03-05 20:45:48 -08:00
										 |  |  |         files = files.reject { |p| p =~ %r{^test/os/linux(/.*|_spec\.rb)$} } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-15 09:14:44 +00:00
										 |  |  |       puts "Randomized with seed #{seed}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-07 17:28:39 +01:00
										 |  |  |       if parallel | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |         system "bundle", "exec", "parallel_rspec", *opts, "--", *bundle_args, "--", *files | 
					
						
							| 
									
										
										
										
											2017-05-07 17:28:39 +01:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |         system "bundle", "exec", "rspec", *bundle_args, "--", *files | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-10 20:12:55 +03:00
										 |  |  |       return if $CHILD_STATUS.success? | 
					
						
							| 
									
										
										
										
											2017-02-28 14:33:39 +01:00
										 |  |  |       Homebrew.failed = true | 
					
						
							| 
									
										
										
										
											2012-04-16 16:44:11 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-03-25 00:49:18 +11:00
										 |  |  | end |