diff options
| author | AnastasiaSulyagina | 2016-08-18 22:11:42 +0300 |
|---|---|---|
| committer | AnastasiaSulyagina | 2016-08-19 14:50:14 +0300 |
| commit | e81f4ab7deeb40308f240be5ea00091fc8786d7a (patch) | |
| tree | b5418f9149de71c0f05f90cb2b39ab47f46e27b4 /Library/Homebrew/cask/test | |
| parent | 5c7c9de669025bbe4cad9829be39c5cf3b31ad25 (diff) | |
| download | brew-e81f4ab7deeb40308f240be5ea00091fc8786d7a.tar.bz2 | |
init
Diffstat (limited to 'Library/Homebrew/cask/test')
187 files changed, 5792 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/test/Casks/compliance_test.rb b/Library/Homebrew/cask/test/Casks/compliance_test.rb new file mode 100644 index 000000000..fff3e0798 --- /dev/null +++ b/Library/Homebrew/cask/test/Casks/compliance_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +describe "Casks" do + Hbc.all.reject {|c| c.is_a?(Hbc::TestCask) }.each do |cask| + describe "#{cask}" do + it "passes audit" do + audit = Hbc::Audit.new(cask) + audit.run! + audit.errors.must_equal [], "[#{cask}] Cask audit must be error free" + audit.warnings.must_equal [], "[#{cask}] Cask audit must be warning free" + end + end + end +end diff --git a/Library/Homebrew/cask/test/README.md b/Library/Homebrew/cask/test/README.md new file mode 100644 index 000000000..4b73af8c4 --- /dev/null +++ b/Library/Homebrew/cask/test/README.md @@ -0,0 +1,3 @@ +# Naming + +Only files matching `*_test.rb` will be executed as tests. diff --git a/Library/Homebrew/cask/test/cask/accessibility_test.rb b/Library/Homebrew/cask/test/cask/accessibility_test.rb new file mode 100644 index 000000000..ee192b4cb --- /dev/null +++ b/Library/Homebrew/cask/test/cask/accessibility_test.rb @@ -0,0 +1,60 @@ +require "test_helper" + +# TODO: this test should be named after the corresponding class, once +# that class is abstracted from installer.rb. +describe "Accessibility Access" do + before do + cask = Hbc.load("with-accessibility-access") + with_fake_command = { command: Hbc::FakeSystemCommand } + @installer = Hbc::Installer.new(cask, with_fake_command) + end + + describe "install" do + it "can enable accessibility access" do + MacOS.stubs(version: MacOS::Version.new("10.9")) + + @installer.stubs(bundle_identifier: "com.example.BasicCask") + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/bin/sqlite3", Hbc.tcc_db, "INSERT OR REPLACE INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"] + ) + shutup do + @installer.enable_accessibility_access + end + end + + it "can enable accessibility access in OS X releases prior to Mavericks" do + MacOS.stubs(version: MacOS::Version.new("10.8")) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/bin/touch", Hbc.pre_mavericks_accessibility_dotfile] + ) + shutup do + @installer.enable_accessibility_access + end + end + end + + describe "uninstall" do + it "can disable accessibility access" do + MacOS.stubs(version: MacOS::Version.new("10.9")) + + @installer.stubs(bundle_identifier: "com.example.BasicCask") + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/bin/sqlite3", Hbc.tcc_db, "DELETE FROM access WHERE client='com.example.BasicCask';"] + ) + shutup do + @installer.disable_accessibility_access + end + end + it "warns about disabling accessibility access on old OS X releases" do + MacOS.stubs(version: MacOS::Version.new("10.8")) + + @installer.stubs(bundle_identifier: "com.example.BasicCask") + + capture_io { @installer.disable_accessibility_access }[1] + .must_match("Warning: Accessibility access was enabled for with-accessibility-access, but it is not safe to disable") + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/alt_target_test.rb b/Library/Homebrew/cask/test/cask/artifact/alt_target_test.rb new file mode 100644 index 000000000..1d1dba254 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/alt_target_test.rb @@ -0,0 +1,85 @@ +require "test_helper" + +describe Hbc::Artifact::App do + let(:local_alt_caffeine) { + Hbc.load("with-alt-target").tap do |cask| + TestHelper.install_without_artifacts(cask) + end + } + + describe "activate to alternate target" do + it "installs the given apps using the proper target directory" do + cask = local_alt_caffeine + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory" + File.exist?(cask.staged_path.join("AnotherName.app")).must_equal false + end + + it "works with an application in a subdir" do + subdir_cask = Hbc::Cask.new("subdir") do + url TestHelper.local_binary_url("caffeine.zip") + homepage "http://example.com/local-caffeine" + version "1.2.3" + sha256 "9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853" + app "subdir/Caffeine.app", target: "AnotherName.app" + end + + begin + TestHelper.install_without_artifacts(subdir_cask) + + appsubdir = subdir_cask.staged_path.join("subdir").tap(&:mkpath) + FileUtils.mv(subdir_cask.staged_path.join("Caffeine.app"), appsubdir) + + shutup do + Hbc::Artifact::App.new(subdir_cask).install_phase + end + + File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory" + File.exist?(appsubdir.join("AnotherName.app")).must_equal false + ensure + if defined?(subdir_cask) + shutup do + Hbc::Installer.new(subdir_cask).uninstall + end + end + end + end + + it "only uses apps when they are specified" do + cask = local_alt_caffeine + + staged_app_path = cask.staged_path.join("Caffeine.app") + staged_app_copy = staged_app_path.sub("Caffeine.app", "CaffeineAgain.app") + FileUtils.cp_r staged_app_path, staged_app_copy + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("AnotherName.app")).must_equal "directory" + File.exist?(staged_app_path).must_equal false + + File.exist?(Hbc.appdir.join("AnotherNameAgain.app")).must_equal false + File.exist?(cask.staged_path.join("CaffeineAgain.app")).must_equal true + end + + it "avoids clobbering an existing app by moving over it" do + cask = local_alt_caffeine + + existing_app_path = Hbc.appdir.join("AnotherName.app") + existing_app_path.mkpath + + TestHelper.must_output(self, lambda { + Hbc::Artifact::App.new(cask).install_phase + }, "==> It seems there is already an App at '#{existing_app_path}'; not moving.") + + source_path = cask.staged_path.join("Caffeine.app") + + File.identical?(source_path, existing_app_path).must_equal false + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/app_test.rb b/Library/Homebrew/cask/test/cask/artifact/app_test.rb new file mode 100644 index 000000000..c5aa78365 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/app_test.rb @@ -0,0 +1,301 @@ +require "test_helper" + +describe Hbc::Artifact::App do + let(:local_caffeine) { + Hbc.load("local-caffeine").tap do |cask| + TestHelper.install_without_artifacts(cask) + end + } + + describe "install_phase" do + it "installs the given apps using the proper target directory" do + cask = local_caffeine + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false + end + + it "works with an application in a subdir" do + subdir_cask = Hbc::Cask.new("subdir") do + url TestHelper.local_binary_url("caffeine.zip") + homepage "http://example.com/local-caffeine" + version "1.2.3" + sha256 "9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853" + app "subdir/Caffeine.app" + end + + begin + TestHelper.install_without_artifacts(subdir_cask) + + appsubdir = subdir_cask.staged_path.join("subdir").tap(&:mkpath) + FileUtils.mv(subdir_cask.staged_path.join("Caffeine.app"), appsubdir) + + shutup do + Hbc::Artifact::App.new(subdir_cask).install_phase + end + + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(appsubdir.join("Caffeine.app")).must_equal false + ensure + if defined?(subdir_cask) + shutup do + Hbc::Installer.new(subdir_cask).uninstall + end + end + end + end + + it "only uses apps when they are specified" do + cask = local_caffeine + + staged_app_path = cask.staged_path.join("Caffeine.app") + staged_app_copy = staged_app_path.sub("Caffeine.app", "CaffeineAgain.app") + FileUtils.cp_r staged_app_path, staged_app_copy + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(staged_app_path).must_equal false + + File.exist?(Hbc.appdir.join("CaffeineAgain.app")).must_equal false + File.exist?(cask.staged_path.join("CaffeineAgain.app")).must_equal true + end + + describe "when the target already exists" do + let(:target_path) { + target_path = Hbc.appdir.join("Caffeine.app") + target_path.mkpath + target_path + } + + it "avoids clobbering an existing app" do + cask = local_caffeine + + TestHelper.must_output(self, lambda { + Hbc::Artifact::App.new(cask).install_phase + }, "==> It seems there is already an App at '#{target_path}'; not moving.") + + source_path = cask.staged_path.join("Caffeine.app") + + File.identical?(source_path, target_path).must_equal false + + contents_path = target_path.join("Contents/Info.plist") + File.exist?(contents_path).must_equal false + end + + describe "given the force option" do + let(:install_phase) { + lambda do |given_options = {}| + options = { force: true }.merge(given_options) + Hbc::Artifact::App.new(local_caffeine, options).install_phase + end + } + + let(:chmod_cmd) { + ["/bin/chmod", "-R", "--", "u+rwx", target_path] + } + + let(:chmod_n_cmd) { + ["/bin/chmod", "-R", "-N", target_path] + } + + let(:chflags_cmd) { + ["/usr/bin/chflags", "-R", "--", "000", target_path] + } + + before do + Hbc::Utils.stubs(current_user: "fake_user") + end + + describe "target is both writable and user-owned" do + it "overwrites the existing app" do + cask = local_caffeine + + expected = [ + "==> It seems there is already an App at '#{target_path}'; overwriting.", + "==> Removing App: '#{target_path}'", + "==> Moving App 'Caffeine.app' to '#{target_path}'", + ] + TestHelper.must_output(self, install_phase, + expected.join("\n")) + + source_path = cask.staged_path.join("Caffeine.app") + + File.exist?(source_path).must_equal false + File.ftype(target_path).must_equal "directory" + + contents_path = target_path.join("Contents/Info.plist") + File.exist?(contents_path).must_equal true + end + end + + describe "target is user-owned but contains read-only files" do + before do + system "/usr/bin/touch", "--", "#{target_path}/foo" + system "/bin/chmod", "--", "0555", target_path + end + + it "tries to make the target world-writable" do + Hbc::FakeSystemCommand.expect_and_pass_through(chflags_cmd) + Hbc::FakeSystemCommand.expect_and_pass_through(chmod_cmd) + Hbc::FakeSystemCommand.expect_and_pass_through(chmod_n_cmd) + + shutup do + install_phase.call(command: Hbc::FakeSystemCommand) + end + end + + it "overwrites the existing app" do + cask = local_caffeine + + expected = [ + "==> It seems there is already an App at '#{target_path}'; overwriting.", + "==> Removing App: '#{target_path}'", + "==> Moving App 'Caffeine.app' to '#{target_path}'", + ] + TestHelper.must_output(self, install_phase, + expected.join("\n")) + + source_path = cask.staged_path.join("Caffeine.app") + + File.exist?(source_path).must_equal false + File.ftype(target_path).must_equal "directory" + + contents_path = target_path.join("Contents/Info.plist") + File.exist?(contents_path).must_equal true + end + + after do + system "/bin/chmod", "--", "0755", target_path + end + end + end + end + + describe "when the target is a broken symlink" do + let(:target_path) { + Hbc.appdir.join("Caffeine.app") + } + + let(:deleted_path) { + local_caffeine.staged_path.join( + "Deleted.app" + ) + } + + before do + deleted_path.mkdir + File.symlink(deleted_path, target_path) + deleted_path.rmdir + end + + it "leaves the target alone" do + cask = local_caffeine + TestHelper.must_output(self, lambda { + Hbc::Artifact::App.new(cask).install_phase + }, "==> It seems there is already an App at '#{target_path}'; not moving.") + + File.symlink?(target_path).must_equal true + end + + describe "given the force option" do + let(:install_phase) { + lambda do + Hbc::Artifact::App.new( + local_caffeine, force: true + ).install_phase + end + } + + it "overwrites the existing app" do + cask = local_caffeine + + expected = [ + "==> It seems there is already an App at '#{target_path}'; overwriting.", + "==> Removing App: '#{target_path}'", + "==> Moving App 'Caffeine.app' to '#{target_path}'", + ] + TestHelper.must_output(self, install_phase, + expected.join("\n")) + + source_path = cask.staged_path.join("Caffeine.app") + + File.exist?(source_path).must_equal false + File.ftype(target_path).must_equal "directory" + + contents_path = target_path.join("Contents/Info.plist") + File.exist?(contents_path).must_equal true + end + end + end + + it "gives a warning if the source doesn't exist" do + cask = local_caffeine + staged_app_path = cask.staged_path.join("Caffeine.app") + staged_app_path.rmtree + + installation = -> { Hbc::Artifact::App.new(cask).install_phase } + message = "It seems the App source is not there: '#{staged_app_path}'" + + error = installation.must_raise(Hbc::CaskError) + error.message.must_equal message + end + end + + describe "uninstall_phase" do + it "deletes managed apps" do + cask = local_caffeine + + shutup do + Hbc::Artifact::App.new(cask).install_phase + Hbc::Artifact::App.new(cask).uninstall_phase + end + + app_path = Hbc.appdir.join("Caffeine.app") + File.exist?(app_path).must_equal false + end + end + + describe "summary" do + it "returns the correct english_description" do + cask = local_caffeine + + description = Hbc::Artifact::App.new(cask).summary[:english_description] + + description.must_equal "Apps" + end + + describe "app is correctly installed" do + it "returns the path to the app" do + cask = local_caffeine + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + contents = Hbc::Artifact::App.new(cask).summary[:contents] + app_path = Hbc.appdir.join("Caffeine.app") + + contents.must_equal ["#{app_path} (#{app_path.abv})"] + end + end + + describe "app is missing" do + it "returns a warning and the supposed path to the app" do + cask = local_caffeine + + contents = Hbc::Artifact::App.new(cask).summary[:contents] + app_path = Hbc.appdir.join("Caffeine.app") + + contents.size.must_equal 1 + contents[0].must_match(%r{.*Missing App.*: #{app_path}}) + end + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/generic_artifact_test.rb b/Library/Homebrew/cask/test/cask/artifact/generic_artifact_test.rb new file mode 100644 index 000000000..d4a1733ba --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/generic_artifact_test.rb @@ -0,0 +1,44 @@ +require "test_helper" + +describe Hbc::Artifact::Artifact do + let(:cask) { + Hbc.load("with-generic-artifact").tap do |cask| + TestHelper.install_without_artifacts(cask) + end + } + let(:expected_path) { + Hbc.appdir.join("Caffeine.app") + } + + it "fails to install with no target" do + no_target = Hbc.load("with-generic-artifact-no-target") + TestHelper.install_without_artifacts(no_target) + + lambda { + shutup do + Hbc::Artifact::Artifact.new(no_target).install_phase + end + }.must_raise(Hbc::CaskInvalidError) + end + + it "moves the artifact to the proper directory" do + shutup do + Hbc::Artifact::Artifact.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false + end + + it "avoids clobbering an existing artifact" do + FileUtils.touch expected_path + + shutup do + Hbc::Artifact::Artifact.new(cask).install_phase + end + + source_path = cask.staged_path.join("Caffeine.app") + + File.identical?(source_path, expected_path).must_equal false + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/nested_container_test.rb b/Library/Homebrew/cask/test/cask/artifact/nested_container_test.rb new file mode 100644 index 000000000..b771ba345 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/nested_container_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +describe Hbc::Artifact::NestedContainer do + describe "install" do + it "extracts the specified paths as containers" do + cask = Hbc.load("nested-app").tap do |c| + TestHelper.install_without_artifacts(c) + end + + shutup do + Hbc::Artifact::NestedContainer.new(cask).install_phase + end + + cask.staged_path.join("MyNestedApp.app").must_be :directory? + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb new file mode 100644 index 000000000..e87db7a7a --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/pkg_test.rb @@ -0,0 +1,33 @@ +require "test_helper" + +describe Hbc::Artifact::Pkg do + before do + @cask = Hbc.load("with-installable") + shutup do + TestHelper.install_without_artifacts(@cask) + end + end + + describe "install_phase" do + it "runs the system installer on the specified pkgs" do + pkg = Hbc::Artifact::Pkg.new(@cask, + command: Hbc::FakeSystemCommand) + + Hbc::FakeSystemCommand.expects_command(["/usr/bin/sudo", "-E", "--", "/usr/sbin/installer", "-pkg", @cask.staged_path.join("MyFancyPkg", "Fancy.pkg"), "-target", "/"]) + + shutup do + pkg.install_phase + end + end + end + + describe "uninstall_phase" do + it "does nothing, because the uninstall_phase method is a no-op" do + pkg = Hbc::Artifact::Pkg.new(@cask, + command: Hbc::FakeSystemCommand) + shutup do + pkg.uninstall_phase + end + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/postflight_block_test.rb b/Library/Homebrew/cask/test/cask/artifact/postflight_block_test.rb new file mode 100644 index 000000000..47dcdd905 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/postflight_block_test.rb @@ -0,0 +1,41 @@ +require "test_helper" + +describe Hbc::Artifact::PostflightBlock do + describe "install_phase" do + it "calls the specified block after installing, passing a Cask mini-dsl" do + called = false + yielded_arg = nil + + cask = Hbc::Cask.new("with-postflight") do + postflight do |c| + called = true + yielded_arg = c + end + end + + Hbc::Artifact::PostflightBlock.new(cask).install_phase + + called.must_equal true + yielded_arg.must_be_kind_of Hbc::DSL::Postflight + end + end + + describe "uninstall_phase" do + it "calls the specified block after uninstalling, passing a Cask mini-dsl" do + called = false + yielded_arg = nil + + cask = Hbc::Cask.new("with-uninstall-postflight") do + uninstall_postflight do |c| + called = true + yielded_arg = c + end + end + + Hbc::Artifact::PostflightBlock.new(cask).uninstall_phase + + called.must_equal true + yielded_arg.must_be_kind_of Hbc::DSL::UninstallPostflight + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/preflight_block_test.rb b/Library/Homebrew/cask/test/cask/artifact/preflight_block_test.rb new file mode 100644 index 000000000..440b1db3a --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/preflight_block_test.rb @@ -0,0 +1,41 @@ +require "test_helper" + +describe Hbc::Artifact::PreflightBlock do + describe "install_phase" do + it "calls the specified block before installing, passing a Cask mini-dsl" do + called = false + yielded_arg = nil + + cask = Hbc::Cask.new("with-preflight") do + preflight do |c| + called = true + yielded_arg = c + end + end + + Hbc::Artifact::PreflightBlock.new(cask).install_phase + + called.must_equal true + yielded_arg.must_be_kind_of Hbc::DSL::Preflight + end + end + + describe "uninstall_phase" do + it "calls the specified block before uninstalling, passing a Cask mini-dsl" do + called = false + yielded_arg = nil + + cask = Hbc::Cask.new("with-uninstall-preflight") do + uninstall_preflight do |c| + called = true + yielded_arg = c + end + end + + Hbc::Artifact::PreflightBlock.new(cask).uninstall_phase + + called.must_equal true + yielded_arg.must_be_kind_of Hbc::DSL::UninstallPreflight + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/suite_test.rb b/Library/Homebrew/cask/test/cask/artifact/suite_test.rb new file mode 100644 index 000000000..5f72c4565 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/suite_test.rb @@ -0,0 +1,41 @@ +require "test_helper" + +describe Hbc::Artifact::Suite do + let(:cask) { + Hbc.load("with-suite").tap do |cask| + TestHelper.install_without_artifacts(cask) + end + } + let(:expected_path) { + Hbc.appdir.join("caffeine_suite") + } + let(:source_path) { cask.staged_path.join("caffeine_suite") } + + it "moves the suite to the proper directory" do + shutup do + Hbc::Artifact::Suite.new(cask).install_phase + end + + expected_path.must_be :directory? + TestHelper.valid_alias?(expected_path).must_equal false + File.exist?(source_path).must_equal false + end + + it "creates a suite containing the expected app" do + shutup do + Hbc::Artifact::Suite.new(cask).install_phase + end + + expected_path.join("Caffeine.app").must_be :exist? + end + + it "avoids clobbering an existing suite by moving over it" do + FileUtils.touch expected_path + + shutup do + Hbc::Artifact::Suite.new(cask).install_phase + end + + File.identical?(source_path, expected_path).must_equal false + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb b/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb new file mode 100644 index 000000000..3432597e0 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/two_apps_correct_test.rb @@ -0,0 +1,97 @@ +require "test_helper" + +describe Hbc::Artifact::App do + let(:local_two_apps_caffeine) { + Hbc.load("with-two-apps-correct").tap do |cask| + TestHelper.install_without_artifacts(cask) + end + } + + let(:local_two_apps_subdir) { + Hbc.load("with-two-apps-subdir").tap do |cask| + TestHelper.install_without_artifacts(cask) + end + } + + describe "multiple apps" do + it "installs both apps using the proper target directory" do + cask = local_two_apps_caffeine + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false + + File.ftype(Hbc.appdir.join("Caffeine-2.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine-2.app")).must_equal false + end + + it "works with an application in a subdir" do + cask = local_two_apps_subdir + TestHelper.install_without_artifacts(cask) + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false + + File.ftype(Hbc.appdir.join("Caffeine-2.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine-2.app")).must_equal false + end + + it "only uses apps when they are specified" do + cask = local_two_apps_caffeine + + app_path = cask.staged_path.join("Caffeine.app") + FileUtils.cp_r app_path, app_path.sub("Caffeine.app", "CaffeineAgain.app") + + shutup do + Hbc::Artifact::App.new(cask).install_phase + end + + File.ftype(Hbc.appdir.join("Caffeine.app")).must_equal "directory" + File.exist?(cask.staged_path.join("Caffeine.app")).must_equal false + + File.exist?(Hbc.appdir.join("CaffeineAgain.app")).must_equal false + File.exist?(cask.staged_path.join("CaffeineAgain.app")).must_equal true + end + + it "avoids clobbering an existing app (app 1)" do + cask = local_two_apps_caffeine + + Hbc.appdir.join("Caffeine.app").mkpath + + TestHelper.must_output(self, lambda { + Hbc::Artifact::App.new(cask).install_phase + }, <<-MESSAGE.undent.chomp) + ==> Moving App 'Caffeine-2.app' to '#{Hbc.appdir.join('Caffeine-2.app')}' + ==> It seems there is already an App at '#{Hbc.appdir.join('Caffeine.app')}'; not moving. + MESSAGE + + source_path = cask.staged_path.join("Caffeine.app") + + File.identical?(source_path, Hbc.appdir.join("Caffeine.app")).must_equal false + end + + it "avoids clobbering an existing app (app 2)" do + cask = local_two_apps_caffeine + + Hbc.appdir.join("Caffeine-2.app").mkpath + + TestHelper.must_output(self, lambda { + Hbc::Artifact::App.new(cask).install_phase + }, <<-MESSAGE.undent.chomp) + ==> It seems there is already an App at '#{Hbc.appdir.join('Caffeine-2.app')}'; not moving. + ==> Moving App 'Caffeine.app' to '#{Hbc.appdir.join('Caffeine.app')}' + MESSAGE + + source_path = cask.staged_path.join("Caffeine-2.app") + + File.identical?(source_path, Hbc.appdir.join("Caffeine-2.app")).must_equal false + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/two_apps_incorrect_test.rb b/Library/Homebrew/cask/test/cask/artifact/two_apps_incorrect_test.rb new file mode 100644 index 000000000..a89a94fba --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/two_apps_incorrect_test.rb @@ -0,0 +1,14 @@ +require "test_helper" + +describe Hbc::Artifact::App do + it "must raise" do + exception_raised = begin + Hbc.load("two-apps-incorrect") + false + rescue + true + end + # TODO: later give the user a nice exception for this case and check for it here + assert exception_raised + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/uninstall_test.rb b/Library/Homebrew/cask/test/cask/artifact/uninstall_test.rb new file mode 100644 index 000000000..4d6c5df1b --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/uninstall_test.rb @@ -0,0 +1,334 @@ +require "test_helper" + +describe Hbc::Artifact::Uninstall do + let(:cask) { Hbc.load("with-installable") } + + let(:uninstall_artifact) { + Hbc::Artifact::Uninstall.new(cask, command: Hbc::FakeSystemCommand) + } + + before do + shutup do + TestHelper.install_without_artifacts(cask) + end + end + + describe "install_phase" do + it "does nothing, because the install_phase method is a no-op" do + shutup do + uninstall_artifact.install_phase + end + end + end + + describe "zap_phase" do + it "does nothing, because the zap_phase method is a no-op" do + shutup do + uninstall_artifact.zap_phase + end + end + end + + describe "uninstall_phase" do + subject do + shutup do + uninstall_artifact.uninstall_phase + end + end + + describe "when using launchctl" do + let(:cask) { Hbc.load("with-uninstall-launchctl") } + let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } + let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } + let(:unknown_response) { "launchctl list returned unknown response\n" } + let(:service_info) { + <<-PLIST.undent + { + "LimitLoadToSessionType" = "Aqua"; + "Label" = "my.fancy.package.service"; + "TimeOut" = 30; + "OnDemand" = true; + "LastExitStatus" = 0; + "ProgramArguments" = ( + "argument"; + ); + }; + PLIST + } + + describe "when launchctl job is owned by user" do + it "can uninstall" do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + service_info + ) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + unknown_response + ) + + Hbc::FakeSystemCommand.expects_command(launchctl_remove_cmd) + + subject + end + end + + describe "when launchctl job is owned by system" do + it "can uninstall" do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + unknown_response + ) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + service_info + ) + + Hbc::FakeSystemCommand.expects_command(sudo(launchctl_remove_cmd)) + + subject + end + end + end + + describe "when using pkgutil" do + let(:cask) { Hbc.load("with-uninstall-pkgutil") } + let(:main_pkg_id) { "my.fancy.package.main" } + let(:agent_pkg_id) { "my.fancy.package.agent" } + let(:main_files) { + %w[ + fancy/bin/fancy.exe + fancy/var/fancy.data + ] + } + let(:main_dirs) { + %w[ + fancy + fancy/bin + fancy/var + ] + } + let(:agent_files) { + %w[ + fancy/agent/fancy-agent.exe + fancy/agent/fancy-agent.pid + fancy/agent/fancy-agent.log + ] + } + let(:agent_dirs) { + %w[ + fancy + fancy/agent + ] + } + let(:pkg_info_plist) { + <<-PLIST.undent + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + <plist version="1.0"> + <dict> + <key>install-location</key> + <string>tmp</string> + <key>volume</key> + <string>/</string> + </dict> + </plist> + PLIST + } + + it "can uninstall" do + Hbc::FakeSystemCommand.stubs_command( + %w[/usr/sbin/pkgutil --pkgs=my.fancy.package.*], + "#{main_pkg_id}\n#{agent_pkg_id}" + ) + + [ + [main_pkg_id, main_files, main_dirs], + [agent_pkg_id, agent_files, agent_dirs], + ].each do |pkg_id, pkg_files, pkg_dirs| + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-files --files #{pkg_id}], + pkg_files.join("\n") + ) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-dirs --files #{pkg_id}], + pkg_dirs.join("\n") + ) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --files #{pkg_id}], + (pkg_files + pkg_dirs).join("\n") + ) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --pkg-info-plist #{pkg_id}], + pkg_info_plist + ) + + Hbc::FakeSystemCommand.expects_command(sudo(%W[/usr/sbin/pkgutil --forget #{pkg_id}])) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}") }) + ) + end + + subject + end + end + + describe "when using kext" do + let(:cask) { Hbc.load("with-uninstall-kext") } + let(:kext_id) { "my.fancy.package.kernelextension" } + + it "can uninstall" do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), "loaded" + ) + + Hbc::FakeSystemCommand.expects_command( + sudo(%W[/sbin/kextunload -b #{kext_id}]) + ) + + subject + end + end + + describe "when using quit" do + let(:cask) { Hbc.load("with-uninstall-quit") } + let(:bundle_id) { "my.fancy.package.app" } + let(:count_processes_script) { + 'tell application "System Events" to count processes ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + let(:quit_application_script) { + %Q{tell application id "#{bundle_id}" to quit} + } + + it "can uninstall" do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), "1" + ) + + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{quit_application_script}]) + ) + + subject + end + end + + describe "when using signal" do + let(:cask) { Hbc.load("with-uninstall-signal") } + let(:bundle_id) { "my.fancy.package.app" } + let(:signals) { %w[TERM KILL] } + let(:unix_pids) { [12_345, 67_890] } + let(:get_unix_pids_script) { + 'tell application "System Events" to get the unix id of every process ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + + it "can uninstall" do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(", ") + ) + + signals.each do |signal| + Process.expects(:kill).with(signal, *unix_pids) + end + + subject + end + end + + describe "when using delete" do + let(:cask) { Hbc.load("with-uninstall-delete") } + + it "can uninstall" do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) + + subject + end + end + + describe "when using trash" do + let(:cask) { Hbc.load("with-uninstall-trash") } + + it "can uninstall" do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) + + subject + end + end + + describe "when using rmdir" do + let(:cask) { Hbc.load("with-uninstall-rmdir") } + let(:dir_pathname) { Pathname(TestHelper.local_binary_path("empty_directory")) } + + it "can uninstall" do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --], dir_pathname.join(".DS_Store")) + ) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rmdir --], dir_pathname) + ) + + subject + end + end + + describe "when using script" do + let(:cask) { Hbc.load("with-uninstall-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } + + it "can uninstall" do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) + + subject + end + end + + describe "when using early_script" do + let(:cask) { Hbc.load("with-uninstall-early-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } + + it "can uninstall" do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) + + subject + end + end + + describe "when using login_item" do + let(:cask) { Hbc.load("with-uninstall-login-item") } + + it "can uninstall" do + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/osascript", "-e", 'tell application "System Events" to delete every login ' \ + 'item whose name is "Fancy"'] + ) + + subject + end + end + end +end diff --git a/Library/Homebrew/cask/test/cask/artifact/zap_test.rb b/Library/Homebrew/cask/test/cask/artifact/zap_test.rb new file mode 100644 index 000000000..8ffa1c5e3 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/artifact/zap_test.rb @@ -0,0 +1,335 @@ +require "test_helper" + +# TODO: test that zap removes an alternate version of the same Cask +describe Hbc::Artifact::Zap do + let(:cask) { Hbc.load("with-installable") } + + let(:zap_artifact) { + Hbc::Artifact::Zap.new(cask, command: Hbc::FakeSystemCommand) + } + + before do + shutup do + TestHelper.install_without_artifacts(cask) + end + end + + describe "install_phase" do + it "does nothing, because the install_phase method is a no-op" do + shutup do + zap_artifact.install_phase + end + end + end + + describe "uninstall_phase" do + it "does nothing, because the uninstall_phase method is a no-op" do + shutup do + zap_artifact.uninstall_phase + end + end + end + + describe "zap_phase" do + subject do + shutup do + zap_artifact.zap_phase + end + end + + describe "when using launchctl" do + let(:cask) { Hbc.load("with-zap-launchctl") } + let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } + let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } + let(:unknown_response) { "launchctl list returned unknown response\n" } + let(:service_info) { + <<-PLIST.undent + { + "LimitLoadToSessionType" = "Aqua"; + "Label" = "my.fancy.package.service"; + "TimeOut" = 30; + "OnDemand" = true; + "LastExitStatus" = 0; + "ProgramArguments" = ( + "argument"; + ); + }; + PLIST + } + + describe "when launchctl job is owned by user" do + it "can zap" do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + service_info + ) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + unknown_response + ) + + Hbc::FakeSystemCommand.expects_command(launchctl_remove_cmd) + + subject + end + end + + describe "when launchctl job is owned by system" do + it "can zap" do + Hbc::FakeSystemCommand.stubs_command( + launchctl_list_cmd, + unknown_response + ) + + Hbc::FakeSystemCommand.stubs_command( + sudo(launchctl_list_cmd), + service_info + ) + + Hbc::FakeSystemCommand.expects_command(sudo(launchctl_remove_cmd)) + + subject + end + end + end + + describe "when using pkgutil" do + let(:cask) { Hbc.load("with-zap-pkgutil") } + let(:main_pkg_id) { "my.fancy.package.main" } + let(:agent_pkg_id) { "my.fancy.package.agent" } + let(:main_files) { + %w[ + fancy/bin/fancy.exe + fancy/var/fancy.data + ] + } + let(:main_dirs) { + %w[ + fancy + fancy/bin + fancy/var + ] + } + let(:agent_files) { + %w[ + fancy/agent/fancy-agent.exe + fancy/agent/fancy-agent.pid + fancy/agent/fancy-agent.log + ] + } + let(:agent_dirs) { + %w[ + fancy + fancy/agent + ] + } + let(:pkg_info_plist) { + <<-PLIST.undent + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + <plist version="1.0"> + <dict> + <key>install-location</key> + <string>tmp</string> + <key>volume</key> + <string>/</string> + </dict> + </plist> + PLIST + } + + it "can zap" do + Hbc::FakeSystemCommand.stubs_command( + %w[/usr/sbin/pkgutil --pkgs=my.fancy.package.*], + "#{main_pkg_id}\n#{agent_pkg_id}" + ) + + [ + [main_pkg_id, main_files, main_dirs], + [agent_pkg_id, agent_files, agent_dirs], + ].each do |pkg_id, pkg_files, pkg_dirs| + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-files --files #{pkg_id}], + pkg_files.join("\n") + ) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --only-dirs --files #{pkg_id}], + pkg_dirs.join("\n") + ) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --files #{pkg_id}], + (pkg_files + pkg_dirs).join("\n") + ) + + Hbc::FakeSystemCommand.stubs_command( + %W[/usr/sbin/pkgutil --pkg-info-plist #{pkg_id}], + pkg_info_plist + ) + + Hbc::FakeSystemCommand.expects_command(sudo(%W[/usr/sbin/pkgutil --forget #{pkg_id}])) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --] + pkg_files.map { |path| Pathname("/tmp/#{path}") }) + ) + end + + subject + end + end + + describe "when using kext" do + let(:cask) { Hbc.load("with-zap-kext") } + let(:kext_id) { "my.fancy.package.kernelextension" } + + it "can zap" do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/sbin/kextstat -l -b #{kext_id}]), "loaded" + ) + + Hbc::FakeSystemCommand.expects_command( + sudo(%W[/sbin/kextunload -b #{kext_id}]) + ) + + subject + end + end + + describe "when using quit" do + let(:cask) { Hbc.load("with-zap-quit") } + let(:bundle_id) { "my.fancy.package.app" } + let(:count_processes_script) { + 'tell application "System Events" to count processes ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + let(:quit_application_script) { + %Q{tell application id "#{bundle_id}" to quit} + } + + it "can zap" do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{count_processes_script}]), "1" + ) + + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{quit_application_script}]) + ) + + subject + end + end + + describe "when using signal" do + let(:cask) { Hbc.load("with-zap-signal") } + let(:bundle_id) { "my.fancy.package.app" } + let(:signals) { %w[TERM KILL] } + let(:unix_pids) { [12_345, 67_890] } + let(:get_unix_pids_script) { + 'tell application "System Events" to get the unix id of every process ' + + %Q{whose bundle identifier is "#{bundle_id}"} + } + + it "can zap" do + Hbc::FakeSystemCommand.stubs_command( + sudo(%W[/usr/bin/osascript -e #{get_unix_pids_script}]), unix_pids.join(", ") + ) + + signals.each do |signal| + Process.expects(:kill).with(signal, *unix_pids) + end + + subject + end + end + + describe "when using delete" do + let(:cask) { Hbc.load("with-zap-delete") } + + it "can zap" do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) + + subject + end + end + + describe "when using trash" do + let(:cask) { Hbc.load("with-zap-trash") } + + it "can zap" do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -rf --], + Pathname.new("/permissible/absolute/path"), + Pathname.new("~/permissible/path/with/tilde").expand_path) + ) + + subject + end + end + + describe "when using rmdir" do + let(:cask) { Hbc.load("with-zap-rmdir") } + let(:dir_pathname) { Pathname(TestHelper.local_binary_path("empty_directory")) } + + it "can zap" do + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rm -f --], dir_pathname.join(".DS_Store")) + ) + + Hbc::FakeSystemCommand.expects_command( + sudo(%w[/bin/rmdir --], dir_pathname) + ) + + subject + end + end + + describe "when using script" do + let(:cask) { Hbc.load("with-zap-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } + + it "can zap" do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) + + subject + end + end + + describe "when using early_script" do + let(:cask) { Hbc.load("with-zap-early-script") } + let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } + + it "can zap" do + Hbc::FakeSystemCommand.expects_command(%w[/bin/chmod -- +x] + [script_pathname]) + + Hbc::FakeSystemCommand.expects_command( + sudo(cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool"), "--please") + ) + + subject + end + end + + describe "when using login_item" do + let(:cask) { Hbc.load("with-zap-login-item") } + + it "can zap" do + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/osascript", "-e", 'tell application "System Events" to delete every login ' \ + 'item whose name is "Fancy"'] + ) + + subject + end + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/audit_test.rb b/Library/Homebrew/cask/test/cask/cli/audit_test.rb new file mode 100644 index 000000000..b55c4ea30 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/audit_test.rb @@ -0,0 +1,63 @@ +require "test_helper" + +describe Hbc::CLI::Audit do + let(:auditor) { mock } + let(:cask) { mock } + + describe "selection of Casks to audit" do + it "audits all Casks if no tokens are given" do + Hbc.stubs(all: [cask, cask]) + auditor.expects(:audit).times(2) + + run_audit([], auditor) + end + + it "audits specified Casks if tokens are given" do + cask_token = "nice-app" + Hbc.expects(:load).with(cask_token).returns(cask) + auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false) + + run_audit([cask_token], auditor) + end + end + + describe "rules for downloading a Cask" do + it "does not download the Cask per default" do + Hbc.stubs(load: cask) + + auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false) + + run_audit(["casktoken"], auditor) + end + + it "download a Cask if --download flag is set" do + Hbc.stubs(load: cask) + + auditor.expects(:audit).with(cask, audit_download: true, check_token_conflicts: false) + + run_audit(["casktoken", "--download"], auditor) + end + end + + describe "rules for checking token conflicts" do + it "does not check for token conflicts per default" do + Hbc.stubs(load: cask) + + auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: false) + + run_audit(["casktoken"], auditor) + end + + it "checks for token conflicts if --token-conflicts flag is set" do + Hbc.stubs(load: cask) + + auditor.expects(:audit).with(cask, audit_download: false, check_token_conflicts: true) + + run_audit(["casktoken", "--token-conflicts"], auditor) + end + end + + def run_audit(args, auditor) + Hbc::CLI::Audit.new(args, auditor).run + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/cat_test.rb b/Library/Homebrew/cask/test/cask/cli/cat_test.rb new file mode 100644 index 000000000..f51fe4be0 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/cat_test.rb @@ -0,0 +1,59 @@ +require "test_helper" + +describe Hbc::CLI::Cat do + describe "given a basic Cask" do + before do + @expected_output = <<-CLIOUTPUT.undent + test_cask 'basic-cask' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/TestCask.dmg' + homepage 'http://example.com/' + + app 'TestCask.app' + end + CLIOUTPUT + end + + it "displays the Cask file content about the specified Cask" do + lambda { + Hbc::CLI::Cat.run("basic-cask") + }.must_output(@expected_output) + end + + it "throws away additional Cask arguments and uses the first" do + lambda { + Hbc::CLI::Cat.run("basic-cask", "local-caffeine") + }.must_output(@expected_output) + end + + it "throws away stray options" do + lambda { + Hbc::CLI::Cat.run("--notavalidoption", "basic-cask") + }.must_output(@expected_output) + end + end + + it "raises an exception when the Cask does not exist" do + lambda { + Hbc::CLI::Cat.run("notacask") + }.must_raise Hbc::CaskUnavailableError + end + + describe "when no Cask is specified" do + it "raises an exception" do + lambda { + Hbc::CLI::Cat.run + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + lambda { + Hbc::CLI::Cat.run("--notavalidoption") + }.must_raise Hbc::CaskUnspecifiedError + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/create_test.rb b/Library/Homebrew/cask/test/cask/cli/create_test.rb new file mode 100644 index 000000000..85d888cfa --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/create_test.rb @@ -0,0 +1,97 @@ +require "test_helper" + +# monkeypatch for testing +class Hbc::CLI::Create + def self.exec_editor(*command) + editor_commands << command + end + + def self.reset! + @editor_commands = [] + end + + def self.editor_commands + @editor_commands ||= [] + end +end + +describe Hbc::CLI::Create do + before do + Hbc::CLI::Create.reset! + end + + after do + %w[new-cask additional-cask another-cask yet-another-cask feine].each do |cask| + path = Hbc.path(cask) + path.delete if path.exist? + end + end + + it "opens the editor for the specified Cask" do + Hbc::CLI::Create.run("new-cask") + Hbc::CLI::Create.editor_commands.must_equal [ + [Hbc.path("new-cask")], + ] + end + + it "drops a template down for the specified Cask" do + Hbc::CLI::Create.run("new-cask") + template = File.read(Hbc.path("new-cask")) + template.must_equal <<-TEMPLATE.undent + cask 'new-cask' do + version '' + sha256 '' + + url 'https://' + name '' + homepage '' + license :unknown # TODO: change license and remove this comment; ':unknown' is a machine-generated placeholder + + app '' + end + TEMPLATE + end + + it "throws away additional Cask arguments and uses the first" do + Hbc::CLI::Create.run("additional-cask", "another-cask") + Hbc::CLI::Create.editor_commands.must_equal [ + [Hbc.path("additional-cask")], + ] + end + + it "throws away stray options" do + Hbc::CLI::Create.run("--notavalidoption", "yet-another-cask") + Hbc::CLI::Create.editor_commands.must_equal [ + [Hbc.path("yet-another-cask")], + ] + end + + it "raises an exception when the Cask already exists" do + lambda { + Hbc::CLI::Create.run("caffeine") + }.must_raise Hbc::CaskAlreadyCreatedError + end + + it "allows creating Casks that are substrings of existing Casks" do + Hbc::CLI::Create.run("feine") + Hbc::CLI::Create.editor_commands.must_equal [ + [Hbc.path("feine")], + ] + end + + describe "when no Cask is specified" do + it "raises an exception" do + lambda { + Hbc::CLI::Create.run + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + lambda { + Hbc::CLI::Create.run("--notavalidoption") + }.must_raise Hbc::CaskUnspecifiedError + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/edit_test.rb b/Library/Homebrew/cask/test/cask/cli/edit_test.rb new file mode 100644 index 000000000..ebec5f414 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/edit_test.rb @@ -0,0 +1,58 @@ +require "test_helper" + +# monkeypatch for testing +class Hbc::CLI::Edit + def self.exec_editor(*command) + editor_commands << command + end + + def self.reset! + @editor_commands = [] + end + + def self.editor_commands + @editor_commands ||= [] + end +end + +describe Hbc::CLI::Edit do + before do + Hbc::CLI::Edit.reset! + end + + it "opens the editor for the specified Cask" do + Hbc::CLI::Edit.run("alfred") + Hbc::CLI::Edit.editor_commands.must_equal [ + [Hbc.path("alfred")], + ] + end + + it "throws away additional arguments and uses the first" do + Hbc::CLI::Edit.run("adium", "alfred") + Hbc::CLI::Edit.editor_commands.must_equal [ + [Hbc.path("adium")], + ] + end + + it "raises an exception when the Cask doesnt exist" do + lambda { + Hbc::CLI::Edit.run("notacask") + }.must_raise Hbc::CaskUnavailableError + end + + describe "when no Cask is specified" do + it "raises an exception" do + lambda { + Hbc::CLI::Edit.run + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + lambda { + Hbc::CLI::Edit.run("--notavalidoption") + }.must_raise Hbc::CaskUnspecifiedError + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/fetch_test.rb b/Library/Homebrew/cask/test/cask/cli/fetch_test.rb new file mode 100644 index 000000000..70c25646d --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/fetch_test.rb @@ -0,0 +1,78 @@ +require "test_helper" + +describe Hbc::CLI::Fetch do + let(:local_transmission) { + Hbc.load("local-transmission") + } + + let(:local_caffeine) { + Hbc.load("local-caffeine") + } + + it "allows download the installer of a Cask" do + shutup do + Hbc::CLI::Fetch.run("local-transmission", "local-caffeine") + end + Hbc::CurlDownloadStrategy.new(local_transmission).cached_location.must_be :exist? + Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location.must_be :exist? + end + + it "prevents double fetch (without nuking existing installation)" do + download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission) + + shutup do + Hbc::Download.new(local_transmission).perform + end + old_ctime = File.stat(download_stategy.cached_location).ctime + + shutup do + Hbc::CLI::Fetch.run("local-transmission") + end + new_ctime = File.stat(download_stategy.cached_location).ctime + + old_ctime.to_i.must_equal new_ctime.to_i + end + + it "allows double fetch with --force" do + shutup do + Hbc::Download.new(local_transmission).perform + end + + download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission) + old_ctime = File.stat(download_stategy.cached_location).ctime + sleep(1) + + shutup do + Hbc::CLI::Fetch.run("local-transmission", "--force") + end + download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission) + new_ctime = File.stat(download_stategy.cached_location).ctime + + # new_ctime.to_i.must_be :>, old_ctime.to_i + new_ctime.to_i.must_be :>, old_ctime.to_i + end + + it "properly handles Casks that are not present" do + lambda { + shutup do + Hbc::CLI::Fetch.run("notacask") + end + }.must_raise Hbc::CaskUnavailableError + end + + describe "when no Cask is specified" do + it "raises an exception" do + lambda { + Hbc::CLI::Fetch.run + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + lambda { + Hbc::CLI::Fetch.run("--notavalidoption") + }.must_raise Hbc::CaskUnspecifiedError + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/home_test.rb b/Library/Homebrew/cask/test/cask/cli/home_test.rb new file mode 100644 index 000000000..28fd2a391 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/home_test.rb @@ -0,0 +1,44 @@ +require "test_helper" + +# monkeypatch for testing +class Hbc::CLI::Home + def self.system(*command) + system_commands << command + end + + def self.reset! + @system_commands = [] + end + + def self.system_commands + @system_commands ||= [] + end +end + +describe Hbc::CLI::Home do + before do + Hbc::CLI::Home.reset! + end + + it "opens the homepage for the specified Cask" do + Hbc::CLI::Home.run("alfred") + Hbc::CLI::Home.system_commands.must_equal [ + ["/usr/bin/open", "--", "https://www.alfredapp.com/"], + ] + end + + it "works for multiple Casks" do + Hbc::CLI::Home.run("alfred", "adium") + Hbc::CLI::Home.system_commands.must_equal [ + ["/usr/bin/open", "--", "https://www.alfredapp.com/"], + ["/usr/bin/open", "--", "https://www.adium.im/"], + ] + end + + it "opens the project page when no Cask is specified" do + Hbc::CLI::Home.run + Hbc::CLI::Home.system_commands.must_equal [ + ["/usr/bin/open", "--", "http://caskroom.io/"], + ] + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/info_test.rb b/Library/Homebrew/cask/test/cask/cli/info_test.rb new file mode 100644 index 000000000..441f9d835 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/info_test.rb @@ -0,0 +1,110 @@ +require "test_helper" + +describe Hbc::CLI::Info do + it "displays some nice info about the specified Cask" do + lambda { + Hbc::CLI::Info.run("local-caffeine") + }.must_output <<-EOS.undent + local-caffeine: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/local-caffeine.rb + ==> Name + None + ==> Artifacts + Caffeine.app (app) + EOS + end + + describe "given multiple Casks" do + before do + @expected_output = <<-EOS.undent + local-caffeine: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/local-caffeine.rb + ==> Name + None + ==> Artifacts + Caffeine.app (app) + local-transmission: 2.61 + http://example.com/local-transmission + Not installed + From: https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/local-transmission.rb + ==> Name + None + ==> Artifacts + Transmission.app (app) + EOS + end + + it "displays the info" do + lambda { + Hbc::CLI::Info.run("local-caffeine", "local-transmission") + }.must_output(@expected_output) + end + + it "throws away stray options" do + lambda { + Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission") + }.must_output(@expected_output) + end + end + + it "should print caveats if the Cask provided one" do + lambda { + Hbc::CLI::Info.run("with-caveats") + }.must_output <<-EOS.undent + with-caveats: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/with-caveats.rb + ==> Name + None + ==> Artifacts + Caffeine.app (app) + ==> Caveats + Here are some things you might want to know. + + Cask token: with-caveats + + Custom text via puts followed by DSL-generated text: + To use with-caveats, you may need to add the /custom/path/bin directory + to your PATH environment variable, eg (for bash shell): + + export PATH=/custom/path/bin:"$PATH" + + EOS + end + + it 'should not print "Caveats" section divider if the caveats block has no output' do + lambda { + Hbc::CLI::Info.run("with-conditional-caveats") + }.must_output <<-EOS.undent + with-conditional-caveats: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-testcasks/blob/master/Casks/with-conditional-caveats.rb + ==> Name + None + ==> Artifacts + Caffeine.app (app) + EOS + end + + describe "when no Cask is specified" do + it "raises an exception" do + lambda { + Hbc::CLI::Info.run + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + lambda { + Hbc::CLI::Info.run("--notavalidoption") + }.must_raise Hbc::CaskUnspecifiedError + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/install_test.rb b/Library/Homebrew/cask/test/cask/cli/install_test.rb new file mode 100644 index 000000000..2d09846b7 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/install_test.rb @@ -0,0 +1,109 @@ +require "test_helper" + +describe Hbc::CLI::Install do + it "allows staging and activation of multiple Casks at once" do + shutup do + Hbc::CLI::Install.run("local-transmission", "local-caffeine") + end + + Hbc.load("local-transmission").must_be :installed? + Hbc.appdir.join("Transmission.app").must_be :directory? + Hbc.load("local-caffeine").must_be :installed? + Hbc.appdir.join("Caffeine.app").must_be :directory? + end + + it "skips double install (without nuking existing installation)" do + shutup do + Hbc::CLI::Install.run("local-transmission") + end + shutup do + Hbc::CLI::Install.run("local-transmission") + end + Hbc.load("local-transmission").must_be :installed? + end + + it "prints a warning message on double install" do + shutup do + Hbc::CLI::Install.run("local-transmission") + end + + TestHelper.must_output(self, lambda { + Hbc::CLI::Install.run("local-transmission", "") + }, %r{Warning: A Cask for local-transmission is already installed. Add the "--force" option to force re-install.}) + end + + it "allows double install with --force" do + shutup do + Hbc::CLI::Install.run("local-transmission") + end + + TestHelper.must_output(self, lambda { + Hbc::CLI::Install.run("local-transmission", "--force") + }, %r{==> Success! local-transmission was successfully installed!}) + end + + it "skips dependencies with --skip-cask-deps" do + shutup do + Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") + end + Hbc.load("with-depends-on-cask-multiple").must_be :installed? + Hbc.load("local-caffeine").wont_be :installed? + Hbc.load("local-transmission").wont_be :installed? + end + + it "properly handles Casks that are not present" do + lambda { + shutup do + Hbc::CLI::Install.run("notacask") + end + }.must_raise Hbc::CaskError + end + + it "returns a suggestion for a misspelled Cask" do + _, err = capture_io do + begin + Hbc::CLI::Install.run("googlechrome") + rescue Hbc::CaskError + return + end + end + err.must_match %r{No available Cask for googlechrome\. Did you mean:\ngoogle-chrome} + end + + it "returns multiple suggestions for a Cask fragment" do + _, err = capture_io do + begin + Hbc::CLI::Install.run("google") + rescue Hbc::CaskError + return + end + end + err.must_match %r{No available Cask for google\. Did you mean one of:\ngoogle} + end + + describe "when no Cask is specified" do + with_options = lambda do |options| + it "raises an exception" do + lambda { + Hbc::CLI::Install.run(*options) + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "without options" do + with_options.call([]) + end + + describe "with --force" do + with_options.call(["--force"]) + end + + describe "with --skip-cask-deps" do + with_options.call(["--skip-cask-deps"]) + end + + describe "with an invalid option" do + with_options.call(["--notavalidoption"]) + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/list_test.rb b/Library/Homebrew/cask/test/cask/cli/list_test.rb new file mode 100644 index 000000000..2189498d4 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/list_test.rb @@ -0,0 +1,88 @@ +require "test_helper" + +describe Hbc::CLI::List do + it "lists the installed Casks in a pretty fashion" do + casks = %w[local-caffeine local-transmission].map { |c| Hbc.load(c) } + + casks.each do |c| + TestHelper.install_with_caskfile(c) + end + + lambda { + Hbc::CLI::List.run + }.must_output <<-EOS.undent + local-caffeine + local-transmission + EOS + end + + describe "lists versions" do + let(:casks) { ["local-caffeine", "local-transmission"] } + let(:output) { + <<-EOS.undent + local-caffeine 1.2.3 + local-transmission 2.61 + EOS + } + + before(:each) do + casks.map(&Hbc.method(:load)).each(&TestHelper.method(:install_with_caskfile)) + end + + it "of all installed Casks" do + lambda { + Hbc::CLI::List.run("--versions") + }.must_output(output) + end + + it "of given Casks" do + lambda { + Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission") + }.must_output(output) + end + end + + describe "when Casks have been renamed" do + let(:caskroom_path) { Hbc.caskroom.join("ive-been-renamed") } + let(:staged_path) { caskroom_path.join("latest") } + + before do + staged_path.mkpath + end + + after do + caskroom_path.rmtree + end + + it "lists installed Casks without backing ruby files (due to renames or otherwise)" do + lambda { + Hbc::CLI::List.run + }.must_output <<-EOS.undent + ive-been-renamed (!) + EOS + end + end + + describe "given a set of installed Casks" do + let(:caffeine) { Hbc.load("local-caffeine") } + let(:transmission) { Hbc.load("local-transmission") } + let(:casks) { [caffeine, transmission] } + + it "lists the installed files for those Casks" do + casks.each(&TestHelper.method(:install_without_artifacts_with_caskfile)) + + shutup do + Hbc::Artifact::App.new(transmission).install_phase + end + + lambda { + Hbc::CLI::List.run("local-transmission", "local-caffeine") + }.must_output <<-EOS.undent + ==> Apps + #{Hbc.appdir.join('Transmission.app')} (#{Hbc.appdir.join('Transmission.app').abv}) + ==> Apps + Missing App: #{Hbc.appdir.join('Caffeine.app')} + EOS + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/options_test.rb b/Library/Homebrew/cask/test/cask/cli/options_test.rb new file mode 100644 index 000000000..32bd2e2d7 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/options_test.rb @@ -0,0 +1,130 @@ +require "test_helper" + +describe Hbc::CLI do + it "supports setting the appdir" do + Hbc::CLI.process_options %w[help --appdir=/some/path/foo] + + Hbc.appdir.must_equal Pathname("/some/path/foo") + end + + it "supports setting the appdir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + Hbc.appdir.must_equal Pathname("/some/path/bar") + end + + it "supports setting the prefpanedir" do + Hbc::CLI.process_options %w[help --prefpanedir=/some/path/foo] + + Hbc.prefpanedir.must_equal Pathname("/some/path/foo") + end + + it "supports setting the prefpanedir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + Hbc.prefpanedir.must_equal Pathname("/some/path/bar") + end + + it "supports setting the qlplugindir" do + Hbc::CLI.process_options %w[help --qlplugindir=/some/path/foo] + + Hbc.qlplugindir.must_equal Pathname("/some/path/foo") + end + + it "supports setting the qlplugindir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + Hbc.qlplugindir.must_equal Pathname("/some/path/bar") + end + + it "supports setting the colorpickerdir" do + Hbc::CLI.process_options %w[help --colorpickerdir=/some/path/foo] + + Hbc.colorpickerdir.must_equal Pathname("/some/path/foo") + end + + it "supports setting the colorpickerdir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + Hbc.colorpickerdir.must_equal Pathname("/some/path/bar") + end + + it "supports setting the fontdir" do + Hbc::CLI.process_options %w[help --fontdir=/some/path/foo] + + Hbc.fontdir.must_equal Pathname("/some/path/foo") + end + + it "supports setting the fontdir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + Hbc.fontdir.must_equal Pathname("/some/path/bar") + end + + it "supports setting the servicedir" do + Hbc::CLI.process_options %w[help --servicedir=/some/path/foo] + + Hbc.servicedir.must_equal Pathname("/some/path/foo") + end + + it "supports setting the servicedir from ENV" do + ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" + + Hbc::CLI.process_options %w[help] + + Hbc.servicedir.must_equal Pathname("/some/path/bar") + end + + it "allows additional options to be passed through" do + rest = Hbc::CLI.process_options %w[edit foo --create --appdir=/some/path/qux] + + Hbc.appdir.must_equal Pathname("/some/path/qux") + rest.must_equal %w[edit foo --create] + end + + describe "when a mandatory argument is missing" do + it "shows a user-friendly error message" do + lambda { + Hbc::CLI.process_options %w[install -f] + }.must_raise Hbc::CaskError + end + end + + describe "given an ambiguous option" do + it "shows a user-friendly error message" do + lambda { + Hbc::CLI.process_options %w[edit -c] + }.must_raise Hbc::CaskError + end + end + + describe "--debug" do + it "sets the Cask debug method to true" do + Hbc::CLI.process_options %w[help --debug] + Hbc.debug.must_equal true + Hbc.debug = false + end + end + + describe "--help" do + it "sets the Cask help method to true" do + Hbc::CLI.process_options %w[foo --help] + Hbc.help.must_equal true + Hbc.help = false + end + end + + after do + ENV["HOMEBREW_CASK_OPTS"] = nil + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/search_test.rb b/Library/Homebrew/cask/test/cask/cli/search_test.rb new file mode 100644 index 000000000..a0365862e --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/search_test.rb @@ -0,0 +1,59 @@ +require "test_helper" + +describe Hbc::CLI::Search do + it "lists the available Casks that match the search term" do + lambda { + Hbc::CLI::Search.run("photoshop") + }.must_output <<-OUTPUT.gsub(%r{^ *}, "") + ==> Partial matches + adobe-photoshop-cc + adobe-photoshop-lightroom + OUTPUT + end + + it "shows that there are no Casks matching a search term that did not result in anything" do + lambda { + Hbc::CLI::Search.run("foo-bar-baz") + }.must_output("No Cask found for \"foo-bar-baz\".\n") + end + + it "lists all available Casks with no search term" do + out = capture_io { Hbc::CLI::Search.run }[0] + out.must_match(%r{google-chrome}) + out.length.must_be :>, 1000 + end + + it "ignores hyphens in search terms" do + out = capture_io { Hbc::CLI::Search.run("goo-gle-chrome") }[0] + out.must_match(%r{google-chrome}) + out.length.must_be :<, 100 + end + + it "ignores hyphens in Cask tokens" do + out = capture_io { Hbc::CLI::Search.run("googlechrome") }[0] + out.must_match(%r{google-chrome}) + out.length.must_be :<, 100 + end + + it "accepts multiple arguments" do + out = capture_io { Hbc::CLI::Search.run("google chrome") }[0] + out.must_match(%r{google-chrome}) + out.length.must_be :<, 100 + end + + it "accepts a regexp argument" do + lambda { + Hbc::CLI::Search.run("/^google-c[a-z]rome$/") + }.must_output "==> Regexp matches\ngoogle-chrome\n" + end + + it "Returns both exact and partial matches" do + out = capture_io { Hbc::CLI::Search.run("mnemosyne") }[0] + out.must_match(%r{^==> Exact match\nmnemosyne\n==> Partial matches\nsubclassed-mnemosyne}) + end + + it "does not search the Tap name" do + out = capture_io { Hbc::CLI::Search.run("caskroom") }[0] + out.must_match(%r{^No Cask found for "caskroom"\.\n}) + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/uninstall_test.rb b/Library/Homebrew/cask/test/cask/cli/uninstall_test.rb new file mode 100644 index 000000000..e2909873a --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/uninstall_test.rb @@ -0,0 +1,154 @@ +require "test_helper" + +describe Hbc::CLI::Uninstall do + it "shows an error when a bad Cask is provided" do + lambda { + Hbc::CLI::Uninstall.run("notacask") + }.must_raise Hbc::CaskUnavailableError + end + + it "shows an error when a Cask is provided that's not installed" do + lambda { + Hbc::CLI::Uninstall.run("anvil") + }.must_raise Hbc::CaskNotInstalledError + end + + it "tries anyway on a non-present Cask when --force is given" do + lambda do + Hbc::CLI::Uninstall.run("anvil", "--force") + end # wont_raise + end + + it "can uninstall and unlink multiple Casks at once" do + caffeine = Hbc.load("local-caffeine") + transmission = Hbc.load("local-transmission") + + shutup do + Hbc::Installer.new(caffeine).install + Hbc::Installer.new(transmission).install + end + + caffeine.must_be :installed? + transmission.must_be :installed? + + shutup do + Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission") + end + + caffeine.wont_be :installed? + File.exist?(Hbc.appdir.join("Transmission.app")).must_equal false + transmission.wont_be :installed? + File.exist?(Hbc.appdir.join("Caffeine.app")).must_equal false + end + + describe "when multiple versions of a cask are installed" do + let(:token) { "versioned-cask" } + let(:first_installed_version) { "1.2.3" } + let(:last_installed_version) { "4.5.6" } + let(:timestamped_versions) { + [ + [first_installed_version, "123000"], + [last_installed_version, "456000"], + ] + } + let(:caskroom_path) { Hbc.caskroom.join(token).tap(&:mkpath) } + + before(:each) do + timestamped_versions.each do |timestamped_version| + caskroom_path.join(".metadata", *timestamped_version, "Casks").tap(&:mkpath) + .join("#{token}.rb").open("w") do |caskfile| + caskfile.puts <<-EOF.undent + cask '#{token}' do + version '#{timestamped_version[0]}' + end + EOF + end + caskroom_path.join(timestamped_version[0]).mkpath + end + end + + after(:each) do + caskroom_path.rmtree if caskroom_path.exist? + end + + it "uninstalls one version at a time" do + shutup do + Hbc::CLI::Uninstall.run("versioned-cask") + end + + caskroom_path.join(first_installed_version).must_be :exist? + caskroom_path.join(last_installed_version).wont_be :exist? + caskroom_path.must_be :exist? + + shutup do + Hbc::CLI::Uninstall.run("versioned-cask") + end + + caskroom_path.join(first_installed_version).wont_be :exist? + caskroom_path.wont_be :exist? + end + + it "displays a message when versions remain installed" do + out, err = capture_io do + Hbc::CLI::Uninstall.run("versioned-cask") + end + + out.must_match(%r{#{token} #{first_installed_version} is still installed.}) + err.must_be :empty? + end + end + + describe "when Casks in Taps have been renamed or removed" do + let(:app) { Hbc.appdir.join("ive-been-renamed.app") } + let(:caskroom_path) { Hbc.caskroom.join("ive-been-renamed").tap(&:mkpath) } + let(:saved_caskfile) { caskroom_path.join(".metadata", "latest", "timestamp", "Casks").join("ive-been-renamed.rb") } + + before do + app.tap(&:mkpath) + .join("Contents").tap(&:mkpath) + .join("Info.plist").tap(&FileUtils.method(:touch)) + + caskroom_path.mkpath + + saved_caskfile.dirname.mkpath + + IO.write saved_caskfile, <<-EOF.undent + cask 'ive-been-renamed' do + version :latest + + app 'ive-been-renamed.app' + end + EOF + end + + after do + app.rmtree if app.exist? + caskroom_path.rmtree if caskroom_path.exist? + end + + it "can still uninstall those Casks" do + shutup do + Hbc::CLI::Uninstall.run("ive-been-renamed") + end + + app.wont_be :exist? + caskroom_path.wont_be :exist? + end + end + + describe "when no Cask is specified" do + it "raises an exception" do + lambda { + Hbc::CLI::Uninstall.run + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + lambda { + Hbc::CLI::Uninstall.run("--notavalidoption") + }.must_raise Hbc::CaskUnspecifiedError + end + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/version_test.rb b/Library/Homebrew/cask/test/cask/cli/version_test.rb new file mode 100644 index 000000000..b451780c1 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/version_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +describe "brew cask --version" do + it "respects the --version argument" do + lambda { + Hbc::CLI::NullCommand.new("--version").run + }.must_output "#{Hbc.full_version}\n" + end +end diff --git a/Library/Homebrew/cask/test/cask/cli/zap_test.rb b/Library/Homebrew/cask/test/cask/cli/zap_test.rb new file mode 100644 index 000000000..a9e862b11 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/cli/zap_test.rb @@ -0,0 +1,75 @@ +require "test_helper" + +describe Hbc::CLI::Zap do + it "shows an error when a bad Cask is provided" do + lambda { + Hbc::CLI::Zap.run("notacask") + }.must_raise Hbc::CaskUnavailableError + end + + it "can zap and unlink multiple Casks at once" do + caffeine = Hbc.load("local-caffeine") + transmission = Hbc.load("local-transmission") + + shutup do + Hbc::Installer.new(caffeine).install + Hbc::Installer.new(transmission).install + end + + caffeine.must_be :installed? + transmission.must_be :installed? + + shutup do + Hbc::CLI::Zap.run("--notavalidoption", + "local-caffeine", "local-transmission") + end + + caffeine.wont_be :installed? + Hbc.appdir.join("Transmission.app").wont_be :symlink? + transmission.wont_be :installed? + Hbc.appdir.join("Caffeine.app").wont_be :symlink? + end + + # TODO: Explicit test that both zap and uninstall directives get dispatched. + # The above tests that implicitly. + # + # it "dispatches both uninstall and zap stanzas" do + # with_zap = Hbc.load('with-zap') + # + # shutup do + # Hbc::Installer.new(with_zap).install + # end + # + # with_zap.must_be :installed? + # + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app"'], '1') + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app" to quit']) + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application "System Events" to count processes whose bundle identifier is "my.fancy.package.app.from.uninstall"'], '1') + # Hbc::FakeSystemCommand.stubs_command(['/usr/bin/sudo', '-E', '--', '/usr/bin/osascript', '-e', 'tell application id "my.fancy.package.app.from.uninstall" to quit']) + # + # Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', with_zap.staged_path.join('MyFancyPkg','FancyUninstaller.tool'), '--please']) + # Hbc::FakeSystemCommand.expects_command(['/usr/bin/sudo', '-E', '--', '/bin/rm', '-rf', '--', + # Pathname.new('~/Library/Preferences/my.fancy.app.plist').expand_path]) + # + # shutup do + # Hbc::CLI::Zap.run('with-zap') + # end + # with_zap.wont_be :installed? + # end + + describe "when no Cask is specified" do + it "raises an exception" do + lambda { + Hbc::CLI::Zap.run + }.must_raise Hbc::CaskUnspecifiedError + end + end + + describe "when no Cask is specified, but an invalid option" do + it "raises an exception" do + lambda { + Hbc::CLI::Zap.run("--notavalidoption") + }.must_raise Hbc::CaskUnspecifiedError + end + end +end diff --git a/Library/Homebrew/cask/test/cask/container/dmg_test.rb b/Library/Homebrew/cask/test/cask/container/dmg_test.rb new file mode 100644 index 000000000..2c33b88b6 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/container/dmg_test.rb @@ -0,0 +1,22 @@ +require "test_helper" + +describe Hbc::Container::Dmg do + describe "mount!" do + it "does not store nil mounts for dmgs with extra data" do + transmission = Hbc.load("local-transmission") + + dmg = Hbc::Container::Dmg.new( + transmission, + Pathname(transmission.url.path), + Hbc::SystemCommand + ) + + begin + dmg.mount! + dmg.mounts.wont_include nil + ensure + dmg.eject! + end + end + end +end diff --git a/Library/Homebrew/cask/test/cask/container/naked_test.rb b/Library/Homebrew/cask/test/cask/container/naked_test.rb new file mode 100644 index 000000000..d40c16de5 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/container/naked_test.rb @@ -0,0 +1,20 @@ +require "test_helper" + +describe Hbc::Container::Naked do + it "saves files with spaces in them from uris with encoded spaces" do + cask = Hbc::Cask.new("spacey") do + url "http://example.com/kevin%20spacey.pkg" + version "1.2" + end + + path = "/tmp/downloads/kevin-spacey-1.2.pkg" + expected_destination = cask.staged_path.join("kevin spacey.pkg") + expected_command = ["/usr/bin/ditto", "--", path, expected_destination] + Hbc::FakeSystemCommand.stubs_command(expected_command) + + container = Hbc::Container::Naked.new(cask, path, Hbc::FakeSystemCommand) + container.extract + + Hbc::FakeSystemCommand.system_calls[expected_command].must_equal 1 + end +end diff --git a/Library/Homebrew/cask/test/cask/depends_on_test.rb b/Library/Homebrew/cask/test/cask/depends_on_test.rb new file mode 100644 index 000000000..31e51b5e5 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/depends_on_test.rb @@ -0,0 +1,121 @@ +require "test_helper" + +# TODO: this test should be named after the corresponding class, once +# that class is abstracted from installer.rb +describe "Satisfy Dependencies and Requirements" do + # TODO: test that depends_on formula invokes Homebrew + # + # describe "depends_on formula" do + # it "" do + # end + # end + # + + describe "depends_on cask" do + it "raises an exception when depends_on cask is cyclic" do + dep_cask = Hbc.load("with-depends-on-cask-cyclic") + lambda { + shutup do + Hbc::Installer.new(dep_cask).install + end + }.must_raise(Hbc::CaskCyclicCaskDependencyError) + end + + it "installs the dependency of a Cask and the Cask itself" do + csk = Hbc.load("with-depends-on-cask") + dependency = Hbc.load(csk.depends_on.cask.first) + shutup do + Hbc::Installer.new(csk).install + end + + csk.must_be :installed? + dependency.must_be :installed? + end + end + + describe "depends_on macos" do + it "understands depends_on macos: <array>" do + macos_cask = Hbc.load("with-depends-on-macos-array") + shutup do + Hbc::Installer.new(macos_cask).install + end + end + + it "understands depends_on macos: <comparison>" do + macos_cask = Hbc.load("with-depends-on-macos-comparison") + shutup do + Hbc::Installer.new(macos_cask).install + end + end + + it "understands depends_on macos: <string>" do + macos_cask = Hbc.load("with-depends-on-macos-string") + shutup do + Hbc::Installer.new(macos_cask).install + end + end + + it "understands depends_on macos: <symbol>" do + macos_cask = Hbc.load("with-depends-on-macos-symbol") + shutup do + Hbc::Installer.new(macos_cask).install + end + end + + it "raises an exception when depends_on macos is not satisfied" do + macos_cask = Hbc.load("with-depends-on-macos-failure") + lambda { + shutup do + Hbc::Installer.new(macos_cask).install + end + }.must_raise(Hbc::CaskError) + end + end + + describe "depends_on arch" do + it "succeeds when depends_on arch is satisfied" do + arch_cask = Hbc.load("with-depends-on-arch") + shutup do + Hbc::Installer.new(arch_cask).install + end + end + + it "raises an exception when depends_on arch is not satisfied" do + arch_cask = Hbc.load("with-depends-on-arch-failure") + lambda { + shutup do + Hbc::Installer.new(arch_cask).install + end + }.must_raise(Hbc::CaskError) + end + end + + describe "depends_on x11" do + it "succeeds when depends_on x11 is satisfied" do + x11_cask = Hbc.load("with-depends-on-x11") + shutup do + Hbc::Installer.new(x11_cask).install + end + end + + it "raises an exception when depends_on x11 is not satisfied" do + x11_cask = Hbc.load("with-depends-on-x11") + Hbc.stubs(:x11_libpng).returns([Pathname.new("/usr/path/does/not/exist")]) + lambda { + shutup do + Hbc::Installer.new(x11_cask).install + end + }.must_raise(Hbc::CaskX11DependencyError) + end + + it "never raises when depends_on x11: false" do + x11_cask = Hbc.load("with-depends-on-x11-false") + Hbc.stubs(:x11_executable).returns(Pathname.new("/usr/path/does/not/exist")) + lambda do + shutup do + Hbc::Installer.new(x11_cask).install + end + end # won't raise + end + end +end diff --git a/Library/Homebrew/cask/test/cask/dsl/caveats_test.rb b/Library/Homebrew/cask/test/cask/dsl/caveats_test.rb new file mode 100644 index 000000000..d0c7eef34 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/dsl/caveats_test.rb @@ -0,0 +1,10 @@ +require "test_helper" + +describe Hbc::DSL::Caveats do + let(:cask) { Hbc.load("basic-cask") } + let(:dsl) { Hbc::DSL::Caveats.new(cask) } + + it_behaves_like Hbc::DSL::Base + + # TODO: add tests for Caveats DSL methods +end diff --git a/Library/Homebrew/cask/test/cask/dsl/postflight_test.rb b/Library/Homebrew/cask/test/cask/dsl/postflight_test.rb new file mode 100644 index 000000000..c5e80b6d0 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/dsl/postflight_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +describe Hbc::DSL::Postflight do + let(:cask) { Hbc.load("basic-cask") } + let(:dsl) { Hbc::DSL::Postflight.new(cask, Hbc::FakeSystemCommand) } + + it_behaves_like Hbc::DSL::Base + + it_behaves_like Hbc::Staged do + let(:staged) { dsl } + end +end diff --git a/Library/Homebrew/cask/test/cask/dsl/preflight_test.rb b/Library/Homebrew/cask/test/cask/dsl/preflight_test.rb new file mode 100644 index 000000000..1c49a62ad --- /dev/null +++ b/Library/Homebrew/cask/test/cask/dsl/preflight_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +describe Hbc::DSL::Preflight do + let(:cask) { Hbc.load("basic-cask") } + let(:dsl) { Hbc::DSL::Preflight.new(cask, Hbc::FakeSystemCommand) } + + it_behaves_like Hbc::DSL::Base + + it_behaves_like Hbc::Staged do + let(:staged) { dsl } + end +end diff --git a/Library/Homebrew/cask/test/cask/dsl/uninstall_postflight_test.rb b/Library/Homebrew/cask/test/cask/dsl/uninstall_postflight_test.rb new file mode 100644 index 000000000..c704706ad --- /dev/null +++ b/Library/Homebrew/cask/test/cask/dsl/uninstall_postflight_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +describe Hbc::DSL::UninstallPostflight do + let(:cask) { Hbc.load("basic-cask") } + let(:dsl) { Hbc::DSL::UninstallPostflight.new(cask, Hbc::FakeSystemCommand) } + + it_behaves_like Hbc::DSL::Base +end diff --git a/Library/Homebrew/cask/test/cask/dsl/uninstall_preflight_test.rb b/Library/Homebrew/cask/test/cask/dsl/uninstall_preflight_test.rb new file mode 100644 index 000000000..f6ab36b60 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/dsl/uninstall_preflight_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +describe Hbc::DSL::UninstallPreflight do + let(:cask) { Hbc.load("basic-cask") } + let(:dsl) { Hbc::DSL::UninstallPreflight.new(cask, Hbc::FakeSystemCommand) } + + it_behaves_like Hbc::DSL::Base + + it_behaves_like Hbc::Staged do + let(:staged) { dsl } + end +end diff --git a/Library/Homebrew/cask/test/cask/dsl_test.rb b/Library/Homebrew/cask/test/cask/dsl_test.rb new file mode 100644 index 000000000..4cd30d241 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/dsl_test.rb @@ -0,0 +1,431 @@ +require "test_helper" + +describe Hbc::DSL do + it "lets you set url, homepage, and version" do + test_cask = Hbc.load("basic-cask") + test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg" + test_cask.homepage.must_equal "http://example.com/" + test_cask.version.to_s.must_equal "1.2.3" + end + + describe "when a Cask includes an unknown method" do + attempt_unknown_method = nil + + before do + attempt_unknown_method = lambda do + Hbc::Cask.new("unexpected-method-cask") do + future_feature :not_yet_on_your_machine + end + end + end + + it "prints a warning that it has encountered an unexpected method" do + expected = Regexp.compile(<<-EOREGEX.undent.lines.map(&:chomp).join("")) + (?m) + Warning: + .* + Unexpected method 'future_feature' called on Cask unexpected-method-cask\\. + .* + brew update; brew cleanup; brew cask cleanup + .* + https://github.com/caskroom/homebrew-cask#reporting-bugs + EOREGEX + + TestHelper.must_output(self, attempt_unknown_method, expected) + end + + it "will simply warn, not throw an exception" do + begin + capture_subprocess_io do + attempt_unknown_method.call + end + rescue StandardError => e + flunk("Wanted unexpected method to simply warn, but got exception #{e}") + end + end + end + + describe "header line" do + it "requires a valid header format" do + lambda { + Hbc.load("invalid/invalid-header-format") + }.must_raise(SyntaxError) + end + + it "requires the header token to match the file name" do + err = lambda { + Hbc.load("invalid/invalid-header-token-mismatch") + }.must_raise(Hbc::CaskTokenDoesNotMatchError) + err.message.must_include "Bad header line:" + err.message.must_include "does not match file name" + end + + it "does not require a DSL version in the header" do + test_cask = Hbc.load("no-dsl-version") + test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg" + test_cask.homepage.must_equal "http://example.com/" + test_cask.version.to_s.must_equal "1.2.3" + end + end + + describe "name stanza" do + it "lets you set the full name via a name stanza" do + cask = Hbc::Cask.new("name-cask") do + name "Proper Name" + end + + cask.name.must_equal [ + "Proper Name", + ] + end + + it "Accepts an array value to the name stanza" do + cask = Hbc::Cask.new("array-name-cask") do + name ["Proper Name", "Alternate Name"] + end + + cask.name.must_equal [ + "Proper Name", + "Alternate Name", + ] + end + + it "Accepts multiple name stanzas" do + cask = Hbc::Cask.new("multi-name-cask") do + name "Proper Name" + name "Alternate Name" + end + + cask.name.must_equal [ + "Proper Name", + "Alternate Name", + ] + end + end + + describe "sha256 stanza" do + it "lets you set checksum via sha256" do + cask = Hbc::Cask.new("checksum-cask") do + sha256 "imasha2" + end + + cask.sha256.must_equal "imasha2" + end + end + + describe "app stanza" do + it "allows you to specify app stanzas" do + cask = Hbc::Cask.new("cask-with-apps") do + app "Foo.app" + app "Bar.app" + end + + Array(cask.artifacts[:app]).must_equal [["Foo.app"], ["Bar.app"]] + end + + it "allow app stanzas to be empty" do + cask = Hbc::Cask.new("cask-with-no-apps") + Array(cask.artifacts[:app]).must_equal %w[] + end + end + + describe "caveats stanza" do + it "allows caveats to be specified via a method define" do + cask = Hbc::Cask.new("plain-cask") + + cask.caveats.must_be :empty? + + cask = Hbc::Cask.new("cask-with-caveats") do + def caveats; <<-EOS.undent + When you install this Cask, you probably want to know this. + EOS + end + end + + cask.caveats.must_equal "When you install this Cask, you probably want to know this.\n" + end + end + + describe "pkg stanza" do + it "allows installable pkgs to be specified" do + cask = Hbc::Cask.new("cask-with-pkgs") do + pkg "Foo.pkg" + pkg "Bar.pkg" + end + + Array(cask.artifacts[:pkg]).must_equal [["Foo.pkg"], ["Bar.pkg"]] + end + end + + describe "url stanza" do + it "prevents defining multiple urls" do + err = lambda { + Hbc.load("invalid/invalid-two-url") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'url' stanza may only appear once" + end + end + + describe "homepage stanza" do + it "prevents defining multiple homepages" do + err = lambda { + Hbc.load("invalid/invalid-two-homepage") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'homepage' stanza may only appear once" + end + end + + describe "version stanza" do + it "prevents defining multiple versions" do + err = lambda { + Hbc.load("invalid/invalid-two-version") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'version' stanza may only appear once" + end + end + + describe "appcast stanza" do + it "allows appcasts to be specified" do + cask = Hbc.load("with-appcast") + cask.appcast.to_s.must_match %r{^http} + end + + it "prevents defining multiple appcasts" do + err = lambda { + Hbc.load("invalid/invalid-appcast-multiple") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'appcast' stanza may only appear once" + end + + it "refuses to load invalid appcast URLs" do + lambda { + Hbc.load("invalid/invalid-appcast-url") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "gpg stanza" do + it "allows gpg stanza to be specified" do + cask = Hbc.load("with-gpg") + cask.gpg.to_s.must_match %r{\S} + end + + it "allows gpg stanza to be specified with :key_url" do + cask = Hbc.load("with-gpg-key-url") + cask.gpg.to_s.must_match %r{\S} + end + + it "prevents specifying gpg stanza multiple times" do + err = lambda { + Hbc.load("invalid/invalid-gpg-multiple-stanzas") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'gpg' stanza may only appear once" + end + + it "prevents missing gpg key parameters" do + err = lambda { + Hbc.load("invalid/invalid-gpg-missing-key") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'gpg' stanza must include exactly one" + end + + it "prevents conflicting gpg key parameters" do + err = lambda { + Hbc.load("invalid/invalid-gpg-conflicting-keys") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'gpg' stanza must include exactly one" + end + + it "refuses to load invalid gpg signature URLs" do + lambda { + Hbc.load("invalid/invalid-gpg-signature-url") + }.must_raise(Hbc::CaskInvalidError) + end + + it "refuses to load invalid gpg key URLs" do + lambda { + Hbc.load("invalid/invalid-gpg-key-url") + }.must_raise(Hbc::CaskInvalidError) + end + + it "refuses to load invalid gpg key IDs" do + lambda { + Hbc.load("invalid/invalid-gpg-key-id") + }.must_raise(Hbc::CaskInvalidError) + end + + it "refuses to load if gpg parameter is unknown" do + lambda { + Hbc.load("invalid/invalid-gpg-parameter") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "depends_on stanza" do + it "refuses to load with an invalid depends_on key" do + lambda { + Hbc.load("invalid/invalid-depends-on-key") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "depends_on formula" do + it "allows depends_on formula to be specified" do + cask = Hbc.load("with-depends-on-formula") + cask.depends_on.formula.wont_be_nil + end + + it "allows multiple depends_on formula to be specified" do + cask = Hbc.load("with-depends-on-formula-multiple") + cask.depends_on.formula.wont_be_nil + end + end + + describe "depends_on cask" do + it "allows depends_on cask to be specified" do + cask = Hbc.load("with-depends-on-cask") + cask.depends_on.cask.wont_be_nil + end + + it "allows multiple depends_on cask to be specified" do + cask = Hbc.load("with-depends-on-cask-multiple") + cask.depends_on.cask.wont_be_nil + end + end + + describe "depends_on macos" do + it "allows depends_on macos to be specified" do + cask = Hbc.load("with-depends-on-macos-string") + cask.depends_on.macos.wont_be_nil + end + it "refuses to load with an invalid depends_on macos value" do + lambda { + Hbc.load("invalid/invalid-depends-on-macos-bad-release") + }.must_raise(Hbc::CaskInvalidError) + end + it "refuses to load with conflicting depends_on macos forms" do + lambda { + Hbc.load("invalid/invalid-depends-on-macos-conflicting-forms") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "depends_on arch" do + it "allows depends_on arch to be specified" do + cask = Hbc.load("with-depends-on-arch") + cask.depends_on.arch.wont_be_nil + end + it "refuses to load with an invalid depends_on arch value" do + lambda { + Hbc.load("invalid/invalid-depends-on-arch-value") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "depends_on x11" do + it "allows depends_on x11 to be specified" do + cask = Hbc.load("with-depends-on-x11") + cask.depends_on.x11.wont_be_nil + end + it "refuses to load with an invalid depends_on x11 value" do + lambda { + Hbc.load("invalid/invalid-depends-on-x11-value") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "conflicts_with stanza" do + it "allows conflicts_with stanza to be specified" do + cask = Hbc.load("with-conflicts-with") + cask.conflicts_with.formula.wont_be_nil + end + + it "refuses to load invalid conflicts_with key" do + lambda { + Hbc.load("invalid/invalid-conflicts-with-key") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "license stanza" do + it "allows the license to be specified" do + cask = Hbc.load("with-license") + cask.license.value.must_equal :gpl + end + + it "the license has a category" do + cask = Hbc.load("with-license") + cask.license.category.must_equal :oss + end + + it "prevents defining multiple license stanzas" do + err = lambda { + Hbc.load("invalid/invalid-license-multiple") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'license' stanza may only appear once" + end + + it "refuses to load on invalid license value" do + lambda { + Hbc.load("invalid/invalid-license-value") + }.must_raise(Hbc::CaskInvalidError) + end + end + + describe "installer stanza" do + it "allows installer script to be specified" do + cask = Hbc.load("with-installer-script") + cask.artifacts[:installer].first.script[:executable].must_equal "/usr/bin/true" + cask.artifacts[:installer].first.script[:args].must_equal ["--flag"] + cask.artifacts[:installer].to_a[1].script[:executable].must_equal "/usr/bin/false" + cask.artifacts[:installer].to_a[1].script[:args].must_equal ["--flag"] + end + it "allows installer manual to be specified" do + cask = Hbc.load("with-installer-manual") + cask.artifacts[:installer].first.manual.must_equal "Caffeine.app" + end + end + + describe "stage_only stanza" do + it "allows stage_only stanza to be specified" do + cask = Hbc.load("stage-only") + cask.artifacts[:stage_only].first.must_equal [true] + end + + it "prevents specifying stage_only with other activatables" do + err = lambda { + Hbc.load("invalid/invalid-stage-only-conflict") + }.must_raise(Hbc::CaskInvalidError) + err.message.must_include "'stage_only' must be the only activatable artifact" + end + end + + describe "auto_updates stanza" do + it "allows auto_updates stanza to be specified" do + cask = Hbc.load("auto-updates") + cask.auto_updates.must_equal true + end + end + + describe "appdir" do + it "allows interpolation of the appdir value in stanzas" do + cask = Hbc.load("appdir-interpolation") + cask.artifacts[:binary].first.must_equal ["#{Hbc.appdir}/some/path"] + end + + it "does not include a trailing slash" do + original_appdir = Hbc.appdir + Hbc.appdir = "#{original_appdir}/" + + begin + cask = Hbc::Cask.new("appdir-trailing-slash") do + binary "#{appdir}/some/path" + end + + cask.artifacts[:binary].first.must_equal ["#{original_appdir}/some/path"] + ensure + Hbc.appdir = original_appdir + end + end + end +end diff --git a/Library/Homebrew/cask/test/cask/installer_test.rb b/Library/Homebrew/cask/test/cask/installer_test.rb new file mode 100644 index 000000000..6efd4affc --- /dev/null +++ b/Library/Homebrew/cask/test/cask/installer_test.rb @@ -0,0 +1,418 @@ +require "test_helper" + +describe Hbc::Installer do + describe "install" do + it "downloads and installs a nice fresh Cask" do + caffeine = Hbc.load("local-caffeine") + + shutup do + Hbc::Installer.new(caffeine).install + end + + dest_path = Hbc.caskroom.join("local-caffeine", caffeine.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("Caffeine.app") + application.must_be :directory? + end + + it "works with dmg-based Casks" do + transmission = Hbc.load("local-transmission") + + shutup do + Hbc::Installer.new(transmission).install + end + + dest_path = Hbc.caskroom.join("local-transmission", transmission.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("Transmission.app") + application.must_be :directory? + end + + it "works with tar-based Casks" do + tarball = Hbc.load("tarball") + + shutup do + Hbc::Installer.new(tarball).install + end + + dest_path = Hbc.caskroom.join("tarball", tarball.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("Tarball.app") + application.must_be :directory? + end + + it "works with cab-based Casks" do + skip("cabextract not installed") unless Hbc.homebrew_prefix.join("bin", "cabextract").exist? + cab_container = Hbc.load("cab-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) + cab_container.stubs(:depends_on).returns(empty) + + shutup do + Hbc::Installer.new(cab_container).install + end + + dest_path = Hbc.caskroom.join("cab-container", cab_container.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("Application.app") + application.must_be :directory? + end + + it "works with Adobe AIR-based Casks" do + skip("Adobe AIR not installed") unless Hbc::Container::Air.installer_exist? + air_container = Hbc.load("adobe-air-container") + + shutup do + Hbc::Installer.new(air_container).install + end + + dest_path = Hbc.caskroom.join("adobe-air-container", air_container.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("GMDesk.app") + application.must_be :directory? + end + + it "works with 7z-based Casks" do + skip("unar not installed") unless Hbc.homebrew_prefix.join("bin", "unar").exist? + sevenzip_container = Hbc.load("sevenzip-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) + sevenzip_container.stubs(:depends_on).returns(empty) + + shutup do + Hbc::Installer.new(sevenzip_container).install + end + + dest_path = Hbc.caskroom.join("sevenzip-container", sevenzip_container.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("Application.app") + application.must_be :directory? + end + + it "works with xar-based Casks" do + xar_container = Hbc.load("xar-container") + + shutup do + Hbc::Installer.new(xar_container).install + end + + dest_path = Hbc.caskroom.join("xar-container", xar_container.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("Application.app") + application.must_be :directory? + end + + it "works with Stuffit-based Casks" do + skip("unar not installed") unless Hbc.homebrew_prefix.join("bin", "unar").exist? + stuffit_container = Hbc.load("stuffit-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) + stuffit_container.stubs(:depends_on).returns(empty) + + shutup do + Hbc::Installer.new(stuffit_container).install + end + + dest_path = Hbc.caskroom.join("stuffit-container", stuffit_container.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("sheldonmac", "v1.0") + application.must_be :directory? + end + + it "works with RAR-based Casks" do + skip("unar not installed") unless Hbc.homebrew_prefix.join("bin", "unar").exist? + rar_container = Hbc.load("rar-container") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) + rar_container.stubs(:depends_on).returns(empty) + + shutup do + Hbc::Installer.new(rar_container).install + end + + dest_path = Hbc.caskroom.join("rar-container", rar_container.version) + dest_path.must_be :directory? + application = Hbc.appdir.join("Application.app") + application.must_be :directory? + end + + it "works with bz2-based Casks" do + asset = Hbc.load("bzipped-asset") + + shutup do + Hbc::Installer.new(asset).install + end + + dest_path = Hbc.caskroom.join("bzipped-asset", asset.version) + dest_path.must_be :directory? + file = Hbc.appdir.join("bzipped-asset--#{asset.version}") + file.must_be :file? + end + + it "works with pure gz-based Casks" do + asset = Hbc.load("gzipped-asset") + + shutup do + Hbc::Installer.new(asset).install + end + + dest_path = Hbc.caskroom.join("gzipped-asset", asset.version) + dest_path.must_be :directory? + file = Hbc.appdir.join("gzipped-asset--#{asset.version}") + file.must_be :file? + end + + it "works with xz-based Casks" do + skip("unxz not installed") unless Hbc.homebrew_prefix.join("bin", "unxz").exist? + asset = Hbc.load("xzipped-asset") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) + asset.stubs(:depends_on).returns(empty) + + shutup do + Hbc::Installer.new(asset).install + end + + dest_path = Hbc.caskroom.join("xzipped-asset", asset.version) + dest_path.must_be :directory? + file = Hbc.appdir.join("xzipped-asset--#{asset.version}") + file.must_be :file? + end + + it "works with lzma-based Casks" do + skip("unlzma not installed") unless Hbc.homebrew_prefix.join("bin", "unlzma").exist? + asset = Hbc.load("lzma-asset") + empty = stub(formula: [], cask: [], macos: nil, arch: nil, x11: nil) + asset.stubs(:depends_on).returns(empty) + + shutup do + Hbc::Installer.new(asset).install + end + + dest_path = Hbc.caskroom.join("lzma-asset", asset.version) + dest_path.must_be :directory? + file = Hbc.appdir.join("lzma-asset--#{asset.version}") + file.must_be :file? + end + + it "blows up on a bad checksum" do + bad_checksum = Hbc.load("bad-checksum") + lambda { + shutup do + Hbc::Installer.new(bad_checksum).install + end + }.must_raise(Hbc::CaskSha256MismatchError) + end + + it "blows up on a missing checksum" do + missing_checksum = Hbc.load("missing-checksum") + lambda { + shutup do + Hbc::Installer.new(missing_checksum).install + end + }.must_raise(Hbc::CaskSha256MissingError) + end + + it "installs fine if sha256 :no_check is used" do + no_checksum = Hbc.load("no-checksum") + + shutup do + Hbc::Installer.new(no_checksum).install + end + + no_checksum.must_be :installed? + end + + it "fails to install if sha256 :no_check is used with --require-sha" do + no_checksum = Hbc.load("no-checksum") + lambda { + Hbc::Installer.new(no_checksum, require_sha: true).install + }.must_raise(Hbc::CaskNoShasumError) + end + + it "installs fine if sha256 :no_check is used with --require-sha and --force" do + no_checksum = Hbc.load("no-checksum") + + shutup do + Hbc::Installer.new(no_checksum, require_sha: true, force: true).install + end + + no_checksum.must_be :installed? + end + + it "prints caveats if they're present" do + with_caveats = Hbc.load("with-caveats") + TestHelper.must_output(self, lambda { + Hbc::Installer.new(with_caveats).install + }, %r{Here are some things you might want to know}) + with_caveats.must_be :installed? + end + + it "prints installer :manual instructions when present" do + with_installer_manual = Hbc.load("with-installer-manual") + TestHelper.must_output(self, lambda { + Hbc::Installer.new(with_installer_manual).install + }, %r{To complete the installation of Cask with-installer-manual, you must also\nrun the installer at\n\n '#{with_installer_manual.staged_path.join('Caffeine.app')}'}) + with_installer_manual.must_be :installed? + end + + it "does not extract __MACOSX directories from zips" do + with_macosx_dir = Hbc.load("with-macosx-dir") + + shutup do + Hbc::Installer.new(with_macosx_dir).install + end + + with_macosx_dir.staged_path.join("__MACOSX").wont_be :directory? + end + + it "installer method raises an exception when already-installed Casks which auto-update are attempted" do + auto_updates = Hbc.load("auto-updates") + auto_updates.installed?.must_equal false + installer = Hbc::Installer.new(auto_updates) + + shutup do + installer.install + end + + lambda { + installer.install + }.must_raise(Hbc::CaskAutoUpdatesError) + end + + it "allows already-installed Casks which auto-update to be installed if force is provided" do + auto_updates = Hbc.load("auto-updates") + auto_updates.installed?.must_equal false + + shutup do + Hbc::Installer.new(auto_updates).install + end + + shutup do + Hbc::Installer.new(auto_updates, force: true).install + end # wont_raise + end + + # unlike the CLI, the internal interface throws exception on double-install + it "installer method raises an exception when already-installed Casks are attempted" do + transmission = Hbc.load("local-transmission") + transmission.installed?.must_equal false + installer = Hbc::Installer.new(transmission) + + shutup do + installer.install + end + + lambda { + installer.install + }.must_raise(Hbc::CaskAlreadyInstalledError) + end + + it "allows already-installed Casks to be installed if force is provided" do + transmission = Hbc.load("local-transmission") + transmission.installed?.must_equal false + + shutup do + Hbc::Installer.new(transmission).install + end + + shutup do + Hbc::Installer.new(transmission, force: true).install + end # wont_raise + end + + it "works properly with a direct URL to a pkg" do + naked_pkg = Hbc.load("naked-pkg") + + shutup do + Hbc::Installer.new(naked_pkg).install + end + + dest_path = Hbc.caskroom.join("naked-pkg", naked_pkg.version) + pkg = dest_path.join("Naked.pkg") + pkg.must_be :file? + end + + it "works properly with an overridden container :type" do + naked_executable = Hbc.load("naked-executable") + + shutup do + Hbc::Installer.new(naked_executable).install + end + + dest_path = Hbc.caskroom.join("naked-executable", naked_executable.version) + executable = dest_path.join("naked_executable") + executable.must_be :file? + end + + it "works fine with a nested container" do + nested_app = Hbc.load("nested-app") + + shutup do + Hbc::Installer.new(nested_app).install + end + + dest_path = Hbc.appdir.join("MyNestedApp.app") + File.ftype(dest_path).must_equal "directory" + end + + it "generates and finds a timestamped metadata directory for an installed Cask" do + caffeine = Hbc.load("local-caffeine") + + shutup do + Hbc::Installer.new(caffeine).install + end + + m_path = caffeine.metadata_path(:now, true) + caffeine.metadata_path(:now, false).must_equal(m_path) + caffeine.metadata_path(:latest).must_equal(m_path) + end + + it "generates and finds a metadata subdirectory for an installed Cask" do + caffeine = Hbc.load("local-caffeine") + + shutup do + Hbc::Installer.new(caffeine).install + end + + subdir_name = "Casks" + m_subdir = caffeine.metadata_subdir(subdir_name, :now, true) + caffeine.metadata_subdir(subdir_name, :now, false).must_equal(m_subdir) + caffeine.metadata_subdir(subdir_name, :latest).must_equal(m_subdir) + end + end + + describe "uninstall" do + it "fully uninstalls a Cask" do + caffeine = Hbc.load("local-caffeine") + installer = Hbc::Installer.new(caffeine) + + shutup do + installer.install + installer.uninstall + end + + Hbc.caskroom.join("local-caffeine", caffeine.version, "Caffeine.app").wont_be :directory? + Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? + Hbc.caskroom.join("local-caffeine").wont_be :directory? + end + + it "uninstalls all versions if force is set" do + caffeine = Hbc.load("local-caffeine") + mutated_version = caffeine.version + ".1" + + shutup do + Hbc::Installer.new(caffeine).install + end + + Hbc.caskroom.join("local-caffeine", caffeine.version).must_be :directory? + Hbc.caskroom.join("local-caffeine", mutated_version).wont_be :directory? + FileUtils.mv(Hbc.caskroom.join("local-caffeine", caffeine.version), Hbc.caskroom.join("local-caffeine", mutated_version)) + Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? + Hbc.caskroom.join("local-caffeine", mutated_version).must_be :directory? + + shutup do + Hbc::Installer.new(caffeine, force: true).uninstall + end + + Hbc.caskroom.join("local-caffeine", caffeine.version).wont_be :directory? + Hbc.caskroom.join("local-caffeine", mutated_version).wont_be :directory? + Hbc.caskroom.join("local-caffeine").wont_be :directory? + end + end +end diff --git a/Library/Homebrew/cask/test/cask/pkg_test.rb b/Library/Homebrew/cask/test/cask/pkg_test.rb new file mode 100644 index 000000000..5734a58f6 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/pkg_test.rb @@ -0,0 +1,94 @@ +require "test_helper" + +describe Hbc::Pkg do + describe "uninstall" do + it "removes files and dirs referenced by the pkg" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) + + some_files = Array.new(3) { Pathname(Tempfile.new("testfile").path) } + pkg.stubs(:pkgutil_bom_files).returns some_files + + some_specials = Array.new(3) { Pathname(Tempfile.new("testfile").path) } + pkg.stubs(:pkgutil_bom_specials).returns some_specials + + some_dirs = Array.new(3) { Pathname(Dir.mktmpdir) } + pkg.stubs(:pkgutil_bom_dirs).returns some_dirs + + pkg.stubs(:forget) + + pkg.uninstall + + some_files.each do |file| + file.wont_be :exist? + end + + some_dirs.each do |dir| + dir.wont_be :exist? + end + end + + it "forgets the pkg" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::FakeSystemCommand) + + Hbc::FakeSystemCommand.stubs_command( + ["/usr/sbin/pkgutil", "--only-files", "--files", "my.fake.pkg"] + ) + Hbc::FakeSystemCommand.stubs_command( + ["/usr/sbin/pkgutil", "--only-dirs", "--files", "my.fake.pkg"] + ) + Hbc::FakeSystemCommand.stubs_command( + ["/usr/sbin/pkgutil", "--files", "my.fake.pkg"] + ) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/pkgutil", "--forget", "my.fake.pkg"] + ) + + pkg.uninstall + end + + it "cleans broken symlinks, but leaves AOK symlinks" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) + + fake_dir = Pathname(Dir.mktmpdir) + fake_file = fake_dir.join("ima_file").tap { |path| FileUtils.touch(path) } + + intact_symlink = fake_dir.join("intact_symlink").tap { |path| path.make_symlink(fake_file) } + broken_symlink = fake_dir.join("broken_symlink").tap { |path| path.make_symlink("im_nota_file") } + + pkg.stubs(:pkgutil_bom_specials).returns([]) + pkg.stubs(:pkgutil_bom_files).returns([]) + pkg.stubs(:pkgutil_bom_dirs).returns([fake_dir]) + pkg.stubs(:forget) + + pkg.uninstall + + intact_symlink.must_be :exist? + broken_symlink.wont_be :exist? + fake_dir.must_be :exist? + end + + it "snags permissions on ornery dirs, but returns them afterwords" do + pkg = Hbc::Pkg.new("my.fake.pkg", Hbc::NeverSudoSystemCommand) + + fake_dir = Pathname(Dir.mktmpdir) + + fake_file = fake_dir.join("ima_installed_file").tap { |path| FileUtils.touch(path) } + + fake_dir.chmod(0o000) + + pkg.stubs(:pkgutil_bom_specials).returns([]) + pkg.stubs(:pkgutil_bom_files).returns([fake_file]) + pkg.stubs(:pkgutil_bom_dirs).returns([fake_dir]) + pkg.stubs(:forget) + + shutup do + pkg.uninstall + end + + fake_dir.must_be :directory? + fake_file.wont_be :file? + (fake_dir.stat.mode % 0o1000).to_s(8).must_equal "0" + end + end +end diff --git a/Library/Homebrew/cask/test/cask/staged_test.rb b/Library/Homebrew/cask/test/cask/staged_test.rb new file mode 100644 index 000000000..fe3bf2339 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/staged_test.rb @@ -0,0 +1,18 @@ +require "test_helper" + +# TODO: this test should be named after the corresponding class, once +# that class is abstracted from installer.rb. It makes little sense +# to be invoking bundle_identifier off of the installer instance. +describe "Operations on staged Casks" do + describe "bundle ID" do + it "fetches the bundle ID from a staged cask" do + transmission_cask = Hbc.load("local-transmission") + tr_installer = Hbc::Installer.new(transmission_cask) + + shutup do + tr_installer.install + end + tr_installer.bundle_identifier.must_equal("org.m0k.transmission") + end + end +end diff --git a/Library/Homebrew/cask/test/cask/url_checker_test.rb b/Library/Homebrew/cask/test/cask/url_checker_test.rb new file mode 100644 index 000000000..cb0e50d57 --- /dev/null +++ b/Library/Homebrew/cask/test/cask/url_checker_test.rb @@ -0,0 +1,31 @@ +require "test_helper" + +describe Hbc::UrlChecker do + describe "request processing" do + it "adds an error if response is empty" do + cask = TestHelper.test_cask + TestHelper.fake_response_for(cask.url, "") + checker = Hbc::UrlChecker.new(cask, TestHelper.fake_fetcher) + checker.run + checker.errors.must_include "timeout while requesting #{cask.url}" + end + + it "properly populates the response code and headers from an http response" do + TestHelper.fake_response_for(TestHelper.test_cask.url, <<-RESPONSE.gsub(%r{^ *}, "")) + HTTP/1.1 200 OK + Content-Type: application/x-apple-diskimage + ETag: "b4208f3e84967be4b078ecaa03fba941" + Content-Length: 23726161 + Last-Modified: Sun, 12 Aug 2012 21:17:21 GMT + RESPONSE + + checker = Hbc::UrlChecker.new(TestHelper.test_cask, TestHelper.fake_fetcher) + checker.run + checker.response_status.must_equal "HTTP/1.1 200 OK" + checker.headers.must_equal("Content-Type" => "application/x-apple-diskimage", + "ETag" => '"b4208f3e84967be4b078ecaa03fba941"', + "Content-Length" => "23726161", + "Last-Modified" => "Sun, 12 Aug 2012 21:17:21 GMT") + end + end +end diff --git a/Library/Homebrew/cask/test/cask_test.rb b/Library/Homebrew/cask/test/cask_test.rb new file mode 100644 index 000000000..05bdb6eff --- /dev/null +++ b/Library/Homebrew/cask/test/cask_test.rb @@ -0,0 +1,70 @@ +require "test_helper" + +describe "Cask" do + describe "load" do + it "returns an instance of the Cask for the given token" do + c = Hbc.load("adium") + c.must_be_kind_of(Hbc::Cask) + c.token.must_equal("adium") + end + + it "returns an instance of the Cask from a specific file location" do + location = File.expand_path("./Casks/dia.rb") + c = Hbc.load(location) + c.must_be_kind_of(Hbc::Cask) + c.token.must_equal("dia") + end + + it "returns an instance of the Cask from a url" do + url = "file://" + File.expand_path("./Casks/dia.rb") + c = shutup do + Hbc.load(url) + end + c.must_be_kind_of(Hbc::Cask) + c.token.must_equal("dia") + end + + it "raises an error when failing to download a Cask from a url" do + lambda { + url = "file://" + File.expand_path("./Casks/notacask.rb") + shutup do + Hbc.load(url) + end + }.must_raise(Hbc::CaskUnavailableError) + end + + it "returns an instance of the Cask from a relative file location" do + c = Hbc.load("./Casks/bbedit.rb") + c.must_be_kind_of(Hbc::Cask) + c.token.must_equal("bbedit") + end + + it "uses exact match when loading by token" do + Hbc.load("test-opera").token.must_equal("test-opera") + Hbc.load("test-opera-mail").token.must_equal("test-opera-mail") + end + + it "raises an error when attempting to load a Cask that doesn't exist" do + lambda { + Hbc.load("notacask") + }.must_raise(Hbc::CaskUnavailableError) + end + end + + describe "all_tokens" do + it "returns a token for every Cask" do + all_cask_tokens = Hbc.all_tokens + all_cask_tokens.count.must_be :>, 20 + all_cask_tokens.each { |token| token.must_be_kind_of String } + end + end + + describe "metadata" do + it "proposes a versioned metadata directory name for each instance" do + cask_token = "adium" + c = Hbc.load(cask_token) + metadata_path = Hbc.caskroom.join(cask_token, ".metadata", c.version) + c.metadata_versioned_container_path.to_s.must_equal(metadata_path.to_s) + end + end +end diff --git a/Library/Homebrew/cask/test/layout_test.rb b/Library/Homebrew/cask/test/layout_test.rb new file mode 100644 index 000000000..110725f31 --- /dev/null +++ b/Library/Homebrew/cask/test/layout_test.rb @@ -0,0 +1,94 @@ +require "test_helper" + +describe "Repo layout" do + project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../")) + + # TODO: a more clever way to do this would be to dispense with + # the imperfect IGNORE lists and read the actual repo + # contents by reading the output of "git ls-files" + + # dot dirs are always a project of Dir.entries + # other files are items that the developer hopefully has gitignored + IGNORE_FILES = %w[ + . + .. + .DS_Store + .bundle + .rubocop.yml + .rubocop_todo.yml + .ruby-version + coverage + vendor + ].freeze + + # the developer has hopefully gitignored these + IGNORE_REGEXPS = [ + %r{~$}, # emacs + %r{.sublime-\w+}, # Sublime Text + ].freeze + + TOPLEVEL_DIRS = %w[ + .git + .github + Casks + Formula + ci + cmd + developer + doc + lib + man + spec + test + ].freeze + + TOPLEVEL_FILES = %w[ + .editorconfig + .gitattributes + .gitignore + .rspec + .rubocop.yml + .simplecov + .travis.yml + CONDUCT.md + CONTRIBUTING.md + Gemfile + Gemfile.lock + LICENSE + README.md + Rakefile + tap_migrations.json + USAGE.md + ].freeze + + describe "toplevel dir" do + it "finds some files at the top level" do + entries = Dir.entries(project_root) + entries.length.must_be :>, 0 + end + + it "only finds expected files at the top level" do + entries = Dir.entries(project_root) - IGNORE_FILES - TOPLEVEL_DIRS - TOPLEVEL_FILES + IGNORE_REGEXPS.each do |regexp| + entries.reject! { |elt| elt.match(regexp) } + end + entries.must_equal [] + end + end + + describe "Casks dir" do + it "finds some files in the Casks dir" do + entries = Dir.entries(project_root.join("Casks")) + entries.length.must_be :>, 0 + end + + it "only finds .rb files in the Casks dir" do + entries = Dir.entries(project_root.join("Casks")) - IGNORE_FILES + IGNORE_REGEXPS.each do |regexp| + entries.reject! { |elt| elt.match(regexp) } + end + entries.reject! { |elt| elt.match(%r{\.rb$}) } + entries.must_equal [] + end + end +end diff --git a/Library/Homebrew/cask/test/plist/parser_test.rb b/Library/Homebrew/cask/test/plist/parser_test.rb new file mode 100644 index 000000000..a73d1f7f5 --- /dev/null +++ b/Library/Homebrew/cask/test/plist/parser_test.rb @@ -0,0 +1,106 @@ +require "test_helper" + +describe Plist do + it "parses some hdiutil output okay" do + hdiutil_output = <<-HDIUTILOUTPUT +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>system-entities</key> + <array> + <dict> + <key>content-hint</key> + <string>Apple_partition_map</string> + <key>dev-entry</key> + <string>/dev/disk3s1</string> + <key>potentially-mountable</key> + <false/> + <key>unmapped-content-hint</key> + <string>Apple_partition_map</string> + </dict> + <dict> + <key>content-hint</key> + <string>Apple_partition_scheme</string> + <key>dev-entry</key> + <string>/dev/disk3</string> + <key>potentially-mountable</key> + <false/> + <key>unmapped-content-hint</key> + <string>Apple_partition_scheme</string> + </dict> + <dict> + <key>content-hint</key> + <string>Apple_HFS</string> + <key>dev-entry</key> + <string>/dev/disk3s2</string> + <key>mount-point</key> + <string>/private/tmp/dmg.BhfS2g</string> + <key>potentially-mountable</key> + <true/> + <key>unmapped-content-hint</key> + <string>Apple_HFS</string> + <key>volume-kind</key> + <string>hfs</string> + </dict> + </array> +</dict> +</plist> + HDIUTILOUTPUT + + parsed = Plist.parse_xml(hdiutil_output) + + parsed.keys.must_equal ["system-entities"] + parsed["system-entities"].length.must_equal 3 + parsed["system-entities"].map { |e| e["dev-entry"] }.must_equal %w[ + /dev/disk3s1 + /dev/disk3 + /dev/disk3s2 + ] + end + + it "can ignore garbage output before xml starts" do + hdiutil_output = <<-HDIUTILOUTPUT +Hello there! I am in no way XML am I?!?! + + That's a little silly... you were expexting XML here! + +What is a parser to do? + +Hopefully <not> explode! + +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>system-entities</key> + <array> + <dict> + <key>content-hint</key> + <string>Apple_HFS</string> + <key>dev-entry</key> + <string>/dev/disk3s2</string> + <key>mount-point</key> + <string>/private/tmp/dmg.BhfS2g</string> + <key>potentially-mountable</key> + <true/> + <key>unmapped-content-hint</key> + <string>Apple_HFS</string> + <key>volume-kind</key> + <string>hfs</string> + </dict> + </array> +</dict> +</plist> + HDIUTILOUTPUT + + parsed = Plist.parse_xml(hdiutil_output) + + parsed.keys.must_equal ["system-entities"] + parsed["system-entities"].length.must_equal 1 + end + + it "does not choke on empty input" do + Plist.parse_xml("").must_equal {} + end +end diff --git a/Library/Homebrew/cask/test/support/Casks/.rubocop.yml b/Library/Homebrew/cask/test/support/Casks/.rubocop.yml new file mode 120000 index 000000000..ee5c2b948 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/.rubocop.yml @@ -0,0 +1 @@ +../../../Casks/.rubocop.yml
\ No newline at end of file diff --git a/Library/Homebrew/cask/test/support/Casks/adobe-air-container.rb b/Library/Homebrew/cask/test/support/Casks/adobe-air-container.rb new file mode 100644 index 000000000..302f15703 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/adobe-air-container.rb @@ -0,0 +1,9 @@ +test_cask 'adobe-air-container' do + version '1.0.1' + sha256 '9b6e4174afa76f2af50238364fcf87525bc4ed2287acbe62925107ab6cda5c99' + + url TestHelper.local_binary_url('GMDesk-1.01.air') + homepage 'http://robertnyman.com/gmdesk/' + + app 'GMDesk.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/appdir-interpolation.rb b/Library/Homebrew/cask/test/support/Casks/appdir-interpolation.rb new file mode 100644 index 000000000..6aa3f29c3 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/appdir-interpolation.rb @@ -0,0 +1,9 @@ +test_cask 'appdir-interpolation' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/appdir-interpolation' + + binary "#{appdir}/some/path" +end diff --git a/Library/Homebrew/cask/test/support/Casks/auto-updates.rb b/Library/Homebrew/cask/test/support/Casks/auto-updates.rb new file mode 100644 index 000000000..f49060f83 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/auto-updates.rb @@ -0,0 +1,11 @@ +test_cask 'auto-updates' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/auto-updates' + + auto_updates true + + app 'Transmission.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/bad-checksum.rb b/Library/Homebrew/cask/test/support/Casks/bad-checksum.rb new file mode 100644 index 000000000..074dae01f --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/bad-checksum.rb @@ -0,0 +1,9 @@ +test_cask 'bad-checksum' do + version '1.2.3' + sha256 'badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/basic-cask.rb b/Library/Homebrew/cask/test/support/Casks/basic-cask.rb new file mode 100644 index 000000000..d3aaa283e --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/basic-cask.rb @@ -0,0 +1,9 @@ +test_cask 'basic-cask' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/TestCask.dmg' + homepage 'http://example.com/' + + app 'TestCask.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/bzipped-asset.rb b/Library/Homebrew/cask/test/support/Casks/bzipped-asset.rb new file mode 100644 index 000000000..69c31b43c --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/bzipped-asset.rb @@ -0,0 +1,9 @@ +test_cask 'bzipped-asset' do + version '1.2.3' + sha256 'eaf67b3a62cb9275f96e45d05c70b94bef9ef1dae344083e93eda6b0b388a61c' + + url TestHelper.local_binary_url('bzipped_asset.bz2') + homepage 'http://example.com/bzipped-asset' + + app 'bzipped-asset--1.2.3' +end diff --git a/Library/Homebrew/cask/test/support/Casks/cab-container.rb b/Library/Homebrew/cask/test/support/Casks/cab-container.rb new file mode 100644 index 000000000..59e25af4e --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/cab-container.rb @@ -0,0 +1,11 @@ +test_cask 'cab-container' do + version '1.2.3' + sha256 '192d0cf6b727473f9ba0f55cec793ee2a8f7113c5cfe9d49e05a087436c5efe2' + + url TestHelper.local_binary_url('cabcontainer.cab') + homepage 'http://example.com/cab-container' + + depends_on formula: 'cabextract' + + app 'cabcontainer/Application.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/gzipped-asset.rb b/Library/Homebrew/cask/test/support/Casks/gzipped-asset.rb new file mode 100644 index 000000000..20872922c --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/gzipped-asset.rb @@ -0,0 +1,9 @@ +test_cask 'gzipped-asset' do + version '1.2.3' + sha256 '832506ade94b3e41ecdf2162654eb75891a0749803229e82b2e0420fd1b9e8d2' + + url TestHelper.local_binary_url('gzipped_asset.gz') + homepage 'http://example.com/gzipped-asset' + + app 'gzipped-asset--1.2.3' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-appcast-multiple.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-appcast-multiple.rb new file mode 100644 index 000000000..c257b05a1 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-appcast-multiple.rb @@ -0,0 +1,13 @@ +test_cask 'invalid-appcast-multiple' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + appcast 'http://example.com/appcast1.xml', + checkpoint: '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + appcast 'http://example.com/appcast2.xml', + checkpoint: '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + homepage 'http://example.com/invalid-appcast-multiple' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-appcast-url.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-appcast-url.rb new file mode 100644 index 000000000..c38702964 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-appcast-url.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-appcast-url' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + appcast 1, + checkpoint: '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + homepage 'http://example.com/invalid-appcast-url' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-conflicts-with-key.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-conflicts-with-key.rb new file mode 100644 index 000000000..c3cdaf90c --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-conflicts-with-key.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-conflicts-with-key' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-conflicts-with-key' + + conflicts_with no_such_key: 'unar' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-arch-value.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-arch-value.rb new file mode 100644 index 000000000..68cefaee9 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-arch-value.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-depends-on-arch-value' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-depends-on-arch-value' + + depends_on arch: :no_such_arch + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-key.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-key.rb new file mode 100644 index 000000000..99b438731 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-key.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-depends-on-key' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-depends-on-key' + + depends_on no_such_key: 'unar' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-macos-bad-release.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-macos-bad-release.rb new file mode 100644 index 000000000..fdf4d6faf --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-macos-bad-release.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-depends-on-macos-bad-release' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-depends-on-macos-bad-release' + + depends_on macos: :no_such_release + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb new file mode 100644 index 000000000..d00960ecf --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb @@ -0,0 +1,12 @@ +test_cask 'invalid-depends-on-macos-conflicting-forms' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-depends-on-macos-conflicting-forms' + + depends_on macos: :yosemite + depends_on macos: '>= :mavericks' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-x11-value.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-x11-value.rb new file mode 100644 index 000000000..e15e25933 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-depends-on-x11-value.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-depends-on-x11-value' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-depends-on-x11-value' + + depends_on x11: :no_such_value + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-conflicting-keys.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-conflicting-keys.rb new file mode 100644 index 000000000..a61b7b045 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-conflicting-keys.rb @@ -0,0 +1,12 @@ +test_cask 'invalid-gpg-conflicting-keys' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-conflicting-keys' + gpg 'http://example.com/gpg-signature.asc', + key_id: '01234567', + key_url: 'http://example.com/gpg-key-url' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-key-id.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-key-id.rb new file mode 100644 index 000000000..ba6761311 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-key-id.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-gpg-key-id' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-key-id' + gpg 'http://example.com/gpg-signature.asc', + key_id: '012' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-key-url.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-key-url.rb new file mode 100644 index 000000000..7e4fc33c1 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-key-url.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-gpg-key-url' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-key-url' + gpg 'http://example.com/gpg-signature.asc', + key_url: 1 + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-missing-key.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-missing-key.rb new file mode 100644 index 000000000..339228626 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-missing-key.rb @@ -0,0 +1,10 @@ +test_cask 'invalid-gpg-missing-key' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-missing-keys' + gpg 'http://example.com/gpg-signature.asc' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-multiple-stanzas.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-multiple-stanzas.rb new file mode 100644 index 000000000..94125f9d9 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-multiple-stanzas.rb @@ -0,0 +1,13 @@ +test_cask 'invalid-gpg-multiple-stanzas' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-multiple-stanzas' + gpg 'http://example.com/gpg-signature.asc', + key_id: '01234567' + gpg 'http://example.com/gpg-signature.asc', + key_id: '01234567' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-parameter.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-parameter.rb new file mode 100644 index 000000000..0e08f0c18 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-parameter.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-gpg-parameter' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-type' + gpg 'http://example.com/gpg-signature.asc', + no_such_parameter: :value + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-signature-url.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-signature-url.rb new file mode 100644 index 000000000..f1cdfcb63 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-signature-url.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-gpg-signature-url' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-signature-url' + gpg 1, + key_id: '01234567' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-type.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-type.rb new file mode 100644 index 000000000..bfb67b3f9 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-gpg-type.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-gpg-type' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/invalid-gpg-type' + gpg 'http://example.com/gpg-signature.asc', + no_such_parameter: :value + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-format.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-format.rb new file mode 100644 index 000000000..90ede3b2f --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-format.rb @@ -0,0 +1,9 @@ +test_cask => 'invalid-header-format' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-token-mismatch.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-token-mismatch.rb new file mode 100644 index 000000000..a69b0d752 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-token-mismatch.rb @@ -0,0 +1,9 @@ +test_cask 'invalid-header-token-mismatch-this-text-does-not-belong' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-version.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-version.rb new file mode 100644 index 000000000..d49b83467 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-header-version.rb @@ -0,0 +1,9 @@ +test_cask 'invalid-header-version' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-license-multiple.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-license-multiple.rb new file mode 100644 index 000000000..5144152f5 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-license-multiple.rb @@ -0,0 +1,11 @@ +test_cask 'invalid-license-multiple' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/invalid-license-multiple' + license :gpl + license :gpl + + app 'Transmission.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-license-value.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-license-value.rb new file mode 100644 index 000000000..5cb1b08ea --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-license-value.rb @@ -0,0 +1,10 @@ +test_cask 'invalid-license-value' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/invalid-license-value' + license :no_such_license + + app 'Transmission.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-stage-only-conflict.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-stage-only-conflict.rb new file mode 100644 index 000000000..6efd64b22 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-stage-only-conflict.rb @@ -0,0 +1,10 @@ +test_cask 'invalid-stage-only-conflict' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/invalid-stage-only-conflict' + + app 'Transmission.app' + stage_only true +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-homepage.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-homepage.rb new file mode 100644 index 000000000..ee90fa81a --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-homepage.rb @@ -0,0 +1,10 @@ +test_cask 'invalid-two-homepage' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + homepage 'http://www.example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-url.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-url.rb new file mode 100644 index 000000000..7a4dce7ae --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-url.rb @@ -0,0 +1,10 @@ +test_cask 'invalid-two-url' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + url 'http://example.com/caffeine.zip' + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-version.rb b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-version.rb new file mode 100644 index 000000000..a3c47c907 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/invalid/invalid-two-version.rb @@ -0,0 +1,10 @@ +test_cask 'invalid-two-version' do + version '1.2.3' + version '2.0' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/local-caffeine.rb b/Library/Homebrew/cask/test/support/Casks/local-caffeine.rb new file mode 100644 index 000000000..fb217cc20 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/local-caffeine.rb @@ -0,0 +1,9 @@ +test_cask 'local-caffeine' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/local-transmission.rb b/Library/Homebrew/cask/test/support/Casks/local-transmission.rb new file mode 100644 index 000000000..e0aa719a5 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/local-transmission.rb @@ -0,0 +1,9 @@ +test_cask 'local-transmission' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/local-transmission' + + app 'Transmission.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/lzma-asset.rb b/Library/Homebrew/cask/test/support/Casks/lzma-asset.rb new file mode 100644 index 000000000..f69bc7974 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/lzma-asset.rb @@ -0,0 +1,11 @@ +test_cask 'lzma-asset' do + version '1.2.3' + sha256 '9d7edb32d02ab9bd9749a5bde8756595ea4cfcb1da02ca11c30fb591d4c1ed85' + + url TestHelper.local_binary_url('lzma-asset.lzma') + homepage 'http://example.com/xzipped-asset' + + depends_on formula: 'lzma' + + app 'lzma-asset--1.2.3' +end diff --git a/Library/Homebrew/cask/test/support/Casks/missing-checksum.rb b/Library/Homebrew/cask/test/support/Casks/missing-checksum.rb new file mode 100644 index 000000000..3187f6fd2 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/missing-checksum.rb @@ -0,0 +1,8 @@ +test_cask 'missing-checksum' do + version '1.2.3' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/naked-executable.rb b/Library/Homebrew/cask/test/support/Casks/naked-executable.rb new file mode 100644 index 000000000..03e89e97b --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/naked-executable.rb @@ -0,0 +1,9 @@ +test_cask 'naked-executable' do + version '1.2.3' + sha256 '306c6ca7407560340797866e077e053627ad409277d1b9da58106fce4cf717cb' + + url TestHelper.local_binary_url('naked_executable') + homepage 'http://example.com/naked-executable' + + container type: :naked +end diff --git a/Library/Homebrew/cask/test/support/Casks/naked-pkg.rb b/Library/Homebrew/cask/test/support/Casks/naked-pkg.rb new file mode 100644 index 000000000..4650ce55d --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/naked-pkg.rb @@ -0,0 +1,7 @@ +test_cask 'naked-pkg' do + version '1.2.3' + sha256 '611c50c8a2a2098951d2cd0fd54787ed81b92cd97b4b08bd7cba17f1e1d8e40b' + + url TestHelper.local_binary_url('Naked.pkg') + homepage 'http://example.com/naked-pkg' +end diff --git a/Library/Homebrew/cask/test/support/Casks/nested-app.rb b/Library/Homebrew/cask/test/support/Casks/nested-app.rb new file mode 100644 index 000000000..77bd04127 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/nested-app.rb @@ -0,0 +1,11 @@ +test_cask 'nested-app' do + version '1.2.3' + sha256 '1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216' + + url TestHelper.local_binary_url('NestedApp.dmg.zip') + homepage 'http://example.com/nested-app' + + container nested: 'NestedApp.dmg' + + app 'MyNestedApp.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/no-checksum.rb b/Library/Homebrew/cask/test/support/Casks/no-checksum.rb new file mode 100644 index 000000000..dbe62b02b --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/no-checksum.rb @@ -0,0 +1,9 @@ +test_cask 'no-checksum' do + version '1.2.3' + sha256 :no_check + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/no-dsl-version.rb b/Library/Homebrew/cask/test/support/Casks/no-dsl-version.rb new file mode 100644 index 000000000..ee557b1e4 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/no-dsl-version.rb @@ -0,0 +1,9 @@ +test_cask 'no-dsl-version' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/TestCask.dmg' + homepage 'http://example.com/' + + app 'TestCask.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/rar-container.rb b/Library/Homebrew/cask/test/support/Casks/rar-container.rb new file mode 100644 index 000000000..60c525b60 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/rar-container.rb @@ -0,0 +1,11 @@ +test_cask 'rar-container' do + version '1.2.3' + sha256 '35fb13fb13e6aefc38b60486627eff6b6b55b2f99f64bf47938530c6cf9e0a0f' + + url TestHelper.local_binary_url('rarcontainer.rar') + homepage 'http://example.com/rar-container' + + depends_on formula: 'unar' + + app 'rarcontainer/Application.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/sevenzip-container.rb b/Library/Homebrew/cask/test/support/Casks/sevenzip-container.rb new file mode 100644 index 000000000..7f8cfdb4e --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/sevenzip-container.rb @@ -0,0 +1,11 @@ +test_cask 'sevenzip-container' do + version '1.2.3' + sha256 '1550701e7848fcb94f5b0085cca527083a8662ddeb8c0a7bc5af6bd145797cc1' + + url TestHelper.local_binary_url('sevenzipcontainer.7z') + homepage 'http://example.com/sevenzip-container' + + depends_on formula: 'unar' + + app 'sevenzipcontainer/Application.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/stage-only.rb b/Library/Homebrew/cask/test/support/Casks/stage-only.rb new file mode 100644 index 000000000..25fa7460c --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/stage-only.rb @@ -0,0 +1,9 @@ +test_cask 'stage-only' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/stage-only' + + stage_only true +end diff --git a/Library/Homebrew/cask/test/support/Casks/stuffit-container.rb b/Library/Homebrew/cask/test/support/Casks/stuffit-container.rb new file mode 100644 index 000000000..a42971ff5 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/stuffit-container.rb @@ -0,0 +1,11 @@ +test_cask 'stuffit-container' do + version '1.2.3' + sha256 '892b6d49a98c546381d41dec9b0bbc04267ac008d72b99755968d357099993b7' + + url TestHelper.local_binary_url('sheldonmac.sit') + homepage 'http://www.tobias-jung.de/seekingprofont/' + + depends_on formula: 'unar' + + artifact 'sheldonmac/v1.0', target: "#{Hbc.appdir}/sheldonmac/v1.0" +end diff --git a/Library/Homebrew/cask/test/support/Casks/tarball.rb b/Library/Homebrew/cask/test/support/Casks/tarball.rb new file mode 100644 index 000000000..3134a2f94 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/tarball.rb @@ -0,0 +1,9 @@ +test_cask 'tarball' do + version '1.2.3' + sha256 :no_check + + url TestHelper.local_binary_url('tarball.tgz') + homepage 'http://example.com/tarball' + + app 'Tarball.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/test-opera-mail.rb b/Library/Homebrew/cask/test/support/Casks/test-opera-mail.rb new file mode 100644 index 000000000..afc8387c7 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/test-opera-mail.rb @@ -0,0 +1,9 @@ +test_cask 'test-opera-mail' do + version '1.0' + sha256 'afd192e308f8ea8ddb3d426fd6663d97078570417ee78b8e1fa15f515ae3d677' + + url 'http://get-ash-1.opera.com/pub/opera/mail/1.0/mac/Opera-Mail-1.0-1040.i386.dmg' + homepage 'http://www.opera.com/computer/mail' + + app 'Opera Mail.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/test-opera.rb b/Library/Homebrew/cask/test/support/Casks/test-opera.rb new file mode 100644 index 000000000..ec32828f7 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/test-opera.rb @@ -0,0 +1,9 @@ +test_cask 'test-opera' do + version '19.0.1326.47' + sha256 '7b91f20ab754f7b3fef8dc346e0393917e11676b74c8f577408841619f76040a' + + url 'http://get.geo.opera.com/pub/opera/desktop/19.0.1326.47/mac/Opera_19.0.1326.47_Setup.dmg' + homepage 'http://www.opera.com/' + + app 'Opera.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-accessibility-access.rb b/Library/Homebrew/cask/test/support/Casks/with-accessibility-access.rb new file mode 100644 index 000000000..1aa7bc8f7 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-accessibility-access.rb @@ -0,0 +1,11 @@ +test_cask 'with-accessibility-access' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/TestCask.dmg' + homepage 'http://example.com/' + + accessibility_access true + + app 'TestCask.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-alt-target.rb b/Library/Homebrew/cask/test/support/Casks/with-alt-target.rb new file mode 100644 index 000000000..6d6456d86 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-alt-target.rb @@ -0,0 +1,9 @@ +test_cask 'with-alt-target' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app', target: 'AnotherName.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-appcast.rb b/Library/Homebrew/cask/test/support/Casks/with-appcast.rb new file mode 100644 index 000000000..acfb1565f --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-appcast.rb @@ -0,0 +1,11 @@ +test_cask 'with-appcast' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + appcast 'http://example.com/appcast.xml', + checkpoint: '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + homepage 'http://example.com/with-appcast' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-caveats.rb b/Library/Homebrew/cask/test/support/Casks/with-caveats.rb new file mode 100644 index 000000000..4412ceb3a --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-caveats.rb @@ -0,0 +1,23 @@ +test_cask 'with-caveats' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' + + # simple string is evaluated at compile-time + caveats <<-EOS.undent + Here are some things you might want to know. + EOS + # do block is evaluated at install-time + caveats do + "Cask token: #{token}" + end + # a do block may print and use a DSL + caveats do + puts 'Custom text via puts followed by DSL-generated text:' + path_environment_variable('/custom/path/bin') + end +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-conditional-caveats.rb b/Library/Homebrew/cask/test/support/Casks/with-conditional-caveats.rb new file mode 100644 index 000000000..2690649c3 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-conditional-caveats.rb @@ -0,0 +1,14 @@ +test_cask 'with-conditional-caveats' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' + + # a do block may print and use a DSL + caveats do + puts 'This caveat is conditional' if false # rubocop:disable Lint/LiteralInCondition + end +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-conflicts-with.rb b/Library/Homebrew/cask/test/support/Casks/with-conflicts-with.rb new file mode 100644 index 000000000..789c9839a --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-conflicts-with.rb @@ -0,0 +1,11 @@ +test_cask 'with-conflicts-with' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-conflicts-with' + + conflicts_with formula: 'unar' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-arch-failure.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-arch-failure.rb new file mode 100644 index 000000000..a257d7bbb --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-arch-failure.rb @@ -0,0 +1,12 @@ +test_cask 'with-depends-on-arch-failure' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-arch-failure' + + # guarantee mismatched hardware + depends_on arch: Hardware::CPU.intel? ? :ppc : :intel + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-arch.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-arch.rb new file mode 100644 index 000000000..9fc5baf1a --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-arch.rb @@ -0,0 +1,12 @@ +test_cask 'with-depends-on-arch' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-arch' + + # covers all known hardware; always succeeds + depends_on arch: [:ppc, :intel] + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-cyclic-helper.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-cyclic-helper.rb new file mode 100644 index 000000000..735289591 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-cyclic-helper.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-cask-cyclic-helper' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-cask-cyclic-helper' + + depends_on cask: 'with-depends-on-cask-cyclic' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-cyclic.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-cyclic.rb new file mode 100644 index 000000000..776929e83 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-cyclic.rb @@ -0,0 +1,12 @@ +test_cask 'with-depends-on-cask-cyclic' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-cask-cyclic' + + depends_on cask: 'local-caffeine' + depends_on cask: 'with-depends-on-cask-cyclic-helper' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-multiple.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-multiple.rb new file mode 100644 index 000000000..f08e73ac4 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask-multiple.rb @@ -0,0 +1,12 @@ +test_cask 'with-depends-on-cask-multiple' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-cask-multiple' + + depends_on cask: 'local-caffeine' + depends_on cask: 'local-transmission' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask.rb new file mode 100644 index 000000000..013da2379 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-cask.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-cask' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-cask' + + depends_on cask: 'local-transmission' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-formula-multiple.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-formula-multiple.rb new file mode 100644 index 000000000..bdc4e1f8b --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-formula-multiple.rb @@ -0,0 +1,12 @@ +test_cask 'with-depends-on-formula-multiple' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-formula-multiple' + + depends_on formula: 'unar' + depends_on formula: 'fileutils' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-formula.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-formula.rb new file mode 100644 index 000000000..3d365a187 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-formula.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-formula' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-formula' + + depends_on formula: 'unar' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-array.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-array.rb new file mode 100644 index 000000000..4b3b8320e --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-array.rb @@ -0,0 +1,12 @@ +test_cask 'with-depends-on-macos-array' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-macos-array' + + # since all OS releases are included, this should always pass + depends_on macos: ['10.4', '10.5', '10.6', '10.7', '10.8', '10.9', '10.10', MacOS.version.to_s] + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-comparison.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-comparison.rb new file mode 100644 index 000000000..448e44a03 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-comparison.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-macos-comparison' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-macos-comparison' + + depends_on macos: '>= 10.4' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-failure.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-failure.rb new file mode 100644 index 000000000..8e7a9a1d6 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-failure.rb @@ -0,0 +1,12 @@ +test_cask 'with-depends-on-macos-failure' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-macos-failure' + + # guarantee a mismatched release + depends_on macos: MacOS.version.to_s == '10.4' ? '10.5' : '10.4' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-string.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-string.rb new file mode 100644 index 000000000..1dab7654c --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-string.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-macos-string' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-macos-string' + + depends_on macos: MacOS.version.to_s + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-symbol.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-symbol.rb new file mode 100644 index 000000000..00a99c525 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-macos-symbol.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-macos-symbol' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-macos-symbol' + + depends_on macos: MacOS.version.to_sym + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-x11-false.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-x11-false.rb new file mode 100644 index 000000000..00ea1cef9 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-x11-false.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-x11-false' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-x11-false' + + depends_on x11: false + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-depends-on-x11.rb b/Library/Homebrew/cask/test/support/Casks/with-depends-on-x11.rb new file mode 100644 index 000000000..234547334 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-depends-on-x11.rb @@ -0,0 +1,11 @@ +test_cask 'with-depends-on-x11' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-depends-on-x11' + + depends_on x11: true + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-generic-artifact-no-target.rb b/Library/Homebrew/cask/test/support/Casks/with-generic-artifact-no-target.rb new file mode 100644 index 000000000..5e6eb51b8 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-generic-artifact-no-target.rb @@ -0,0 +1,9 @@ +test_cask 'with-generic-artifact-no-target' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-generic-artifact' + + artifact 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-generic-artifact.rb b/Library/Homebrew/cask/test/support/Casks/with-generic-artifact.rb new file mode 100644 index 000000000..87bf43cba --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-generic-artifact.rb @@ -0,0 +1,9 @@ +test_cask 'with-generic-artifact' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-generic-artifact' + + artifact 'Caffeine.app', target: "#{Hbc.appdir}/Caffeine.app" +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-gpg-key-url.rb b/Library/Homebrew/cask/test/support/Casks/with-gpg-key-url.rb new file mode 100644 index 000000000..68fa8123a --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-gpg-key-url.rb @@ -0,0 +1,11 @@ +test_cask 'with-gpg-key-url' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-gpg-key-url' + gpg 'http://example.com/gpg-signature.asc', + key_url: 'http://example.com/gpg-key-url' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-gpg.rb b/Library/Homebrew/cask/test/support/Casks/with-gpg.rb new file mode 100644 index 000000000..84c29fe65 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-gpg.rb @@ -0,0 +1,11 @@ +test_cask 'with-gpg' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-gpg' + gpg 'http://example.com/gpg-signature.asc', + key_id: '01234567' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-installable.rb b/Library/Homebrew/cask/test/support/Casks/with-installable.rb new file mode 100644 index 000000000..b32273a6c --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-installable.rb @@ -0,0 +1,20 @@ +test_cask 'with-installable' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall script: { executable: 'MyFancyPkg/FancyUninstaller.tool', args: %w[--please] }, + quit: 'my.fancy.package.app', + login_item: 'Fancy', + delete: [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ], + rmdir: TestHelper.local_binary_path('empty_directory') +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-installer-manual.rb b/Library/Homebrew/cask/test/support/Casks/with-installer-manual.rb new file mode 100644 index 000000000..6291d7f88 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-installer-manual.rb @@ -0,0 +1,9 @@ +test_cask 'with-installer-manual' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + installer manual: 'Caffeine.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-installer-script.rb b/Library/Homebrew/cask/test/support/Casks/with-installer-script.rb new file mode 100644 index 000000000..3014a3945 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-installer-script.rb @@ -0,0 +1,15 @@ +test_cask 'with-installer-script' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/with-install-script' + + installer script: '/usr/bin/true', + args: ['--flag'] + # acceptable alternate form + installer script: { + executable: '/usr/bin/false', + args: ['--flag'], + } +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-license.rb b/Library/Homebrew/cask/test/support/Casks/with-license.rb new file mode 100644 index 000000000..ed2572cf2 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-license.rb @@ -0,0 +1,10 @@ +test_cask 'with-license' do + version '2.61' + sha256 'd26d7481cf1229f879c05e11cbdf440d99db6d6342f26c73d8ba7861b975532f' + + url TestHelper.local_binary_url('transmission-2.61.dmg') + homepage 'http://example.com/with-license' + license :gpl + + app 'Transmission.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-macosx-dir.rb b/Library/Homebrew/cask/test/support/Casks/with-macosx-dir.rb new file mode 100644 index 000000000..24c4ec4dd --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-macosx-dir.rb @@ -0,0 +1,9 @@ +test_cask 'with-macosx-dir' do + version '1.2.3' + sha256 '5633c3a0f2e572cbf021507dec78c50998b398c343232bdfc7e26221d0a5db4d' + + url TestHelper.local_binary_url('MyFancyApp.zip') + homepage 'http://example.com/MyFancyApp' + + app 'MyFancyApp/MyFancyApp.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-pkgutil-zap.rb b/Library/Homebrew/cask/test/support/Casks/with-pkgutil-zap.rb new file mode 100644 index 000000000..6440285a0 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-pkgutil-zap.rb @@ -0,0 +1,13 @@ +test_cask 'with-pkgutil-zap' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + zap pkgutil: 'my.fancy.package.*', + kext: 'my.fancy.package.kernelextension', + launchctl: 'my.fancy.package.service' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-suite.rb b/Library/Homebrew/cask/test/support/Casks/with-suite.rb new file mode 100644 index 000000000..594276574 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-suite.rb @@ -0,0 +1,11 @@ +test_cask 'with-suite' do + version '1.2.3' + sha256 'd1302a0dc25aff72ad395ed01a830468b92253ffd28269574f3ac0b5eb8aad54' + + url TestHelper.local_binary_url('caffeine_suite.zip') + name 'Caffeine' + homepage 'http://example.com/with-suite' + license :unknown # TODO: change license and remove this comment; ':unknown' is a machine-generated placeholder + + suite 'caffeine_suite' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-two-apps-correct.rb b/Library/Homebrew/cask/test/support/Casks/with-two-apps-correct.rb new file mode 100644 index 000000000..a0b142528 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-two-apps-correct.rb @@ -0,0 +1,10 @@ +test_cask 'with-two-apps-correct' do + version '1.2.3' + sha256 'c0c79dce9511c80603328013dbbcb80b859cc8b9190660b6832b5f0e60d74c82' + + url TestHelper.local_binary_url('2_app_caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' + app 'Caffeine-2.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-two-apps-incorrect.rb b/Library/Homebrew/cask/test/support/Casks/with-two-apps-incorrect.rb new file mode 100644 index 000000000..0ae37a79c --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-two-apps-incorrect.rb @@ -0,0 +1,9 @@ +test_cask 'with-two-apps-incorrect' do + version '1.2.3' + sha256 '9203c30951f9aab41ac294bbeb1dcef7bed401ff0b353dcb34d68af32ea51853' + + url TestHelper.local_binary_url('caffeine.zip') + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app', 'Caffeine.app/Contents/MacOS/Caffeine' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-two-apps-subdir.rb b/Library/Homebrew/cask/test/support/Casks/with-two-apps-subdir.rb new file mode 100644 index 000000000..61adefab6 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-two-apps-subdir.rb @@ -0,0 +1,10 @@ +test_cask 'with-two-apps-subdir' do + version '1.2.3' + sha256 '03edce6992a6095e120dcfadf7049158589ae6f0548c145ed1b1c6f2883f6dca' + + url TestHelper.local_binary_url('2_app_subdir.zip') + homepage 'http://example.com/local-caffeine' + + app 'subdir/Caffeine.app' + app 'subdir/Caffeine-2.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-delete.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-delete.rb new file mode 100644 index 000000000..c85b3bd0f --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-delete.rb @@ -0,0 +1,16 @@ +test_cask 'with-uninstall-delete' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + uninstall delete: [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-early-script.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-early-script.rb new file mode 100644 index 000000000..6fe3842e2 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-early-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-early-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall early_script: { executable: 'MyFancyPkg/FancyUninstaller.tool', args: %w[--please] } +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-kext.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-kext.rb new file mode 100644 index 000000000..682ce689e --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-kext.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-kext' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + uninstall kext: 'my.fancy.package.kernelextension' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-launchctl.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-launchctl.rb new file mode 100644 index 000000000..0e601b41e --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-launchctl.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-launchctl' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyApp.zip') + homepage 'http://example.com/fancy' + + app 'Fancy.app' + + uninstall launchctl: 'my.fancy.package.service' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-login-item.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-login-item.rb new file mode 100644 index 000000000..d977b31e3 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-login-item.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-login-item' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall login_item: 'Fancy' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-pkgutil.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-pkgutil.rb new file mode 100644 index 000000000..773e1e43b --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-pkgutil.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-pkgutil' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + uninstall pkgutil: 'my.fancy.package.*' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-quit.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-quit.rb new file mode 100644 index 000000000..88e063c62 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-quit.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-quit' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall quit: 'my.fancy.package.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-rmdir.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-rmdir.rb new file mode 100644 index 000000000..ce1c66518 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-rmdir.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-rmdir' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall rmdir: TestHelper.local_binary_path('empty_directory') +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-script.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-script.rb new file mode 100644 index 000000000..975a14442 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-uninstall-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall script: { executable: 'MyFancyPkg/FancyUninstaller.tool', args: %w[--please] } +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-signal.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-signal.rb new file mode 100644 index 000000000..808768173 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-signal.rb @@ -0,0 +1,14 @@ +test_cask 'with-uninstall-signal' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall signal: [ + ['TERM', 'my.fancy.package.app'], + ['KILL', 'my.fancy.package.app'], + ] +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-uninstall-trash.rb b/Library/Homebrew/cask/test/support/Casks/with-uninstall-trash.rb new file mode 100644 index 000000000..16f174c2d --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-uninstall-trash.rb @@ -0,0 +1,16 @@ +test_cask 'with-uninstall-trash' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + uninstall trash: [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-delete.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-delete.rb new file mode 100644 index 000000000..77d50ffba --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-delete.rb @@ -0,0 +1,16 @@ +test_cask 'with-zap-delete' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + zap delete: [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-early-script.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-early-script.rb new file mode 100644 index 000000000..299c4d135 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-early-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-early-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap early_script: { executable: 'MyFancyPkg/FancyUninstaller.tool', args: %w[--please] } +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-kext.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-kext.rb new file mode 100644 index 000000000..d8809b409 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-kext.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-kext' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + zap kext: 'my.fancy.package.kernelextension' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-launchctl.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-launchctl.rb new file mode 100644 index 000000000..321e17a78 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-launchctl.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-launchctl' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyApp.zip') + homepage 'http://example.com/fancy' + + app 'Fancy.app' + + zap launchctl: 'my.fancy.package.service' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-login-item.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-login-item.rb new file mode 100644 index 000000000..a7af6ce63 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-login-item.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-login-item' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap login_item: 'Fancy' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-pkgutil.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-pkgutil.rb new file mode 100644 index 000000000..ded6508cd --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-pkgutil.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-pkgutil' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + zap pkgutil: 'my.fancy.package.*' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-quit.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-quit.rb new file mode 100644 index 000000000..0b21221c8 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-quit.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-quit' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap quit: 'my.fancy.package.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-rmdir.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-rmdir.rb new file mode 100644 index 000000000..f3f799919 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-rmdir.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-rmdir' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap rmdir: TestHelper.local_binary_path('empty_directory') +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-script.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-script.rb new file mode 100644 index 000000000..9e8ae0d12 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-script.rb @@ -0,0 +1,11 @@ +test_cask 'with-zap-script' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap script: { executable: 'MyFancyPkg/FancyUninstaller.tool', args: %w[--please] } +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-signal.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-signal.rb new file mode 100644 index 000000000..7338b67b0 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-signal.rb @@ -0,0 +1,14 @@ +test_cask 'with-zap-signal' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + zap signal: [ + ['TERM', 'my.fancy.package.app'], + ['KILL', 'my.fancy.package.app'], + ] +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap-trash.rb b/Library/Homebrew/cask/test/support/Casks/with-zap-trash.rb new file mode 100644 index 000000000..7295b7a23 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap-trash.rb @@ -0,0 +1,16 @@ +test_cask 'with-zap-trash' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'Fancy.pkg' + + zap trash: [ + '/permissible/absolute/path', + '~/permissible/path/with/tilde', + 'impermissible/relative/path', + '/another/impermissible/../relative/path', + ] +end diff --git a/Library/Homebrew/cask/test/support/Casks/with-zap.rb b/Library/Homebrew/cask/test/support/Casks/with-zap.rb new file mode 100644 index 000000000..752aca019 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/with-zap.rb @@ -0,0 +1,19 @@ +test_cask 'with-zap' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url TestHelper.local_binary_url('MyFancyPkg.zip') + homepage 'http://example.com/fancy-pkg' + + pkg 'MyFancyPkg/Fancy.pkg' + + uninstall quit: 'my.fancy.package.app.from.uninstall' + + zap script: { + executable: 'MyFancyPkg/FancyUninstaller.tool', + args: %w[--please], + }, + quit: 'my.fancy.package.app', + login_item: 'Fancy', + delete: '~/Library/Preferences/my.fancy.app.plist' +end diff --git a/Library/Homebrew/cask/test/support/Casks/xar-container.rb b/Library/Homebrew/cask/test/support/Casks/xar-container.rb new file mode 100644 index 000000000..158c4f717 --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/xar-container.rb @@ -0,0 +1,9 @@ +test_cask 'xar-container' do + version '1.2.3' + sha256 '1418752ac49e859f88590db245015cb2f8b459f619e0c50fd6ff87b902c72ee1' + + url TestHelper.local_binary_url('xarcontainer.xar') + homepage 'http://example.com/xar-container' + + app 'xarcontainer/Application.app' +end diff --git a/Library/Homebrew/cask/test/support/Casks/xzipped-asset.rb b/Library/Homebrew/cask/test/support/Casks/xzipped-asset.rb new file mode 100644 index 000000000..badb252ee --- /dev/null +++ b/Library/Homebrew/cask/test/support/Casks/xzipped-asset.rb @@ -0,0 +1,11 @@ +test_cask 'xzipped-asset' do + version '1.2.3' + sha256 '839263f474edde1d54a9101606e6f0dc9d963acc93f6dcc5af8d10ebc3187c02' + + url TestHelper.local_binary_url('xzipped-asset.xz') + homepage 'http://example.com/xzipped-asset' + + depends_on formula: 'xz' + + app 'xzipped-asset--1.2.3' +end diff --git a/Library/Homebrew/cask/test/support/binaries/2_app_caffeine.zip b/Library/Homebrew/cask/test/support/binaries/2_app_caffeine.zip Binary files differnew file mode 100755 index 000000000..a678f7c11 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/2_app_caffeine.zip diff --git a/Library/Homebrew/cask/test/support/binaries/2_app_subdir.zip b/Library/Homebrew/cask/test/support/binaries/2_app_subdir.zip Binary files differnew file mode 100755 index 000000000..27637a731 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/2_app_subdir.zip diff --git a/Library/Homebrew/cask/test/support/binaries/GMDesk-1.01.air b/Library/Homebrew/cask/test/support/binaries/GMDesk-1.01.air Binary files differnew file mode 100644 index 000000000..215cd2b8b --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/GMDesk-1.01.air diff --git a/Library/Homebrew/cask/test/support/binaries/MyFancyApp.zip b/Library/Homebrew/cask/test/support/binaries/MyFancyApp.zip Binary files differnew file mode 100644 index 000000000..ba09ee681 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/MyFancyApp.zip diff --git a/Library/Homebrew/cask/test/support/binaries/MyFancyPkg.zip b/Library/Homebrew/cask/test/support/binaries/MyFancyPkg.zip Binary files differnew file mode 100644 index 000000000..ec4f97f07 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/MyFancyPkg.zip diff --git a/Library/Homebrew/cask/test/support/binaries/Naked.pkg b/Library/Homebrew/cask/test/support/binaries/Naked.pkg Binary files differnew file mode 100644 index 000000000..274f27e7a --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/Naked.pkg diff --git a/Library/Homebrew/cask/test/support/binaries/NestedApp.dmg.zip b/Library/Homebrew/cask/test/support/binaries/NestedApp.dmg.zip Binary files differnew file mode 100644 index 000000000..ae6686c7e --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/NestedApp.dmg.zip diff --git a/Library/Homebrew/cask/test/support/binaries/bzipped_asset.bz2 b/Library/Homebrew/cask/test/support/binaries/bzipped_asset.bz2 Binary files differnew file mode 100644 index 000000000..6ec60f31f --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/bzipped_asset.bz2 diff --git a/Library/Homebrew/cask/test/support/binaries/cabcontainer.cab b/Library/Homebrew/cask/test/support/binaries/cabcontainer.cab Binary files differnew file mode 100644 index 000000000..f1dec52dc --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/cabcontainer.cab diff --git a/Library/Homebrew/cask/test/support/binaries/caffeine.zip b/Library/Homebrew/cask/test/support/binaries/caffeine.zip Binary files differnew file mode 100644 index 000000000..74aca21db --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/caffeine.zip diff --git a/Library/Homebrew/cask/test/support/binaries/caffeine_suite.zip b/Library/Homebrew/cask/test/support/binaries/caffeine_suite.zip Binary files differnew file mode 100644 index 000000000..7fa5c958e --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/caffeine_suite.zip diff --git a/Library/Homebrew/cask/test/support/binaries/empty_directory/.gitignore b/Library/Homebrew/cask/test/support/binaries/empty_directory/.gitignore new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/empty_directory/.gitignore diff --git a/Library/Homebrew/cask/test/support/binaries/gzipped_asset.gz b/Library/Homebrew/cask/test/support/binaries/gzipped_asset.gz Binary files differnew file mode 100644 index 000000000..1ff300b4b --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/gzipped_asset.gz diff --git a/Library/Homebrew/cask/test/support/binaries/lzma-asset.lzma b/Library/Homebrew/cask/test/support/binaries/lzma-asset.lzma Binary files differnew file mode 100644 index 000000000..2ff7ccee7 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/lzma-asset.lzma diff --git a/Library/Homebrew/cask/test/support/binaries/naked_executable b/Library/Homebrew/cask/test/support/binaries/naked_executable new file mode 100755 index 000000000..039e4d006 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/naked_executable @@ -0,0 +1,2 @@ +#!/bin/sh +exit 0 diff --git a/Library/Homebrew/cask/test/support/binaries/rarcontainer.rar b/Library/Homebrew/cask/test/support/binaries/rarcontainer.rar Binary files differnew file mode 100644 index 000000000..988699306 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/rarcontainer.rar diff --git a/Library/Homebrew/cask/test/support/binaries/sevenzipcontainer.7z b/Library/Homebrew/cask/test/support/binaries/sevenzipcontainer.7z Binary files differnew file mode 100644 index 000000000..226f620cd --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/sevenzipcontainer.7z diff --git a/Library/Homebrew/cask/test/support/binaries/sheldonmac.sit b/Library/Homebrew/cask/test/support/binaries/sheldonmac.sit Binary files differnew file mode 100644 index 000000000..8814fc31e --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/sheldonmac.sit diff --git a/Library/Homebrew/cask/test/support/binaries/tarball.tgz b/Library/Homebrew/cask/test/support/binaries/tarball.tgz Binary files differnew file mode 100644 index 000000000..0a9fb5695 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/tarball.tgz diff --git a/Library/Homebrew/cask/test/support/binaries/transmission-2.61.dmg b/Library/Homebrew/cask/test/support/binaries/transmission-2.61.dmg Binary files differnew file mode 100644 index 000000000..b9629f837 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/transmission-2.61.dmg diff --git a/Library/Homebrew/cask/test/support/binaries/xarcontainer.xar b/Library/Homebrew/cask/test/support/binaries/xarcontainer.xar Binary files differnew file mode 100644 index 000000000..bd37cd4d6 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/xarcontainer.xar diff --git a/Library/Homebrew/cask/test/support/binaries/xzipped-asset.xz b/Library/Homebrew/cask/test/support/binaries/xzipped-asset.xz Binary files differnew file mode 100644 index 000000000..74db22090 --- /dev/null +++ b/Library/Homebrew/cask/test/support/binaries/xzipped-asset.xz diff --git a/Library/Homebrew/cask/test/support/cleanup.rb b/Library/Homebrew/cask/test/support/cleanup.rb new file mode 100644 index 000000000..0cb9c02fa --- /dev/null +++ b/Library/Homebrew/cask/test/support/cleanup.rb @@ -0,0 +1,12 @@ +module Hbc::CleanupHooks + def after_teardown + super + Hbc.installed.each do |cask| + Hbc::Installer.new(cask).purge_versioned_files + end + end +end + +class MiniTest::Spec + include Hbc::CleanupHooks +end diff --git a/Library/Homebrew/cask/test/support/fake_dirs.rb b/Library/Homebrew/cask/test/support/fake_dirs.rb new file mode 100644 index 000000000..89612f850 --- /dev/null +++ b/Library/Homebrew/cask/test/support/fake_dirs.rb @@ -0,0 +1,29 @@ +# wire in a set of fake link dirs per-test +module FakeDirHooks + DIRS = [:appdir, :qlplugindir, :binarydir].freeze + + def before_setup + super + + @canned_dirs = {} + + DIRS.each do |dir_name| + dir = Hbc.homebrew_prefix.join("#{dir_name}-#{Time.now.to_i}-#{rand(1024)}") + dir.mkpath + Hbc.send("#{dir_name}=", dir) + @canned_dirs[:dir_name] = dir + end + end + + def after_teardown + super + + @canned_dirs.each_value do |dir| + dir.rmtree if dir.exist? + end + end +end + +class MiniTest::Spec + include FakeDirHooks +end diff --git a/Library/Homebrew/cask/test/support/fake_fetcher.rb b/Library/Homebrew/cask/test/support/fake_fetcher.rb new file mode 100644 index 000000000..a49a89f7f --- /dev/null +++ b/Library/Homebrew/cask/test/support/fake_fetcher.rb @@ -0,0 +1,35 @@ +class Hbc::FakeFetcher + def self.fake_response_for(url, response) + @responses[url] = response + end + + def self.head(url) + @responses ||= {} + raise("no response faked for #{url.inspect}") unless @responses.key?(url) + @responses[url] + end + + def self.init + @responses = {} + end + + def self.clear + @responses = {} + end +end + +module FakeFetcherHooks + def before_setup + super + Hbc::FakeFetcher.init + end + + def after_teardown + super + Hbc::FakeFetcher.clear + end +end + +class MiniTest::Spec + include FakeFetcherHooks +end diff --git a/Library/Homebrew/cask/test/support/fake_system_command.rb b/Library/Homebrew/cask/test/support/fake_system_command.rb new file mode 100644 index 000000000..e19330fd0 --- /dev/null +++ b/Library/Homebrew/cask/test/support/fake_system_command.rb @@ -0,0 +1,73 @@ +class Hbc::FakeSystemCommand + def self.responses + @responses ||= {} + end + + def self.expectations + @expectations ||= {} + end + + def self.system_calls + @system_calls ||= Hash.new(0) + end + + def self.clear + @responses = nil + @expectations = nil + @system_calls = nil + end + + def self.stubs_command(command, response = "") + responses[command] = response + end + + def self.expects_command(command, response = "", times = 1) + stubs_command(command, response) + expectations[command] = times + end + + def self.expect_and_pass_through(command, times = 1) + pass_through = ->(cmd, opts) { Hbc::SystemCommand.run(cmd, opts) } + expects_command(command, pass_through, times) + end + + def self.verify_expectations! + expectations.each do |command, times| + unless system_calls[command] == times + raise("expected #{command.inspect} to be run #{times} times, but got #{system_calls[command]}") + end + end + end + + def self.run(command_string, options = {}) + command = Hbc::SystemCommand.new(command_string, options).command + unless responses.key?(command) + raise("no response faked for #{command.inspect}, faked responses are: #{responses.inspect}") + end + system_calls[command] += 1 + + response = responses[command] + if response.respond_to?(:call) + response.call(command_string, options) + else + Hbc::SystemCommand::Result.new(command, response, "", 0) + end + end + + def self.run!(command, options = {}) + run(command, options.merge(must_succeed: true)) + end +end + +module FakeSystemCommandHooks + def after_teardown + super + Hbc::FakeSystemCommand.verify_expectations! + ensure + Hbc::FakeSystemCommand.clear + end +end + +class MiniTest::Spec + include FakeSystemCommandHooks +end diff --git a/Library/Homebrew/cask/test/support/never_sudo_system_command.rb b/Library/Homebrew/cask/test/support/never_sudo_system_command.rb new file mode 100644 index 000000000..50f510a7a --- /dev/null +++ b/Library/Homebrew/cask/test/support/never_sudo_system_command.rb @@ -0,0 +1,5 @@ +class Hbc::NeverSudoSystemCommand < Hbc::SystemCommand + def self.run(command, options = {}) + super(command, options.merge(sudo: false)) + end +end diff --git a/Library/Homebrew/cask/test/support/shared_examples.rb b/Library/Homebrew/cask/test/support/shared_examples.rb new file mode 100644 index 000000000..e846af404 --- /dev/null +++ b/Library/Homebrew/cask/test/support/shared_examples.rb @@ -0,0 +1,21 @@ +# Adapted from https://gist.github.com/jodosha/1560208 +MiniTest::Spec.class_eval do + def self.shared_examples + @shared_examples ||= {} + end +end + +module MiniTest::Spec::SharedExamples + def shared_examples_for(desc, &block) + MiniTest::Spec.shared_examples[desc] = block + end + + def it_behaves_like(desc, *args, &block) + instance_exec(*args, &MiniTest::Spec.shared_examples[desc]) + instance_eval(&block) if block_given? + end +end + +Object.class_eval do + include(MiniTest::Spec::SharedExamples) +end diff --git a/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb b/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb new file mode 100644 index 000000000..28115bb4b --- /dev/null +++ b/Library/Homebrew/cask/test/support/shared_examples/dsl_base.rb @@ -0,0 +1,23 @@ +require "test_helper" + +shared_examples_for Hbc::DSL::Base do + it "supports the token method" do + dsl.token.must_equal cask.token + end + + it "supports the version method" do + dsl.version.must_equal cask.version + end + + it "supports the caskroom_path method" do + dsl.caskroom_path.must_equal cask.caskroom_path + end + + it "supports the staged_path method" do + dsl.staged_path.must_equal cask.staged_path + end + + it "supports the appdir method" do + dsl.appdir.must_equal cask.appdir + end +end diff --git a/Library/Homebrew/cask/test/support/shared_examples/staged.rb b/Library/Homebrew/cask/test/support/shared_examples/staged.rb new file mode 100644 index 000000000..ef4ff0341 --- /dev/null +++ b/Library/Homebrew/cask/test/support/shared_examples/staged.rb @@ -0,0 +1,109 @@ +require "test_helper" + +shared_examples_for Hbc::Staged do + let(:fake_pathname_exists) { + fake_pathname = Pathname("/path/to/file/that/exists") + fake_pathname.stubs(exist?: true, expand_path: fake_pathname) + fake_pathname + } + + let(:fake_pathname_does_not_exist) { + fake_pathname = Pathname("/path/to/file/that/does/not/exist") + fake_pathname.stubs(exist?: false, expand_path: fake_pathname) + fake_pathname + } + + it "can run system commands with list-form arguments" do + Hbc::FakeSystemCommand.expects_command( + ["echo", "homebrew-cask", "rocks!"] + ) + staged.system_command("echo", args: ["homebrew-cask", "rocks!"]) + end + + it "can get the Info.plist file for the primary app" do + staged.info_plist_file.to_s.must_include Hbc.appdir.join("TestCask.app/Contents/Info.plist") + end + + it "can execute commands on the Info.plist file" do + staged.stubs(bundle_identifier: "com.example.BasicCask") + + Hbc::FakeSystemCommand.expects_command( + ["/usr/libexec/PlistBuddy", "-c", "Print CFBundleIdentifier", staged.info_plist_file] + ) + staged.plist_exec("Print CFBundleIdentifier") + end + + it "can set a key in the Info.plist file" do + staged.stubs(bundle_identifier: "com.example.BasicCask") + + Hbc::FakeSystemCommand.expects_command( + ["/usr/libexec/PlistBuddy", "-c", "Set :JVMOptions:JVMVersion 1.6+", staged.info_plist_file] + ) + staged.plist_set(":JVMOptions:JVMVersion", "1.6+") + end + + it "can set the permissions of a file" do + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/bin/chmod", "-R", "--", "777", fake_pathname] + ) + staged.set_permissions(fake_pathname.to_s, "777") + end + + it "can set the permissions of multiple files" do + fake_pathname = fake_pathname_exists + staged.stubs(:Pathname).returns(fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/bin/chmod", "-R", "--", "777", fake_pathname, fake_pathname] + ) + staged.set_permissions([fake_pathname.to_s, fake_pathname.to_s], "777") + end + + it "cannot set the permissions of a file that does not exist" do + fake_pathname = fake_pathname_does_not_exist + staged.stubs(Pathname: fake_pathname) + staged.set_permissions(fake_pathname.to_s, "777") + end + + it "can set the ownership of a file" do + staged.stubs(current_user: "fake_user") + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname] + ) + staged.set_ownership(fake_pathname.to_s) + end + + it "can set the ownership of multiple files" do + staged.stubs(current_user: "fake_user") + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "fake_user:staff", fake_pathname, fake_pathname] + ) + staged.set_ownership([fake_pathname.to_s, fake_pathname.to_s]) + end + + it "can set the ownership of a file with a different user and group" do + fake_pathname = fake_pathname_exists + staged.stubs(Pathname: fake_pathname) + + Hbc::FakeSystemCommand.expects_command( + ["/usr/bin/sudo", "-E", "--", "/usr/sbin/chown", "-R", "--", "other_user:other_group", fake_pathname] + ) + staged.set_ownership(fake_pathname.to_s, user: "other_user", group: "other_group") + end + + it "cannot set the ownership of a file that does not exist" do + staged.stubs(current_user: "fake_user") + fake_pathname = fake_pathname_does_not_exist + staged.stubs(Pathname: fake_pathname) + staged.set_ownership(fake_pathname.to_s) + end +end diff --git a/Library/Homebrew/cask/test/syntax_test.rb b/Library/Homebrew/cask/test/syntax_test.rb new file mode 100644 index 000000000..0ea832bde --- /dev/null +++ b/Library/Homebrew/cask/test/syntax_test.rb @@ -0,0 +1,17 @@ +require "test_helper" + +describe "Syntax check" do + project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../")) + backend_files = Dir[project_root.join("**", "*.rb")].reject { |f| f.match %r{/vendor/|/Casks/} } + interpreter = RUBY_PATH + flags = %w[-c] + flags.unshift "--disable-all" + backend_files.each do |file| + it "#{file} is valid Ruby" do + args = flags + ["--", file] + shutup do + raise SyntaxError, "#{file} failed syntax check" unless system(interpreter, *args) + end + end + end +end diff --git a/Library/Homebrew/cask/test/test_helper.rb b/Library/Homebrew/cask/test/test_helper.rb new file mode 100644 index 000000000..dfe2484ed --- /dev/null +++ b/Library/Homebrew/cask/test/test_helper.rb @@ -0,0 +1,183 @@ +require "bundler" +require "bundler/setup" +require "pathname" + +if ENV["COVERAGE"] + require "coveralls" + Coveralls.wear_merged! +end + +project_root = Pathname.new(File.expand_path("../..", __FILE__)) + +# add Homebrew to load path +$LOAD_PATH.unshift(File.expand_path("#{ENV['HOMEBREW_REPOSITORY']}/Library/Homebrew")) + +require "global" +require "extend/pathname" + +# add Homebrew-Cask to load path +$LOAD_PATH.push(project_root.join("lib").to_s) + +# force some environment variables +ENV["HOMEBREW_NO_EMOJI"] = "1" +ENV["HOMEBREW_CASK_OPTS"] = nil + +# TODO: temporary, copied from old Homebrew, this method is now moved inside a class +def shutup + if ENV.key?("VERBOSE_TESTS") + yield + else + begin + tmperr = $stderr.clone + tmpout = $stdout.clone + $stderr.reopen "/dev/null", "w" + $stdout.reopen "/dev/null", "w" + yield + ensure + $stderr.reopen tmperr + $stdout.reopen tmpout + end + end +end + +def sudo(*args) + %w[/usr/bin/sudo -E --] + Array(args).flatten +end + +TEST_TMPDIR = Dir.mktmpdir("homebrew_cask_tests") +at_exit do + FileUtils.remove_entry(TEST_TMPDIR) +end + +# must be called after testing_env so at_exit hooks are in proper order +require "minitest/autorun" +require "minitest/reporters" +Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true) + +# Force mocha to patch MiniTest since we have both loaded thanks to homebrew's testing_env +require "mocha/api" +require "mocha/integration/mini_test" +Mocha::Integration::MiniTest.activate + +# our baby +require "hbc" + +# override Homebrew locations +Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join("prefix") +Hbc.homebrew_repository = Hbc.homebrew_prefix + +# Override Tap::TAP_DIRECTORY to use our test Tap directory. +class Tap + send(:remove_const, :TAP_DIRECTORY) + TAP_DIRECTORY = Hbc.homebrew_prefix.join("Library", "Taps") +end + +Hbc.default_tap = Tap.fetch("caskroom", "testcasks") + +# also jack in some test Casks +FileUtils.ln_s project_root.join("test", "support"), Tap::TAP_DIRECTORY.join("caskroom").tap(&:mkpath).join("homebrew-testcasks") + +# pretend that the caskroom/cask Tap is installed +FileUtils.ln_s project_root, Tap::TAP_DIRECTORY.join("caskroom").tap(&:mkpath).join("homebrew-cask") + +# create cache directory +Hbc.homebrew_cache = Pathname.new(TEST_TMPDIR).join("cache") +Hbc.cache.mkpath + +# our own testy caskroom +Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom") + +class TestHelper + # helpers for test Casks to reference local files easily + def self.local_binary_path(name) + File.expand_path(File.join(File.dirname(__FILE__), "support", "binaries", name)) + end + + def self.local_binary_url(name) + "file://" + local_binary_path(name) + end + + def self.test_cask + @test_cask ||= Hbc.load("basic-cask") + end + + def self.fake_fetcher + Hbc::FakeFetcher + end + + def self.fake_response_for(*args) + Hbc::FakeFetcher.fake_response_for(*args) + end + + def self.must_output(test, lambda, expected = nil) + out, err = test.capture_subprocess_io do + lambda.call + end + + if block_given? + yield (out + err).chomp + elsif expected.is_a?(Regexp) + (out + err).chomp.must_match expected + else + (out + err).chomp.must_equal expected.gsub(%r{^ *}, "") + end + end + + def self.valid_alias?(candidate) + return false unless candidate.symlink? + candidate.readlink.exist? + end + + def self.install_without_artifacts(cask) + Hbc::Installer.new(cask).tap do |i| + shutup do + i.download + i.extract_primary_container + end + end + end + + def self.install_with_caskfile(cask) + Hbc::Installer.new(cask).tap do |i| + shutup do + i.save_caskfile + end + end + end + + def self.install_without_artifacts_with_caskfile(cask) + Hbc::Installer.new(cask).tap do |i| + shutup do + i.download + i.extract_primary_container + i.save_caskfile + end + end + end +end + +# Extend MiniTest API with support for RSpec-style shared examples +require "support/shared_examples" +require "support/shared_examples/dsl_base.rb" +require "support/shared_examples/staged.rb" + +require "support/fake_fetcher" +require "support/fake_dirs" +require "support/fake_system_command" +require "support/cleanup" +require "support/never_sudo_system_command" +require "tmpdir" +require "tempfile" + +# create directories +FileUtils.mkdir_p Hbc.homebrew_prefix.join("bin") + +# Common superclass for test Casks for when we need to filter them out +class Hbc::TestCask < Hbc::Cask; end + +# jack in some optional utilities +FileUtils.ln_s "/usr/local/bin/cabextract", Hbc.homebrew_prefix.join("bin/cabextract") +FileUtils.ln_s "/usr/local/bin/unar", Hbc.homebrew_prefix.join("bin/unar") +FileUtils.ln_s "/usr/local/bin/unlzma", Hbc.homebrew_prefix.join("bin/unlzma") +FileUtils.ln_s "/usr/local/bin/unxz", Hbc.homebrew_prefix.join("bin/unxz") +FileUtils.ln_s "/usr/local/bin/lsar", Hbc.homebrew_prefix.join("bin/lsar") |
