aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorMike McQuaid2017-02-26 20:48:36 +0000
committerMike McQuaid2017-02-26 20:48:36 +0000
commitc2a460ec6d857ba33c89174d8d93fcaa403c3717 (patch)
tree089045fec4c46fb74e3b48868e2b335497df7b84 /Library/Homebrew/test
parentd3ae1cc264dc9eb9b602dd6aa21c4282dc049c79 (diff)
parentff93e1624b214c9b48731174a9135789fc3695a8 (diff)
downloadbrew-c2a460ec6d857ba33c89174d8d93fcaa403c3717.tar.bz2
Merge branch 'master' into filter_all_env_vars_932
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/ARGV_spec.rb149
-rw-r--r--Library/Homebrew/test/ARGV_test.rb80
-rw-r--r--Library/Homebrew/test/ENV_spec.rb189
-rw-r--r--Library/Homebrew/test/ENV_test.rb201
-rw-r--r--Library/Homebrew/test/Gemfile22
-rw-r--r--Library/Homebrew/test/Gemfile.lock68
-rw-r--r--Library/Homebrew/test/analytics_test.rb26
-rw-r--r--Library/Homebrew/test/audit_test.rb64
-rw-r--r--Library/Homebrew/test/bash_spec.rb52
-rw-r--r--Library/Homebrew/test/bash_test.rb35
-rw-r--r--Library/Homebrew/test/blacklist_spec.rb115
-rw-r--r--Library/Homebrew/test/blacklist_test.rb68
-rw-r--r--Library/Homebrew/test/bottle_collector_test.rb38
-rw-r--r--Library/Homebrew/test/bottle_hooks_spec.rb50
-rw-r--r--Library/Homebrew/test/bottle_hooks_test.rb47
-rw-r--r--Library/Homebrew/test/bottle_test.rb21
-rw-r--r--Library/Homebrew/test/build_environment_spec.rb66
-rw-r--r--Library/Homebrew/test/build_environment_test.rb45
-rw-r--r--Library/Homebrew/test/build_options_spec.rb52
-rw-r--r--Library/Homebrew/test/build_options_test.rb49
-rw-r--r--Library/Homebrew/test/bundle_test.rb22
-rw-r--r--Library/Homebrew/test/cache_formula_test.rb8
-rw-r--r--Library/Homebrew/test/cache_test.rb8
-rw-r--r--Library/Homebrew/test/cask_test.rb10
-rw-r--r--Library/Homebrew/test/cat_test.rb8
-rw-r--r--Library/Homebrew/test/caveats_spec.rb29
-rw-r--r--Library/Homebrew/test/caveats_test.rb29
-rw-r--r--Library/Homebrew/test/cellar_formula_test.rb8
-rw-r--r--Library/Homebrew/test/cellar_test.rb8
-rw-r--r--Library/Homebrew/test/checksum_spec.rb19
-rw-r--r--Library/Homebrew/test/checksum_test.rb22
-rw-r--r--Library/Homebrew/test/checksum_verification_test.rb4
-rw-r--r--Library/Homebrew/test/cleaner_test.rb5
-rw-r--r--Library/Homebrew/test/cleanup_test.rb41
-rw-r--r--Library/Homebrew/test/cmd/--cache_spec.rb15
-rw-r--r--Library/Homebrew/test/cmd/--cellar_spec.rb15
-rw-r--r--Library/Homebrew/test/cmd/--env_spec.rb44
-rw-r--r--Library/Homebrew/test/cmd/--prefix_spec.rb15
-rw-r--r--Library/Homebrew/test/cmd/--repository_spec.rb15
-rw-r--r--Library/Homebrew/test/cmd/--version_spec.rb8
-rw-r--r--Library/Homebrew/test/cmd/analytics_spec.rb52
-rw-r--r--Library/Homebrew/test/cmd/bundle_spec.rb24
-rw-r--r--Library/Homebrew/test/cmd/cask_spec.rb8
-rw-r--r--Library/Homebrew/test/cmd/cat_spec.rb11
-rw-r--r--Library/Homebrew/test/cmd/cleanup_spec.rb12
-rw-r--r--Library/Homebrew/test/cmd/command_spec.rb13
-rw-r--r--Library/Homebrew/test/cmd/commands_spec.rb7
-rw-r--r--Library/Homebrew/test/cmd/config_spec.rb8
-rw-r--r--Library/Homebrew/test/cmd/custom-external-command_spec.rb21
-rw-r--r--Library/Homebrew/test/cmd/desc_spec.rb40
-rw-r--r--Library/Homebrew/test/cmd/doctor_spec.rb6
-rw-r--r--Library/Homebrew/test/cmd/fetch_spec.rb13
-rw-r--r--Library/Homebrew/test/cmd/help_spec.rb47
-rw-r--r--Library/Homebrew/test/cmd/home_spec.rb17
-rw-r--r--Library/Homebrew/test/cmd/info_spec.rb30
-rw-r--r--Library/Homebrew/test/cmd/install_spec.rb243
-rw-r--r--Library/Homebrew/test/cmd/irb_spec.rb24
-rw-r--r--Library/Homebrew/test/cmd/leaves_spec.rb23
-rw-r--r--Library/Homebrew/test/cmd/link_spec.rb56
-rw-r--r--Library/Homebrew/test/cmd/linkapps_spec.rb24
-rw-r--r--Library/Homebrew/test/cmd/list_spec.rb14
-rw-r--r--Library/Homebrew/test/cmd/log_spec.rb41
-rw-r--r--Library/Homebrew/test/cmd/migrate_spec.rb46
-rw-r--r--Library/Homebrew/test/cmd/missing_spec.rb41
-rw-r--r--Library/Homebrew/test/cmd/options_spec.rb12
-rw-r--r--Library/Homebrew/test/cmd/outdated_spec.rb11
-rw-r--r--Library/Homebrew/test/cmd/pin_spec.rb13
-rw-r--r--Library/Homebrew/test/cmd/prune_spec.rb28
-rw-r--r--Library/Homebrew/test/cmd/readall_spec.rb20
-rw-r--r--Library/Homebrew/test/cmd/reinstall_spec.rb44
-rw-r--r--Library/Homebrew/test/cmd/search_remote_tap_spec.rb19
-rw-r--r--Library/Homebrew/test/cmd/search_spec.rb57
-rw-r--r--Library/Homebrew/test/cmd/services_spec.rb10
-rw-r--r--Library/Homebrew/test/cmd/sh_spec.rb8
-rw-r--r--Library/Homebrew/test/cmd/switch_spec.rb34
-rw-r--r--Library/Homebrew/test/cmd/tap-new_spec.rb10
-rw-r--r--Library/Homebrew/test/cmd/uninstall_spec.rb12
-rw-r--r--Library/Homebrew/test/cmd/unlink_spec.rb14
-rw-r--r--Library/Homebrew/test/cmd/unlinkapps_spec.rb24
-rw-r--r--Library/Homebrew/test/cmd/unpack_spec.rb16
-rw-r--r--Library/Homebrew/test/cmd/unpin_spec.rb14
-rw-r--r--Library/Homebrew/test/cmd/update-report_spec.rb127
-rw-r--r--Library/Homebrew/test/cmd/upgrade_spec.rb12
-rw-r--r--Library/Homebrew/test/cmd/uses_spec.rb25
-rw-r--r--Library/Homebrew/test/command_test.rb11
-rw-r--r--Library/Homebrew/test/commands_test.rb13
-rw-r--r--Library/Homebrew/test/compiler_failure_spec.rb37
-rw-r--r--Library/Homebrew/test/compiler_failure_test.rb52
-rw-r--r--Library/Homebrew/test/compiler_selector_spec.rb122
-rw-r--r--Library/Homebrew/test/compiler_selector_test.rb116
-rw-r--r--Library/Homebrew/test/config_test.rb8
-rw-r--r--Library/Homebrew/test/create_test.rb12
-rw-r--r--Library/Homebrew/test/custom_command_test.rb18
-rw-r--r--Library/Homebrew/test/cxxstdlib_spec.rb68
-rw-r--r--Library/Homebrew/test/dependencies_test.rb2
-rw-r--r--Library/Homebrew/test/dependency_collector_test.rb2
-rw-r--r--Library/Homebrew/test/dependency_expansion_spec.rb136
-rw-r--r--Library/Homebrew/test/dependency_expansion_test.rb137
-rw-r--r--Library/Homebrew/test/dependency_test.rb6
-rw-r--r--Library/Homebrew/test/deps_spec.rb31
-rw-r--r--Library/Homebrew/test/deps_test.rb16
-rw-r--r--Library/Homebrew/test/desc_test.rb17
-rw-r--r--Library/Homebrew/test/descriptions_spec.rb42
-rw-r--r--Library/Homebrew/test/descriptions_test.rb45
-rw-r--r--Library/Homebrew/test/dev-cmd/bottle_spec.rb30
-rw-r--r--Library/Homebrew/test/dev-cmd/create_spec.rb13
-rw-r--r--Library/Homebrew/test/dev-cmd/edit_spec.rb16
-rw-r--r--Library/Homebrew/test/dev-cmd/formula_spec.rb10
-rw-r--r--Library/Homebrew/test/dev-cmd/pull_spec.rb60
-rw-r--r--Library/Homebrew/test/dev-cmd/tap_spec.rb75
-rw-r--r--Library/Homebrew/test/dev-cmd/test_spec.rb56
-rw-r--r--Library/Homebrew/test/diagnostic_spec.rb188
-rw-r--r--Library/Homebrew/test/diagnostic_test.rb198
-rw-r--r--Library/Homebrew/test/doctor_test.rb8
-rw-r--r--Library/Homebrew/test/download_strategies_spec.rb232
-rw-r--r--Library/Homebrew/test/download_strategies_test.rb262
-rw-r--r--Library/Homebrew/test/edit_test.rb11
-rw-r--r--Library/Homebrew/test/emoji_spec.rb16
-rw-r--r--Library/Homebrew/test/exceptions_spec.rb188
-rw-r--r--Library/Homebrew/test/exceptions_test.rb142
-rw-r--r--Library/Homebrew/test/fetch_test.rb11
-rw-r--r--Library/Homebrew/test/formula_installer_test.rb15
-rw-r--r--Library/Homebrew/test/formula_lock_spec.rb34
-rw-r--r--Library/Homebrew/test/formula_lock_test.rb22
-rw-r--r--Library/Homebrew/test/formula_pin_spec.rb41
-rw-r--r--Library/Homebrew/test/formula_pin_test.rb54
-rw-r--r--Library/Homebrew/test/formula_spec.rb1295
-rw-r--r--Library/Homebrew/test/formula_test.rb1210
-rw-r--r--Library/Homebrew/test/formulary_spec.rb227
-rw-r--r--Library/Homebrew/test/formulary_test.rb208
-rw-r--r--Library/Homebrew/test/gpg2_requirement_spec.rb23
-rw-r--r--Library/Homebrew/test/gpg2_requirement_test.rb24
-rw-r--r--Library/Homebrew/test/gpg_spec.rb21
-rw-r--r--Library/Homebrew/test/gpg_test.rb20
-rw-r--r--Library/Homebrew/test/hardware_spec.rb40
-rw-r--r--Library/Homebrew/test/hardware_test.rb15
-rw-r--r--Library/Homebrew/test/help_test.rb21
-rw-r--r--Library/Homebrew/test/home_test.rb12
-rw-r--r--Library/Homebrew/test/info_test.rb29
-rw-r--r--Library/Homebrew/test/inreplace_spec.rb251
-rw-r--r--Library/Homebrew/test/inreplace_test.rb119
-rw-r--r--Library/Homebrew/test/install_test.rb147
-rw-r--r--Library/Homebrew/test/irb_test.rb19
-rw-r--r--Library/Homebrew/test/java_requirement_spec.rb107
-rw-r--r--Library/Homebrew/test/json_test.rb20
-rw-r--r--Library/Homebrew/test/keg_spec.rb486
-rw-r--r--Library/Homebrew/test/keg_test.rb484
-rw-r--r--Library/Homebrew/test/language/go_spec.rb15
-rw-r--r--Library/Homebrew/test/language/python_spec.rb106
-rw-r--r--Library/Homebrew/test/language_go_test.rb17
-rw-r--r--Library/Homebrew/test/language_module_requirement_spec.rb49
-rw-r--r--Library/Homebrew/test/language_module_requirement_test.rb55
-rw-r--r--Library/Homebrew/test/language_python_test.rb99
-rw-r--r--Library/Homebrew/test/leaves_test.rb15
-rw-r--r--Library/Homebrew/test/link_test.rb23
-rw-r--r--Library/Homebrew/test/linkapps_test.rb15
-rw-r--r--Library/Homebrew/test/list_test.rb13
-rw-r--r--Library/Homebrew/test/log_formula_test.rb27
-rw-r--r--Library/Homebrew/test/log_test.rb13
-rw-r--r--Library/Homebrew/test/migrate_test.rb18
-rw-r--r--Library/Homebrew/test/migrator_spec.rb264
-rw-r--r--Library/Homebrew/test/migrator_test.rb264
-rw-r--r--Library/Homebrew/test/missing_test.rb34
-rw-r--r--Library/Homebrew/test/mpi_requirement_spec.rb14
-rw-r--r--Library/Homebrew/test/mpi_requirement_test.rb12
-rw-r--r--Library/Homebrew/test/options_spec.rb148
-rw-r--r--Library/Homebrew/test/options_test.rb157
-rw-r--r--Library/Homebrew/test/os/mac/blacklist_test.rb12
-rw-r--r--Library/Homebrew/test/os/mac/bottle_collector_test.rb26
-rw-r--r--Library/Homebrew/test/os/mac/bottle_tag_test.rb79
-rw-r--r--Library/Homebrew/test/os/mac/dependency_collector_spec.rb50
-rw-r--r--Library/Homebrew/test/os/mac/dependency_collector_test.rb57
-rw-r--r--Library/Homebrew/test/os/mac/diagnostic_spec.rb42
-rw-r--r--Library/Homebrew/test/os/mac/diagnostic_test.rb49
-rw-r--r--Library/Homebrew/test/os/mac/java_requirement_spec.rb34
-rw-r--r--Library/Homebrew/test/os/mac/keg_spec.rb32
-rw-r--r--Library/Homebrew/test/os/mac/keg_test.rb69
-rw-r--r--Library/Homebrew/test/os/mac/language_test.rb19
-rw-r--r--Library/Homebrew/test/os/mac/mach_spec.rb198
-rw-r--r--Library/Homebrew/test/os/mac/mach_test.rb208
-rw-r--r--Library/Homebrew/test/os/mac/version_spec.rb51
-rw-r--r--Library/Homebrew/test/os/mac/version_test.rb53
-rw-r--r--Library/Homebrew/test/os/mac_spec.rb22
-rw-r--r--Library/Homebrew/test/outdated_test.rb10
-rw-r--r--Library/Homebrew/test/patch_spec.rb165
-rw-r--r--Library/Homebrew/test/patch_test.rb154
-rw-r--r--Library/Homebrew/test/patching_spec.rb289
-rw-r--r--Library/Homebrew/test/patching_test.rb253
-rw-r--r--Library/Homebrew/test/pathname_spec.rb300
-rw-r--r--Library/Homebrew/test/pathname_test.rb267
-rw-r--r--Library/Homebrew/test/pin_unpin_test.rb18
-rw-r--r--Library/Homebrew/test/pkg_version_spec.rb81
-rw-r--r--Library/Homebrew/test/pkg_version_test.rb51
-rw-r--r--Library/Homebrew/test/prefix_formula_test.rb8
-rw-r--r--Library/Homebrew/test/prefix_test.rb8
-rw-r--r--Library/Homebrew/test/prune_test.rb21
-rw-r--r--Library/Homebrew/test/pull_offline_test.rb10
-rw-r--r--Library/Homebrew/test/pull_test.rb27
-rw-r--r--Library/Homebrew/test/readall_test.rb12
-rw-r--r--Library/Homebrew/test/reinstall_pinned_test.rb15
-rw-r--r--Library/Homebrew/test/reinstall_test.rb15
-rw-r--r--Library/Homebrew/test/repository_test.rb10
-rw-r--r--Library/Homebrew/test/requirement_spec.rb288
-rw-r--r--Library/Homebrew/test/requirement_test.rb152
-rw-r--r--Library/Homebrew/test/resource_spec.rb147
-rw-r--r--Library/Homebrew/test/resource_test.rb132
-rw-r--r--Library/Homebrew/test/sandbox_test.rb15
-rw-r--r--Library/Homebrew/test/search_remote_tap_test.rb19
-rw-r--r--Library/Homebrew/test/search_test.rb30
-rw-r--r--Library/Homebrew/test/services_test.rb11
-rw-r--r--Library/Homebrew/test/sh_test.rb8
-rw-r--r--Library/Homebrew/test/shell_test.rb59
-rw-r--r--Library/Homebrew/test/software_spec_spec.rb184
-rw-r--r--Library/Homebrew/test/software_spec_test.rb181
-rw-r--r--Library/Homebrew/test/spec_helper.rb101
-rw-r--r--Library/Homebrew/test/stdlib_test.rb62
-rw-r--r--Library/Homebrew/test/string_spec.rb49
-rw-r--r--Library/Homebrew/test/string_test.rb40
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/appcast-checkpoint-sha256-for-empty-string.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/appcast-invalid-checkpoint.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/appcast-missing-checkpoint.rb3
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/appcast-valid-checkpoint.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/appdir-interpolation.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/auto-updates.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/bad-checksum.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/basic-cask.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/booby-trap.rb8
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-7z.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-air.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-bzip2.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-cab.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-dmg.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-gzip.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-lzma.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-pkg.rb7
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-rar.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-sit.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-tar-gz.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-xar.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/container-xz.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb3
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb3
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-relative-target.rb3
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid-sha256.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-multiple.rb13
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-url.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-conflicts-with-key.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-arch-value.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-key.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-bad-release.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-x11-value.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-conflicting-keys.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-id.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-url.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-missing-key.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-multiple-stanzas.rb13
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-parameter.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-signature-url.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-type.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-format.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-token-mismatch.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-version.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-stage-only-conflict.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-homepage.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-url.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-version.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/local-caffeine.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/local-transmission.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/missing-checksum.rb8
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/missing-homepage.rb5
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/missing-name.rb5
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/missing-sha256.rb5
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/missing-url.rb5
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/missing-version.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/naked-executable.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/nested-app.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/no-checksum.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/no-dsl-version.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/osdn-correct-url-format.rb6
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/osdn-incorrect-url-format.rb6
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/sha256-for-empty-string.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-correct-url-format.rb6
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-incorrect-url-format.rb6
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-version-latest-correct-url-format.rb6
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/stage-only.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/test-opera-mail.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/test-opera.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/version-latest-string.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/version-latest-with-checksum.rb4
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-accessibility-access.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-alt-target.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-appcast.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-binary.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-caveats.rb23
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-choices.rb16
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-caveats.rb14
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-arch.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic-helper.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-multiple.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-formula-multiple.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-formula.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-array.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-comparison.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-failure.rb12
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-string.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-symbol.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-x11-false.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-x11.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-dsl-version.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-embedded-binary.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact-no-target.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-gpg-key-url.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-gpg.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb21
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-manual.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-script.rb15
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-macosx-dir.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb13
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-suite.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-correct.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb9
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-subdir.rb10
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-delete.rb17
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-early-script.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-kext.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-launchctl.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-login-item.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-pkgutil.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-quit.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-rmdir.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script-app.rb21
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-signal.rb14
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-trash.rb17
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb17
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-early-script.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-kext.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-launchctl.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-login-item.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-pkgutil.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-quit.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-rmdir.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-script.rb11
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-signal.rb14
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-trash.rb17
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb19
-rw-r--r--Library/Homebrew/test/support/fixtures/cask/empty_directory/.gitignore0
-rw-r--r--Library/Homebrew/test/support/helper/env.rb15
-rw-r--r--Library/Homebrew/test/support/helper/fixtures.rb13
-rw-r--r--Library/Homebrew/test/support/helper/formula.rb19
-rw-r--r--Library/Homebrew/test/support/helper/fs_leak_logger.rb4
-rw-r--r--Library/Homebrew/test/support/helper/integration_command_test_case.rb109
-rw-r--r--Library/Homebrew/test/support/helper/lifecycle_enforcer.rb22
-rw-r--r--Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb176
-rw-r--r--Library/Homebrew/test/support/helper/test_case.rb58
-rw-r--r--Library/Homebrew/test/support/lib/config.rb5
-rw-r--r--Library/Homebrew/test/switch_test.rb20
-rw-r--r--Library/Homebrew/test/tab_spec.rb341
-rw-r--r--Library/Homebrew/test/tab_test.rb315
-rw-r--r--Library/Homebrew/test/tap_new_test.rb9
-rw-r--r--Library/Homebrew/test/tap_test.rb60
-rw-r--r--Library/Homebrew/test/test_formula_test.rb30
-rw-r--r--Library/Homebrew/test/testing_env.rb23
-rw-r--r--Library/Homebrew/test/uninstall_test.rb16
-rw-r--r--Library/Homebrew/test/unlink_test.rb10
-rw-r--r--Library/Homebrew/test/unlinkapps_test.rb19
-rw-r--r--Library/Homebrew/test/unpack_test.rb13
-rw-r--r--Library/Homebrew/test/update_report_test.rb134
-rw-r--r--Library/Homebrew/test/upgrade_test.rb12
-rw-r--r--Library/Homebrew/test/uses_test.rb16
-rw-r--r--Library/Homebrew/test/utils/bottles/bintray_spec.rb18
-rw-r--r--Library/Homebrew/test/utils/bottles/bottles_spec.rb80
-rw-r--r--Library/Homebrew/test/utils/bottles/collector_spec.rb45
-rw-r--r--Library/Homebrew/test/utils/popen_spec.rb28
-rw-r--r--Library/Homebrew/test/utils/shell_spec.rb93
-rw-r--r--Library/Homebrew/test/utils/tty_spec.rb67
-rw-r--r--Library/Homebrew/test/utils/tty_test.rb46
-rw-r--r--Library/Homebrew/test/utils_spec.rb277
-rw-r--r--Library/Homebrew/test/utils_test.rb235
-rw-r--r--Library/Homebrew/test/version_test.rb8
-rw-r--r--Library/Homebrew/test/versions_test.rb2
-rw-r--r--Library/Homebrew/test/x11_requirement_spec.rb36
-rw-r--r--Library/Homebrew/test/x11_requirement_test.rb31
388 files changed, 11458 insertions, 8298 deletions
diff --git a/Library/Homebrew/test/ARGV_spec.rb b/Library/Homebrew/test/ARGV_spec.rb
new file mode 100644
index 000000000..89ef9cabc
--- /dev/null
+++ b/Library/Homebrew/test/ARGV_spec.rb
@@ -0,0 +1,149 @@
+require "extend/ARGV"
+
+describe HomebrewArgvExtension do
+ subject { argv.extend(described_class) }
+ let(:argv) { ["mxcl"] }
+
+ describe "#formulae" do
+ it "raises an error when a Formula is unavailable" do
+ expect { subject.formulae }.to raise_error FormulaUnavailableError
+ end
+
+ context "when there are no Formulae" do
+ let(:argv) { [] }
+
+ it "returns an empty array" do
+ expect(subject.formulae).to be_empty
+ end
+ end
+ end
+
+ describe "#casks" do
+ it "returns an empty array if there is no match" do
+ expect(subject.casks).to eq []
+ end
+ end
+
+ describe "#kegs" do
+ context "when there are matching Kegs" do
+ before(:each) do
+ keg = HOMEBREW_CELLAR + "mxcl/10.0"
+ keg.mkpath
+ end
+
+ it "returns an array of Kegs" do
+ expect(subject.kegs.length).to eq 1
+ end
+ end
+
+ context "when there are no matching Kegs" do
+ let(:argv) { [] }
+
+ it "returns an empty array" do
+ expect(subject.kegs).to be_empty
+ end
+ end
+ end
+
+ describe "#named" do
+ let(:argv) { ["foo", "--debug", "-v"] }
+
+ it "returns an array of non-option arguments" do
+ expect(subject.named).to eq ["foo"]
+ end
+
+ context "when there are no named arguments" do
+ let(:argv) { [] }
+
+ it "returns an empty array" do
+ expect(subject.named).to be_empty
+ end
+ end
+ end
+
+ describe "#options_only" do
+ let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] }
+
+ it "returns an array of option arguments" do
+ expect(subject.options_only).to eq ["--foo", "-vds"]
+ end
+ end
+
+ describe "#flags_only" do
+ let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] }
+
+ it "returns an array of flags" do
+ expect(subject.flags_only).to eq ["--foo"]
+ end
+ end
+
+ describe "#empty?" do
+ let(:argv) { [] }
+
+ it "returns true if it is empty" do
+ expect(subject).to be_empty
+ end
+ end
+
+ describe "#switch?" do
+ let(:argv) { ["-ns", "-i", "--bar", "-a-bad-arg"] }
+
+ it "returns true if the given string is a switch" do
+ %w[n s i].each do |s|
+ expect(subject.switch?(s)).to be true
+ end
+ end
+
+ it "returns false if the given string is not a switch" do
+ %w[b ns bar --bar -n a bad arg].each do |s|
+ expect(subject.switch?(s)).to be false
+ end
+ end
+ end
+
+ describe "#flag?" do
+ let(:argv) { ["--foo", "-bq", "--bar"] }
+
+ it "returns true if the given string is a flag" do
+ expect(subject.flag?("--foo")).to eq true
+ expect(subject.flag?("--bar")).to eq true
+ end
+
+ it "returns true if there is a switch with the same initial character" do
+ expect(subject.flag?("--baz")).to eq true
+ expect(subject.flag?("--qux")).to eq true
+ end
+
+ it "returns false if there is no matching flag" do
+ expect(subject.flag?("--frotz")).to eq false
+ expect(subject.flag?("--debug")).to eq false
+ end
+ end
+
+ describe "#value" do
+ let(:argv) { ["--foo=", "--bar=ab"] }
+
+ it "returns the value for a given string" do
+ expect(subject.value("foo")).to eq ""
+ expect(subject.value("bar")).to eq "ab"
+ end
+
+ it "returns nil if there is no matching argument" do
+ expect(subject.value("baz")).to be nil
+ end
+ end
+
+ describe "#values" do
+ let(:argv) { ["--foo=", "--bar=a", "--baz=b,c"] }
+
+ it "returns the value for a given argument" do
+ expect(subject.values("foo")).to eq []
+ expect(subject.values("bar")).to eq ["a"]
+ expect(subject.values("baz")).to eq ["b", "c"]
+ end
+
+ it "returns nil if there is no matching argument" do
+ expect(subject.values("qux")).to be nil
+ end
+ end
+end
diff --git a/Library/Homebrew/test/ARGV_test.rb b/Library/Homebrew/test/ARGV_test.rb
deleted file mode 100644
index 6805e0c62..000000000
--- a/Library/Homebrew/test/ARGV_test.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-require "testing_env"
-require "extend/ARGV"
-
-class ArgvExtensionTests < Homebrew::TestCase
- def setup
- @argv = [].extend(HomebrewArgvExtension)
- end
-
- def test_argv_formulae
- @argv.unshift "mxcl"
- assert_raises(FormulaUnavailableError) { @argv.formulae }
- end
-
- def test_argv_casks
- @argv.unshift "mxcl"
- assert_equal [], @argv.casks
- end
-
- def test_argv_kegs
- keg = HOMEBREW_CELLAR + "mxcl/10.0"
- keg.mkpath
- @argv << "mxcl"
- assert_equal 1, @argv.kegs.length
- ensure
- keg.parent.rmtree
- end
-
- def test_argv_named
- @argv << "foo" << "--debug" << "-v"
- assert_equal %w[foo], @argv.named
- end
-
- def test_options_only
- @argv << "--foo" << "-vds" << "a" << "b" << "cdefg"
- assert_equal %w[--foo -vds], @argv.options_only
- end
-
- def test_flags_only
- @argv << "--foo" << "-vds" << "a" << "b" << "cdefg"
- assert_equal %w[--foo], @argv.flags_only
- end
-
- def test_empty_argv
- assert_empty @argv.named
- assert_empty @argv.kegs
- assert_empty @argv.formulae
- assert_empty @argv
- end
-
- def test_switch?
- @argv << "-ns" << "-i" << "--bar" << "-a-bad-arg"
- %w[n s i].each { |s| assert @argv.switch?(s) }
- %w[b ns bar --bar -n a bad arg].each { |s| assert !@argv.switch?(s) }
- end
-
- def test_flag?
- @argv << "--foo" << "-bq" << "--bar"
- assert @argv.flag?("--foo")
- assert @argv.flag?("--bar")
- assert @argv.flag?("--baz")
- assert @argv.flag?("--qux")
- assert !@argv.flag?("--frotz")
- assert !@argv.flag?("--debug")
- end
-
- def test_value
- @argv << "--foo=" << "--bar=ab"
- assert_equal "", @argv.value("foo")
- assert_equal "ab", @argv.value("bar")
- assert_nil @argv.value("baz")
- end
-
- def test_values
- @argv << "--foo=" << "--bar=a" << "--baz=b,c"
- assert_equal [], @argv.values("foo")
- assert_equal ["a"], @argv.values("bar")
- assert_equal ["b", "c"], @argv.values("baz")
- assert_nil @argv.values("qux")
- end
-end
diff --git a/Library/Homebrew/test/ENV_spec.rb b/Library/Homebrew/test/ENV_spec.rb
new file mode 100644
index 000000000..7b50ca1d4
--- /dev/null
+++ b/Library/Homebrew/test/ENV_spec.rb
@@ -0,0 +1,189 @@
+require "extend/ENV"
+
+shared_examples EnvActivation do
+ subject { env.extend(described_class) }
+ let(:env) { {}.extend(EnvActivation) }
+
+ it "supports switching compilers" do
+ subject.clang
+ expect(subject["LD"]).to be nil
+ expect(subject["CC"]).to eq(subject["OBJC"])
+ end
+
+ describe "#with_build_environment" do
+ it "restores the environment" do
+ before = subject.dup
+
+ subject.with_build_environment do
+ subject["foo"] = "bar"
+ end
+
+ expect(subject["foo"]).to be nil
+ expect(subject).to eq(before)
+ end
+
+ it "ensures the environment is restored" do
+ before = subject.dup
+
+ expect {
+ subject.with_build_environment do
+ subject["foo"] = "bar"
+ raise StandardError
+ end
+ }.to raise_error(StandardError)
+
+ expect(subject["foo"]).to be nil
+ expect(subject).to eq(before)
+ end
+
+ it "returns the value of the block" do
+ expect(subject.with_build_environment { 1 }).to eq(1)
+ end
+
+ it "does not mutate the interface" do
+ expected = subject.methods
+
+ subject.with_build_environment do
+ expect(subject.methods).to eq(expected)
+ end
+
+ expect(subject.methods).to eq(expected)
+ end
+ end
+
+ describe "#append" do
+ it "appends to an existing key" do
+ subject["foo"] = "bar"
+ subject.append "foo", "1"
+ expect(subject["foo"]).to eq("bar 1")
+ end
+
+ it "appends to an existing empty key" do
+ subject["foo"] = ""
+ subject.append "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ it "appends to a non-existant key" do
+ subject.append "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ # NOTE: this may be a wrong behavior; we should probably reject objects that
+ # do not respond to #to_str. For now this documents existing behavior.
+ it "coerces a value to a string" do
+ subject.append "foo", 42
+ expect(subject["foo"]).to eq("42")
+ end
+ end
+
+ describe "#prepend" do
+ it "prepends to an existing key" do
+ subject["foo"] = "bar"
+ subject.prepend "foo", "1"
+ expect(subject["foo"]).to eq("1 bar")
+ end
+
+ it "prepends to an existing empty key" do
+ subject["foo"] = ""
+ subject.prepend "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ it "prepends to a non-existant key" do
+ subject.prepend "foo", "1"
+ expect(subject["foo"]).to eq("1")
+ end
+
+ # NOTE: this may be a wrong behavior; we should probably reject objects that
+ # do not respond to #to_str. For now this documents existing behavior.
+ it "coerces a value to a string" do
+ subject.prepend "foo", 42
+ expect(subject["foo"]).to eq("42")
+ end
+ end
+
+ describe "#append_path" do
+ it "appends to a path" do
+ subject.append_path "FOO", "/usr/bin"
+ expect(subject["FOO"]).to eq("/usr/bin")
+
+ subject.append_path "FOO", "/bin"
+ expect(subject["FOO"]).to eq("/usr/bin#{File::PATH_SEPARATOR}/bin")
+ end
+ end
+
+ describe "#prepend_path" do
+ it "prepends to a path" do
+ subject.prepend_path "FOO", "/usr/bin"
+ expect(subject["FOO"]).to eq("/usr/bin")
+
+ subject.prepend_path "FOO", "/bin"
+ expect(subject["FOO"]).to eq("/bin#{File::PATH_SEPARATOR}/usr/bin")
+ end
+ end
+
+ describe "#compiler" do
+ it "allows switching compilers" do
+ [:clang, :gcc_4_2, :gcc_4_0].each do |compiler|
+ subject.public_send(compiler)
+ expect(subject.compiler).to eq(compiler)
+ end
+ end
+ end
+
+ example "deparallelize_block_form_restores_makeflags" do
+ subject["MAKEFLAGS"] = "-j4"
+
+ subject.deparallelize do
+ expect(subject["MAKEFLAGS"]).to be nil
+ end
+
+ expect(subject["MAKEFLAGS"]).to eq("-j4")
+ end
+end
+
+describe Stdenv do
+ include_examples EnvActivation
+end
+
+describe Superenv do
+ include_examples EnvActivation
+
+ it "initializes deps" do
+ expect(subject.deps).to eq([])
+ expect(subject.keg_only_deps).to eq([])
+ end
+
+ describe "#cxx11" do
+ it "raises an error when the compiler isn't supported" do
+ %w[gcc gcc-4.7].each do |compiler|
+ subject["HOMEBREW_CC"] = compiler
+
+ expect { subject.cxx11 }
+ .to raise_error(/The selected compiler doesn't support C\+\+11:/)
+
+ expect(subject["HOMEBREW_CCCFG"]).to be nil
+ end
+ end
+
+ it "supports gcc-5" do
+ subject["HOMEBREW_CC"] = "gcc-5"
+ subject.cxx11
+ expect(subject["HOMEBREW_CCCFG"]).to include("x")
+ end
+
+ example "supports gcc-6" do
+ subject["HOMEBREW_CC"] = "gcc-6"
+ subject.cxx11
+ expect(subject["HOMEBREW_CCCFG"]).to include("x")
+ end
+
+ it "supports clang" do
+ subject["HOMEBREW_CC"] = "clang"
+ subject.cxx11
+ expect(subject["HOMEBREW_CCCFG"]).to include("x")
+ expect(subject["HOMEBREW_CCCFG"]).to include("g")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/ENV_test.rb b/Library/Homebrew/test/ENV_test.rb
deleted file mode 100644
index dd6025084..000000000
--- a/Library/Homebrew/test/ENV_test.rb
+++ /dev/null
@@ -1,201 +0,0 @@
-require "testing_env"
-require "extend/ENV"
-require "testing_env"
-
-class IntegrationCommandTestEnv < IntegrationCommandTestCase
- def test_env
- assert_match(/CMAKE_PREFIX_PATH="#{Regexp.escape(HOMEBREW_PREFIX)}[:"]/,
- cmd("--env"))
- end
-
- def test_env_fish
- assert_match(/set [-]gx CMAKE_PREFIX_PATH "#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/,
- cmd("--env", "--shell=fish"))
- end
-
- def test_env_csh
- assert_match(/setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)};/,
- cmd("--env", "--shell=tcsh"))
- end
-
- def test_env_bash
- assert_match(/export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/,
- cmd("--env", "--shell=bash"))
- end
-
- def test_env_plain
- assert_match(/CMAKE_PREFIX_PATH: #{Regexp.quote(HOMEBREW_PREFIX)}/,
- cmd("--env", "--plain"))
- end
-end
-
-module SharedEnvTests
- def setup
- @env = {}.extend(EnvActivation)
- end
-
- def test_switching_compilers
- @env.clang
- assert_nil @env["LD"]
- assert_equal @env["OBJC"], @env["CC"]
- end
-
- def test_with_build_environment_restores_env
- before = @env.dup
- @env.with_build_environment do
- @env["foo"] = "bar"
- end
- assert_nil @env["foo"]
- assert_equal before, @env
- end
-
- def test_with_build_environment_ensures_env_restored
- before = @env.dup
- begin
- @env.with_build_environment do
- @env["foo"] = "bar"
- raise Exception
- end
- rescue Exception
- end
- assert_nil @env["foo"]
- assert_equal before, @env
- end
-
- def test_with_build_environment_returns_block_value
- assert_equal 1, @env.with_build_environment { 1 }
- end
-
- def test_with_build_environment_does_not_mutate_interface
- expected = @env.methods
- @env.with_build_environment { assert_equal expected, @env.methods }
- assert_equal expected, @env.methods
- end
-
- def test_append_existing_key
- @env["foo"] = "bar"
- @env.append "foo", "1"
- assert_equal "bar 1", @env["foo"]
- end
-
- def test_append_existing_key_empty
- @env["foo"] = ""
- @env.append "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- def test_append_missing_key
- @env.append "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- def test_prepend_existing_key
- @env["foo"] = "bar"
- @env.prepend "foo", "1"
- assert_equal "1 bar", @env["foo"]
- end
-
- def test_prepend_existing_key_empty
- @env["foo"] = ""
- @env.prepend "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- def test_prepend_missing_key
- @env.prepend "foo", "1"
- assert_equal "1", @env["foo"]
- end
-
- # NOTE: this may be a wrong behavior; we should probably reject objects that
- # do not respond to #to_str. For now this documents existing behavior.
- def test_append_coerces_value_to_string
- @env.append "foo", 42
- assert_equal "42", @env["foo"]
- end
-
- def test_prepend_coerces_value_to_string
- @env.prepend "foo", 42
- assert_equal "42", @env["foo"]
- end
-
- def test_append_path
- @env.append_path "FOO", "/usr/bin"
- assert_equal "/usr/bin", @env["FOO"]
- @env.append_path "FOO", "/bin"
- assert_equal "/usr/bin#{File::PATH_SEPARATOR}/bin", @env["FOO"]
- end
-
- def test_prepend_path
- @env.prepend_path "FOO", "/usr/bin"
- assert_equal "/usr/bin", @env["FOO"]
- @env.prepend_path "FOO", "/bin"
- assert_equal "/bin#{File::PATH_SEPARATOR}/usr/bin", @env["FOO"]
- end
-
- def test_switching_compilers_updates_compiler
- [:clang, :gcc_4_2, :gcc_4_0].each do |compiler|
- @env.send(compiler)
- assert_equal compiler, @env.compiler
- end
- end
-
- def test_deparallelize_block_form_restores_makeflags
- @env["MAKEFLAGS"] = "-j4"
- @env.deparallelize do
- assert_nil @env["MAKEFLAGS"]
- end
- assert_equal "-j4", @env["MAKEFLAGS"]
- end
-end
-
-class StdenvTests < Homebrew::TestCase
- include SharedEnvTests
-
- def setup
- super
- @env.extend(Stdenv)
- end
-end
-
-class SuperenvTests < Homebrew::TestCase
- include SharedEnvTests
-
- def setup
- super
- @env.extend(Superenv)
- end
-
- def test_initializes_deps
- assert_equal [], @env.deps
- assert_equal [], @env.keg_only_deps
- end
-
- def test_unsupported_cxx11
- %w[gcc gcc-4.7].each do |compiler|
- @env["HOMEBREW_CC"] = compiler
- assert_raises do
- @env.cxx11
- end
- refute_match "x", @env["HOMEBREW_CCCFG"]
- end
- end
-
- def test_supported_cxx11_gcc_5
- @env["HOMEBREW_CC"] = "gcc-5"
- @env.cxx11
- assert_match "x", @env["HOMEBREW_CCCFG"]
- end
-
- def test_supported_cxx11_gcc_6
- @env["HOMEBREW_CC"] = "gcc-6"
- @env.cxx11
- assert_match "x", @env["HOMEBREW_CCCFG"]
- end
-
- def test_supported_cxx11_clang
- @env["HOMEBREW_CC"] = "clang"
- @env.cxx11
- assert_match "x", @env["HOMEBREW_CCCFG"]
- assert_match "g", @env["HOMEBREW_CCCFG"]
- end
-end
diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile
index a7e9eb834..25c8ce7ec 100644
--- a/Library/Homebrew/test/Gemfile
+++ b/Library/Homebrew/test/Gemfile
@@ -1,20 +1,14 @@
source "https://rubygems.org"
-gem "mocha", "~> 1.1"
-gem "minitest", "~> 5.3"
-gem "rake", "~> 10.3"
-gem "parallel_tests", "~> 2.9"
+gem "mocha"
+gem "minitest"
+gem "minitest-reporters"
+gem "parallel_tests"
+gem "rspec"
+gem "rspec-its", require: false
+gem "rspec-wait", require: false
group :coverage do
- # This is SimpleCov v0.12.0 with two fixes merged on top, that finally resolve
- # all issues with parallel tests, uncovered files, and tracked files. Switch
- # back to stable as soon as v0.12.1 or v0.13.0 is released. For details, see:
- # - https://github.com/colszowka/simplecov/pull/513
- # - https://github.com/colszowka/simplecov/pull/520
- gem "simplecov", "0.12.0",
- git: "https://github.com/colszowka/simplecov.git",
- branch: "master",
- ref: "83d8031ddde0927f87ef9327200a98583ca18d77",
- require: false
+ gem "simplecov", require: false
gem "codecov", require: false
end
diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock
index aa4800f34..fba45d77b 100644
--- a/Library/Homebrew/test/Gemfile.lock
+++ b/Library/Homebrew/test/Gemfile.lock
@@ -1,31 +1,50 @@
-GIT
- remote: https://github.com/colszowka/simplecov.git
- revision: 83d8031ddde0927f87ef9327200a98583ca18d77
- ref: 83d8031ddde0927f87ef9327200a98583ca18d77
- branch: master
- specs:
- simplecov (0.12.0)
- docile (~> 1.1.0)
- json (>= 1.8, < 3)
- simplecov-html (~> 0.10.0)
-
GEM
remote: https://rubygems.org/
specs:
- codecov (0.1.6)
+ ansi (1.5.0)
+ builder (3.2.3)
+ codecov (0.1.9)
json
simplecov
url
+ diff-lcs (1.3)
docile (1.1.5)
- json (2.0.2)
+ json (2.0.3)
metaclass (0.0.4)
- minitest (5.9.1)
+ minitest (5.10.1)
+ minitest-reporters (1.1.14)
+ ansi
+ builder
+ minitest (>= 5.0)
+ ruby-progressbar
mocha (1.2.1)
metaclass (~> 0.0.1)
- parallel (1.9.0)
- parallel_tests (2.10.0)
+ parallel (1.10.0)
+ parallel_tests (2.13.0)
parallel
- rake (10.5.0)
+ rspec (3.5.0)
+ rspec-core (~> 3.5.0)
+ rspec-expectations (~> 3.5.0)
+ rspec-mocks (~> 3.5.0)
+ rspec-core (3.5.4)
+ rspec-support (~> 3.5.0)
+ rspec-expectations (3.5.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.5.0)
+ rspec-its (1.2.0)
+ rspec-core (>= 3.0.0)
+ rspec-expectations (>= 3.0.0)
+ rspec-mocks (3.5.0)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.5.0)
+ rspec-support (3.5.0)
+ rspec-wait (0.0.9)
+ rspec (>= 3, < 4)
+ ruby-progressbar (1.8.1)
+ simplecov (0.13.0)
+ docile (~> 1.1.0)
+ json (>= 1.8, < 3)
+ simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
url (0.3.2)
@@ -34,11 +53,14 @@ PLATFORMS
DEPENDENCIES
codecov
- minitest (~> 5.3)
- mocha (~> 1.1)
- parallel_tests (~> 2.9)
- rake (~> 10.3)
- simplecov (= 0.12.0)!
+ minitest
+ minitest-reporters
+ mocha
+ parallel_tests
+ rspec
+ rspec-its
+ rspec-wait
+ simplecov
BUNDLED WITH
- 1.13.6
+ 1.14.3
diff --git a/Library/Homebrew/test/analytics_test.rb b/Library/Homebrew/test/analytics_test.rb
deleted file mode 100644
index 37040f3cd..000000000
--- a/Library/Homebrew/test/analytics_test.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestAnalytics < IntegrationCommandTestCase
- def test_analytics
- HOMEBREW_REPOSITORY.cd do
- shutup do
- system "git", "init"
- end
- end
-
- assert_match "Analytics is disabled (by HOMEBREW_NO_ANALYTICS)",
- cmd("analytics", "HOMEBREW_NO_ANALYTICS" => "1")
-
- cmd("analytics", "off")
- assert_match "Analytics is disabled",
- cmd("analytics", "HOMEBREW_NO_ANALYTICS" => nil)
-
- cmd("analytics", "on")
- assert_match "Analytics is enabled", cmd("analytics",
- "HOMEBREW_NO_ANALYTICS" => nil)
-
- assert_match "Invalid usage", cmd_fail("analytics", "on", "off")
- assert_match "Invalid usage", cmd_fail("analytics", "testball")
- cmd("analytics", "regenerate-uuid")
- end
-end
diff --git a/Library/Homebrew/test/audit_test.rb b/Library/Homebrew/test/audit_test.rb
index dace4dc2b..f4b7cae4a 100644
--- a/Library/Homebrew/test/audit_test.rb
+++ b/Library/Homebrew/test/audit_test.rb
@@ -6,13 +6,10 @@ require "dev-cmd/audit"
class FormulaTextTests < Homebrew::TestCase
def setup
+ super
@dir = mktmpdir
end
- def teardown
- FileUtils.rm_rf @dir
- end
-
def formula_text(name, body = nil, options = {})
path = Pathname.new "#{@dir}/#{name}.rb"
path.open("w") do |f|
@@ -58,13 +55,10 @@ end
class FormulaAuditorTests < Homebrew::TestCase
def setup
+ super
@dir = mktmpdir
end
- def teardown
- FileUtils.rm_rf @dir
- end
-
def formula_auditor(name, text, options = {})
path = Pathname.new "#{@dir}/#{name}.rb"
path.open("w") do |f|
@@ -249,7 +243,7 @@ class FormulaAuditorTests < Homebrew::TestCase
needs_compat
require "compat/formula_specialties"
- ARGV.stubs(:homebrew_developer?).returns false
+ ENV.delete("HOMEBREW_DEVELOPER")
fa = shutup do
formula_auditor "foo", <<-EOS.undent
class Foo < GithubGistFormula
@@ -266,7 +260,7 @@ class FormulaAuditorTests < Homebrew::TestCase
needs_compat
require "compat/formula_specialties"
- ARGV.stubs(:homebrew_developer?).returns false
+ ENV.delete("HOMEBREW_DEVELOPER")
fa = formula_auditor "foo", <<-EOS.undent
class Foo < ScriptFileFormula
url "http://example.com/foo-1.0.tgz"
@@ -281,7 +275,7 @@ class FormulaAuditorTests < Homebrew::TestCase
needs_compat
require "compat/formula_specialties"
- ARGV.stubs(:homebrew_developer?).returns false
+ ENV.delete("HOMEBREW_DEVELOPER")
fa = formula_auditor "foo", <<-EOS.undent
class Foo < AmazonWebServicesFormula
url "http://example.com/foo-1.0.tgz"
@@ -367,13 +361,10 @@ class FormulaAuditorTests < Homebrew::TestCase
end
EOS
- original_value = ENV["HOMEBREW_NO_GITHUB_API"]
ENV["HOMEBREW_NO_GITHUB_API"] = "1"
fa.audit_github_repository
assert_equal [], fa.problems
- ensure
- ENV["HOMEBREW_NO_GITHUB_API"] = original_value
end
def test_audit_caveats
@@ -428,9 +419,8 @@ class FormulaAuditorTests < Homebrew::TestCase
EOS
fa.audit_homepage
- assert_equal ["The homepage should start with http or https " \
- "(URL is #{fa.formula.homepage}).", "The homepage #{fa.formula.homepage} is not reachable " \
- "(HTTP status code 000)"], fa.problems
+ assert_equal ["The homepage should start with http or https (URL is #{fa.formula.homepage})."],
+ fa.problems
formula_homepages = {
"bar" => "http://www.freedesktop.org/wiki/bar",
@@ -440,6 +430,10 @@ class FormulaAuditorTests < Homebrew::TestCase
"corge" => "http://savannah.nongnu.org/corge",
"grault" => "http://grault.github.io/",
"garply" => "http://www.gnome.org/garply",
+ "sf1" => "http://foo.sourceforge.net/",
+ "sf2" => "http://foo.sourceforge.net",
+ "sf3" => "http://foo.sf.net/",
+ "sf4" => "http://foo.sourceforge.io/",
"waldo" => "http://www.gnu.org/waldo",
}
@@ -464,9 +458,45 @@ class FormulaAuditorTests < Homebrew::TestCase
end
elsif homepage =~ %r{https:\/\/code\.google\.com}
assert_match "#{homepage} should end with a slash", fa.problems.first
+ elsif homepage =~ /foo\.(sf|sourceforge)\.net/
+ assert_match "#{homepage} should be `https://foo.sourceforge.io/`", fa.problems.first
else
assert_match "Please use https:// for #{homepage}", fa.problems.first
end
end
end
+
+ def test_audit_xcodebuild_suggests_symroot
+ fa = formula_auditor "foo", <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+
+ def install
+ xcodebuild "-project", "meow.xcodeproject"
+ end
+ end
+ EOS
+
+ fa.audit_text
+
+ assert_match 'xcodebuild should be passed an explicit "SYMROOT"', fa.problems.first
+ end
+
+ def test_audit_bare_xcodebuild_suggests_symroot_also
+ fa = formula_auditor "foo", <<-EOS.undent
+ class Foo < Formula
+ url "http://example.com/foo-1.0.tgz"
+ homepage "http://example.com"
+
+ def install
+ xcodebuild
+ end
+ end
+ EOS
+
+ fa.audit_text
+
+ assert_match 'xcodebuild should be passed an explicit "SYMROOT"', fa.problems.first
+ end
end
diff --git a/Library/Homebrew/test/bash_spec.rb b/Library/Homebrew/test/bash_spec.rb
new file mode 100644
index 000000000..1b0f15066
--- /dev/null
+++ b/Library/Homebrew/test/bash_spec.rb
@@ -0,0 +1,52 @@
+require "open3"
+
+RSpec::Matchers.define :have_valid_bash_syntax do
+ match do |file|
+ stdout, stderr, status = Open3.capture3("/bin/bash", "-n", file)
+
+ @actual = [file, stderr]
+
+ stdout.empty? && status.success?
+ end
+
+ failure_message do |(file, stderr)|
+ "expected that #{file} is a valid Bash file:\n#{stderr}"
+ end
+end
+
+describe "Bash" do
+ context "brew" do
+ subject { HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew" }
+ it { is_expected.to have_valid_bash_syntax }
+ end
+
+ context "every `.sh` file" do
+ it "has valid bash syntax" do
+ Pathname.glob("#{HOMEBREW_LIBRARY_PATH}/**/*.sh").each do |path|
+ relative_path = path.relative_path_from(HOMEBREW_LIBRARY_PATH)
+ next if relative_path.to_s.start_with?("shims/", "test/", "vendor/")
+
+ expect(path).to have_valid_bash_syntax
+ end
+ end
+ end
+
+ context "Bash completion" do
+ subject { HOMEBREW_LIBRARY_PATH.parent.parent/"completions/bash/brew" }
+ it { is_expected.to have_valid_bash_syntax }
+ end
+
+ context "every shim script" do
+ it "has valid bash syntax" do
+ # These have no file extension, but can be identified by their shebang.
+ (HOMEBREW_LIBRARY_PATH/"shims").find do |path|
+ next if path.directory?
+ next if path.symlink?
+ next unless path.executable?
+ next unless path.read(12) == "#!/bin/bash\n"
+
+ expect(path).to have_valid_bash_syntax
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/bash_test.rb b/Library/Homebrew/test/bash_test.rb
deleted file mode 100644
index 671ab5ec8..000000000
--- a/Library/Homebrew/test/bash_test.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require "testing_env"
-
-class BashTests < Homebrew::TestCase
- def assert_valid_bash_syntax(file)
- return unless file.exist?
- output = Utils.popen_read("/bin/bash -n #{file} 2>&1")
- assert $?.success?, output
- end
-
- def test_bin_brew
- assert_valid_bash_syntax HOMEBREW_LIBRARY_PATH.parent.parent/"bin/brew"
- end
-
- def test_bash_code
- Pathname.glob("#{HOMEBREW_LIBRARY_PATH}/**/*.sh").each do |pn|
- pn_relative = pn.relative_path_from(HOMEBREW_LIBRARY_PATH)
- next if pn_relative.to_s.start_with?("shims/", "test/", "vendor/")
- assert_valid_bash_syntax pn
- end
- end
-
- def test_bash_completion
- script = HOMEBREW_LIBRARY_PATH.parent.parent/"completions/bash/brew"
- assert_valid_bash_syntax script
- end
-
- def test_bash_shims
- # These have no file extension, but can be identified by their shebang.
- (HOMEBREW_LIBRARY_PATH/"shims").find do |pn|
- next if pn.directory? || pn.symlink?
- next unless pn.executable? && pn.read(12) == "#!/bin/bash\n"
- assert_valid_bash_syntax pn
- end
- end
-end
diff --git a/Library/Homebrew/test/blacklist_spec.rb b/Library/Homebrew/test/blacklist_spec.rb
new file mode 100644
index 000000000..01882167d
--- /dev/null
+++ b/Library/Homebrew/test/blacklist_spec.rb
@@ -0,0 +1,115 @@
+require "blacklist"
+
+describe "Blacklist" do
+ matcher(:be_blacklisted) { match(&method(:blacklisted?)) }
+
+ context "rubygems" do
+ %w[gem rubygem rubygems].each do |s|
+ subject { s }
+
+ it { is_expected.to be_blacklisted }
+ end
+ end
+
+ context "latex" do
+ %w[latex tex tex-live texlive TexLive].each do |s|
+ subject { s }
+
+ it { is_expected.to be_blacklisted }
+ end
+ end
+
+ context "pip" do
+ subject { "pip" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "pil" do
+ subject { "pil" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "macruby" do
+ subject { "MacRuby" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "lzma" do
+ %w[lzma liblzma].each do |s|
+ subject { s }
+
+ it { is_expected.to be_blacklisted }
+ end
+ end
+
+ context "gtest" do
+ %w[gtest googletest google-test].each do |s|
+ subject { s }
+
+ it { is_expected.to be_blacklisted }
+ end
+ end
+
+ context "gmock" do
+ %w[gmock googlemock google-mock].each do |s|
+ subject { s }
+
+ it { is_expected.to be_blacklisted }
+ end
+ end
+
+ context "sshpass" do
+ subject { "sshpass" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "gsutil" do
+ subject { "gsutil" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "clojure" do
+ subject { "clojure" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "osmium" do
+ %w[osmium Osmium].each do |s|
+ subject { s }
+
+ it { is_expected.to be_blacklisted }
+ end
+ end
+
+ context "gfortran" do
+ subject { "gfortran" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "play" do
+ subject { "play" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "haskell-platform" do
+ subject { "haskell-platform" }
+
+ it { is_expected.to be_blacklisted }
+ end
+
+ context "xcode", :needs_macos do
+ %w[xcode Xcode].each do |s|
+ subject { s }
+
+ it { is_expected.to be_blacklisted }
+ end
+ end
+end
diff --git a/Library/Homebrew/test/blacklist_test.rb b/Library/Homebrew/test/blacklist_test.rb
deleted file mode 100644
index 585a35484..000000000
--- a/Library/Homebrew/test/blacklist_test.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-require "testing_env"
-require "blacklist"
-
-class BlacklistTests < Homebrew::TestCase
- def assert_blacklisted(s)
- assert blacklisted?(s), "'#{s}' should be blacklisted"
- end
-
- def test_rubygems
- %w[gem rubygem rubygems].each { |s| assert_blacklisted s }
- end
-
- def test_latex
- %w[latex tex tex-live texlive TexLive].each { |s| assert_blacklisted s }
- end
-
- def test_pip
- assert_blacklisted "pip"
- end
-
- def test_pil
- assert_blacklisted "pil"
- end
-
- def test_macruby
- assert_blacklisted "MacRuby"
- end
-
- def test_lzma
- %w[lzma liblzma].each { |s| assert_blacklisted s }
- end
-
- def test_gtest
- %w[gtest googletest google-test].each { |s| assert_blacklisted s }
- end
-
- def test_gmock
- %w[gmock googlemock google-mock].each { |s| assert_blacklisted s }
- end
-
- def test_sshpass
- assert_blacklisted "sshpass"
- end
-
- def test_gsutil
- assert_blacklisted "gsutil"
- end
-
- def test_clojure
- assert_blacklisted "clojure"
- end
-
- def test_osmium
- %w[osmium Osmium].each { |s| assert_blacklisted s }
- end
-
- def test_gfortran
- assert_blacklisted "gfortran"
- end
-
- def test_play
- assert_blacklisted "play"
- end
-
- def test_haskell_platform
- assert_blacklisted "haskell-platform"
- end
-end
diff --git a/Library/Homebrew/test/bottle_collector_test.rb b/Library/Homebrew/test/bottle_collector_test.rb
deleted file mode 100644
index d75e29ec8..000000000
--- a/Library/Homebrew/test/bottle_collector_test.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require "testing_env"
-require "utils/bottles"
-
-class BottleCollectorTests < Homebrew::TestCase
- def setup
- @collector = Utils::Bottles::Collector.new
- end
-
- def checksum_for(tag)
- @collector.fetch_checksum_for(tag)
- end
-
- def test_collector_returns_passed_tags
- @collector[:lion] = "foo"
- @collector[:mountain_lion] = "bar"
- assert_equal ["bar", :mountain_lion], checksum_for(:mountain_lion)
- end
-
- def test_collector_returns_when_empty
- assert_nil checksum_for(:foo)
- end
-
- def test_collector_returns_nil_for_no_match
- @collector[:lion] = "foo"
- assert_nil checksum_for(:foo)
- end
-
- def test_collector_returns_nil_for_no_match_when_later_tag_present
- @collector[:lion_or_later] = "foo"
- assert_nil checksum_for(:foo)
- end
-
- def test_collector_prefers_exact_matches
- @collector[:lion_or_later] = "foo"
- @collector[:mountain_lion] = "bar"
- assert_equal ["bar", :mountain_lion], checksum_for(:mountain_lion)
- end
-end
diff --git a/Library/Homebrew/test/bottle_hooks_spec.rb b/Library/Homebrew/test/bottle_hooks_spec.rb
new file mode 100644
index 000000000..05c6ea7f0
--- /dev/null
+++ b/Library/Homebrew/test/bottle_hooks_spec.rb
@@ -0,0 +1,50 @@
+require "formula_installer"
+require "hooks/bottles"
+
+RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle
+
+describe Homebrew::Hooks::Bottles do
+ subject { FormulaInstaller.new formula }
+
+ let(:formula) do
+ double(
+ bottle: nil,
+ local_bottle_path: nil,
+ bottle_disabled?: false,
+ some_random_method: true,
+ )
+ end
+
+ after(:each) do
+ described_class.reset_hooks
+ end
+
+ describe "#setup_formula_has_bottle" do
+ context "given a block which evaluates to true" do
+ before(:each) do
+ described_class.setup_formula_has_bottle(&:some_random_method)
+ end
+
+ it { is_expected.to pour_bottle }
+ end
+
+ context "given a block which evaluates to false" do
+ before(:each) do
+ described_class.setup_formula_has_bottle { |f| !f.some_random_method }
+ end
+
+ it { is_expected.not_to pour_bottle }
+ end
+ end
+
+ describe "#setup_pour_formula_bottle" do
+ before(:each) do
+ described_class.setup_formula_has_bottle { true }
+ described_class.setup_pour_formula_bottle(&:some_random_method)
+ end
+
+ it "does not raise an error" do
+ expect { subject.pour }.not_to raise_error
+ end
+ end
+end
diff --git a/Library/Homebrew/test/bottle_hooks_test.rb b/Library/Homebrew/test/bottle_hooks_test.rb
deleted file mode 100644
index 3535d80ef..000000000
--- a/Library/Homebrew/test/bottle_hooks_test.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require "testing_env"
-require "formula_installer"
-require "hooks/bottles"
-
-class BottleHookTests < Homebrew::TestCase
- class FormulaDouble
- def bottle; end
- def local_bottle_path; end
-
- def bottle_disabled?
- false
- end
-
- def some_random_method
- true
- end
- end
-
- def setup
- @fi = FormulaInstaller.new FormulaDouble.new
- end
-
- def test_has_bottle
- Homebrew::Hooks::Bottles.setup_formula_has_bottle(&:some_random_method)
- assert_predicate @fi, :pour_bottle?
- end
-
- def test_has_no_bottle
- Homebrew::Hooks::Bottles.setup_formula_has_bottle do |f|
- !f.some_random_method
- end
- refute_predicate @fi, :pour_bottle?
- end
-
- def test_pour_formula_bottle
- Homebrew::Hooks::Bottles.setup_formula_has_bottle do |_f|
- true
- end
-
- Homebrew::Hooks::Bottles.setup_pour_formula_bottle(&:some_random_method)
- @fi.pour
- end
-
- def teardown
- Homebrew::Hooks::Bottles.reset_hooks
- end
-end
diff --git a/Library/Homebrew/test/bottle_test.rb b/Library/Homebrew/test/bottle_test.rb
deleted file mode 100644
index c10746e09..000000000
--- a/Library/Homebrew/test/bottle_test.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestBottle < IntegrationCommandTestCase
- def test_bottle
- cmd("install", "--build-bottle", testball)
- assert_match "Formula not from core or any taps",
- cmd_fail("bottle", "--no-rebuild", testball)
-
- setup_test_formula "testball"
-
- # `brew bottle` should not fail with dead symlink
- # https://github.com/Homebrew/legacy-homebrew/issues/49007
- (HOMEBREW_CELLAR/"testball/0.1").cd do
- FileUtils.ln_s "not-exist", "symlink"
- end
- assert_match(/testball-0\.1.*\.bottle\.tar\.gz/,
- cmd_output("bottle", "--no-rebuild", "testball"))
- ensure
- FileUtils.rm_f Dir["testball-0.1*.bottle.tar.gz"]
- end
-end
diff --git a/Library/Homebrew/test/build_environment_spec.rb b/Library/Homebrew/test/build_environment_spec.rb
new file mode 100644
index 000000000..5a3cec452
--- /dev/null
+++ b/Library/Homebrew/test/build_environment_spec.rb
@@ -0,0 +1,66 @@
+require "build_environment"
+
+RSpec::Matchers.alias_matcher :use_userpaths, :be_userpaths
+
+describe BuildEnvironment do
+ let(:env) { described_class.new }
+
+ describe "#<<" do
+ it "returns itself" do
+ expect(env << :foo).to be env
+ end
+ end
+
+ describe "#merge" do
+ it "returns itself" do
+ expect(env.merge([])).to be env
+ end
+ end
+
+ describe "#std?" do
+ it "returns true if the environment contains :std" do
+ env << :std
+ expect(env).to be_std
+ end
+
+ it "returns false if the environment does not contain :std" do
+ expect(env).not_to be_std
+ end
+ end
+
+ describe "#userpaths?" do
+ it "returns true if the environment contains :userpaths" do
+ env << :userpaths
+ expect(env).to use_userpaths
+ end
+
+ it "returns false if the environment does not contain :userpaths" do
+ expect(env).not_to use_userpaths
+ end
+ end
+end
+
+describe BuildEnvironmentDSL do
+ subject { double.extend(described_class) }
+
+ context "single argument" do
+ before(:each) do
+ subject.instance_eval do
+ env :userpaths
+ end
+ end
+
+ its(:env) { is_expected.to use_userpaths }
+ end
+
+ context "multiple arguments" do
+ before(:each) do
+ subject.instance_eval do
+ env :userpaths, :std
+ end
+ end
+
+ its(:env) { is_expected.to be_std }
+ its(:env) { is_expected.to use_userpaths }
+ end
+end
diff --git a/Library/Homebrew/test/build_environment_test.rb b/Library/Homebrew/test/build_environment_test.rb
deleted file mode 100644
index 73a1c95f7..000000000
--- a/Library/Homebrew/test/build_environment_test.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require "testing_env"
-require "build_environment"
-
-class BuildEnvironmentTests < Homebrew::TestCase
- def setup
- @env = BuildEnvironment.new
- end
-
- def test_shovel_returns_self
- assert_same @env, @env << :foo
- end
-
- def test_merge_returns_self
- assert_same @env, @env.merge([])
- end
-
- def test_std?
- @env << :std
- assert_predicate @env, :std?
- end
-
- def test_userpaths?
- @env << :userpaths
- assert_predicate @env, :userpaths?
- end
-end
-
-class BuildEnvironmentDSLTests < Homebrew::TestCase
- def make_instance(&block)
- obj = Object.new.extend(BuildEnvironmentDSL)
- obj.instance_eval(&block)
- obj
- end
-
- def test_env_single_argument
- obj = make_instance { env :userpaths }
- assert_predicate obj.env, :userpaths?
- end
-
- def test_env_multiple_arguments
- obj = make_instance { env :userpaths, :std }
- assert_predicate obj.env, :userpaths?
- assert_predicate obj.env, :std?
- end
-end
diff --git a/Library/Homebrew/test/build_options_spec.rb b/Library/Homebrew/test/build_options_spec.rb
new file mode 100644
index 000000000..5acc12f30
--- /dev/null
+++ b/Library/Homebrew/test/build_options_spec.rb
@@ -0,0 +1,52 @@
+require "build_options"
+require "options"
+
+RSpec::Matchers.alias_matcher :be_built_with, :be_with
+RSpec::Matchers.alias_matcher :be_built_without, :be_without
+
+describe BuildOptions do
+ subject { described_class.new(args, opts) }
+ let(:bad_build) { described_class.new(bad_args, opts) }
+ let(:args) { Options.create(%w[--with-foo --with-bar --without-qux]) }
+ let(:opts) { Options.create(%w[--with-foo --with-bar --without-baz --without-qux]) }
+ let(:bad_args) { Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc]) }
+
+ specify "#include?" do
+ expect(subject).to include("with-foo")
+ expect(subject).not_to include("with-qux")
+ expect(subject).not_to include("--with-foo")
+ end
+
+ specify "#with?" do
+ expect(subject).to be_built_with("foo")
+ expect(subject).to be_built_with("bar")
+ expect(subject).to be_built_with("baz")
+ end
+
+ specify "#without?" do
+ expect(subject).to be_built_without("qux")
+ expect(subject).to be_built_without("xyz")
+ end
+
+ specify "#used_options" do
+ expect(subject.used_options).to include("--with-foo")
+ expect(subject.used_options).to include("--with-bar")
+ end
+
+ specify "#unused_options" do
+ expect(subject.unused_options).to include("--without-baz")
+ end
+
+ specify "#invalid_options" do
+ expect(subject.invalid_options).to be_empty
+ expect(bad_build.invalid_options).to include("--without-bas")
+ expect(bad_build.invalid_options).to include("--without-abc")
+ expect(bad_build.invalid_options).not_to include("--with-foo")
+ expect(bad_build.invalid_options).not_to include("--with-baz")
+ end
+
+ specify "#invalid_option_names" do
+ expect(subject.invalid_option_names).to be_empty
+ expect(bad_build.invalid_option_names).to eq(%w[--without-abc --without-bas])
+ end
+end
diff --git a/Library/Homebrew/test/build_options_test.rb b/Library/Homebrew/test/build_options_test.rb
deleted file mode 100644
index e460d25cc..000000000
--- a/Library/Homebrew/test/build_options_test.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require "testing_env"
-require "build_options"
-require "options"
-
-class BuildOptionsTests < Homebrew::TestCase
- def setup
- args = Options.create(%w[--with-foo --with-bar --without-qux])
- opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
- @build = BuildOptions.new(args, opts)
- bad_args = Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc])
- @bad_build = BuildOptions.new(bad_args, opts)
- end
-
- def test_include
- assert_includes @build, "with-foo"
- refute_includes @build, "with-qux"
- refute_includes @build, "--with-foo"
- end
-
- def test_with_without
- assert @build.with?("foo")
- assert @build.with?("bar")
- assert @build.with?("baz")
- assert @build.without?("qux")
- assert @build.without?("xyz")
- end
-
- def test_used_options
- assert_includes @build.used_options, "--with-foo"
- assert_includes @build.used_options, "--with-bar"
- end
-
- def test_unused_options
- assert_includes @build.unused_options, "--without-baz"
- end
-
- def test_invalid_options
- assert_empty @build.invalid_options
- assert_includes @bad_build.invalid_options, "--without-bas"
- assert_includes @bad_build.invalid_options, "--without-abc"
- refute_includes @bad_build.invalid_options, "--with-foo"
- refute_includes @bad_build.invalid_options, "--with-baz"
- end
-
- def test_invalid_option_names
- assert_empty @build.invalid_option_names
- assert_equal @bad_build.invalid_option_names, %w[--without-abc --without-bas]
- end
-end
diff --git a/Library/Homebrew/test/bundle_test.rb b/Library/Homebrew/test/bundle_test.rb
deleted file mode 100644
index ae47977d8..000000000
--- a/Library/Homebrew/test/bundle_test.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestBundle < IntegrationCommandTestCase
- def test_bundle
- needs_test_cmd_taps
- setup_remote_tap("homebrew/bundle")
- HOMEBREW_REPOSITORY.cd do
- shutup do
- system "git", "init"
- system "git", "commit", "--allow-empty", "-m", "This is a test commit"
- end
- end
-
- mktmpdir do |path|
- FileUtils.touch "#{path}/Brewfile"
- Dir.chdir path do
- assert_equal "The Brewfile's dependencies are satisfied.",
- cmd("bundle", "check")
- end
- end
- end
-end
diff --git a/Library/Homebrew/test/cache_formula_test.rb b/Library/Homebrew/test/cache_formula_test.rb
deleted file mode 100644
index 6dcb6a745..000000000
--- a/Library/Homebrew/test/cache_formula_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCacheFormula < IntegrationCommandTestCase
- def test_cache_formula
- assert_match %r{#{HOMEBREW_CACHE}/testball-},
- cmd("--cache", testball)
- end
-end
diff --git a/Library/Homebrew/test/cache_test.rb b/Library/Homebrew/test/cache_test.rb
deleted file mode 100644
index 3a9e6b011..000000000
--- a/Library/Homebrew/test/cache_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCache < IntegrationCommandTestCase
- def test_cache
- assert_equal HOMEBREW_CACHE.to_s,
- cmd("--cache")
- end
-end
diff --git a/Library/Homebrew/test/cask_test.rb b/Library/Homebrew/test/cask_test.rb
deleted file mode 100644
index d5b81facb..000000000
--- a/Library/Homebrew/test/cask_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCask < IntegrationCommandTestCase
- def test_cask
- needs_test_cmd_taps
- needs_macos
- setup_remote_tap("caskroom/cask")
- cmd("cask", "list", "--caskroom=#{HOMEBREW_PREFIX}/Caskroom")
- end
-end
diff --git a/Library/Homebrew/test/cat_test.rb b/Library/Homebrew/test/cat_test.rb
deleted file mode 100644
index bb37b5fde..000000000
--- a/Library/Homebrew/test/cat_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCat < IntegrationCommandTestCase
- def test_cat
- formula_file = setup_test_formula "testball"
- assert_equal formula_file.read.chomp, cmd("cat", "testball")
- end
-end
diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb
new file mode 100644
index 000000000..d8be9dc52
--- /dev/null
+++ b/Library/Homebrew/test/caveats_spec.rb
@@ -0,0 +1,29 @@
+require "formula"
+require "caveats"
+
+describe Caveats do
+ subject { described_class.new(f) }
+ let(:f) { formula { url "foo-1.0" } }
+
+ specify "#f" do
+ expect(subject.f).to eq(f)
+ end
+
+ describe "#empty?" do
+ it "returns true if the Formula has no caveats" do
+ expect(subject).to be_empty
+ end
+
+ it "returns false if the Formula has caveats" do
+ f = formula do
+ url "foo-1.0"
+
+ def caveats
+ "something"
+ end
+ end
+
+ expect(described_class.new(f)).not_to be_empty
+ end
+ end
+end
diff --git a/Library/Homebrew/test/caveats_test.rb b/Library/Homebrew/test/caveats_test.rb
deleted file mode 100644
index 9eaac5792..000000000
--- a/Library/Homebrew/test/caveats_test.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require "testing_env"
-require "formula"
-require "caveats"
-
-class CaveatsTests < Homebrew::TestCase
- def setup
- @f = formula { url "foo-1.0" }
- @c = Caveats.new @f
- end
-
- def test_f
- assert_equal @f, @c.f
- end
-
- def test_empty?
- assert @c.empty?
-
- f = formula do
- url "foo-1.0"
-
- def caveats
- "something"
- end
- end
- c = Caveats.new f
-
- refute c.empty?
- end
-end
diff --git a/Library/Homebrew/test/cellar_formula_test.rb b/Library/Homebrew/test/cellar_formula_test.rb
deleted file mode 100644
index 38a934a7b..000000000
--- a/Library/Homebrew/test/cellar_formula_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCellarFormula < IntegrationCommandTestCase
- def test_cellar_formula
- assert_match "#{HOMEBREW_CELLAR}/testball",
- cmd("--cellar", testball)
- end
-end
diff --git a/Library/Homebrew/test/cellar_test.rb b/Library/Homebrew/test/cellar_test.rb
deleted file mode 100644
index 74d5389f8..000000000
--- a/Library/Homebrew/test/cellar_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCellar < IntegrationCommandTestCase
- def test_cellar
- assert_equal HOMEBREW_CELLAR.to_s,
- cmd("--cellar")
- end
-end
diff --git a/Library/Homebrew/test/checksum_spec.rb b/Library/Homebrew/test/checksum_spec.rb
new file mode 100644
index 000000000..acab348b7
--- /dev/null
+++ b/Library/Homebrew/test/checksum_spec.rb
@@ -0,0 +1,19 @@
+require "checksum"
+
+describe Checksum do
+ describe "#empty?" do
+ subject { described_class.new(:sha256, "") }
+ it { is_expected.to be_empty }
+ end
+
+ describe "#==" do
+ subject { described_class.new(:sha256, TEST_SHA256) }
+ let(:other) { described_class.new(:sha256, TEST_SHA256) }
+ let(:other_reversed) { described_class.new(:sha256, TEST_SHA256.reverse) }
+ let(:other_sha1) { described_class.new(:sha1, TEST_SHA1) }
+
+ it { is_expected.to eq(other) }
+ it { is_expected.not_to eq(other_reversed) }
+ it { is_expected.not_to eq(other_sha1) }
+ end
+end
diff --git a/Library/Homebrew/test/checksum_test.rb b/Library/Homebrew/test/checksum_test.rb
deleted file mode 100644
index 5505f6824..000000000
--- a/Library/Homebrew/test/checksum_test.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require "testing_env"
-require "checksum"
-
-class ChecksumTests < Homebrew::TestCase
- def test_empty?
- assert_empty Checksum.new(:sha256, "")
- end
-
- def test_equality
- a = Checksum.new(:sha256, TEST_SHA256)
- b = Checksum.new(:sha256, TEST_SHA256)
- assert_equal a, b
-
- a = Checksum.new(:sha256, TEST_SHA256)
- b = Checksum.new(:sha256, TEST_SHA256.reverse)
- refute_equal a, b
-
- a = Checksum.new(:sha1, TEST_SHA1)
- b = Checksum.new(:sha256, TEST_SHA256)
- refute_equal a, b
- end
-end
diff --git a/Library/Homebrew/test/checksum_verification_test.rb b/Library/Homebrew/test/checksum_verification_test.rb
index 9017b528d..4c674edd2 100644
--- a/Library/Homebrew/test/checksum_verification_test.rb
+++ b/Library/Homebrew/test/checksum_verification_test.rb
@@ -17,10 +17,6 @@ class ChecksumVerificationTests < Homebrew::TestCase
end
end
- def teardown
- @_f.clear_cache
- end
-
def test_good_sha256
formula do
sha256 TESTBALL_SHA256
diff --git a/Library/Homebrew/test/cleaner_test.rb b/Library/Homebrew/test/cleaner_test.rb
index ac108421c..05a91b90b 100644
--- a/Library/Homebrew/test/cleaner_test.rb
+++ b/Library/Homebrew/test/cleaner_test.rb
@@ -6,14 +6,11 @@ class CleanerTests < Homebrew::TestCase
include FileUtils
def setup
+ super
@f = formula("cleaner_test") { url "foo-1.0" }
@f.prefix.mkpath
end
- def teardown
- @f.rack.rmtree if @f.rack.exist?
- end
-
def test_clean_file
@f.bin.mkpath
@f.lib.mkpath
diff --git a/Library/Homebrew/test/cleanup_test.rb b/Library/Homebrew/test/cleanup_test.rb
index bb8e1cdc6..bc7a6713c 100644
--- a/Library/Homebrew/test/cleanup_test.rb
+++ b/Library/Homebrew/test/cleanup_test.rb
@@ -5,23 +5,16 @@ require "fileutils"
require "pathname"
require "testing_env"
-class IntegrationCommandTestCleanup < IntegrationCommandTestCase
- def test_cleanup
- (HOMEBREW_CACHE/"test").write "test"
- assert_match "#{HOMEBREW_CACHE}/test", cmd("cleanup", "--prune=all")
- end
-end
-
class CleanupTests < Homebrew::TestCase
def setup
+ super
@ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store"
FileUtils.touch @ds_store
end
def teardown
FileUtils.rm_f @ds_store
- ARGV.delete "--dry-run"
- ARGV.delete "--prune=all"
+ super
end
def test_cleanup
@@ -36,28 +29,40 @@ class CleanupTests < Homebrew::TestCase
end
def test_cleanup_formula
- f1 = Class.new(Testball) { version "0.1" }.new
- f2 = Class.new(Testball) { version "0.2" }.new
- f3 = Class.new(Testball) { version "0.3" }.new
+ f1 = Class.new(Testball) do
+ version "1.0"
+ end.new
+ f2 = Class.new(Testball) do
+ version "0.2"
+ version_scheme 1
+ end.new
+ f3 = Class.new(Testball) do
+ version "0.3"
+ version_scheme 1
+ end.new
+ f4 = Class.new(Testball) do
+ version "0.1"
+ version_scheme 2
+ end.new
shutup do
- f1.brew { f1.install }
- f2.brew { f2.install }
- f3.brew { f3.install }
+ [f1, f2, f3, f4].each do |f|
+ f.brew { f.install }
+ Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
+ end
end
assert_predicate f1, :installed?
assert_predicate f2, :installed?
assert_predicate f3, :installed?
+ assert_predicate f4, :installed?
shutup { Homebrew::Cleanup.cleanup_formula f3 }
refute_predicate f1, :installed?
refute_predicate f2, :installed?
assert_predicate f3, :installed?
- ensure
- [f1, f2, f3].each(&:clear_cache)
- f3.rack.rmtree
+ assert_predicate f4, :installed?
end
def test_cleanup_logs
diff --git a/Library/Homebrew/test/cmd/--cache_spec.rb b/Library/Homebrew/test/cmd/--cache_spec.rb
new file mode 100644
index 000000000..fb3c9cee6
--- /dev/null
+++ b/Library/Homebrew/test/cmd/--cache_spec.rb
@@ -0,0 +1,15 @@
+describe "brew --cache", :integration_test do
+ it "print the location of Homebrew's cache when no argument is given" do
+ expect { brew "--cache" }
+ .to output("#{HOMEBREW_CACHE}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "prints all cache files for a given Formula" do
+ expect { brew "--cache", testball }
+ .to output(%r{#{HOMEBREW_CACHE}/testball-}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/--cellar_spec.rb b/Library/Homebrew/test/cmd/--cellar_spec.rb
new file mode 100644
index 000000000..6c8d7dea6
--- /dev/null
+++ b/Library/Homebrew/test/cmd/--cellar_spec.rb
@@ -0,0 +1,15 @@
+describe "brew --cellar", :integration_test do
+ it "print the location of Homebrew's Cellar when no argument is given" do
+ expect { brew "--cellar" }
+ .to output("#{HOMEBREW_CELLAR}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "returns the Cellar subdirectory for a given Formula" do
+ expect { brew "--cellar", testball }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/--env_spec.rb b/Library/Homebrew/test/cmd/--env_spec.rb
new file mode 100644
index 000000000..7dd84132a
--- /dev/null
+++ b/Library/Homebrew/test/cmd/--env_spec.rb
@@ -0,0 +1,44 @@
+describe "brew --env", :integration_test do
+ it "prints the Homebrew build environment variables" do
+ expect { brew "--env" }
+ .to output(/CMAKE_PREFIX_PATH="#{Regexp.escape(HOMEBREW_PREFIX)}[:"]/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ describe "--shell=bash" do
+ it "prints the Homebrew build environment variables in Bash syntax" do
+ expect { brew "--env", "--shell=bash" }
+ .to output(/export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+
+ describe "--shell=fish" do
+ it "prints the Homebrew build environment variables in Fish syntax" do
+ expect { brew "--env", "--shell=fish" }
+ .to output(/set [-]gx CMAKE_PREFIX_PATH "#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+
+ describe "--shell=tcsh" do
+ it "prints the Homebrew build environment variables in Tcsh syntax" do
+ expect { brew "--env", "--shell=tcsh" }
+ .to output(/setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)};/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+
+ describe "--plain" do
+ it "prints the Homebrew build environment variables without quotes" do
+ expect { brew "--env", "--plain" }
+ .to output(/CMAKE_PREFIX_PATH: #{Regexp.quote(HOMEBREW_PREFIX)}/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/--prefix_spec.rb b/Library/Homebrew/test/cmd/--prefix_spec.rb
new file mode 100644
index 000000000..80ef73a97
--- /dev/null
+++ b/Library/Homebrew/test/cmd/--prefix_spec.rb
@@ -0,0 +1,15 @@
+describe "brew --prefix", :integration_test do
+ it "prints the Homebrew prefix when no argument is given" do
+ expect { brew "--prefix" }
+ .to output("#{HOMEBREW_PREFIX}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "prints a given Formula's prefix" do
+ expect { brew "--prefix", testball }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/--repository_spec.rb b/Library/Homebrew/test/cmd/--repository_spec.rb
new file mode 100644
index 000000000..d3e531f7b
--- /dev/null
+++ b/Library/Homebrew/test/cmd/--repository_spec.rb
@@ -0,0 +1,15 @@
+describe "brew --repository", :integration_test do
+ it "prints the path of the Homebrew repository" do
+ expect { brew "--repository" }
+ .to output("#{HOMEBREW_REPOSITORY}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "prints the path of a given Tap" do
+ expect { brew "--repository", "foo/bar" }
+ .to output("#{HOMEBREW_LIBRARY}/Taps/foo/homebrew-bar\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/--version_spec.rb b/Library/Homebrew/test/cmd/--version_spec.rb
new file mode 100644
index 000000000..8992629d7
--- /dev/null
+++ b/Library/Homebrew/test/cmd/--version_spec.rb
@@ -0,0 +1,8 @@
+describe "brew --version", :integration_test do
+ it "prints the Homebrew version" do
+ expect { brew "--version" }
+ .to output(/^Homebrew #{Regexp.escape(HOMEBREW_VERSION.to_s)}\n/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/analytics_spec.rb b/Library/Homebrew/test/cmd/analytics_spec.rb
new file mode 100644
index 000000000..aed3a7a33
--- /dev/null
+++ b/Library/Homebrew/test/cmd/analytics_spec.rb
@@ -0,0 +1,52 @@
+describe "brew analytics", :integration_test do
+ before(:each) do
+ HOMEBREW_REPOSITORY.cd do
+ shutup do
+ system "git", "init"
+ end
+ end
+ end
+
+ it "is disabled when HOMEBREW_NO_ANALYTICS is set" do
+ expect { brew "analytics", "HOMEBREW_NO_ANALYTICS" => "1" }
+ .to output(/Analytics is disabled \(by HOMEBREW_NO_ANALYTICS\)/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ context "when HOMEBREW_NO_ANALYTICS is unset" do
+ it "is disabled after running `brew analytics off`" do
+ brew "analytics", "off"
+ expect { brew "analytics", "HOMEBREW_NO_ANALYTICS" => nil }
+ .to output(/Analytics is disabled/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "is enabled after running `brew analytics on`" do
+ brew "analytics", "on"
+ expect { brew "analytics", "HOMEBREW_NO_ANALYTICS" => nil }
+ .to output(/Analytics is enabled/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+
+ it "fails when running `brew analytics on off`" do
+ expect { brew "analytics", "on", "off" }
+ .to output(/Invalid usage/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fails when running `brew analytics testball`" do
+ expect { brew "analytics", "testball" }
+ .to output(/Invalid usage/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "can generate a new UUID" do
+ expect { brew "analytics", "regenerate-uuid" }.to be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/bundle_spec.rb b/Library/Homebrew/test/cmd/bundle_spec.rb
new file mode 100644
index 000000000..755f9ab3d
--- /dev/null
+++ b/Library/Homebrew/test/cmd/bundle_spec.rb
@@ -0,0 +1,24 @@
+describe "brew bundle", :integration_test, :needs_test_cmd_taps do
+ describe "check" do
+ it "checks if a Brewfile's dependencies are satisfied" do
+ setup_remote_tap "homebrew/bundle"
+
+ HOMEBREW_REPOSITORY.cd do
+ shutup do
+ system "git", "init"
+ system "git", "commit", "--allow-empty", "-m", "This is a test commit"
+ end
+ end
+
+ Dir.mktmpdir do |path|
+ FileUtils.touch "#{path}/Brewfile"
+ Dir.chdir path do
+ expect { brew "bundle", "check" }
+ .to output("The Brewfile's dependencies are satisfied.\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/cask_spec.rb b/Library/Homebrew/test/cmd/cask_spec.rb
new file mode 100644
index 000000000..e46843cab
--- /dev/null
+++ b/Library/Homebrew/test/cmd/cask_spec.rb
@@ -0,0 +1,8 @@
+describe "brew cask", :integration_test, :needs_macos, :needs_official_cmd_taps do
+ describe "list" do
+ it "returns a list of installed Casks" do
+ setup_remote_tap("caskroom/cask")
+ expect { brew "cask", "list" }.to be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/cat_spec.rb b/Library/Homebrew/test/cmd/cat_spec.rb
new file mode 100644
index 000000000..8c230abee
--- /dev/null
+++ b/Library/Homebrew/test/cmd/cat_spec.rb
@@ -0,0 +1,11 @@
+describe "brew cat", :integration_test do
+ it "prints the content of a given Formula" do
+ formula_file = setup_test_formula "testball"
+ content = formula_file.read
+
+ expect { brew "cat", "testball" }
+ .to output(content).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/cleanup_spec.rb b/Library/Homebrew/test/cmd/cleanup_spec.rb
new file mode 100644
index 000000000..9e2cf493f
--- /dev/null
+++ b/Library/Homebrew/test/cmd/cleanup_spec.rb
@@ -0,0 +1,12 @@
+describe "brew cleanup", :integration_test do
+ describe "--prune=all" do
+ it "removes all files in Homebrew's cache" do
+ (HOMEBREW_CACHE/"test").write "test"
+
+ expect { brew "cleanup", "--prune=all" }
+ .to output(%r{#{Regexp.escape(HOMEBREW_CACHE)}/test}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/command_spec.rb b/Library/Homebrew/test/cmd/command_spec.rb
new file mode 100644
index 000000000..5d6a67b70
--- /dev/null
+++ b/Library/Homebrew/test/cmd/command_spec.rb
@@ -0,0 +1,13 @@
+describe "brew command", :integration_test do
+ it "returns the file for a given command" do
+ expect { brew "command", "info" }
+ .to output(%r{#{Regexp.escape(HOMEBREW_LIBRARY_PATH)}/cmd/info.rb}).to_stdout
+ .and be_a_success
+ end
+
+ it "fails when the given command is unknown" do
+ expect { brew "command", "does-not-exist" }
+ .to output(/Unknown command/).to_stderr
+ .and be_a_failure
+ end
+end
diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb
new file mode 100644
index 000000000..f42072956
--- /dev/null
+++ b/Library/Homebrew/test/cmd/commands_spec.rb
@@ -0,0 +1,7 @@
+describe "brew commands", :integration_test do
+ it "prints a list of all available commands" do
+ expect { brew "commands" }
+ .to output(/Built-in commands/).to_stdout
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/config_spec.rb b/Library/Homebrew/test/cmd/config_spec.rb
new file mode 100644
index 000000000..7687fcdc7
--- /dev/null
+++ b/Library/Homebrew/test/cmd/config_spec.rb
@@ -0,0 +1,8 @@
+describe "brew config", :integration_test do
+ it "prints information about the current Homebrew configuration" do
+ expect { brew "config" }
+ .to output(/HOMEBREW_VERSION: #{HOMEBREW_VERSION}/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/custom-external-command_spec.rb b/Library/Homebrew/test/cmd/custom-external-command_spec.rb
new file mode 100644
index 000000000..8ccc21fa7
--- /dev/null
+++ b/Library/Homebrew/test/cmd/custom-external-command_spec.rb
@@ -0,0 +1,21 @@
+describe "brew custom-external-command", :integration_test do
+ it "is supported" do
+ Dir.mktmpdir do |path|
+ path = Pathname.new(path)
+
+ cmd = "custom-external-command-#{rand}"
+ file = path/"brew-#{cmd}"
+
+ file.write <<-EOS.undent
+ #!/bin/sh
+ echo 'I am #{cmd}.'
+ EOS
+ FileUtils.chmod "+x", file
+
+ expect { brew cmd, "PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}" }
+ .to output("I am #{cmd}.\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/desc_spec.rb b/Library/Homebrew/test/cmd/desc_spec.rb
new file mode 100644
index 000000000..b09819d81
--- /dev/null
+++ b/Library/Homebrew/test/cmd/desc_spec.rb
@@ -0,0 +1,40 @@
+describe "brew desc", :integration_test do
+ let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" }
+
+ it "shows a given Formula's description" do
+ setup_test_formula "testball"
+
+ expect { brew "desc", "testball" }
+ .to output("testball: Some test\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "fails when both --search and --name are specified" do
+ expect { brew "desc", "--search", "--name" }
+ .to output(/Pick one, and only one/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ describe "--search" do
+ it "fails when no search term is given" do
+ expect { brew "desc", "--search" }
+ .to output(/You must provide a search term/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+ end
+
+ describe "--description" do
+ it "creates a description cache" do
+ expect(desc_cache).not_to exist
+
+ shutup do
+ expect { brew "desc", "--description", "testball" }.to be_a_success
+ end
+
+ expect(desc_cache).to exist
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/doctor_spec.rb b/Library/Homebrew/test/cmd/doctor_spec.rb
new file mode 100644
index 000000000..530adcd98
--- /dev/null
+++ b/Library/Homebrew/test/cmd/doctor_spec.rb
@@ -0,0 +1,6 @@
+describe "brew doctor", :integration_test do
+ specify "check_integration_test" do
+ expect { brew "doctor", "check_integration_test" }
+ .to output(/This is an integration test/).to_stderr
+ end
+end
diff --git a/Library/Homebrew/test/cmd/fetch_spec.rb b/Library/Homebrew/test/cmd/fetch_spec.rb
new file mode 100644
index 000000000..111d9f85c
--- /dev/null
+++ b/Library/Homebrew/test/cmd/fetch_spec.rb
@@ -0,0 +1,13 @@
+describe "brew fetch", :integration_test do
+ it "downloads the Formula's URL" do
+ setup_test_formula "testball"
+
+ expect(HOMEBREW_CACHE/"testball-0.1.tbz").not_to exist
+
+ shutup do
+ expect { brew "fetch", "testball" }.to be_a_success
+ end
+
+ expect(HOMEBREW_CACHE/"testball-0.1.tbz").to exist
+ end
+end
diff --git a/Library/Homebrew/test/cmd/help_spec.rb b/Library/Homebrew/test/cmd/help_spec.rb
new file mode 100644
index 000000000..6d94d7444
--- /dev/null
+++ b/Library/Homebrew/test/cmd/help_spec.rb
@@ -0,0 +1,47 @@
+describe "brew", :integration_test do
+ it "prints help when no argument is given" do
+ expect { brew }
+ .to output(/Example usage:\n/).to_stderr
+ .and be_a_failure
+ end
+
+ describe "help" do
+ it "prints help" do
+ expect { brew "help" }
+ .to output(/Example usage:\n/).to_stdout
+ .and be_a_success
+ end
+
+ it "prints help for a documented Ruby command" do
+ expect { brew "help", "cat" }
+ .to output(/^brew cat/).to_stdout
+ .and be_a_success
+ end
+
+ it "prints help for a documented shell command" do
+ expect { brew "help", "update" }
+ .to output(/^brew update/).to_stdout
+ .and be_a_success
+ end
+
+ it "prints help for a documented Ruby developer command" do
+ expect { brew "help", "update-test" }
+ .to output(/^brew update-test/).to_stdout
+ .and be_a_success
+ end
+
+ it "fails when given an unknown command" do
+ expect { brew "help", "command-that-does-not-exist" }
+ .to output(/Unknown command: command-that-does-not-exist/).to_stderr
+ .and be_a_failure
+ end
+ end
+
+ describe "cat" do
+ it "prints help when no argument is given" do
+ expect { brew "cat" }
+ .to output(/^brew cat/).to_stderr
+ .and be_a_failure
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/home_spec.rb b/Library/Homebrew/test/cmd/home_spec.rb
new file mode 100644
index 000000000..5a4070492
--- /dev/null
+++ b/Library/Homebrew/test/cmd/home_spec.rb
@@ -0,0 +1,17 @@
+describe "brew home", :integration_test do
+ it "opens the Homebrew homepage when no argument is given" do
+ expect { brew "home", "HOMEBREW_BROWSER" => "echo" }
+ .to output("#{HOMEBREW_WWW}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "opens the homepage for a given Formula" do
+ setup_test_formula "testball"
+
+ expect { brew "home", "testball", "HOMEBREW_BROWSER" => "echo" }
+ .to output("#{Formula["testball"].homepage}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/info_spec.rb b/Library/Homebrew/test/cmd/info_spec.rb
new file mode 100644
index 000000000..8deef3d23
--- /dev/null
+++ b/Library/Homebrew/test/cmd/info_spec.rb
@@ -0,0 +1,30 @@
+require "cmd/info"
+
+describe "brew info", :integration_test do
+ it "prints information about a given Formula" do
+ setup_test_formula "testball"
+
+ expect { brew "info", "testball" }
+ .to output(/testball: stable 0.1/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
+
+describe Homebrew do
+ let(:remote) { "https://github.com/Homebrew/homebrew-core" }
+
+ specify "::github_remote_path" do
+ expect(subject.github_remote_path(remote, "Formula/git.rb"))
+ .to eq("https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb")
+
+ expect(subject.github_remote_path("#{remote}.git", "Formula/git.rb"))
+ .to eq("https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb")
+
+ expect(subject.github_remote_path("git@github.com:user/repo", "foo.rb"))
+ .to eq("https://github.com/user/repo/blob/master/foo.rb")
+
+ expect(subject.github_remote_path("https://mywebsite.com", "foo/bar.rb"))
+ .to eq("https://mywebsite.com/foo/bar.rb")
+ end
+end
diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb
new file mode 100644
index 000000000..c1240a30e
--- /dev/null
+++ b/Library/Homebrew/test/cmd/install_spec.rb
@@ -0,0 +1,243 @@
+describe "brew install", :integration_test do
+ it "installs Formulae" do
+ setup_test_formula "testball1"
+
+ expect { brew "install", "testball1", "--head" }
+ .to output(/Specify `\-\-HEAD`/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ expect { brew "install", "testball1", "--HEAD" }
+ .to output(/No head is defined/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ expect { brew "install", "testball1", "--devel" }
+ .to output(/No devel block/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ expect { brew "install", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "install", "testball1" }
+ .to output(/testball1\-0\.1 already installed/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_success
+
+ expect { brew "install", "macruby" }
+ .to output(/MacRuby is not packaged/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ expect { brew "install", "formula" }
+ .to output(/No available formula/).to_stderr
+ .and output(/Searching for similarly named formulae/).to_stdout
+ .and be_a_failure
+
+ expect { brew "install", "testball" }
+ .to output(/This similarly named formula was found/).to_stdout
+ .and output(/No available formula/).to_stderr
+ .and be_a_failure
+
+ setup_test_formula "testball2"
+ expect { brew "install", "testball" }
+ .to output(/These similarly named formulae were found/).to_stdout
+ .and output(/No available formula/).to_stderr
+ .and be_a_failure
+
+ install_and_rename_coretap_formula "testball1", "testball2"
+ expect { brew "install", "testball2" }
+ .to output(/testball1 already installed, it's just not migrated/).to_stderr
+ .and output(/You can migrate formula with `brew migrate testball2`/).to_stdout
+ .and be_a_success
+ end
+
+ specify "install failures" do
+ path = setup_test_formula "testball1", <<-EOS.undent
+ version "1.0"
+ EOS
+
+ expect { brew "install", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ FileUtils.rm path
+ setup_test_formula "testball1", <<-EOS.undent
+ version "2.0"
+
+ devel do
+ url "#{Formulary.factory("testball1").stable.url}"
+ sha256 "#{TESTBALL_SHA256}"
+ version "3.0"
+ end
+ EOS
+
+ expect { brew "install", "testball1" }
+ .to output(/first `brew unlink testball1`/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ expect { brew "unlink", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "install", "testball1", "--devel" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "unlink", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "install", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/2\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ shutup do
+ expect { brew "switch", "testball1", "3.0" }.to be_a_success
+ end
+
+ expect { brew "install", "testball1" }
+ .to output(/already installed, however linked version is/).to_stderr
+ .and output(/`brew switch testball1 2.0`/).to_stdout
+ .and be_a_success
+
+ expect { brew "unlink", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/3\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "install", "testball1" }
+ .to output(/just not linked/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_success
+ end
+
+ it "can install keg-only Formulae" do
+ path_keg_only = setup_test_formula "testball1", <<-EOS.undent
+ version "1.0"
+
+ keg_only "test reason"
+ EOS
+
+ expect { brew "install", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ FileUtils.rm path_keg_only
+ setup_test_formula "testball1", <<-EOS.undent
+ version "2.0"
+
+ keg_only "test reason"
+ EOS
+
+ expect { brew "install", "testball1" }
+ .to output(/keg-only and another version is linked to opt/).to_stderr
+ .and output(/Use `brew install --force`/).to_stdout
+ .and be_a_success
+
+ expect { brew "install", "testball1", "--force" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/2\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "can install HEAD Formulae" do
+ repo_path = HOMEBREW_CACHE.join("repo")
+ repo_path.join("bin").mkpath
+
+ repo_path.cd do
+ shutup do
+ system "git", "init"
+ system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
+ FileUtils.touch "bin/something.bin"
+ FileUtils.touch "README"
+ system "git", "add", "--all"
+ system "git", "commit", "-m", "Initial repo commit"
+ end
+ end
+
+ setup_test_formula "testball1", <<-EOS.undent
+ version "1.0"
+
+ head "file://#{repo_path}", :using => :git
+
+ def install
+ prefix.install Dir["*"]
+ end
+ EOS
+
+ # Ignore dependencies, because we'll try to resolve requirements in build.rb
+ # and there will be the git requirement, but we cannot instantiate git
+ # formula since we only have testball1 formula.
+ expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout
+ .and output(/Cloning into/).to_stderr
+ .and be_a_success
+
+ expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" }
+ .to output(/testball1\-HEAD\-d5eb689 already installed/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_success
+
+ expect { brew "unlink", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "install", "testball1" }
+ .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "ignores invalid options" do
+ setup_test_formula "testball1"
+ expect { brew "install", "testball1", "--with-fo" }
+ .to output(/testball1: this formula has no \-\-with\-fo option so it will be ignored!/).to_stderr
+ .and output(/Downloading file/).to_stdout
+ .and be_a_success
+ end
+
+ it "succeeds when a non-fatal requirement isn't satisfied" do
+ setup_test_formula "testball1", <<-EOS.undent
+ class NonFatalRequirement < Requirement
+ satisfy { false }
+ end
+
+ depends_on NonFatalRequirement
+ EOS
+
+ # FIXME: This should output to STDERR.
+ expect { brew "install", "testball1" }
+ .to output(/NonFatalRequirement unsatisfied!/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "fails when a fatal requirement isn't satisfied" do
+ setup_test_formula "testball1", <<-EOS.undent
+ class FatalRequirement < Requirement
+ fatal true
+ satisfy { false }
+ end
+
+ depends_on FatalRequirement
+ EOS
+
+ # FIXME: This should output to STDERR.
+ expect { brew "install", "testball1" }
+ .to output(/FatalRequirement unsatisfied!/).to_stdout
+ .and output(/An unsatisfied requirement failed this build./).to_stderr
+ .and be_a_failure
+ end
+end
diff --git a/Library/Homebrew/test/cmd/irb_spec.rb b/Library/Homebrew/test/cmd/irb_spec.rb
new file mode 100644
index 000000000..44410fabe
--- /dev/null
+++ b/Library/Homebrew/test/cmd/irb_spec.rb
@@ -0,0 +1,24 @@
+describe "brew irb", :integration_test do
+ it "starts an interactive Homebrew shell session" do
+ setup_test_formula "testball"
+
+ irb_test = HOMEBREW_TEMP/"irb-test.rb"
+ irb_test.write <<-EOS.undent
+ "testball".f
+ :testball.f
+ exit
+ EOS
+
+ expect { brew "irb", irb_test }
+ .to output(/Interactive Homebrew Shell/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ specify "--examples" do
+ expect { brew "irb", "--examples" }
+ .to output(/'v8'\.f # => instance of the v8 formula/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/leaves_spec.rb b/Library/Homebrew/test/cmd/leaves_spec.rb
new file mode 100644
index 000000000..cd93d7e3d
--- /dev/null
+++ b/Library/Homebrew/test/cmd/leaves_spec.rb
@@ -0,0 +1,23 @@
+describe "brew leaves", :integration_test do
+ it "prints all Formulae that are not dependencies of other Formulae" do
+ setup_test_formula "foo"
+ setup_test_formula "bar"
+
+ expect { brew "leaves" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+
+ (HOMEBREW_CELLAR/"foo/0.1/somedir").mkpath
+ expect { brew "leaves" }
+ .to output("foo\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ (HOMEBREW_CELLAR/"bar/0.1/somedir").mkpath
+ expect { brew "leaves" }
+ .to output("bar\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/link_spec.rb b/Library/Homebrew/test/cmd/link_spec.rb
new file mode 100644
index 000000000..7b85c96dc
--- /dev/null
+++ b/Library/Homebrew/test/cmd/link_spec.rb
@@ -0,0 +1,56 @@
+describe "brew link", :integration_test do
+ it "fails when no argument is given" do
+ expect { brew "link" }
+ .to output(/This command requires a keg argument/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "does not fail if the given Formula is already linked" do
+ setup_test_formula "testball1"
+
+ shutup do
+ expect { brew "install", "testball1" }.to be_a_success
+ expect { brew "link", "testball1" }.to be_a_success
+ end
+ end
+
+ it "links a given Formula" do
+ setup_test_formula "testball1"
+
+ shutup do
+ expect { brew "install", "testball1" }.to be_a_success
+ expect { brew "unlink", "testball1" }.to be_a_success
+ end
+
+ expect { brew "link", "--dry-run", "testball1" }
+ .to output(/Would link/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "link", "--dry-run", "--overwrite", "testball1" }
+ .to output(/Would remove/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "link", "testball1" }
+ .to output(/Linking/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "refuses to link keg-only Formulae" do
+ setup_test_formula "testball1", <<-EOS.undent
+ keg_only "just because"
+ EOS
+
+ shutup do
+ expect { brew "install", "testball1" }.to be_a_success
+ end
+
+ expect { brew "link", "testball1" }
+ .to output(/testball1 is keg-only/).to_stderr
+ .and output(/Note that doing so can interfere with building software\./).to_stdout
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/linkapps_spec.rb b/Library/Homebrew/test/cmd/linkapps_spec.rb
new file mode 100644
index 000000000..42118a215
--- /dev/null
+++ b/Library/Homebrew/test/cmd/linkapps_spec.rb
@@ -0,0 +1,24 @@
+describe "brew linkapps", :integration_test do
+ let(:home_dir) { @home_dir = Pathname.new(Dir.mktmpdir) }
+ let(:apps_dir) { home_dir/"Applications" }
+
+ after(:each) do
+ home_dir.rmtree unless @home_dir.nil?
+ end
+
+ it "symlinks applications" do
+ apps_dir.mkpath
+
+ setup_test_formula "testball"
+
+ source_app = HOMEBREW_CELLAR/"testball/0.1/TestBall.app"
+ source_app.mkpath
+
+ expect { brew "linkapps", "--local", "HOME" => home_dir }
+ .to output(/Linking: #{Regexp.escape(source_app)}/).to_stdout
+ .and output(/`brew linkapps` has been deprecated/).to_stderr
+ .and be_a_success
+
+ expect(apps_dir/"TestBall.app").to be_a_symlink
+ end
+end
diff --git a/Library/Homebrew/test/cmd/list_spec.rb b/Library/Homebrew/test/cmd/list_spec.rb
new file mode 100644
index 000000000..df7394d7b
--- /dev/null
+++ b/Library/Homebrew/test/cmd/list_spec.rb
@@ -0,0 +1,14 @@
+describe "brew list", :integration_test do
+ let(:formulae) { %w[bar foo qux] }
+
+ it "prints all installed Formulae" do
+ formulae.each do |f|
+ (HOMEBREW_CELLAR/f/"1.0/somedir").mkpath
+ end
+
+ expect { brew "list" }
+ .to output("#{formulae.join("\n")}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/log_spec.rb b/Library/Homebrew/test/cmd/log_spec.rb
new file mode 100644
index 000000000..bdbca8912
--- /dev/null
+++ b/Library/Homebrew/test/cmd/log_spec.rb
@@ -0,0 +1,41 @@
+describe "brew log", :integration_test do
+ it "shows the Git log for the Homebrew repository when no argument is given" do
+ HOMEBREW_REPOSITORY.cd do
+ shutup do
+ system "git", "init"
+ system "git", "commit", "--allow-empty", "-m", "This is a test commit"
+ end
+ end
+
+ expect { brew "log" }
+ .to output(/This is a test commit/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "shows the Git log for a given Formula" do
+ setup_test_formula "testball"
+
+ core_tap = CoreTap.new
+ core_tap.path.cd do
+ shutup do
+ system "git", "init"
+ system "git", "add", "--all"
+ system "git", "commit", "-m", "This is a test commit for Testball"
+ end
+ end
+
+ core_tap_url = "file://#{core_tap.path}"
+ shallow_tap = Tap.fetch("homebrew", "shallow")
+ shutup do
+ system "git", "clone", "--depth=1", core_tap_url, shallow_tap.path
+ end
+
+ expect { brew "log", "#{shallow_tap}/testball" }
+ .to output(/This is a test commit for Testball/).to_stdout
+ .and output(/Warning: The git repository is a shallow clone/).to_stderr
+ .and be_a_success
+
+ expect(shallow_tap.path/".git/shallow").to exist, "A shallow clone should have been created."
+ end
+end
diff --git a/Library/Homebrew/test/cmd/migrate_spec.rb b/Library/Homebrew/test/cmd/migrate_spec.rb
new file mode 100644
index 000000000..18c94fa01
--- /dev/null
+++ b/Library/Homebrew/test/cmd/migrate_spec.rb
@@ -0,0 +1,46 @@
+describe "brew migrate", :integration_test do
+ before(:each) do
+ setup_test_formula "testball1"
+ setup_test_formula "testball2"
+ end
+
+ it "fails when no argument is given" do
+ expect { brew "migrate" }
+ .to output(/Invalid usage/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fails when a given Formula doesn't exist" do
+ expect { brew "migrate", "testball" }
+ .to output(/No available formula with the name "testball"/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fails if a given Formula doesn't replace another one" do
+ expect { brew "migrate", "testball1" }
+ .to output(/testball1 doesn't replace any formula/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "migrates a renamed Formula" do
+ install_and_rename_coretap_formula "testball1", "testball2"
+
+ expect { brew "migrate", "testball1" }
+ .to output(/Migrating testball1 to testball2/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "fails if a given Formula is not installed" do
+ install_and_rename_coretap_formula "testball1", "testball2"
+ (HOMEBREW_CELLAR/"testball1").rmtree
+
+ expect { brew "migrate", "testball1" }
+ .to output(/Error: No such keg/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+end
diff --git a/Library/Homebrew/test/cmd/missing_spec.rb b/Library/Homebrew/test/cmd/missing_spec.rb
new file mode 100644
index 000000000..4668e72e0
--- /dev/null
+++ b/Library/Homebrew/test/cmd/missing_spec.rb
@@ -0,0 +1,41 @@
+describe "brew missing", :integration_test do
+ before(:each) do
+ setup_test_formula "foo"
+ setup_test_formula "bar"
+ end
+
+ def make_prefix(name)
+ (HOMEBREW_CELLAR/name/"1.0").mkpath
+ end
+
+ it "prints missing dependencies" do
+ make_prefix "bar"
+
+ expect { brew "missing" }
+ .to output("foo\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "prints nothing if all dependencies are installed" do
+ make_prefix "foo"
+ make_prefix "bar"
+
+ expect { brew "missing" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+ end
+
+ describe "--hide=" do
+ it "pretends that the specified Formulae are not installed" do
+ make_prefix "foo"
+ make_prefix "bar"
+
+ expect { brew "missing", "--hide=foo" }
+ .to output("bar: foo\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/options_spec.rb b/Library/Homebrew/test/cmd/options_spec.rb
new file mode 100644
index 000000000..33fe8b107
--- /dev/null
+++ b/Library/Homebrew/test/cmd/options_spec.rb
@@ -0,0 +1,12 @@
+describe "brew options", :integration_test do
+ it "prints a given Formula's options" do
+ setup_test_formula "testball", <<-EOS.undent
+ depends_on "bar" => :recommended
+ EOS
+
+ expect { brew "options", "testball" }
+ .to output("--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support\n\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/outdated_spec.rb b/Library/Homebrew/test/cmd/outdated_spec.rb
new file mode 100644
index 000000000..2ce0825e8
--- /dev/null
+++ b/Library/Homebrew/test/cmd/outdated_spec.rb
@@ -0,0 +1,11 @@
+describe "brew outdated", :integration_test do
+ it "prints outdated Formulae" do
+ setup_test_formula "testball"
+ (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
+
+ expect { brew "outdated" }
+ .to output("testball\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/pin_spec.rb b/Library/Homebrew/test/cmd/pin_spec.rb
new file mode 100644
index 000000000..9ffc052c3
--- /dev/null
+++ b/Library/Homebrew/test/cmd/pin_spec.rb
@@ -0,0 +1,13 @@
+describe "brew pin", :integration_test do
+ it "pins a Formula's version" do
+ setup_test_formula "testball"
+ (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
+
+ shutup do
+ expect { brew "pin", "testball" }.to be_a_success
+ expect { brew "upgrade" }.to be_a_success
+ end
+
+ expect(HOMEBREW_CELLAR/"testball/0.1").not_to be_a_directory
+ end
+end
diff --git a/Library/Homebrew/test/cmd/prune_spec.rb b/Library/Homebrew/test/cmd/prune_spec.rb
new file mode 100644
index 000000000..c5a9df70c
--- /dev/null
+++ b/Library/Homebrew/test/cmd/prune_spec.rb
@@ -0,0 +1,28 @@
+describe "brew prune", :integration_test do
+ it "removes empty directories and broken symlinks" do
+ share = (HOMEBREW_PREFIX/"share")
+
+ (share/"pruneable/directory/here").mkpath
+ (share/"notpruneable/file").write "I'm here"
+ FileUtils.ln_s "/i/dont/exist/no/really/i/dont", share/"pruneable_symlink"
+
+ expect { brew "prune", "--dry-run" }
+ .to output(%r{Would remove \(empty directory\): .*/pruneable/directory/here}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "prune" }
+ .to output(/Pruned 1 symbolic links and 3 directories/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect(share/"pruneable").not_to be_a_directory
+ expect(share/"notpruneable").to be_a_directory
+ expect(share/"pruneable_symlink").not_to be_a_symlink
+
+ expect { brew "prune", "--verbose" }
+ .to output(/Nothing pruned/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/readall_spec.rb b/Library/Homebrew/test/cmd/readall_spec.rb
new file mode 100644
index 000000000..9165e0cb0
--- /dev/null
+++ b/Library/Homebrew/test/cmd/readall_spec.rb
@@ -0,0 +1,20 @@
+describe "brew readall", :integration_test do
+ it "imports all Formulae for a given Tap" do
+ formula_file = setup_test_formula "testball"
+
+ alias_file = CoreTap.new.alias_dir/"foobar"
+ alias_file.parent.mkpath
+
+ FileUtils.ln_s formula_file, alias_file
+
+ expect { brew "readall", "--aliases", "--syntax" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+
+ expect { brew "readall", "homebrew/core" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+ end
+end
diff --git a/Library/Homebrew/test/cmd/reinstall_spec.rb b/Library/Homebrew/test/cmd/reinstall_spec.rb
new file mode 100644
index 000000000..63584e6be
--- /dev/null
+++ b/Library/Homebrew/test/cmd/reinstall_spec.rb
@@ -0,0 +1,44 @@
+require "extend/ENV"
+
+describe "brew reinstall", :integration_test do
+ before(:each) do
+ setup_test_formula "testball"
+
+ shutup do
+ expect { brew "install", "testball", "--with-foo" }.to be_a_success
+ end
+ end
+
+ it "reinstalls a Formula" do
+ foo_dir = HOMEBREW_CELLAR/"testball/0.1/foo"
+ expect(foo_dir).to exist
+ foo_dir.rmtree
+
+ expect { brew "reinstall", "testball" }
+ .to output(/Reinstalling testball --with-foo/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect(foo_dir).to exist
+ end
+
+ it "reinstalls a Formula even when one of the options is invalid" do
+ expect { brew "reinstall", "testball", "--with-fo" }
+ .to output(/Reinstalling testball --with-foo/).to_stdout
+ .and output(/testball: this formula has no \-\-with-fo option so it will be ignored!/).to_stderr
+ .and be_a_success
+ end
+
+ it "refuses to reinstall a pinned Formula, but doesn't fail" do
+ (HOMEBREW_CELLAR/"testball/0.1").mkpath
+ HOMEBREW_PINNED_KEGS.mkpath
+ FileUtils.ln_s HOMEBREW_CELLAR/"testball/0.1", HOMEBREW_PINNED_KEGS/"testball"
+
+ expect { brew "reinstall", "testball" }
+ .to output(/testball is pinned. You must unpin it to reinstall./).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_success
+
+ HOMEBREW_PINNED_KEGS.rmtree
+ end
+end
diff --git a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb
new file mode 100644
index 000000000..99c2cc20b
--- /dev/null
+++ b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb
@@ -0,0 +1,19 @@
+require "cmd/search"
+
+describe Homebrew do
+ specify "#search_tap" do
+ json_response = {
+ "tree" => [
+ {
+ "path" => "Formula/not-a-formula.rb",
+ "type" => "blob",
+ },
+ ],
+ }
+
+ allow(GitHub).to receive(:open).and_yield(json_response)
+
+ expect(described_class.search_tap("homebrew", "not-a-tap", "not-a-formula"))
+ .to eq(["homebrew/not-a-tap/not-a-formula"])
+ end
+end
diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb
new file mode 100644
index 000000000..06b7073d8
--- /dev/null
+++ b/Library/Homebrew/test/cmd/search_spec.rb
@@ -0,0 +1,57 @@
+describe "brew search", :integration_test do
+ before(:each) do
+ setup_test_formula "testball"
+ end
+
+ it "lists all available Formulae when no argument is given" do
+ expect { brew "search" }
+ .to output(/testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "supports searching by name" do
+ expect { brew "search", "testball" }
+ .to output(/testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ it "supports searching a fully-qualified name " do
+ expect { brew "search", "homebrew/homebrew-core/testball" }
+ .to output(/testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
+ describe "--desc" do
+ let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" }
+
+ it "supports searching in descriptions and creates a description cache" do
+ expect(desc_cache).not_to exist
+
+ expect { brew "search", "--desc", "Some test" }
+ .to output(/testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect(desc_cache).to exist
+ end
+ end
+
+ {
+ "macports" => "https://www.macports.org/ports.php?by=name&substr=testball",
+ "fink" => "http://pdb.finkproject.org/pdb/browse.php?summary=testball",
+ "debian" => "https://packages.debian.org/search?keywords=testball&searchon=names&suite=all&section=all",
+ "opensuse" => "https://software.opensuse.org/search?q=testball",
+ "fedora" => "https://admin.fedoraproject.org/pkgdb/packages/%2Atestball%2A/",
+ "ubuntu" => "http://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all&section=all",
+ }.each do |flag, url|
+ specify "--#{flag}" do
+ expect { brew "search", "--#{flag}", "testball", "HOMEBREW_BROWSER" => "echo" }
+ .to output("#{url}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/services_spec.rb b/Library/Homebrew/test/cmd/services_spec.rb
new file mode 100644
index 000000000..c456fea17
--- /dev/null
+++ b/Library/Homebrew/test/cmd/services_spec.rb
@@ -0,0 +1,10 @@
+describe "brew services", :integration_test, :needs_macos, :needs_official_cmd_taps do
+ it "allows controlling services" do
+ setup_remote_tap "homebrew/services"
+
+ expect { brew "services", "list" }
+ .to output("Warning: No services available to control with `brew services`\n").to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/sh_spec.rb b/Library/Homebrew/test/cmd/sh_spec.rb
new file mode 100644
index 000000000..5260ddb75
--- /dev/null
+++ b/Library/Homebrew/test/cmd/sh_spec.rb
@@ -0,0 +1,8 @@
+describe "brew sh", :integration_test do
+ it "runs a shell with the Homebrew environment" do
+ expect { brew "sh", "SHELL" => which("true") }
+ .to output(/Your shell has been configured/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/switch_spec.rb b/Library/Homebrew/test/cmd/switch_spec.rb
new file mode 100644
index 000000000..c27c96c14
--- /dev/null
+++ b/Library/Homebrew/test/cmd/switch_spec.rb
@@ -0,0 +1,34 @@
+describe "brew switch", :integration_test do
+ it "allows switching between Formula versions" do
+ expect { brew "switch" }
+ .to output(/Usage: brew switch <name> <version>/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ expect { brew "switch", "testball", "0.1" }
+ .to output(/testball not found/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ setup_test_formula "testball", <<-EOS.undent
+ keg_only "just because"
+ EOS
+
+ shutup do
+ expect { brew "install", "testball" }.to be_a_success
+ end
+
+ testball_rack = HOMEBREW_CELLAR/"testball"
+ FileUtils.cp_r testball_rack/"0.1", testball_rack/"0.2"
+
+ expect { brew "switch", "testball", "0.2" }
+ .to output(/link created/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "switch", "testball", "0.3" }
+ .to output("Versions available: 0.1, 0.2\n").to_stdout
+ .and output(/testball does not have a version "0.3"/).to_stderr
+ .and be_a_failure
+ end
+end
diff --git a/Library/Homebrew/test/cmd/tap-new_spec.rb b/Library/Homebrew/test/cmd/tap-new_spec.rb
new file mode 100644
index 000000000..ea4b8aa73
--- /dev/null
+++ b/Library/Homebrew/test/cmd/tap-new_spec.rb
@@ -0,0 +1,10 @@
+describe "brew tap-new", :integration_test do
+ it "initializes a new Tap with a ReadMe file" do
+ expect { brew "tap-new", "homebrew/foo", "--verbose" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+
+ expect(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo/README.md").to exist
+ end
+end
diff --git a/Library/Homebrew/test/cmd/uninstall_spec.rb b/Library/Homebrew/test/cmd/uninstall_spec.rb
new file mode 100644
index 000000000..65f69e802
--- /dev/null
+++ b/Library/Homebrew/test/cmd/uninstall_spec.rb
@@ -0,0 +1,12 @@
+describe "brew uninstall", :integration_test do
+ it "uninstalls a given Formula" do
+ shutup do
+ expect { brew "install", testball }.to be_a_success
+ end
+
+ expect { brew "uninstall", "--force", testball }
+ .to output(/Uninstalling testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/unlink_spec.rb b/Library/Homebrew/test/cmd/unlink_spec.rb
new file mode 100644
index 000000000..5961651fe
--- /dev/null
+++ b/Library/Homebrew/test/cmd/unlink_spec.rb
@@ -0,0 +1,14 @@
+describe "brew unlink", :integration_test do
+ it "unlinks a Formula" do
+ setup_test_formula "testball"
+
+ shutup do
+ expect { brew "install", "testball" }.to be_a_success
+ end
+
+ expect { brew "unlink", "--dry-run", "testball" }
+ .to output(/Would remove/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/unlinkapps_spec.rb b/Library/Homebrew/test/cmd/unlinkapps_spec.rb
new file mode 100644
index 000000000..1e21bd851
--- /dev/null
+++ b/Library/Homebrew/test/cmd/unlinkapps_spec.rb
@@ -0,0 +1,24 @@
+describe "brew unlinkapps", :integration_test do
+ let(:home_dir) { @home_dir = Pathname.new(Dir.mktmpdir) }
+ let(:apps_dir) { home_dir/"Applications" }
+
+ after(:each) do
+ home_dir.rmtree unless @home_dir.nil?
+ end
+
+ it "unlinks symlinked applications" do
+ apps_dir.mkpath
+
+ setup_test_formula "testball"
+
+ source_app = HOMEBREW_CELLAR/"testball/0.1/TestBall.app"
+ source_app.mkpath
+
+ FileUtils.ln_s source_app, apps_dir/"TestBall.app"
+
+ expect { brew "unlinkapps", "--local", "HOME" => home_dir }
+ .to output(%r{Unlinking: #{Regexp.escape(apps_dir)}/TestBall.app}).to_stdout
+ .and output(/`brew unlinkapps` has been deprecated/).to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/cmd/unpack_spec.rb b/Library/Homebrew/test/cmd/unpack_spec.rb
new file mode 100644
index 000000000..244fc0852
--- /dev/null
+++ b/Library/Homebrew/test/cmd/unpack_spec.rb
@@ -0,0 +1,16 @@
+describe "brew unpack", :integration_test do
+ it "unpacks a given Formula's archive" do
+ setup_test_formula "testball"
+
+ Dir.mktmpdir do |path|
+ path = Pathname.new(path)
+
+ shutup do
+ expect { brew "unpack", "testball", "--destdir=#{path}" }
+ .to be_a_success
+ end
+
+ expect(path/"testball-0.1").to be_a_directory
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/unpin_spec.rb b/Library/Homebrew/test/cmd/unpin_spec.rb
new file mode 100644
index 000000000..4f14626d8
--- /dev/null
+++ b/Library/Homebrew/test/cmd/unpin_spec.rb
@@ -0,0 +1,14 @@
+describe "brew unpin", :integration_test do
+ it "unpins a Formula's version" do
+ setup_test_formula "testball"
+ (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
+
+ shutup do
+ expect { brew "pin", "testball" }.to be_a_success
+ expect { brew "unpin", "testball" }.to be_a_success
+ expect { brew "upgrade" }.to be_a_success
+ end
+
+ expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
+ end
+end
diff --git a/Library/Homebrew/test/cmd/update-report_spec.rb b/Library/Homebrew/test/cmd/update-report_spec.rb
new file mode 100644
index 000000000..3665e3c78
--- /dev/null
+++ b/Library/Homebrew/test/cmd/update-report_spec.rb
@@ -0,0 +1,127 @@
+require "cmd/update-report"
+require "formula_versions"
+require "yaml"
+
+describe Reporter do
+ def perform_update(fixture_name = "")
+ allow(Formulary).to receive(:factory).and_return(double(pkg_version: "1.0"))
+ allow(FormulaVersions).to receive(:new).and_return(double(formula_at_revision: "2.0"))
+
+ diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name]
+ allow(subject).to receive(:diff).and_return(diff || "")
+
+ hub.add(subject) if subject.updated?
+ end
+
+ let(:reporter_class) do
+ Class.new(described_class) do
+ def initialize(tap)
+ @tap = tap
+
+ ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "12345678"
+ ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef00"
+
+ super(tap)
+ end
+ end
+ end
+ subject { reporter_class.new(tap) }
+ let(:tap) { CoreTap.new }
+ let(:hub) { ReporterHub.new }
+
+ specify "without revision variable" do
+ ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" }
+
+ expect {
+ described_class.new(tap)
+ }.to raise_error(Reporter::ReporterRevisionUnsetError)
+ end
+
+ specify "without any changes" do
+ perform_update
+ expect(hub).to be_empty
+ end
+
+ specify "without Formula changes" do
+ perform_update("update_git_diff_output_without_formulae_changes")
+
+ expect(hub.select_formula(:M)).to be_empty
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ end
+
+ specify "with Formula changes" do
+ perform_update("update_git_diff_output_with_formulae_changes")
+
+ expect(hub.select_formula(:M)).to eq(%w[xar yajl])
+ expect(hub.select_formula(:A)).to eq(%w[antiword bash-completion ddrescue dict lua])
+ end
+
+ specify "with removed Formulae" do
+ perform_update("update_git_diff_output_with_removed_formulae")
+
+ expect(hub.select_formula(:D)).to eq(%w[libgsasl])
+ end
+
+ specify "with changed file type" do
+ perform_update("update_git_diff_output_with_changed_filetype")
+
+ expect(hub.select_formula(:M)).to eq(%w[elixir])
+ expect(hub.select_formula(:A)).to eq(%w[libbson])
+ expect(hub.select_formula(:D)).to eq(%w[libgsasl])
+ end
+
+ specify "with renamed Formula" do
+ allow(tap).to receive(:formula_renames).and_return("cv" => "progress")
+ perform_update("update_git_diff_output_with_formula_rename")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to eq([["cv", "progress"]])
+ end
+
+ context "when updating a Tap other than the core Tap" do
+ let(:tap) { Tap.new("foo", "bar") }
+
+ before(:each) do
+ (tap.path/"Formula").mkpath
+ end
+
+ after(:each) do
+ tap.path.parent.rmtree
+ end
+
+ specify "with restructured Tap" do
+ perform_update("update_git_diff_output_with_restructured_tap")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to be_empty
+ end
+
+ specify "with renamed Formula and restructured Tap" do
+ allow(tap).to receive(:formula_renames).and_return("xchat" => "xchat2")
+ perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to eq([%w[foo/bar/xchat foo/bar/xchat2]])
+ end
+
+ specify "with simulated 'homebrew/php' restructuring" do
+ perform_update("update_git_diff_simulate_homebrew_php_restructuring")
+
+ expect(hub.select_formula(:A)).to be_empty
+ expect(hub.select_formula(:D)).to be_empty
+ expect(hub.select_formula(:R)).to be_empty
+ end
+
+ specify "with Formula changes" do
+ perform_update("update_git_diff_output_with_tap_formulae_changes")
+
+ expect(hub.select_formula(:A)).to eq(%w[foo/bar/lua])
+ expect(hub.select_formula(:M)).to eq(%w[foo/bar/git])
+ expect(hub.select_formula(:D)).to be_empty
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb
new file mode 100644
index 000000000..84f5c09f4
--- /dev/null
+++ b/Library/Homebrew/test/cmd/upgrade_spec.rb
@@ -0,0 +1,12 @@
+describe "brew upgrade", :integration_test do
+ it "upgrades a Formula to the latest version" do
+ setup_test_formula "testball"
+ (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
+
+ shutup do
+ expect { brew "upgrade" }.to be_a_success
+ end
+
+ expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
+ end
+end
diff --git a/Library/Homebrew/test/cmd/uses_spec.rb b/Library/Homebrew/test/cmd/uses_spec.rb
new file mode 100644
index 000000000..2a6f48cb7
--- /dev/null
+++ b/Library/Homebrew/test/cmd/uses_spec.rb
@@ -0,0 +1,25 @@
+describe "brew uses", :integration_test do
+ it "prints the Formulae a given Formula is used by" do
+ setup_test_formula "foo"
+ setup_test_formula "bar"
+ setup_test_formula "baz", <<-EOS.undent
+ url "https://example.com/baz-1.0"
+ depends_on "bar"
+ EOS
+
+ expect { brew "uses", "baz" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+
+ expect { brew "uses", "bar" }
+ .to output("baz\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "uses", "--recursive", "foo" }
+ .to output(/(bar\nbaz|baz\nbar)/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/command_test.rb b/Library/Homebrew/test/command_test.rb
deleted file mode 100644
index d5c7aaa88..000000000
--- a/Library/Homebrew/test/command_test.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCommand < IntegrationCommandTestCase
- def test_command
- assert_equal "#{HOMEBREW_LIBRARY_PATH}/cmd/info.rb",
- cmd("command", "info")
-
- assert_match "Unknown command",
- cmd_fail("command", "I-don't-exist")
- end
-end
diff --git a/Library/Homebrew/test/commands_test.rb b/Library/Homebrew/test/commands_test.rb
index d44d2da0e..da88ee2d5 100644
--- a/Library/Homebrew/test/commands_test.rb
+++ b/Library/Homebrew/test/commands_test.rb
@@ -4,15 +4,9 @@ require "cmd/commands"
require "fileutils"
require "testing_env"
-class IntegrationCommandTestCommands < IntegrationCommandTestCase
- def test_commands
- assert_match "Built-in commands",
- cmd("commands")
- end
-end
-
class CommandsTests < Homebrew::TestCase
def setup
+ super
@cmds = [
# internal commands
HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb",
@@ -28,6 +22,7 @@ class CommandsTests < Homebrew::TestCase
def teardown
@cmds.each(&:unlink)
+ super
end
def test_internal_commands
@@ -45,8 +40,6 @@ class CommandsTests < Homebrew::TestCase
end
def test_external_commands
- env = ENV.to_hash
-
mktmpdir do |dir|
%w[brew-t1 brew-t2.rb brew-t3.py].each do |file|
path = "#{dir}/#{file}"
@@ -65,8 +58,6 @@ class CommandsTests < Homebrew::TestCase
"Executable files with a non Ruby extension shoudn't be included"
refute cmds.include?("t4"), "Non-executable files shouldn't be included"
end
- ensure
- ENV.replace(env)
end
def test_internal_command_path
diff --git a/Library/Homebrew/test/compiler_failure_spec.rb b/Library/Homebrew/test/compiler_failure_spec.rb
new file mode 100644
index 000000000..b4fab0b27
--- /dev/null
+++ b/Library/Homebrew/test/compiler_failure_spec.rb
@@ -0,0 +1,37 @@
+require "compilers"
+
+RSpec::Matchers.alias_matcher :fail_with, :be_fails_with
+
+describe CompilerFailure do
+ describe "::create" do
+ it "creates a failure when given a symbol" do
+ failure = described_class.create(:clang)
+ expect(failure).to fail_with(double("Compiler", name: :clang, version: 425))
+ end
+
+ it "can be given a build number in a block" do
+ failure = described_class.create(:clang) { build 211 }
+ expect(failure).to fail_with(double("Compiler", name: :clang, version: 210))
+ expect(failure).not_to fail_with(double("Compiler", name: :clang, version: 318))
+ end
+
+ it "can be given an empty block" do
+ failure = described_class.create(:clang) {}
+ expect(failure).to fail_with(double("Compiler", name: :clang, version: 425))
+ end
+
+ it "creates a failure when given a hash" do
+ failure = described_class.create(gcc: "4.8")
+ expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8"))
+ expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.1"))
+ expect(failure).not_to fail_with(double("Compiler", name: "gcc-4.7", version: "4.7"))
+ end
+
+ it "creates a failure when given a hash and a block with aversion" do
+ failure = described_class.create(gcc: "4.8") { version "4.8.1" }
+ expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8"))
+ expect(failure).to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.1"))
+ expect(failure).not_to fail_with(double("Compiler", name: "gcc-4.8", version: "4.8.2"))
+ end
+ end
+end
diff --git a/Library/Homebrew/test/compiler_failure_test.rb b/Library/Homebrew/test/compiler_failure_test.rb
deleted file mode 100644
index c0b74d128..000000000
--- a/Library/Homebrew/test/compiler_failure_test.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-require "testing_env"
-require "compilers"
-
-class CompilerFailureTests < Homebrew::TestCase
- Compiler = Struct.new(:name, :version)
-
- def assert_fails_with(compiler, failure)
- assert_operator failure, :fails_with?, compiler
- end
-
- def refute_fails_with(compiler, failure)
- refute_operator failure, :fails_with?, compiler
- end
-
- def compiler(name, version)
- Compiler.new(name, version)
- end
-
- def create(spec, &block)
- CompilerFailure.create(spec, &block)
- end
-
- def test_create_with_symbol
- failure = create(:clang)
- assert_fails_with compiler(:clang, 425), failure
- end
-
- def test_create_with_block
- failure = create(:clang) { build 211 }
- assert_fails_with compiler(:clang, 210), failure
- refute_fails_with compiler(:clang, 318), failure
- end
-
- def test_create_with_block_without_build
- failure = create(:clang) {}
- assert_fails_with compiler(:clang, 425), failure
- end
-
- def test_create_with_hash
- failure = create(gcc: "4.8")
- assert_fails_with compiler("gcc-4.8", "4.8"), failure
- assert_fails_with compiler("gcc-4.8", "4.8.1"), failure
- refute_fails_with compiler("gcc-4.7", "4.7"), failure
- end
-
- def test_create_with_hash_and_version
- failure = create(gcc: "4.8") { version "4.8.1" }
- assert_fails_with compiler("gcc-4.8", "4.8"), failure
- assert_fails_with compiler("gcc-4.8", "4.8.1"), failure
- refute_fails_with compiler("gcc-4.8", "4.8.2"), failure
- end
-end
diff --git a/Library/Homebrew/test/compiler_selector_spec.rb b/Library/Homebrew/test/compiler_selector_spec.rb
new file mode 100644
index 000000000..0f6f6b5f2
--- /dev/null
+++ b/Library/Homebrew/test/compiler_selector_spec.rb
@@ -0,0 +1,122 @@
+require "compilers"
+require "software_spec"
+
+describe CompilerSelector do
+ subject { described_class.new(software_spec, versions, compilers) }
+ let(:compilers) { [:clang, :gcc, :llvm, :gnu] }
+ let(:software_spec) { SoftwareSpec.new }
+ let(:cc) { :clang }
+ let(:versions) do
+ double(
+ gcc_4_0_build_version: Version::NULL,
+ gcc_build_version: Version.create("5666"),
+ llvm_build_version: Version::NULL,
+ clang_build_version: Version.create("425"),
+ )
+ end
+
+ before(:each) do
+ allow(versions).to receive(:non_apple_gcc_version) do |name|
+ case name
+ when "gcc-4.8" then Version.create("4.8.1")
+ when "gcc-4.7" then Version.create("4.7.1")
+ else Version::NULL
+ end
+ end
+ end
+
+ describe "#compiler" do
+ it "raises an error if no matching compiler can be found" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:llvm)
+ software_spec.fails_with(:gcc)
+ software_spec.fails_with(gcc: "4.8")
+ software_spec.fails_with(gcc: "4.7")
+
+ expect { subject.compiler }.to raise_error(CompilerSelectionError)
+ end
+
+ it "defaults to cc" do
+ expect(subject.compiler).to eq(cc)
+ end
+
+ it "returns gcc if it fails with clang" do
+ software_spec.fails_with(:clang)
+ expect(subject.compiler).to eq(:gcc)
+ end
+
+ it "returns clang if it fails with llvm" do
+ software_spec.fails_with(:llvm)
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ it "returns clang if it fails with gcc" do
+ software_spec.fails_with(:gcc)
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ it "returns clang if it fails with non-Apple gcc" do
+ software_spec.fails_with(gcc: "4.8")
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ it "still returns gcc-4.8 if it fails with gcc without a specific version" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:gcc)
+ expect(subject.compiler).to eq("gcc-4.8")
+ end
+
+ it "returns gcc if it fails with clang and llvm" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:llvm)
+ expect(subject.compiler).to eq(:gcc)
+ end
+
+ it "returns clang if it fails with gcc and llvm" do
+ software_spec.fails_with(:gcc)
+ software_spec.fails_with(:llvm)
+ expect(subject.compiler).to eq(:clang)
+ end
+
+ example "returns gcc if it fails with a specific gcc version" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(gcc: "4.8")
+ expect(subject.compiler).to eq(:gcc)
+ end
+
+ example "returns a lower version of gcc if it fails with the highest version" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:gcc)
+ software_spec.fails_with(:llvm)
+ software_spec.fails_with(gcc: "4.8")
+ expect(subject.compiler).to eq("gcc-4.7")
+ end
+
+ it "prefers gcc" do
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:gcc)
+ expect(subject.compiler).to eq("gcc-4.8")
+ end
+
+ it "raises an error when gcc is missing" do
+ allow(versions).to receive(:gcc_build_version).and_return(Version::NULL)
+
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(:llvm)
+ software_spec.fails_with(gcc: "4.8")
+ software_spec.fails_with(gcc: "4.7")
+
+ expect { subject.compiler }.to raise_error(CompilerSelectionError)
+ end
+
+ it "raises an error when llvm and gcc are missing" do
+ allow(versions).to receive(:gcc_build_version).and_return(Version::NULL)
+
+ software_spec.fails_with(:clang)
+ software_spec.fails_with(gcc: "4.8")
+ software_spec.fails_with(gcc: "4.7")
+
+ expect { subject.compiler }.to raise_error(CompilerSelectionError)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/compiler_selector_test.rb b/Library/Homebrew/test/compiler_selector_test.rb
deleted file mode 100644
index b1591bdbe..000000000
--- a/Library/Homebrew/test/compiler_selector_test.rb
+++ /dev/null
@@ -1,116 +0,0 @@
-require "testing_env"
-require "compilers"
-require "software_spec"
-
-class CompilerSelectorTests < Homebrew::TestCase
- class Double < SoftwareSpec
- def <<(cc)
- fails_with(cc)
- self
- end
- end
-
- class CompilerVersions
- attr_accessor :gcc_4_0_build_version, :gcc_build_version,
- :clang_build_version
-
- def initialize
- @gcc_4_0_build_version = Version::NULL
- @gcc_build_version = Version.create("5666")
- @llvm_build_version = Version::NULL
- @clang_build_version = Version.create("425")
- end
-
- def non_apple_gcc_version(name)
- case name
- when "gcc-4.8" then Version.create("4.8.1")
- when "gcc-4.7" then Version.create("4.7.1")
- else Version::NULL
- end
- end
- end
-
- def setup
- @f = Double.new
- @cc = :clang
- @versions = CompilerVersions.new
- @selector = CompilerSelector.new(
- @f, @versions, [:clang, :gcc, :llvm, :gnu]
- )
- end
-
- def actual_cc
- @selector.compiler
- end
-
- def test_all_compiler_failures
- @f << :clang << :llvm << :gcc << { gcc: "4.8" } << { gcc: "4.7" }
- assert_raises(CompilerSelectionError) { actual_cc }
- end
-
- def test_no_compiler_failures
- assert_equal @cc, actual_cc
- end
-
- def test_fails_with_clang
- @f << :clang
- assert_equal :gcc, actual_cc
- end
-
- def test_fails_with_llvm
- @f << :llvm
- assert_equal :clang, actual_cc
- end
-
- def test_fails_with_gcc
- @f << :gcc
- assert_equal :clang, actual_cc
- end
-
- def test_fails_with_non_apple_gcc
- @f << { gcc: "4.8" }
- assert_equal :clang, actual_cc
- end
-
- def test_mixed_failures_1
- @f << :clang << :gcc
- assert_equal "gcc-4.8", actual_cc
- end
-
- def test_mixed_failures_2
- @f << :clang << :llvm
- assert_equal :gcc, actual_cc
- end
-
- def test_mixed_failures_3
- @f << :gcc << :llvm
- assert_equal :clang, actual_cc
- end
-
- def test_mixed_failures_4
- @f << :clang << { gcc: "4.8" }
- assert_equal :gcc, actual_cc
- end
-
- def test_mixed_failures_5
- @f << :clang << :gcc << :llvm << { gcc: "4.8" }
- assert_equal "gcc-4.7", actual_cc
- end
-
- def test_gcc_precedence
- @f << :clang << :gcc
- assert_equal "gcc-4.8", actual_cc
- end
-
- def test_missing_gcc
- @versions.gcc_build_version = Version::NULL
- @f << :clang << :llvm << { gcc: "4.8" } << { gcc: "4.7" }
- assert_raises(CompilerSelectionError) { actual_cc }
- end
-
- def test_missing_llvm_and_gcc
- @versions.gcc_build_version = Version::NULL
- @f << :clang << { gcc: "4.8" } << { gcc: "4.7" }
- assert_raises(CompilerSelectionError) { actual_cc }
- end
-end
diff --git a/Library/Homebrew/test/config_test.rb b/Library/Homebrew/test/config_test.rb
deleted file mode 100644
index 81da4660a..000000000
--- a/Library/Homebrew/test/config_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestConfig < IntegrationCommandTestCase
- def test_config
- assert_match "HOMEBREW_VERSION: #{HOMEBREW_VERSION}",
- cmd("config")
- end
-end
diff --git a/Library/Homebrew/test/create_test.rb b/Library/Homebrew/test/create_test.rb
deleted file mode 100644
index aeee428aa..000000000
--- a/Library/Homebrew/test/create_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCreate < IntegrationCommandTestCase
- def test_create
- url = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
- cmd("create", url, "HOMEBREW_EDITOR" => "/bin/cat")
-
- formula_file = CoreTap.new.formula_dir/"testball.rb"
- assert formula_file.exist?, "The formula source should have been created"
- assert_match %Q(sha256 "#{TESTBALL_SHA256}"), formula_file.read
- end
-end
diff --git a/Library/Homebrew/test/custom_command_test.rb b/Library/Homebrew/test/custom_command_test.rb
deleted file mode 100644
index 8d05bc6c7..000000000
--- a/Library/Homebrew/test/custom_command_test.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestCustomCommand < IntegrationCommandTestCase
- def test_custom_command
- mktmpdir do |path|
- cmd = "int-test-#{rand}"
- file = "#{path}/brew-#{cmd}"
-
- File.open(file, "w") do |f|
- f.write "#!/bin/sh\necho 'I am #{cmd}'\n"
- end
- FileUtils.chmod 0777, file
-
- assert_match "I am #{cmd}",
- cmd(cmd, "PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}")
- end
- end
-end
diff --git a/Library/Homebrew/test/cxxstdlib_spec.rb b/Library/Homebrew/test/cxxstdlib_spec.rb
new file mode 100644
index 000000000..dd2e4e1c6
--- /dev/null
+++ b/Library/Homebrew/test/cxxstdlib_spec.rb
@@ -0,0 +1,68 @@
+require "formula"
+require "cxxstdlib"
+
+describe CxxStdlib do
+ let(:clang) { CxxStdlib.create(:libstdcxx, :clang) }
+ let(:gcc) { CxxStdlib.create(:libstdcxx, :gcc) }
+ let(:gcc40) { CxxStdlib.create(:libstdcxx, :gcc_4_0) }
+ let(:gcc42) { CxxStdlib.create(:libstdcxx, :gcc_4_2) }
+ let(:gcc48) { CxxStdlib.create(:libstdcxx, "gcc-4.8") }
+ let(:gcc49) { CxxStdlib.create(:libstdcxx, "gcc-4.9") }
+ let(:lcxx) { CxxStdlib.create(:libcxx, :clang) }
+ let(:purec) { CxxStdlib.create(nil, :clang) }
+
+ describe "#compatible_with?" do
+ specify "Apple libstdcxx intercompatibility" do
+ expect(clang).to be_compatible_with(gcc)
+ expect(clang).to be_compatible_with(gcc42)
+ end
+
+ specify "compatibility with itself" do
+ expect(gcc).to be_compatible_with(gcc)
+ expect(gcc48).to be_compatible_with(gcc48)
+ expect(clang).to be_compatible_with(clang)
+ end
+
+ specify "Apple/GNU libstdcxx incompatibility" do
+ expect(clang).not_to be_compatible_with(gcc48)
+ expect(gcc48).not_to be_compatible_with(clang)
+ end
+
+ specify "GNU cross-version incompatibility" do
+ expect(gcc48).not_to be_compatible_with(gcc49)
+ expect(gcc49).not_to be_compatible_with(gcc48)
+ end
+
+ specify "libstdcxx and libcxx incompatibility" do
+ expect(clang).not_to be_compatible_with(lcxx)
+ expect(lcxx).not_to be_compatible_with(clang)
+ end
+
+ specify "compatibility for non-cxx software" do
+ expect(purec).to be_compatible_with(clang)
+ expect(clang).to be_compatible_with(purec)
+ expect(purec).to be_compatible_with(purec)
+ expect(purec).to be_compatible_with(gcc48)
+ expect(gcc48).to be_compatible_with(purec)
+ end
+ end
+
+ describe "#apple_compiler?" do
+ it "returns true for Apple compilers" do
+ expect(clang).to be_an_apple_compiler
+ expect(gcc).to be_an_apple_compiler
+ expect(gcc42).to be_an_apple_compiler
+ end
+
+ it "returns false for non-Apple compilers" do
+ expect(gcc48).not_to be_an_apple_compiler
+ end
+ end
+
+ describe "#type_string" do
+ specify "formatting" do
+ expect(clang.type_string).to eq("libstdc++")
+ expect(lcxx.type_string).to eq("libc++")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/dependencies_test.rb b/Library/Homebrew/test/dependencies_test.rb
index db3b78226..c5444fcbc 100644
--- a/Library/Homebrew/test/dependencies_test.rb
+++ b/Library/Homebrew/test/dependencies_test.rb
@@ -5,6 +5,7 @@ require "requirements"
class DependenciesTests < Homebrew::TestCase
def setup
+ super
@deps = Dependencies.new
end
@@ -89,6 +90,7 @@ end
class RequirementsTests < Homebrew::TestCase
def setup
+ super
@reqs = Requirements.new
end
diff --git a/Library/Homebrew/test/dependency_collector_test.rb b/Library/Homebrew/test/dependency_collector_test.rb
index 1c7f70118..c63d04637 100644
--- a/Library/Homebrew/test/dependency_collector_test.rb
+++ b/Library/Homebrew/test/dependency_collector_test.rb
@@ -11,11 +11,13 @@ class DependencyCollectorTests < Homebrew::TestCase
end
def setup
+ super
@d = DependencyCollector.new
end
def teardown
DependencyCollector.clear_cache
+ super
end
def test_dependency_creation
diff --git a/Library/Homebrew/test/dependency_expansion_spec.rb b/Library/Homebrew/test/dependency_expansion_spec.rb
new file mode 100644
index 000000000..f955237a9
--- /dev/null
+++ b/Library/Homebrew/test/dependency_expansion_spec.rb
@@ -0,0 +1,136 @@
+require "dependency"
+
+describe Dependency do
+ def build_dep(name, tags = [], deps = [])
+ dep = described_class.new(name.to_s, tags)
+ allow(dep).to receive(:to_formula).and_return(double(deps: deps, name: name))
+ dep
+ end
+
+ let(:foo) { build_dep(:foo) }
+ let(:bar) { build_dep(:bar) }
+ let(:baz) { build_dep(:baz) }
+ let(:qux) { build_dep(:qux) }
+ let(:deps) { [foo, bar, baz, qux] }
+ let(:formula) { double(deps: deps, name: "f") }
+
+ describe "::expand" do
+ it "yields dependent and dependency pairs" do
+ i = 0
+ described_class.expand(formula) do |dependent, dep|
+ expect(dependent).to eq(formula)
+ expect(deps[i]).to eq(dep)
+ i += 1
+ end
+ end
+
+ it "returns the dependencies" do
+ expect(described_class.expand(formula)).to eq(deps)
+ end
+
+ it "prunes all when given a block with ::prune" do
+ expect(described_class.expand(formula) { described_class.prune }).to be_empty
+ end
+
+ it "can prune selectively" do
+ deps = described_class.expand(formula) do |_, dep|
+ described_class.prune if dep.name == "foo"
+ end
+
+ expect(deps).to eq([bar, baz, qux])
+ end
+
+ it "preserves dependency order" do
+ allow(foo).to receive(:to_formula).and_return(double(name: "f", deps: [qux, baz]))
+ expect(described_class.expand(formula)).to eq([qux, baz, foo, bar])
+ end
+ end
+
+ it "skips optionals by default" do
+ deps = [build_dep(:foo, [:optional]), bar, baz, qux]
+ f = double(deps: deps, build: double(with?: false), name: "f")
+ expect(described_class.expand(f)).to eq([bar, baz, qux])
+ end
+
+ it "keeps recommended dependencies by default" do
+ deps = [build_dep(:foo, [:recommended]), bar, baz, qux]
+ f = double(deps: deps, build: double(with?: true), name: "f")
+ expect(described_class.expand(f)).to eq(deps)
+ end
+
+ it "merges repeated dependencies with differing options" do
+ foo2 = build_dep(:foo, ["option"])
+ baz2 = build_dep(:baz, ["option"])
+ deps << foo2 << baz2
+ deps = [foo2, bar, baz2, qux]
+ deps.zip(described_class.expand(formula)) do |expected, actual|
+ expect(expected.tags).to eq(actual.tags)
+ expect(expected).to eq(actual)
+ end
+ end
+
+ it "merges dependencies and perserves env_proc" do
+ env_proc = double
+ dep = described_class.new("foo", [], env_proc)
+ allow(dep).to receive(:to_formula).and_return(double(deps: [], name: "foo"))
+ deps.replace([dep])
+ expect(described_class.expand(formula).first.env_proc).to eq(env_proc)
+ end
+
+ it "merges tags without duplicating them" do
+ foo2 = build_dep(:foo, ["option"])
+ foo3 = build_dep(:foo, ["option"])
+ deps << foo2 << foo3
+
+ expect(described_class.expand(formula).first.tags).to eq(%w[option])
+ end
+
+ it "skips parent but yields children with ::skip" do
+ f = double(
+ name: "f",
+ deps: [
+ build_dep(:foo, [], [bar, baz]),
+ build_dep(:foo, [], [baz]),
+ ],
+ )
+
+ deps = described_class.expand(f) do |_dependent, dep|
+ described_class.skip if %w[foo qux].include? dep.name
+ end
+
+ expect(deps).to eq([bar, baz])
+ end
+
+ it "keeps dependency but prunes recursive dependencies with ::keep_but_prune_recursive_deps" do
+ foo = build_dep(:foo, [:build], bar)
+ baz = build_dep(:baz, [:build])
+ f = double(name: "f", deps: [foo, baz])
+
+ deps = described_class.expand(f) do |_dependent, dep|
+ described_class.keep_but_prune_recursive_deps if dep.build?
+ end
+
+ expect(deps).to eq([foo, baz])
+ end
+
+ it "returns only the dependencies given as a collection as second argument" do
+ expect(formula.deps).to eq([foo, bar, baz, qux])
+ expect(described_class.expand(formula, [bar, baz])).to eq([bar, baz])
+ end
+
+ it "doesn't raise an error when a dependency is cyclic" do
+ foo = build_dep(:foo)
+ bar = build_dep(:bar, [], [foo])
+ allow(foo).to receive(:to_formula).and_return(double(deps: [bar], name: foo.name))
+ f = double(name: "f", deps: [foo, bar])
+ expect { described_class.expand(f) }.not_to raise_error
+ end
+
+ it "cleans the expand stack" do
+ foo = build_dep(:foo)
+ allow(foo).to receive(:to_formula).and_raise(FormulaUnavailableError, foo.name)
+ f = double(name: "f", deps: [foo])
+ expect { described_class.expand(f) }.to raise_error(FormulaUnavailableError)
+ expect(described_class.instance_variable_get(:@expand_stack)).to be_empty
+ end
+end
diff --git a/Library/Homebrew/test/dependency_expansion_test.rb b/Library/Homebrew/test/dependency_expansion_test.rb
deleted file mode 100644
index 9d6de35e2..000000000
--- a/Library/Homebrew/test/dependency_expansion_test.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-require "testing_env"
-require "dependency"
-
-class DependencyExpansionTests < Homebrew::TestCase
- def build_dep(name, tags = [], deps = [])
- dep = Dependency.new(name.to_s, tags)
- dep.stubs(:to_formula).returns(stub(deps: deps, name: name))
- dep
- end
-
- def setup
- @foo = build_dep(:foo)
- @bar = build_dep(:bar)
- @baz = build_dep(:baz)
- @qux = build_dep(:qux)
- @deps = [@foo, @bar, @baz, @qux]
- @f = stub(deps: @deps, name: "f")
- end
-
- def test_expand_yields_dependent_and_dep_pairs
- i = 0
- Dependency.expand(@f) do |dependent, dep|
- assert_equal @f, dependent
- assert_equal dep, @deps[i]
- i += 1
- end
- end
-
- def test_expand_no_block
- assert_equal @deps, Dependency.expand(@f)
- end
-
- def test_expand_prune_all
- assert_empty Dependency.expand(@f) { Dependency.prune }
- end
-
- def test_expand_selective_pruning
- deps = Dependency.expand(@f) do |_, dep|
- Dependency.prune if dep.name == "foo"
- end
-
- assert_equal [@bar, @baz, @qux], deps
- end
-
- def test_expand_preserves_dependency_order
- @foo.stubs(:to_formula).returns(stub(name: "f", deps: [@qux, @baz]))
- assert_equal [@qux, @baz, @foo, @bar], Dependency.expand(@f)
- end
-
- def test_expand_skips_optionals_by_default
- deps = [build_dep(:foo, [:optional]), @bar, @baz, @qux]
- f = stub(deps: deps, build: stub(with?: false), name: "f")
- assert_equal [@bar, @baz, @qux], Dependency.expand(f)
- end
-
- def test_expand_keeps_recommendeds_by_default
- deps = [build_dep(:foo, [:recommended]), @bar, @baz, @qux]
- f = stub(deps: deps, build: stub(with?: true), name: "f")
- assert_equal deps, Dependency.expand(f)
- end
-
- def test_merges_repeated_deps_with_differing_options
- @foo2 = build_dep(:foo, ["option"])
- @baz2 = build_dep(:baz, ["option"])
- @deps << @foo2 << @baz2
- deps = [@foo2, @bar, @baz2, @qux]
- deps.zip(Dependency.expand(@f)) do |expected, actual|
- assert_equal expected.tags, actual.tags
- assert_equal expected, actual
- end
- end
-
- def test_merger_preserves_env_proc
- env_proc = stub
- dep = Dependency.new("foo", [], env_proc)
- dep.stubs(:to_formula).returns(stub(deps: [], name: "foo"))
- @deps.replace [dep]
- assert_equal env_proc, Dependency.expand(@f).first.env_proc
- end
-
- def test_merged_tags_no_dupes
- @foo2 = build_dep(:foo, ["option"])
- @foo3 = build_dep(:foo, ["option"])
- @deps << @foo2 << @foo3
-
- assert_equal %w[option], Dependency.expand(@f).first.tags
- end
-
- def test_skip_skips_parent_but_yields_children
- f = stub(
- name: "f",
- deps: [
- build_dep(:foo, [], [@bar, @baz]),
- build_dep(:foo, [], [@baz]),
- ]
- )
-
- deps = Dependency.expand(f) do |_dependent, dep|
- Dependency.skip if %w[foo qux].include? dep.name
- end
-
- assert_equal [@bar, @baz], deps
- end
-
- def test_keep_dep_but_prune_recursive_deps
- foo = build_dep(:foo, [:build], @bar)
- baz = build_dep(:baz, [:build])
- f = stub(name: "f", deps: [foo, baz])
-
- deps = Dependency.expand(f) do |_dependent, dep|
- Dependency.keep_but_prune_recursive_deps if dep.build?
- end
-
- assert_equal [foo, baz], deps
- end
-
- def test_deps_with_collection_argument
- assert_equal [@foo, @bar, @baz, @qux], @f.deps
- assert_equal [@bar, @baz], Dependency.expand(@f, [@bar, @baz])
- end
-
- def test_cyclic_dependency
- foo = build_dep(:foo)
- bar = build_dep(:bar, [], [foo])
- foo.stubs(:to_formula).returns(stub(deps: [bar], name: "foo"))
- f = stub(name: "f", deps: [foo, bar])
- assert_nothing_raised { Dependency.expand(f) }
- end
-
- def test_clean_expand_stack
- foo = build_dep(:foo)
- foo.stubs(:to_formula).raises(FormulaUnavailableError, "foo")
- f = stub(name: "f", deps: [foo])
- assert_raises(FormulaUnavailableError) { Dependency.expand(f) }
- assert_empty Dependency.instance_variable_get(:@expand_stack)
- end
-end
diff --git a/Library/Homebrew/test/dependency_test.rb b/Library/Homebrew/test/dependency_test.rb
index 65255995e..404f26d79 100644
--- a/Library/Homebrew/test/dependency_test.rb
+++ b/Library/Homebrew/test/dependency_test.rb
@@ -3,6 +3,7 @@ require "dependency"
class DependableTests < Homebrew::TestCase
def setup
+ super
@tags = ["foo", "bar", :build]
@dep = Struct.new(:tags).new(@tags).extend(Dependable)
end
@@ -118,6 +119,11 @@ class DependencyTests < Homebrew::TestCase
end
class TapDependencyTests < Homebrew::TestCase
+ def test_tap
+ dep = TapDependency.new("foo/bar/dog")
+ assert_equal Tap.new("foo", "bar"), dep.tap
+ end
+
def test_option_names
dep = TapDependency.new("foo/bar/dog")
assert_equal %w[dog], dep.option_names
diff --git a/Library/Homebrew/test/deps_spec.rb b/Library/Homebrew/test/deps_spec.rb
new file mode 100644
index 000000000..4c892c93d
--- /dev/null
+++ b/Library/Homebrew/test/deps_spec.rb
@@ -0,0 +1,31 @@
+describe "brew deps", :integration_test do
+ before(:each) do
+ setup_test_formula "foo"
+ setup_test_formula "bar"
+ setup_test_formula "baz", <<-EOS.undent
+ url "https://example.com/baz-1.0"
+ depends_on "bar"
+ EOS
+ end
+
+ it "outputs no dependencies for a Formula that has no dependencies" do
+ expect { brew "deps", "foo" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+ end
+
+ it "outputs a dependency for a Formula that has one dependency" do
+ expect { brew "deps", "bar" }
+ .to be_a_success
+ .and output("foo\n").to_stdout
+ .and not_to_output.to_stderr
+ end
+
+ it "outputs all of a Formula's dependencies and their dependencies on separate lines" do
+ expect { brew "deps", "baz" }
+ .to be_a_success
+ .and output("bar\nfoo\n").to_stdout
+ .and not_to_output.to_stderr
+ end
+end
diff --git a/Library/Homebrew/test/deps_test.rb b/Library/Homebrew/test/deps_test.rb
deleted file mode 100644
index 01639857c..000000000
--- a/Library/Homebrew/test/deps_test.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestDeps < IntegrationCommandTestCase
- def test_deps
- setup_test_formula "foo"
- setup_test_formula "bar"
- setup_test_formula "baz", <<-EOS.undent
- url "https://example.com/baz-1.0"
- depends_on "bar"
- EOS
-
- assert_equal "", cmd("deps", "foo")
- assert_equal "foo", cmd("deps", "bar")
- assert_equal "bar\nfoo", cmd("deps", "baz")
- end
-end
diff --git a/Library/Homebrew/test/desc_test.rb b/Library/Homebrew/test/desc_test.rb
deleted file mode 100644
index 2ba498135..000000000
--- a/Library/Homebrew/test/desc_test.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestDesc < IntegrationCommandTestCase
- def test_desc
- setup_test_formula "testball"
-
- assert_equal "testball: Some test", cmd("desc", "testball")
- assert_match "Pick one, and only one", cmd_fail("desc", "--search", "--name")
- assert_match "You must provide a search term", cmd_fail("desc", "--search")
-
- desc_cache = HOMEBREW_CACHE/"desc_cache.json"
- refute_predicate desc_cache, :exist?, "Cached file should not exist"
-
- cmd("desc", "--description", "testball")
- assert_predicate desc_cache, :exist?, "Cached file should not exist"
- end
-end
diff --git a/Library/Homebrew/test/descriptions_spec.rb b/Library/Homebrew/test/descriptions_spec.rb
new file mode 100644
index 000000000..e873c73b4
--- /dev/null
+++ b/Library/Homebrew/test/descriptions_spec.rb
@@ -0,0 +1,42 @@
+require "descriptions"
+
+describe Descriptions do
+ subject { described_class.new(descriptions_hash) }
+ let(:descriptions_hash) { {} }
+
+ it "can print description for a core Formula" do
+ descriptions_hash["homebrew/core/foo"] = "Core foo"
+ expect { subject.print }.to output("foo: Core foo\n").to_stdout
+ end
+
+ it "can print description for an external Formula" do
+ descriptions_hash["somedev/external/foo"] = "External foo"
+ expect { subject.print }.to output("foo: External foo\n").to_stdout
+ end
+
+ it "can print descriptions for duplicate Formulae" do
+ descriptions_hash["homebrew/core/foo"] = "Core foo"
+ descriptions_hash["somedev/external/foo"] = "External foo"
+
+ expect { subject.print }.to output(
+ <<-EOS.undent
+ homebrew/core/foo: Core foo
+ somedev/external/foo: External foo
+ EOS
+ ).to_stdout
+ end
+
+ it "can print descriptions for duplicate core and external Formulae" do
+ descriptions_hash["homebrew/core/foo"] = "Core foo"
+ descriptions_hash["somedev/external/foo"] = "External foo"
+ descriptions_hash["otherdev/external/foo"] = "Other external foo"
+
+ expect { subject.print }.to output(
+ <<-EOS.undent
+ homebrew/core/foo: Core foo
+ otherdev/external/foo: Other external foo
+ somedev/external/foo: External foo
+ EOS
+ ).to_stdout
+ end
+end
diff --git a/Library/Homebrew/test/descriptions_test.rb b/Library/Homebrew/test/descriptions_test.rb
deleted file mode 100644
index de38fdbd1..000000000
--- a/Library/Homebrew/test/descriptions_test.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require "testing_env"
-require "descriptions"
-
-class DescriptionsTest < Homebrew::TestCase
- def setup
- @descriptions_hash = {}
- @descriptions = Descriptions.new(@descriptions_hash)
-
- @old_stdout = $stdout
- $stdout = StringIO.new
- end
-
- def teardown
- $stdout = @old_stdout
- end
-
- def test_single_core_formula
- @descriptions_hash["homebrew/core/foo"] = "Core foo"
- @descriptions.print
- assert_equal "foo: Core foo", $stdout.string.chomp
- end
-
- def test_single_external_formula
- @descriptions_hash["somedev/external/foo"] = "External foo"
- @descriptions.print
- assert_equal "foo: External foo", $stdout.string.chomp
- end
-
- def test_even_dupes
- @descriptions_hash["homebrew/core/foo"] = "Core foo"
- @descriptions_hash["somedev/external/foo"] = "External foo"
- @descriptions.print
- assert_equal "homebrew/core/foo: Core foo\nsomedev/external/foo: External foo",
- $stdout.string.chomp
- end
-
- def test_odd_dupes
- @descriptions_hash["homebrew/core/foo"] = "Core foo"
- @descriptions_hash["somedev/external/foo"] = "External foo"
- @descriptions_hash["otherdev/external/foo"] = "Other external foo"
- @descriptions.print
- assert_equal "homebrew/core/foo: Core foo\notherdev/external/foo: Other external foo\nsomedev/external/foo: External foo",
- $stdout.string.chomp
- end
-end
diff --git a/Library/Homebrew/test/dev-cmd/bottle_spec.rb b/Library/Homebrew/test/dev-cmd/bottle_spec.rb
new file mode 100644
index 000000000..468ef2e90
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/bottle_spec.rb
@@ -0,0 +1,30 @@
+describe "brew bottle", :integration_test do
+ it "builds a bottle for the given Formula" do
+ begin
+ shutup do
+ expect { brew "install", "--build-bottle", testball }
+ .to be_a_success
+ end
+
+ expect { brew "bottle", "--no-rebuild", testball }
+ .to output(/Formula not from core or any taps/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ setup_test_formula "testball"
+
+ # `brew bottle` should not fail with dead symlink
+ # https://github.com/Homebrew/legacy-homebrew/issues/49007
+ (HOMEBREW_CELLAR/"testball/0.1").cd do
+ FileUtils.ln_s "not-exist", "symlink"
+ end
+
+ expect { brew "bottle", "--no-rebuild", "testball" }
+ .to output(/testball-0\.1.*\.bottle\.tar\.gz/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ ensure
+ FileUtils.rm_f Dir.glob("testball-0.1*.bottle.tar.gz")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/dev-cmd/create_spec.rb b/Library/Homebrew/test/dev-cmd/create_spec.rb
new file mode 100644
index 000000000..b7f96ec7f
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/create_spec.rb
@@ -0,0 +1,13 @@
+describe "brew create", :integration_test do
+ let(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" }
+ let(:formula_file) { CoreTap.new.formula_dir/"testball.rb" }
+
+ it "creates a new Formula file for a given URL" do
+ shutup do
+ brew "create", url, "HOMEBREW_EDITOR" => "/bin/cat"
+ end
+
+ expect(formula_file).to exist
+ expect(formula_file.read).to match(%Q(sha256 "#{TESTBALL_SHA256}"))
+ end
+end
diff --git a/Library/Homebrew/test/dev-cmd/edit_spec.rb b/Library/Homebrew/test/dev-cmd/edit_spec.rb
new file mode 100644
index 000000000..5cedb0524
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/edit_spec.rb
@@ -0,0 +1,16 @@
+describe "brew edit", :integration_test do
+ it "opens a given Formula in an editor" do
+ HOMEBREW_REPOSITORY.cd do
+ shutup do
+ system "git", "init"
+ end
+ end
+
+ setup_test_formula "testball"
+
+ expect { brew "edit", "testball", "HOMEBREW_EDITOR" => "/bin/cat" }
+ .to output(/# something here/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/dev-cmd/formula_spec.rb b/Library/Homebrew/test/dev-cmd/formula_spec.rb
new file mode 100644
index 000000000..cc5b3e9e8
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/formula_spec.rb
@@ -0,0 +1,10 @@
+describe "brew formula", :integration_test do
+ it "prints a given Formula's path" do
+ formula_file = setup_test_formula "testball"
+
+ expect { brew "formula", "testball" }
+ .to output("#{formula_file}\n").to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/dev-cmd/pull_spec.rb b/Library/Homebrew/test/dev-cmd/pull_spec.rb
new file mode 100644
index 000000000..3c0108df2
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/pull_spec.rb
@@ -0,0 +1,60 @@
+describe "brew pull", :integration_test do
+ it "fails when no argument is given" do
+ expect { brew "pull" }
+ .to output(/This command requires at least one argument/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fetches a patch from a GitHub commit or pull request and applies it" do
+ skip "Requires network connection." if ENV["HOMEBREW_NO_GITHUB_API"]
+
+ CoreTap.instance.path.cd do
+ shutup do
+ system "git", "init"
+ system "git", "checkout", "-b", "new-branch"
+ end
+ end
+
+ expect { brew "pull", "https://bot.brew.sh/job/Homebrew\%20Testing/1028/" }
+ .to output(/Testing URLs require `\-\-bottle`!/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+
+ expect { brew "pull", "1" }
+ .to output(/Fetching patch/).to_stdout
+ .and output(/Current branch is new\-branch/).to_stderr
+ .and be_a_failure
+
+ expect { brew "pull", "--bump", "8" }
+ .to output(/Fetching patch/).to_stdout
+ .and output(/No changed formulae found to bump/).to_stderr
+ .and be_a_failure
+
+ expect { brew "pull", "--bump", "https://api.github.com/repos/Homebrew/homebrew-core/pulls/122" }
+ .to output(/Fetching patch/).to_stdout
+ .and output(/Can only bump one changed formula/).to_stderr
+ .and be_a_failure
+
+ expect { brew "pull", "https://github.com/Homebrew/homebrew-core/pull/1" }
+ .to output(/Fetching patch/).to_stdout
+ .and output(/Patch failed to apply/).to_stderr
+ .and be_a_failure
+ end
+
+ describe "--rebase" do
+ it "fails" do
+ expect { brew "pull", "--rebase" }
+ .to output(/You meant `git pull --rebase`./).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+ end
+
+ it "fails when given 0" do
+ expect { brew "pull", "0" }
+ .to output(/Not a GitHub pull request or commit/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+end
diff --git a/Library/Homebrew/test/dev-cmd/tap_spec.rb b/Library/Homebrew/test/dev-cmd/tap_spec.rb
new file mode 100644
index 000000000..a24c67aae
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/tap_spec.rb
@@ -0,0 +1,75 @@
+describe "brew tap", :integration_test do
+ it "taps a given Tap" do
+ path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
+ path.mkpath
+ path.cd do
+ shutup do
+ system "git", "init"
+ system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
+ FileUtils.touch "readme"
+ system "git", "add", "--all"
+ system "git", "commit", "-m", "init"
+ end
+ end
+
+ expect { brew "tap" }
+ .to output(%r{homebrew/foo}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap", "--list-official" }
+ .to output(%r{homebrew/science}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap-info" }
+ .to output(/2 taps/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap-info", "homebrew/foo" }
+ .to output(%r{https://github\.com/Homebrew/homebrew-foo}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap-info", "--json=v1", "--installed" }
+ .to output(%r{https://github\.com/Homebrew/homebrew-foo}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap-pin", "homebrew/foo" }
+ .to output(%r{Pinned homebrew/foo}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap", "--list-pinned" }
+ .to output(%r{homebrew/foo}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap-unpin", "homebrew/foo" }
+ .to output(%r{Unpinned homebrew/foo}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap", "homebrew/bar", path/".git" }
+ .to output(/Tapped/).to_stdout
+ .and output(/Cloning/).to_stderr
+ .and be_a_success
+
+ expect { brew "untap", "homebrew/bar" }
+ .to output(/Untapped/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "tap", "homebrew/bar", path/".git", "-q", "--full" }
+ .to be_a_success
+ .and not_to_output.to_stdout
+ .and not_to_output.to_stderr
+
+ expect { brew "untap", "homebrew/bar" }
+ .to output(/Untapped/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/dev-cmd/test_spec.rb b/Library/Homebrew/test/dev-cmd/test_spec.rb
new file mode 100644
index 000000000..b73d042e4
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/test_spec.rb
@@ -0,0 +1,56 @@
+describe "brew test", :integration_test do
+ it "fails when no argument is given" do
+ expect { brew "test" }
+ .to output(/This command requires a formula argument/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fails when a Formula is not installed" do
+ expect { brew "test", testball }
+ .to output(/Testing requires the latest version of testball/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "fails when a Formula has no test" do
+ shutup do
+ expect { brew "install", testball }.to be_a_success
+ end
+
+ expect { brew "test", testball }
+ .to output(/testball defines no test/).to_stderr
+ .and not_to_output.to_stdout
+ .and be_a_failure
+ end
+
+ it "tests a given Formula" do
+ setup_test_formula "testball", <<-EOS.undent
+ head "https://github.com/example/testball2.git"
+
+ devel do
+ url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
+ sha256 "#{TESTBALL_SHA256}"
+ end
+
+ keg_only "just because"
+
+ test do
+ end
+ EOS
+
+ shutup do
+ expect { brew "install", "testball" }.to be_a_success
+ end
+
+ expect { brew "test", "--HEAD", "testball" }
+ .to output(/Testing testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+
+ expect { brew "test", "--devel", "testball" }
+ .to output(/Testing testball/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end
diff --git a/Library/Homebrew/test/diagnostic_spec.rb b/Library/Homebrew/test/diagnostic_spec.rb
new file mode 100644
index 000000000..e749a3b0f
--- /dev/null
+++ b/Library/Homebrew/test/diagnostic_spec.rb
@@ -0,0 +1,188 @@
+require "diagnostic"
+
+describe Homebrew::Diagnostic::Checks do
+ specify "#inject_file_list" do
+ expect(subject.inject_file_list([], "foo:\n")).to eq("foo:\n")
+ expect(subject.inject_file_list(%w[/a /b], "foo:\n")).to eq("foo:\n /a\n /b\n")
+ end
+
+ specify "#check_path_for_trailing_slashes" do
+ ENV["PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
+ expect(subject.check_path_for_trailing_slashes)
+ .to match("Some directories in your path end in a slash")
+ end
+
+ specify "#check_for_anaconda" do
+ Dir.mktmpdir do |path|
+ anaconda = "#{path}/anaconda"
+ python = "#{path}/python"
+ FileUtils.touch anaconda
+ File.open(python, "w") do |file|
+ file.write("#! #{`which bash`}\necho -n '#{python}'\n")
+ end
+ FileUtils.chmod 0755, anaconda
+ FileUtils.chmod 0755, python
+
+ ENV["PATH"] = path + File::PATH_SEPARATOR + ENV["PATH"]
+
+ expect(subject.check_for_anaconda).to match("Anaconda")
+ end
+ end
+
+ specify "#check_access_homebrew_repository" do
+ begin
+ mode = HOMEBREW_REPOSITORY.stat.mode & 0777
+ HOMEBREW_REPOSITORY.chmod 0555
+
+ expect(subject.check_access_homebrew_repository)
+ .to match("#{HOMEBREW_REPOSITORY} is not writable.")
+ ensure
+ HOMEBREW_REPOSITORY.chmod mode
+ end
+ end
+
+ specify "#check_access_logs" do
+ begin
+ mode = HOMEBREW_LOGS.stat.mode & 0777
+ HOMEBREW_LOGS.chmod 0555
+
+ expect(subject.check_access_logs)
+ .to match("#{HOMEBREW_LOGS} isn't writable.")
+ ensure
+ HOMEBREW_LOGS.chmod mode
+ end
+ end
+
+ specify "#check_access_cache" do
+ begin
+ mode = HOMEBREW_CACHE.stat.mode & 0777
+ HOMEBREW_CACHE.chmod 0555
+ expect(subject.check_access_cache)
+ .to match("#{HOMEBREW_CACHE} isn't writable.")
+ ensure
+ HOMEBREW_CACHE.chmod mode
+ end
+ end
+
+ specify "#check_access_cellar" do
+ begin
+ mode = HOMEBREW_CELLAR.stat.mode & 0777
+ HOMEBREW_CELLAR.chmod 0555
+
+ expect(subject.check_access_cellar)
+ .to match("#{HOMEBREW_CELLAR} isn't writable.")
+ ensure
+ HOMEBREW_CELLAR.chmod mode
+ end
+ end
+
+ specify "#check_homebrew_prefix" do
+ ENV.delete("JENKINS_HOME")
+ # the integration tests are run in a special prefix
+ expect(subject.check_homebrew_prefix)
+ .to match("Your Homebrew's prefix is not /usr/local.")
+ end
+
+ specify "#check_user_path_1" do
+ bin = HOMEBREW_PREFIX/"bin"
+ sep = File::PATH_SEPARATOR
+ # ensure /usr/bin is before HOMEBREW_PREFIX/bin in the PATH
+ ENV["PATH"] = "/usr/bin#{sep}#{bin}#{sep}" +
+ ENV["PATH"].gsub(%r{(?:^|#{sep})(?:/usr/bin|#{bin})}, "")
+
+ # ensure there's at least one file with the same name in both /usr/bin/ and
+ # HOMEBREW_PREFIX/bin/
+ (bin/File.basename(Dir["/usr/bin/*"].first)).mkpath
+
+ expect(subject.check_user_path_1)
+ .to match("/usr/bin occurs before #{HOMEBREW_PREFIX}/bin")
+ end
+
+ specify "#check_user_path_2" do
+ ENV["PATH"] = ENV["PATH"].gsub \
+ %r{(?:^|#{File::PATH_SEPARATOR})#{HOMEBREW_PREFIX}/bin}, ""
+
+ expect(subject.check_user_path_1).to be nil
+ expect(subject.check_user_path_2)
+ .to match("Homebrew's bin was not found in your PATH.")
+ end
+
+ specify "#check_user_path_3" do
+ begin
+ sbin = HOMEBREW_PREFIX/"sbin"
+ ENV["PATH"] = "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
+ ENV["PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
+ (sbin/"something").mkpath
+
+ expect(subject.check_user_path_1).to be nil
+ expect(subject.check_user_path_2).to be nil
+ expect(subject.check_user_path_3)
+ .to match("Homebrew's sbin was not found in your PATH")
+ ensure
+ sbin.rmtree
+ end
+ end
+
+ specify "#check_user_curlrc" do
+ Dir.mktmpdir do |path|
+ FileUtils.touch "#{path}/.curlrc"
+ ENV["CURL_HOME"] = path
+
+ expect(subject.check_user_curlrc).to match("You have a curlrc file")
+ end
+ end
+
+ specify "#check_for_config_scripts" do
+ Dir.mktmpdir do |path|
+ file = "#{path}/foo-config"
+ FileUtils.touch file
+ FileUtils.chmod 0755, file
+ ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
+
+ expect(subject.check_for_config_scripts)
+ .to match('"config" scripts exist')
+ end
+ end
+
+ specify "#check_dyld_vars" do
+ ENV["DYLD_INSERT_LIBRARIES"] = "foo"
+ expect(subject.check_dyld_vars).to match("Setting DYLD_INSERT_LIBRARIES")
+ end
+
+ specify "#check_for_symlinked_cellar" do
+ begin
+ HOMEBREW_CELLAR.rmtree
+
+ Dir.mktmpdir do |path|
+ FileUtils.ln_s path, HOMEBREW_CELLAR
+
+ expect(subject.check_for_symlinked_cellar).to match(path)
+ end
+ ensure
+ HOMEBREW_CELLAR.unlink
+ HOMEBREW_CELLAR.mkpath
+ end
+ end
+
+ specify "#check_tmpdir" do
+ ENV["TMPDIR"] = "/i/don/t/exis/t"
+ expect(subject.check_tmpdir).to match("doesn't exist")
+ end
+
+ specify "#check_for_external_cmd_name_conflict" do
+ Dir.mktmpdir do |path1|
+ Dir.mktmpdir do |path2|
+ [path1, path2].each do |path|
+ cmd = "#{path}/brew-foo"
+ FileUtils.touch cmd
+ FileUtils.chmod 0755, cmd
+ end
+
+ ENV["PATH"] = [path1, path2, ENV["PATH"]].join File::PATH_SEPARATOR
+
+ expect(subject.check_for_external_cmd_name_conflict)
+ .to match("brew-foo")
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/diagnostic_test.rb b/Library/Homebrew/test/diagnostic_test.rb
deleted file mode 100644
index c9bb524b0..000000000
--- a/Library/Homebrew/test/diagnostic_test.rb
+++ /dev/null
@@ -1,198 +0,0 @@
-require "testing_env"
-require "fileutils"
-require "pathname"
-require "diagnostic"
-
-class DiagnosticChecksTest < Homebrew::TestCase
- def setup
- @env = ENV.to_hash
- @checks = Homebrew::Diagnostic::Checks.new
- end
-
- def teardown
- ENV.replace(@env)
- end
-
- def test_inject_file_list
- assert_equal "foo:\n",
- @checks.inject_file_list([], "foo:\n")
- assert_equal "foo:\n /a\n /b\n",
- @checks.inject_file_list(%w[/a /b], "foo:\n")
- end
-
- def test_check_path_for_trailing_slashes
- ENV["PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
- assert_match "Some directories in your path end in a slash",
- @checks.check_path_for_trailing_slashes
- end
-
- def test_check_for_anaconda
- mktmpdir do |path|
- anaconda = "#{path}/anaconda"
- python = "#{path}/python"
- FileUtils.touch anaconda
- File.open(python, "w") do |file|
- file.write("#! #{`which bash`}\necho -n '#{python}'\n")
- end
- FileUtils.chmod 0755, anaconda
- FileUtils.chmod 0755, python
-
- ENV["PATH"] = path + File::PATH_SEPARATOR + ENV["PATH"]
-
- assert_match "Anaconda",
- @checks.check_for_anaconda
- end
- end
-
- def test_check_access_homebrew_repository
- mod = HOMEBREW_REPOSITORY.stat.mode & 0777
- HOMEBREW_REPOSITORY.chmod 0555
-
- assert_match "#{HOMEBREW_REPOSITORY} is not writable.",
- @checks.check_access_homebrew_repository
- ensure
- HOMEBREW_REPOSITORY.chmod mod
- end
-
- def test_check_access_logs
- mod = HOMEBREW_LOGS.stat.mode & 0777
- HOMEBREW_LOGS.chmod 0555
-
- assert_match "#{HOMEBREW_LOGS} isn't writable.",
- @checks.check_access_logs
- ensure
- HOMEBREW_LOGS.chmod mod
- end
-
- def test_check_access_cache
- mod = HOMEBREW_CACHE.stat.mode & 0777
- HOMEBREW_CACHE.chmod 0555
- assert_match "#{HOMEBREW_CACHE} isn't writable.",
- @checks.check_access_cache
- ensure
- HOMEBREW_CACHE.chmod mod
- end
-
- def test_check_access_cellar
- mod = HOMEBREW_CELLAR.stat.mode & 0777
- HOMEBREW_CELLAR.chmod 0555
-
- assert_match "#{HOMEBREW_CELLAR} isn't writable.",
- @checks.check_access_cellar
- ensure
- HOMEBREW_CELLAR.chmod mod
- end
-
- def test_check_homebrew_prefix
- ENV.delete("JENKINS_HOME")
- # the integration tests are run in a special prefix
- assert_match "Your Homebrew's prefix is not /usr/local.",
- @checks.check_homebrew_prefix
- end
-
- def test_check_user_path_usr_bin_before_homebrew
- bin = HOMEBREW_PREFIX/"bin"
- sep = File::PATH_SEPARATOR
- # ensure /usr/bin is before HOMEBREW_PREFIX/bin in the PATH
- ENV["PATH"] = "/usr/bin#{sep}#{bin}#{sep}" +
- ENV["PATH"].gsub(%r{(?:^|#{sep})(?:/usr/bin|#{bin})}, "")
-
- # ensure there's at least one file with the same name in both /usr/bin/ and
- # HOMEBREW_PREFIX/bin/
- (bin/File.basename(Dir["/usr/bin/*"].first)).mkpath
-
- assert_match "/usr/bin occurs before #{HOMEBREW_PREFIX}/bin",
- @checks.check_user_path_1
- ensure
- bin.rmtree
- end
-
- def test_check_user_path_bin
- ENV["PATH"] = ENV["PATH"].gsub \
- %r{(?:^|#{File::PATH_SEPARATOR})#{HOMEBREW_PREFIX}/bin}, ""
-
- assert_nil @checks.check_user_path_1
- assert_match "Homebrew's bin was not found in your PATH.",
- @checks.check_user_path_2
- end
-
- def test_check_user_path_sbin
- sbin = HOMEBREW_PREFIX/"sbin"
- ENV["PATH"] = "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
- ENV["PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
- (sbin/"something").mkpath
-
- assert_nil @checks.check_user_path_1
- assert_nil @checks.check_user_path_2
- assert_match "Homebrew's sbin was not found in your PATH",
- @checks.check_user_path_3
- ensure
- sbin.rmtree
- end
-
- def test_check_user_curlrc
- mktmpdir do |path|
- FileUtils.touch "#{path}/.curlrc"
- ENV["CURL_HOME"] = path
-
- assert_match "You have a curlrc file",
- @checks.check_user_curlrc
- end
- end
-
- def test_check_for_config_scripts
- mktmpdir do |path|
- file = "#{path}/foo-config"
- FileUtils.touch file
- FileUtils.chmod 0755, file
- ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
-
- assert_match '"config" scripts exist',
- @checks.check_for_config_scripts
- end
- end
-
- def test_check_dyld_vars
- ENV["DYLD_INSERT_LIBRARIES"] = "foo"
- assert_match "Setting DYLD_INSERT_LIBRARIES",
- @checks.check_dyld_vars
- end
-
- def test_check_for_symlinked_cellar
- HOMEBREW_CELLAR.rmtree
-
- mktmpdir do |path|
- FileUtils.ln_s path, HOMEBREW_CELLAR
-
- assert_match path,
- @checks.check_for_symlinked_cellar
- end
-
- ensure
- HOMEBREW_CELLAR.unlink
- HOMEBREW_CELLAR.mkpath
- end
-
- def test_check_tmpdir
- ENV["TMPDIR"] = "/i/don/t/exis/t"
- assert_match "doesn't exist",
- @checks.check_tmpdir
- end
-
- def test_check_for_external_cmd_name_conflict
- mktmpdir do |path1|
- mktmpdir do |path2|
- [path1, path2].each do |path|
- cmd = "#{path}/brew-foo"
- FileUtils.touch cmd
- FileUtils.chmod 0755, cmd
- end
-
- ENV["PATH"] = [path1, path2, ENV["PATH"]].join File::PATH_SEPARATOR
-
- assert_match "brew-foo",
- @checks.check_for_external_cmd_name_conflict
- end
- end
- end
-end
diff --git a/Library/Homebrew/test/doctor_test.rb b/Library/Homebrew/test/doctor_test.rb
deleted file mode 100644
index d2dc871f4..000000000
--- a/Library/Homebrew/test/doctor_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestDoctor < IntegrationCommandTestCase
- def test_doctor
- assert_match "This is an integration test",
- cmd_fail("doctor", "check_integration_test")
- end
-end
diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb
new file mode 100644
index 000000000..f466b97f4
--- /dev/null
+++ b/Library/Homebrew/test/download_strategies_spec.rb
@@ -0,0 +1,232 @@
+require "download_strategy"
+
+describe AbstractDownloadStrategy do
+ subject { described_class.new(name, resource) }
+ let(:name) { "foo" }
+ let(:url) { "http://example.com/foo.tar.gz" }
+ let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) }
+ let(:args) { %w[foo bar baz] }
+
+ describe "#expand_safe_system_args" do
+ it "works with an explicit quiet flag" do
+ args << { quiet_flag: "--flag" }
+ expanded_args = subject.expand_safe_system_args(args)
+ expect(expanded_args).to eq(%w[foo bar baz --flag])
+ end
+
+ it "adds an implicit quiet flag" do
+ expanded_args = subject.expand_safe_system_args(args)
+ expect(expanded_args).to eq(%w[foo bar -q baz])
+ end
+
+ it "does not mutate the arguments" do
+ result = subject.expand_safe_system_args(args)
+ expect(args).to eq(%w[foo bar baz])
+ expect(result).not_to be args
+ end
+ end
+
+ specify "#source_modified_time" do
+ FileUtils.mktemp "mtime" do
+ FileUtils.touch "foo", mtime: Time.now - 10
+ FileUtils.touch "bar", mtime: Time.now - 100
+ FileUtils.ln_s "not-exist", "baz"
+ expect(subject.source_modified_time).to eq(File.mtime("foo"))
+ end
+ end
+end
+
+describe VCSDownloadStrategy do
+ let(:url) { "http://example.com/bar" }
+ let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) }
+
+ describe "#cached_location" do
+ it "returns the path of the cached resource" do
+ allow_any_instance_of(described_class).to receive(:cache_tag).and_return("foo")
+ downloader = described_class.new("baz", resource)
+ expect(downloader.cached_location).to eq(HOMEBREW_CACHE/"baz--foo")
+ end
+ end
+end
+
+describe GitHubPrivateRepositoryDownloadStrategy do
+ subject { described_class.new("foo", resource) }
+ let(:url) { "https://github.com/owner/repo/archive/1.1.5.tar.gz" }
+ let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) }
+
+ before(:each) do
+ ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
+ allow(GitHub).to receive(:repository).and_return({})
+ end
+
+ it "sets the @github_token instance variable" do
+ expect(subject.instance_variable_get(:@github_token)).to eq("token")
+ end
+
+ it "parses the URL and sets the corresponding instance variables" do
+ expect(subject.instance_variable_get(:@owner)).to eq("owner")
+ expect(subject.instance_variable_get(:@repo)).to eq("repo")
+ expect(subject.instance_variable_get(:@filepath)).to eq("archive/1.1.5.tar.gz")
+ end
+
+ its(:download_url) { is_expected.to eq("https://token@github.com/owner/repo/archive/1.1.5.tar.gz") }
+end
+
+describe GitHubPrivateRepositoryReleaseDownloadStrategy do
+ subject { described_class.new("foo", resource) }
+ let(:url) { "https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz" }
+ let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) }
+
+ before(:each) do
+ ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
+ allow(GitHub).to receive(:repository).and_return({})
+ end
+
+ it "parses the URL and sets the corresponding instance variables" do
+ expect(subject.instance_variable_get(:@owner)).to eq("owner")
+ expect(subject.instance_variable_get(:@repo)).to eq("repo")
+ expect(subject.instance_variable_get(:@tag)).to eq("tag")
+ expect(subject.instance_variable_get(:@filename)).to eq("foo_v0.1.0_darwin_amd64.tar.gz")
+ end
+
+ describe "#download_url" do
+ it "returns the download URL for a given resource" do
+ allow(subject).to receive(:resolve_asset_id).and_return(456)
+ expect(subject.download_url).to eq("https://token@api.github.com/repos/owner/repo/releases/assets/456")
+ end
+ end
+
+ specify "#resolve_asset_id" do
+ release_metadata = {
+ "assets" => [
+ {
+ "id" => 123,
+ "name" => "foo_v0.1.0_linux_amd64.tar.gz",
+ },
+ {
+ "id" => 456,
+ "name" => "foo_v0.1.0_darwin_amd64.tar.gz",
+ },
+ ],
+ }
+ allow(subject).to receive(:fetch_release_metadata).and_return(release_metadata)
+ expect(subject.send(:resolve_asset_id)).to eq(456)
+ end
+
+ describe "#fetch_release_metadata" do
+ it "fetches release metadata from GitHub" do
+ expected_release_url = "https://api.github.com/repos/owner/repo/releases/tags/tag"
+ expect(GitHub).to receive(:open).with(expected_release_url).and_return({})
+ subject.send(:fetch_release_metadata)
+ end
+ end
+end
+
+describe GitHubGitDownloadStrategy do
+ subject { described_class.new(name, resource) }
+ let(:name) { "brew" }
+ let(:url) { "https://github.com/homebrew/brew.git" }
+ let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) }
+
+ it "parses the URL and sets the corresponding instance variables" do
+ expect(subject.instance_variable_get(:@user)).to eq("homebrew")
+ expect(subject.instance_variable_get(:@repo)).to eq("brew")
+ end
+end
+
+describe GitDownloadStrategy do
+ subject { described_class.new(name, resource) }
+ let(:name) { "baz" }
+ let(:url) { "https://github.com/homebrew/foo" }
+ let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: nil) }
+ let(:cached_location) { subject.cached_location }
+
+ before(:each) do
+ @commit_id = 1
+ FileUtils.mkpath cached_location
+ end
+
+ def git_commit_all
+ shutup do
+ system "git", "add", "--all"
+ system "git", "commit", "-m", "commit number #{@commit_id}"
+ @commit_id += 1
+ end
+ end
+
+ def setup_git_repo
+ shutup do
+ system "git", "init"
+ system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
+ end
+ FileUtils.touch "README"
+ git_commit_all
+ end
+
+ describe "#source_modified_time" do
+ it "returns the right modification time" do
+ cached_location.cd do
+ setup_git_repo
+ end
+ expect(subject.source_modified_time.to_i).to eq(1_485_115_153)
+ end
+ end
+
+ specify "#last_commit" do
+ cached_location.cd do
+ setup_git_repo
+ FileUtils.touch "LICENSE"
+ git_commit_all
+ end
+ expect(subject.last_commit).to eq("f68266e")
+ end
+
+ describe "#fetch_last_commit" do
+ let(:url) { "file://#{remote_repo}" }
+ let(:version) { Version.create("HEAD") }
+ let(:resource) { double(Resource, url: url, mirrors: [], specs: {}, version: version) }
+ let(:remote_repo) { HOMEBREW_PREFIX/"remote_repo" }
+
+ before(:each) { remote_repo.mkpath }
+
+ after(:each) { FileUtils.rm_rf remote_repo }
+
+ it "fetches the hash of the last commit" do
+ remote_repo.cd do
+ setup_git_repo
+ FileUtils.touch "LICENSE"
+ git_commit_all
+ end
+
+ subject.shutup!
+ expect(subject.fetch_last_commit).to eq("f68266e")
+ end
+ end
+end
+
+describe DownloadStrategyDetector do
+ describe "::detect" do
+ subject { described_class.detect(url) }
+ let(:url) { Object.new }
+
+ context "when given Git URL" do
+ let(:url) { "git://example.com/foo.git" }
+ it { is_expected.to eq(GitDownloadStrategy) }
+ end
+
+ context "when given a GitHub Git URL" do
+ let(:url) { "https://github.com/homebrew/brew.git" }
+ it { is_expected.to eq(GitHubGitDownloadStrategy) }
+ end
+
+ it "defaults to cURL" do
+ expect(subject).to eq(CurlDownloadStrategy)
+ end
+
+ it "raises an error when passed an unrecognized strategy" do
+ expect {
+ described_class.detect("foo", Class.new)
+ }.to raise_error(TypeError)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/download_strategies_test.rb b/Library/Homebrew/test/download_strategies_test.rb
deleted file mode 100644
index 2b64abbf9..000000000
--- a/Library/Homebrew/test/download_strategies_test.rb
+++ /dev/null
@@ -1,262 +0,0 @@
-require "testing_env"
-require "download_strategy"
-
-class ResourceDouble
- attr_reader :url, :specs, :version, :mirrors
-
- def initialize(url = "http://example.com/foo.tar.gz", specs = {})
- @url = url
- @specs = specs
- @mirrors = []
- end
-end
-
-class AbstractDownloadStrategyTests < Homebrew::TestCase
- include FileUtils
-
- def setup
- @name = "foo"
- @resource = ResourceDouble.new
- @strategy = AbstractDownloadStrategy.new(@name, @resource)
- @args = %w[foo bar baz]
- end
-
- def test_expand_safe_system_args_with_explicit_quiet_flag
- @args << { quiet_flag: "--flag" }
- expanded_args = @strategy.expand_safe_system_args(@args)
- assert_equal %w[foo bar baz --flag], expanded_args
- end
-
- def test_expand_safe_system_args_with_implicit_quiet_flag
- expanded_args = @strategy.expand_safe_system_args(@args)
- assert_equal %w[foo bar -q baz], expanded_args
- end
-
- def test_expand_safe_system_args_does_not_mutate_argument
- result = @strategy.expand_safe_system_args(@args)
- assert_equal %w[foo bar baz], @args
- refute_same @args, result
- end
-
- def test_source_modified_time
- mktemp "mtime" do
- touch "foo", mtime: Time.now - 10
- touch "bar", mtime: Time.now - 100
- ln_s "not-exist", "baz"
- assert_equal File.mtime("foo"), @strategy.source_modified_time
- end
- end
-end
-
-class VCSDownloadStrategyTests < Homebrew::TestCase
- def test_cache_filename
- resource = ResourceDouble.new("http://example.com/bar")
- strategy = Class.new(VCSDownloadStrategy) do
- def cache_tag
- "foo"
- end
- end
- downloader = strategy.new("baz", resource)
- assert_equal HOMEBREW_CACHE.join("baz--foo"), downloader.cached_location
- end
-end
-
-class GitHubPrivateRepositoryDownloadStrategyTests < Homebrew::TestCase
- def setup
- resource = ResourceDouble.new("https://github.com/owner/repo/archive/1.1.5.tar.gz")
- ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
- GitHub.stubs(:repository).returns {}
- @strategy = GitHubPrivateRepositoryDownloadStrategy.new("foo", resource)
- end
-
- def test_set_github_token
- assert_equal "token", @strategy.instance_variable_get(:@github_token)
- end
-
- def test_parse_url_pattern
- assert_equal "owner", @strategy.instance_variable_get(:@owner)
- assert_equal "repo", @strategy.instance_variable_get(:@repo)
- assert_equal "archive/1.1.5.tar.gz", @strategy.instance_variable_get(:@filepath)
- end
-
- def test_download_url
- expected = "https://token@github.com/owner/repo/archive/1.1.5.tar.gz"
- assert_equal expected, @strategy.download_url
- end
-end
-
-class GitHubPrivateRepositoryReleaseDownloadStrategyTests < Homebrew::TestCase
- def setup
- resource = ResourceDouble.new("https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz")
- ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
- GitHub.stubs(:repository).returns {}
- @strategy = GitHubPrivateRepositoryReleaseDownloadStrategy.new("foo", resource)
- end
-
- def test_parse_url_pattern
- assert_equal "owner", @strategy.instance_variable_get(:@owner)
- assert_equal "repo", @strategy.instance_variable_get(:@repo)
- assert_equal "tag", @strategy.instance_variable_get(:@tag)
- assert_equal "foo_v0.1.0_darwin_amd64.tar.gz", @strategy.instance_variable_get(:@filename)
- end
-
- def test_download_url
- @strategy.stubs(:resolve_asset_id).returns(456)
- expected = "https://token@api.github.com/repos/owner/repo/releases/assets/456"
- assert_equal expected, @strategy.download_url
- end
-
- def test_resolve_asset_id
- release_metadata = {
- "assets" => [
- {
- "id" => 123,
- "name" => "foo_v0.1.0_linux_amd64.tar.gz",
- },
- {
- "id" => 456,
- "name" => "foo_v0.1.0_darwin_amd64.tar.gz",
- },
- ],
- }
- @strategy.stubs(:fetch_release_metadata).returns(release_metadata)
- assert_equal 456, @strategy.send(:resolve_asset_id)
- end
-
- def test_fetch_release_metadata
- expected_release_url = "https://api.github.com/repos/owner/repo/releases/tags/tag"
- github_mock = MiniTest::Mock.new
- github_mock.expect :call, {}, [expected_release_url]
- GitHub.stub :open, github_mock do
- @strategy.send(:fetch_release_metadata)
- end
- github_mock.verify
- end
-end
-
-class GitDownloadStrategyTests < Homebrew::TestCase
- include FileUtils
-
- def setup
- resource = ResourceDouble.new("https://github.com/homebrew/foo")
- @commit_id = 1
- @strategy = GitDownloadStrategy.new("baz", resource)
- @cached_location = @strategy.cached_location
- mkpath @cached_location
- end
-
- def teardown
- rmtree @cached_location
- end
-
- def git_commit_all
- shutup do
- system "git", "add", "--all"
- system "git", "commit", "-m", "commit number #{@commit_id}"
- @commit_id += 1
- end
- end
-
- def using_git_env
- initial_env = ENV.to_hash
- %w[AUTHOR COMMITTER].each do |role|
- ENV["GIT_#{role}_NAME"] = "brew tests"
- ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
- ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
- end
- yield
- ensure
- ENV.replace(initial_env)
- end
-
- def setup_git_repo
- using_git_env do
- @cached_location.cd do
- shutup do
- system "git", "init"
- system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
- end
- touch "README"
- git_commit_all
- end
- end
- end
-
- def test_github_git_download_strategy_user_repo
- resource = ResourceDouble.new("https://github.com/homebrew/brew.git")
- strategy = GitHubGitDownloadStrategy.new("brew", resource)
-
- assert_equal strategy.instance_variable_get(:@user), "homebrew"
- assert_equal strategy.instance_variable_get(:@repo), "brew"
- end
-
- def test_source_modified_time
- setup_git_repo
- assert_equal 1_242_860_651, @strategy.source_modified_time.to_i
- end
-
- def test_last_commit
- setup_git_repo
- using_git_env do
- @cached_location.cd do
- touch "LICENSE"
- git_commit_all
- end
- end
- assert_equal "c50c79b", @strategy.last_commit
- end
-
- def test_fetch_last_commit
- remote_repo = HOMEBREW_PREFIX.join("remote_repo")
- remote_repo.mkdir
-
- resource = ResourceDouble.new("file://#{remote_repo}")
- resource.instance_variable_set(:@version, Version.create("HEAD"))
- @strategy = GitDownloadStrategy.new("baz", resource)
-
- using_git_env do
- remote_repo.cd do
- shutup do
- system "git", "init"
- system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
- end
- touch "README"
- git_commit_all
- touch "LICENSE"
- git_commit_all
- end
- end
-
- @strategy.shutup!
- assert_equal "c50c79b", @strategy.fetch_last_commit
- ensure
- remote_repo.rmtree if remote_repo.directory?
- end
-end
-
-class DownloadStrategyDetectorTests < Homebrew::TestCase
- def setup
- @d = DownloadStrategyDetector.new
- end
-
- def test_detect_git_download_startegy
- @d = DownloadStrategyDetector.detect("git://example.com/foo.git")
- assert_equal GitDownloadStrategy, @d
- end
-
- def test_detect_github_git_download_strategy
- @d = DownloadStrategyDetector.detect("https://github.com/homebrew/brew.git")
- assert_equal GitHubGitDownloadStrategy, @d
- end
-
- def test_default_to_curl_strategy
- @d = DownloadStrategyDetector.detect(Object.new)
- assert_equal CurlDownloadStrategy, @d
- end
-
- def test_raises_when_passed_unrecognized_strategy
- assert_raises(TypeError) do
- DownloadStrategyDetector.detect("foo", Class.new)
- end
- end
-end
diff --git a/Library/Homebrew/test/edit_test.rb b/Library/Homebrew/test/edit_test.rb
deleted file mode 100644
index 9b6ded651..000000000
--- a/Library/Homebrew/test/edit_test.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestEdit < IntegrationCommandTestCase
- def test_edit
- (HOMEBREW_REPOSITORY/".git").mkpath
- setup_test_formula "testball"
-
- assert_match "# something here",
- cmd("edit", "testball", "HOMEBREW_EDITOR" => "/bin/cat")
- end
-end
diff --git a/Library/Homebrew/test/emoji_spec.rb b/Library/Homebrew/test/emoji_spec.rb
new file mode 100644
index 000000000..35d077ebe
--- /dev/null
+++ b/Library/Homebrew/test/emoji_spec.rb
@@ -0,0 +1,16 @@
+require "emoji"
+
+describe Emoji do
+ describe "#install_badge" do
+ subject { described_class.install_badge }
+
+ it "returns 🍺 by default" do
+ expect(subject).to eq "🍺"
+ end
+
+ it "returns the contents of HOMEBREW_INSTALL_BADGE if set" do
+ ENV["HOMEBREW_INSTALL_BADGE"] = "foo"
+ expect(subject).to eq "foo"
+ end
+ end
+end
diff --git a/Library/Homebrew/test/exceptions_spec.rb b/Library/Homebrew/test/exceptions_spec.rb
new file mode 100644
index 000000000..33547ea32
--- /dev/null
+++ b/Library/Homebrew/test/exceptions_spec.rb
@@ -0,0 +1,188 @@
+require "exceptions"
+
+describe MultipleVersionsInstalledError do
+ subject { described_class.new("foo") }
+ its(:to_s) { is_expected.to eq("foo has multiple installed versions") }
+end
+
+describe NoSuchKegError do
+ subject { described_class.new("foo") }
+ its(:to_s) { is_expected.to eq("No such keg: #{HOMEBREW_CELLAR}/foo") }
+end
+
+describe FormulaValidationError do
+ subject { described_class.new("foo", "sha257", "magic") }
+ its(:to_s) {
+ is_expected.to eq(%q(invalid attribute for formula 'foo': sha257 ("magic")))
+ }
+end
+
+describe FormulaUnavailableError do
+ subject { described_class.new("foo") }
+
+ describe "#dependent_s" do
+ it "returns nil if there is no dependent" do
+ expect(subject.dependent_s).to be nil
+ end
+
+ it "returns nil if it depended on by itself" do
+ subject.dependent = "foo"
+ expect(subject.dependent_s).to be nil
+ end
+
+ it "returns a string if there is a dependent" do
+ subject.dependent = "foobar"
+ expect(subject.dependent_s).to eq("(dependency of foobar)")
+ end
+ end
+
+ context "without a dependent" do
+ its(:to_s) { is_expected.to eq('No available formula with the name "foo" ') }
+ end
+
+ context "with a dependent" do
+ before(:each) do
+ subject.dependent = "foobar"
+ end
+
+ its(:to_s) {
+ is_expected.to eq('No available formula with the name "foo" (dependency of foobar)')
+ }
+ end
+end
+
+describe TapFormulaUnavailableError do
+ subject { described_class.new(tap, "foo") }
+ let(:tap) { double(Tap, user: "u", repo: "r", to_s: "u/r", installed?: false) }
+ its(:to_s) { is_expected.to match(%r{Please tap it and then try again: brew tap u/r}) }
+end
+
+describe FormulaClassUnavailableError do
+ subject { described_class.new("foo", "foo.rb", "Foo", list) }
+ let(:mod) do
+ Module.new do
+ class Bar < Requirement; end
+ class Baz < Formula; end
+ end
+ end
+
+ context "no classes" do
+ let(:list) { [] }
+ its(:to_s) {
+ is_expected.to match(/Expected to find class Foo, but found no classes\./)
+ }
+ end
+
+ context "class not derived from Formula" do
+ let(:list) { [mod.const_get(:Bar)] }
+ its(:to_s) {
+ is_expected.to match(/Expected to find class Foo, but only found: Bar \(not derived from Formula!\)\./)
+ }
+ end
+
+ context "class derived from Formula" do
+ let(:list) { [mod.const_get(:Baz)] }
+ its(:to_s) { is_expected.to match(/Expected to find class Foo, but only found: Baz\./) }
+ end
+end
+
+describe FormulaUnreadableError do
+ subject { described_class.new("foo", formula_error) }
+ let(:formula_error) { LoadError.new("bar") }
+ its(:to_s) { is_expected.to eq("foo: bar") }
+end
+
+describe TapUnavailableError do
+ subject { described_class.new("foo") }
+ its(:to_s) { is_expected.to eq("No available tap foo.\n") }
+end
+
+describe TapAlreadyTappedError do
+ subject { described_class.new("foo") }
+ its(:to_s) { is_expected.to eq("Tap foo already tapped.\n") }
+end
+
+describe TapPinStatusError do
+ context "pinned" do
+ subject { described_class.new("foo", true) }
+ its(:to_s) { is_expected.to eq("foo is already pinned.") }
+ end
+
+ context "unpinned" do
+ subject { described_class.new("foo", false) }
+ its(:to_s) { is_expected.to eq("foo is already unpinned.") }
+ end
+end
+
+describe BuildError do
+ subject { described_class.new(formula, "badprg", %w[arg1 arg2], {}) }
+ let(:formula) { double(Formula, name: "foo") }
+ its(:to_s) { is_expected.to eq("Failed executing: badprg arg1 arg2") }
+end
+
+describe OperationInProgressError do
+ subject { described_class.new("foo") }
+ its(:to_s) { is_expected.to match(/Operation already in progress for foo/) }
+end
+
+describe FormulaInstallationAlreadyAttemptedError do
+ subject { described_class.new(formula) }
+ let(:formula) { double(Formula, full_name: "foo/bar") }
+ its(:to_s) { is_expected.to eq("Formula installation already attempted: foo/bar") }
+end
+
+describe FormulaConflictError do
+ subject { described_class.new(formula, [conflict]) }
+ let(:formula) { double(Formula, full_name: "foo/qux") }
+ let(:conflict) { double(name: "bar", reason: "I decided to") }
+ its(:to_s) { is_expected.to match(/Please `brew unlink bar` before continuing\./) }
+end
+
+describe CompilerSelectionError do
+ subject { described_class.new(formula) }
+ let(:formula) { double(Formula, full_name: "foo") }
+ its(:to_s) { is_expected.to match(/foo cannot be built with any available compilers\./) }
+end
+
+describe CurlDownloadStrategyError do
+ context "file does not exist" do
+ subject { described_class.new("file:///tmp/foo") }
+ its(:to_s) { is_expected.to eq("File does not exist: /tmp/foo") }
+ end
+
+ context "download failed" do
+ subject { described_class.new("http://brew.sh") }
+ its(:to_s) { is_expected.to eq("Download failed: http://brew.sh") }
+ end
+end
+
+describe ErrorDuringExecution do
+ subject { described_class.new("badprg", %w[arg1 arg2]) }
+ its(:to_s) { is_expected.to eq("Failure while executing: badprg arg1 arg2") }
+end
+
+describe ChecksumMismatchError do
+ subject { described_class.new("/file.tar.gz", hash1, hash2) }
+ let(:hash1) { double(hash_type: "sha256", to_s: "deadbeef") }
+ let(:hash2) { double(hash_type: "sha256", to_s: "deadcafe") }
+ its(:to_s) { is_expected.to match(/SHA256 mismatch/) }
+end
+
+describe ResourceMissingError do
+ subject { described_class.new(formula, resource) }
+ let(:formula) { double(Formula, full_name: "bar") }
+ let(:resource) { double(inspect: "<resource foo>") }
+ its(:to_s) { is_expected.to eq("bar does not define resource <resource foo>") }
+end
+
+describe DuplicateResourceError do
+ subject { described_class.new(resource) }
+ let(:resource) { double(inspect: "<resource foo>") }
+ its(:to_s) { is_expected.to eq("Resource <resource foo> is defined more than once") }
+end
+
+describe BottleVersionMismatchError do
+ subject { described_class.new("/foo.bottle.tar.gz", "1.0", formula, "1.1") }
+ let(:formula) { double(Formula, full_name: "foo") }
+ its(:to_s) { is_expected.to match(/Bottle version mismatch/) }
+end
diff --git a/Library/Homebrew/test/exceptions_test.rb b/Library/Homebrew/test/exceptions_test.rb
deleted file mode 100644
index 689531c6e..000000000
--- a/Library/Homebrew/test/exceptions_test.rb
+++ /dev/null
@@ -1,142 +0,0 @@
-require "testing_env"
-require "exceptions"
-
-class ExceptionsTest < Homebrew::TestCase
- def test_multiple_versions_installed_error
- assert_equal "foo has multiple installed versions",
- MultipleVersionsInstalledError.new("foo").to_s
- end
-
- def test_no_such_keg_error
- assert_equal "No such keg: #{HOMEBREW_CELLAR}/foo",
- NoSuchKegError.new("foo").to_s
- end
-
- def test_formula_validation_error
- assert_equal %q(invalid attribute for formula 'foo': sha257 ("magic")),
- FormulaValidationError.new("foo", "sha257", "magic").to_s
- end
-
- def test_formula_unavailable_error
- e = FormulaUnavailableError.new "foo"
- assert_nil e.dependent_s
-
- e.dependent = "foo"
- assert_nil e.dependent_s
-
- e.dependent = "foobar"
- assert_equal "(dependency of foobar)", e.dependent_s
-
- assert_equal "No available formula with the name \"foo\" (dependency of foobar)",
- e.to_s
- end
-
- def test_tap_formula_unavailable_error
- t = stub(user: "u", repo: "r", to_s: "u/r", installed?: false)
- assert_match "Please tap it and then try again: brew tap u/r",
- TapFormulaUnavailableError.new(t, "foo").to_s
- end
-
- def test_formula_class_unavailable_error
- mod = Module.new
- mod.module_eval <<-EOS.undent
- class Bar < Requirement; end
- class Baz < Formula; end
- EOS
-
- assert_match "Expected to find class Foo, but found no classes.",
- FormulaClassUnavailableError.new("foo", "foo.rb", "Foo", []).to_s
-
- list = [mod.const_get(:Bar)]
- assert_match "Expected to find class Foo, but only found: Bar (not derived from Formula!).",
- FormulaClassUnavailableError.new("foo", "foo.rb", "Foo", list).to_s
-
- list = [mod.const_get(:Baz)]
- assert_match "Expected to find class Foo, but only found: Baz.",
- FormulaClassUnavailableError.new("foo", "foo.rb", "Foo", list).to_s
- end
-
- def test_tap_unavailable_error
- assert_equal "No available tap foo.\n", TapUnavailableError.new("foo").to_s
- end
-
- def test_tap_already_tapped_error
- assert_equal "Tap foo already tapped.\n",
- TapAlreadyTappedError.new("foo").to_s
- end
-
- def test_pin_status_error
- assert_equal "foo is already pinned.",
- TapPinStatusError.new("foo", true).to_s
- assert_equal "foo is already unpinned.",
- TapPinStatusError.new("foo", false).to_s
- end
-
- def test_build_error
- f = stub(name: "foo")
- assert_equal "Failed executing: badprg arg1 arg2",
- BuildError.new(f, "badprg", %w[arg1 arg2], {}).to_s
- end
-
- def test_operation_in_progress_error
- assert_match "Operation already in progress for bar",
- OperationInProgressError.new("bar").to_s
- end
-
- def test_formula_installation_already_attempted_error
- f = stub(full_name: "foo/bar")
- assert_equal "Formula installation already attempted: foo/bar",
- FormulaInstallationAlreadyAttemptedError.new(f).to_s
- end
-
- def test_formula_conflict_error
- f = stub(full_name: "foo/qux")
- c = stub(name: "bar", reason: "I decided to")
- assert_match "Please `brew unlink bar` before continuing.",
- FormulaConflictError.new(f, [c]).to_s
- end
-
- def test_compiler_selection_error
- f = stub(full_name: "foo")
- assert_match "foo cannot be built with any available compilers.",
- CompilerSelectionError.new(f).to_s
- end
-
- def test_curl_download_strategy_error
- assert_equal "File does not exist: /tmp/foo",
- CurlDownloadStrategyError.new("file:///tmp/foo").to_s
- assert_equal "Download failed: http://brew.sh",
- CurlDownloadStrategyError.new("http://brew.sh").to_s
- end
-
- def test_error_during_execution
- assert_equal "Failure while executing: badprg arg1 arg2",
- ErrorDuringExecution.new("badprg", %w[arg1 arg2]).to_s
- end
-
- def test_checksum_mismatch_error
- h1 = stub(hash_type: "sha256", to_s: "deadbeef")
- h2 = stub(hash_type: "sha256", to_s: "deadcafe")
- assert_match "SHA256 mismatch",
- ChecksumMismatchError.new("/file.tar.gz", h1, h2).to_s
- end
-
- def test_resource_missing_error
- f = stub(full_name: "bar")
- r = stub(inspect: "<resource foo>")
- assert_match "bar does not define resource <resource foo>",
- ResourceMissingError.new(f, r).to_s
- end
-
- def test_duplicate_resource_error
- r = stub(inspect: "<resource foo>")
- assert_equal "Resource <resource foo> is defined more than once",
- DuplicateResourceError.new(r).to_s
- end
-
- def test_bottle_version_mismatch_error
- f = stub(full_name: "foo")
- assert_match "Bottle version mismatch",
- BottleVersionMismatchError.new("/foo.bottle.tar.gz", "1.0", f, "1.1").to_s
- end
-end
diff --git a/Library/Homebrew/test/fetch_test.rb b/Library/Homebrew/test/fetch_test.rb
deleted file mode 100644
index e08e545e3..000000000
--- a/Library/Homebrew/test/fetch_test.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestFetch < IntegrationCommandTestCase
- def test_fetch
- setup_test_formula "testball"
-
- cmd("fetch", "testball")
- assert((HOMEBREW_CACHE/"testball-0.1.tbz").exist?,
- "The tarball should have been cached")
- end
-end
diff --git a/Library/Homebrew/test/formula_installer_test.rb b/Library/Homebrew/test/formula_installer_test.rb
index 652548bd7..c99b2de74 100644
--- a/Library/Homebrew/test/formula_installer_test.rb
+++ b/Library/Homebrew/test/formula_installer_test.rb
@@ -84,13 +84,10 @@ class InstallTests < Homebrew::TestCase
cc_arg = "--cc=clang"
ARGV << cc_arg
- begin
- temporary_install(TestballBottle.new) do |f|
- tab = Tab.for_formula(f)
- assert_equal "clang", tab.compiler
- end
- ensure
- ARGV.delete_if { |x| x == cc_arg }
+
+ temporary_install(TestballBottle.new) do |f|
+ tab = Tab.for_formula(f)
+ assert_equal "clang", tab.compiler
end
end
end
@@ -128,11 +125,7 @@ class FormulaInstallerTests < Homebrew::TestCase
fi = FormulaInstaller.new(dependent)
assert_raises(CannotInstallFormulaError) { fi.check_install_sanity }
ensure
- dependency.unpin
dependency_keg.unlink
- dependency_keg.uninstall
- dependency.clear_cache
- dep_path.unlink
Formulary::FORMULAE.delete(dep_path)
end
end
diff --git a/Library/Homebrew/test/formula_lock_spec.rb b/Library/Homebrew/test/formula_lock_spec.rb
new file mode 100644
index 000000000..9b5ece813
--- /dev/null
+++ b/Library/Homebrew/test/formula_lock_spec.rb
@@ -0,0 +1,34 @@
+require "formula_lock"
+
+describe FormulaLock do
+ subject { described_class.new("foo") }
+
+ describe "#lock" do
+ it "does not raise an error when already locked" do
+ subject.lock
+
+ expect { subject.lock }.not_to raise_error
+ end
+
+ it "raises an error if a lock already exists" do
+ subject.lock
+
+ expect {
+ described_class.new("foo").lock
+ }.to raise_error(OperationInProgressError)
+ end
+ end
+
+ describe "#unlock" do
+ it "does not raise an error when already unlocked" do
+ expect { subject.unlock }.not_to raise_error
+ end
+
+ it "unlocks a locked Formula" do
+ subject.lock
+ subject.unlock
+
+ expect { described_class.new("foo").lock }.not_to raise_error
+ end
+ end
+end
diff --git a/Library/Homebrew/test/formula_lock_test.rb b/Library/Homebrew/test/formula_lock_test.rb
deleted file mode 100644
index 80ee9dd25..000000000
--- a/Library/Homebrew/test/formula_lock_test.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require "testing_env"
-require "formula_lock"
-
-class FormulaLockTests < Homebrew::TestCase
- def setup
- @lock = FormulaLock.new("foo")
- @lock.lock
- end
-
- def teardown
- @lock.unlock
- HOMEBREW_LOCK_DIR.children.each(&:unlink)
- end
-
- def test_locking_file_with_existing_lock_raises_error
- assert_raises(OperationInProgressError) { FormulaLock.new("foo").lock }
- end
-
- def test_locking_existing_lock_suceeds
- assert_nothing_raised { @lock.lock }
- end
-end
diff --git a/Library/Homebrew/test/formula_pin_spec.rb b/Library/Homebrew/test/formula_pin_spec.rb
new file mode 100644
index 000000000..909bfbc2b
--- /dev/null
+++ b/Library/Homebrew/test/formula_pin_spec.rb
@@ -0,0 +1,41 @@
+require "formula_pin"
+
+describe FormulaPin do
+ subject { described_class.new(formula) }
+ let(:name) { "double" }
+ let(:formula) { double(Formula, name: name, rack: HOMEBREW_CELLAR/name) }
+
+ before(:each) do
+ formula.rack.mkpath
+
+ allow(formula).to receive(:installed_prefixes) do
+ formula.rack.directory? ? formula.rack.subdirs : []
+ end
+
+ allow(formula).to receive(:installed_kegs) do
+ formula.installed_prefixes.map { |prefix| Keg.new(prefix) }
+ end
+ end
+
+ it "is not pinnable by default" do
+ expect(subject).not_to be_pinnable
+ end
+
+ it "is pinnable if the Keg exists" do
+ (formula.rack/"0.1").mkpath
+ expect(subject).to be_pinnable
+ end
+
+ specify "#pin and #unpin" do
+ (formula.rack/"0.1").mkpath
+
+ subject.pin
+ expect(subject).to be_pinned
+ expect(HOMEBREW_PINNED_KEGS/name).to be_a_directory
+ expect(HOMEBREW_PINNED_KEGS.children.count).to eq(1)
+
+ subject.unpin
+ expect(subject).not_to be_pinned
+ expect(HOMEBREW_PINNED_KEGS).not_to be_a_directory
+ end
+end
diff --git a/Library/Homebrew/test/formula_pin_test.rb b/Library/Homebrew/test/formula_pin_test.rb
deleted file mode 100644
index 297d7703e..000000000
--- a/Library/Homebrew/test/formula_pin_test.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require "testing_env"
-require "formula_pin"
-
-class FormulaPinTests < Homebrew::TestCase
- class FormulaDouble
- def name
- "double"
- end
-
- def rack
- HOMEBREW_CELLAR/name
- end
-
- def installed_prefixes
- rack.directory? ? rack.subdirs : []
- end
-
- def installed_kegs
- installed_prefixes.map { |d| Keg.new d }
- end
- end
-
- def setup
- @f = FormulaDouble.new
- @pin = FormulaPin.new(@f)
- @f.rack.mkpath
- end
-
- def test_not_pinnable
- refute_predicate @pin, :pinnable?
- end
-
- def test_pinnable_if_kegs_exist
- (@f.rack/"0.1").mkpath
- assert_predicate @pin, :pinnable?
- end
-
- def test_unpin
- (@f.rack/"0.1").mkpath
- @pin.pin
-
- assert_predicate @pin, :pinned?
- assert_equal 1, HOMEBREW_PINNED_KEGS.children.length
-
- @pin.unpin
-
- refute_predicate @pin, :pinned?
- refute_predicate HOMEBREW_PINNED_KEGS, :directory?
- end
-
- def teardown
- @f.rack.rmtree
- end
-end
diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb
new file mode 100644
index 000000000..1e064912f
--- /dev/null
+++ b/Library/Homebrew/test/formula_spec.rb
@@ -0,0 +1,1295 @@
+require "test/support/fixtures/testball"
+require "formula"
+
+RSpec::Matchers.alias_matcher :follow_installed_alias, :be_follow_installed_alias
+RSpec::Matchers.alias_matcher :have_any_version_installed, :be_any_version_installed
+RSpec::Matchers.alias_matcher :need_migration, :be_migration_needed
+
+RSpec::Matchers.alias_matcher :have_changed_installed_alias_target, :be_installed_alias_target_changed
+RSpec::Matchers.alias_matcher :supersede_an_installed_formula, :be_supersedes_an_installed_formula
+RSpec::Matchers.alias_matcher :have_changed_alias, :be_alias_changed
+
+RSpec::Matchers.alias_matcher :have_option_defined, :be_option_defined
+RSpec::Matchers.alias_matcher :have_post_install_defined, :be_post_install_defined
+RSpec::Matchers.alias_matcher :have_test_defined, :be_test_defined
+RSpec::Matchers.alias_matcher :pour_bottle, :be_pour_bottle
+
+describe Formula do
+ describe "::new" do
+ let(:klass) do
+ Class.new(described_class) do
+ url "http://example.com/foo-1.0.tar.gz"
+ end
+ end
+
+ let(:name) { "formula_name" }
+ let(:path) { Formulary.core_path(name) }
+ let(:spec) { :stable }
+ let(:alias_name) { "baz@1" }
+ let(:alias_path) { CoreTap.instance.alias_dir/alias_name }
+ let(:f) { klass.new(name, path, spec) }
+ let(:f_alias) { klass.new(name, path, spec, alias_path: alias_path) }
+
+ specify "formula instantiation" do
+ expect(f.name).to eq(name)
+ expect(f.specified_name).to eq(name)
+ expect(f.full_name).to eq(name)
+ expect(f.full_specified_name).to eq(name)
+ expect(f.path).to eq(path)
+ expect(f.alias_path).to be nil
+ expect(f.alias_name).to be nil
+ expect(f.full_alias_name).to be nil
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+
+ specify "formula instantiation with alias" do
+ expect(f_alias.name).to eq(name)
+ expect(f_alias.full_name).to eq(name)
+ expect(f_alias.path).to eq(path)
+ expect(f_alias.alias_path).to eq(alias_path)
+ expect(f_alias.alias_name).to eq(alias_name)
+ expect(f_alias.specified_name).to eq(alias_name)
+ expect(f_alias.full_alias_name).to eq(alias_name)
+ expect(f_alias.full_specified_name).to eq(alias_name)
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+
+ context "in a Tap" do
+ let(:tap) { Tap.new("foo", "bar") }
+ let(:path) { (tap.path/"Formula/#{name}.rb") }
+ let(:full_name) { "#{tap.user}/#{tap.repo}/#{name}" }
+ let(:full_alias_name) { "#{tap.user}/#{tap.repo}/#{alias_name}" }
+
+ specify "formula instantiation" do
+ expect(f.name).to eq(name)
+ expect(f.specified_name).to eq(name)
+ expect(f.full_name).to eq(full_name)
+ expect(f.full_specified_name).to eq(full_name)
+ expect(f.path).to eq(path)
+ expect(f.alias_path).to be nil
+ expect(f.alias_name).to be nil
+ expect(f.full_alias_name).to be nil
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+
+ specify "formula instantiation with alias" do
+ expect(f_alias.name).to eq(name)
+ expect(f_alias.full_name).to eq(full_name)
+ expect(f_alias.path).to eq(path)
+ expect(f_alias.alias_path).to eq(alias_path)
+ expect(f_alias.alias_name).to eq(alias_name)
+ expect(f_alias.specified_name).to eq(alias_name)
+ expect(f_alias.full_alias_name).to eq(full_alias_name)
+ expect(f_alias.full_specified_name).to eq(full_alias_name)
+ expect { klass.new }.to raise_error(ArgumentError)
+ end
+ end
+ end
+
+ describe "#follow_installed_alias?" do
+ let(:f) do
+ formula do
+ url "foo-1.0"
+ end
+ end
+
+ it "returns true by default" do
+ expect(f).to follow_installed_alias
+ end
+
+ it "can be set to true" do
+ f.follow_installed_alias = true
+ expect(f).to follow_installed_alias
+ end
+
+ it "can be set to false" do
+ f.follow_installed_alias = false
+ expect(f).not_to follow_installed_alias
+ end
+ end
+
+ example "installed alias with core" do
+ f = formula do
+ url "foo-1.0"
+ end
+
+ build_values_with_no_installed_alias = [
+ nil,
+ BuildOptions.new({}, {}),
+ Tab.new(source: { "path" => f.path.to_s }),
+ ]
+ build_values_with_no_installed_alias.each do |build|
+ f.build = build
+ expect(f.installed_alias_path).to be nil
+ expect(f.installed_alias_name).to be nil
+ expect(f.full_installed_alias_name).to be nil
+ expect(f.installed_specified_name).to eq(f.name)
+ expect(f.full_installed_specified_name).to eq(f.name)
+ end
+
+ alias_name = "bar"
+ alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
+
+ f.build = Tab.new(source: { "path" => alias_path })
+
+ expect(f.installed_alias_path).to eq(alias_path)
+ expect(f.installed_alias_name).to eq(alias_name)
+ expect(f.full_installed_alias_name).to eq(alias_name)
+ expect(f.installed_specified_name).to eq(alias_name)
+ expect(f.full_installed_specified_name).to eq(alias_name)
+ end
+
+ example "installed alias with tap" do
+ tap = Tap.new("user", "repo")
+ name = "foo"
+ path = "#{tap.path}/Formula/#{name}.rb"
+ f = formula name, path: path do
+ url "foo-1.0"
+ end
+
+ build_values_with_no_installed_alias = [nil, BuildOptions.new({}, {}), Tab.new(source: { "path" => f.path })]
+ build_values_with_no_installed_alias.each do |build|
+ f.build = build
+ expect(f.installed_alias_path).to be nil
+ expect(f.installed_alias_name).to be nil
+ expect(f.full_installed_alias_name).to be nil
+ expect(f.installed_specified_name).to eq(f.name)
+ expect(f.full_installed_specified_name).to eq(f.full_name)
+ end
+
+ alias_name = "bar"
+ full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
+ alias_path = "#{tap.alias_dir}/#{alias_name}"
+
+ f.build = Tab.new(source: { "path" => alias_path })
+
+ expect(f.installed_alias_path).to eq(alias_path)
+ expect(f.installed_alias_name).to eq(alias_name)
+ expect(f.full_installed_alias_name).to eq(full_alias_name)
+ expect(f.installed_specified_name).to eq(alias_name)
+ expect(f.full_installed_specified_name).to eq(full_alias_name)
+ end
+
+ specify "#prefix" do
+ f = Testball.new
+ expect(f.prefix).to eq(HOMEBREW_CELLAR/f.name/"0.1")
+ expect(f.prefix).to be_kind_of(Pathname)
+ end
+
+ example "revised prefix" do
+ f = Class.new(Testball) { revision(1) }.new
+ expect(f.prefix).to eq(HOMEBREW_CELLAR/f.name/"0.1_1")
+ end
+
+ specify "#any_version_installed?" do
+ f = formula do
+ url "foo"
+ version "1.0"
+ end
+
+ expect(f).not_to have_any_version_installed
+
+ prefix = HOMEBREW_CELLAR/f.name/"0.1"
+ prefix.mkpath
+ FileUtils.touch prefix/Tab::FILENAME
+
+ expect(f).to have_any_version_installed
+ end
+
+ specify "#migration_needed" do
+ f = Testball.new("newname")
+ f.instance_variable_set(:@oldname, "oldname")
+ f.instance_variable_set(:@tap, CoreTap.instance)
+
+ oldname_prefix = (HOMEBREW_CELLAR/"oldname/2.20")
+ newname_prefix = (HOMEBREW_CELLAR/"newname/2.10")
+
+ oldname_prefix.mkpath
+ oldname_tab = Tab.empty
+ oldname_tab.tabfile = oldname_prefix/Tab::FILENAME
+ oldname_tab.write
+
+ expect(f).not_to need_migration
+
+ oldname_tab.tabfile.unlink
+ oldname_tab.source["tap"] = "homebrew/core"
+ oldname_tab.write
+
+ expect(f).to need_migration
+
+ newname_prefix.mkpath
+
+ expect(f).not_to need_migration
+ end
+
+ describe "#installed?" do
+ let(:f) { Testball.new }
+
+ it "returns false if the #installed_prefix is not a directory" do
+ allow(f).to receive(:installed_prefix).and_return(double(directory?: false))
+ expect(f).not_to be_installed
+ end
+
+ it "returns false if the #installed_prefix does not have children" do
+ allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: []))
+ expect(f).not_to be_installed
+ end
+
+ it "returns true if the #installed_prefix has children" do
+ allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: [double]))
+ expect(f).to be_installed
+ end
+ end
+
+ describe "#installed prefix" do
+ let(:f) do
+ formula do
+ url "foo"
+ version "1.9"
+
+ head "foo"
+
+ devel do
+ url "foo"
+ version "2.1-devel"
+ end
+ end
+ end
+
+ let(:stable_prefix) { HOMEBREW_CELLAR/f.name/f.version }
+ let(:devel_prefix) { HOMEBREW_CELLAR/f.name/f.devel.version }
+ let(:head_prefix) { HOMEBREW_CELLAR/f.name/f.head.version }
+
+ it "is the same as #prefix by default" do
+ expect(f.installed_prefix).to eq(f.prefix)
+ end
+
+ it "returns the stable prefix if it is installed" do
+ stable_prefix.mkpath
+ expect(f.installed_prefix).to eq(stable_prefix)
+ end
+
+ it "returns the devel prefix if it is installed" do
+ devel_prefix.mkpath
+ expect(f.installed_prefix).to eq(devel_prefix)
+ end
+
+ it "returns the head prefix if it is installed" do
+ head_prefix.mkpath
+ expect(f.installed_prefix).to eq(head_prefix)
+ end
+
+ it "returns the stable prefix if head is outdated" do
+ head_prefix.mkpath
+
+ tab = Tab.empty
+ tab.tabfile = head_prefix/Tab::FILENAME
+ tab.source["versions"] = { "stable" => "1.0" }
+ tab.write
+
+ expect(f.installed_prefix).to eq(stable_prefix)
+ end
+
+ it "returns the stable prefix if head and devel are outdated" do
+ head_prefix.mkpath
+
+ tab = Tab.empty
+ tab.tabfile = head_prefix/Tab::FILENAME
+ tab.source["versions"] = { "stable" => "1.9", "devel" => "2.0" }
+ tab.write
+
+ expect(f.installed_prefix).to eq(stable_prefix)
+ end
+
+ it "returns the devel prefix if the active specification is :devel" do
+ f.active_spec = :devel
+ expect(f.installed_prefix).to eq(devel_prefix)
+ end
+
+ it "returns the head prefix if the active specification is :head" do
+ f.active_spec = :head
+ expect(f.installed_prefix).to eq(head_prefix)
+ end
+ end
+
+ describe "#latest_head_prefix" do
+ let(:f) { Testball.new }
+
+ it "returns the latest head prefix" do
+ stamps_with_revisions = [
+ [111111, 1],
+ [222222, 0],
+ [222222, 1],
+ [222222, 2],
+ ]
+
+ stamps_with_revisions.each do |stamp, revision|
+ version = "HEAD-#{stamp}"
+ version << "_#{revision}" unless revision.zero?
+
+ prefix = f.rack/version
+ prefix.mkpath
+
+ tab = Tab.empty
+ tab.tabfile = prefix/Tab::FILENAME
+ tab.source_modified_time = stamp
+ tab.write
+ end
+
+ prefix = HOMEBREW_CELLAR/f.name/"HEAD-222222_2"
+
+ expect(f.latest_head_prefix).to eq(prefix)
+ end
+ end
+
+ specify "equality" do
+ x = Testball.new
+ y = Testball.new
+
+ expect(x).to eq(y)
+ expect(x).to eql(y)
+ expect(x.hash).to eq(y.hash)
+ end
+
+ specify "inequality" do
+ x = Testball.new("foo")
+ y = Testball.new("bar")
+
+ expect(x).not_to eq(y)
+ expect(x).not_to eql(y)
+ expect(x.hash).not_to eq(y.hash)
+ end
+
+ specify "comparison with non formula objects does not raise" do
+ expect(Object.new).not_to eq(Testball.new)
+ end
+
+ specify "#<=>" do
+ expect(Testball.new <=> Object.new).to be nil
+ end
+
+ describe "#installed_alias_path" do
+ example "alias paths with build options" do
+ alias_path = (CoreTap.instance.alias_dir/"another_name")
+
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+ f.build = BuildOptions.new({}, {})
+
+ expect(f.alias_path).to eq(alias_path)
+ expect(f.installed_alias_path).to be nil
+ end
+
+ example "alias paths with tab with non alias source path" do
+ alias_path = (CoreTap.instance.alias_dir/"another_name")
+ source_path = (CoreTap.instance.formula_dir/"another_other_name")
+
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+ f.build = Tab.new(source: { "path" => source_path.to_s })
+
+ expect(f.alias_path).to eq(alias_path)
+ expect(f.installed_alias_path).to be nil
+ end
+
+ example "alias paths with tab with alias source path" do
+ alias_path = (CoreTap.instance.alias_dir/"another_name")
+ source_path = (CoreTap.instance.alias_dir/"another_other_name")
+
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+ f.build = Tab.new(source: { "path" => source_path.to_s })
+
+ expect(f.alias_path).to eq(alias_path)
+ expect(f.installed_alias_path).to eq(source_path.to_s)
+ end
+ end
+
+ describe "::installed_with_alias_path" do
+ specify "with alias path with nil" do
+ expect(described_class.installed_with_alias_path(nil)).to be_empty
+ end
+
+ specify "with alias path with a path" do
+ alias_path = "#{CoreTap.instance.alias_dir}/alias"
+ different_alias_path = "#{CoreTap.instance.alias_dir}/another_alias"
+
+ formula_with_alias = formula "foo" do
+ url "foo-1.0"
+ end
+ formula_with_alias.build = Tab.empty
+ formula_with_alias.build.source["path"] = alias_path
+
+ formula_without_alias = formula "bar" do
+ url "bar-1.0"
+ end
+ formula_without_alias.build = Tab.empty
+ formula_without_alias.build.source["path"] = formula_without_alias.path.to_s
+
+ formula_with_different_alias = formula "baz" do
+ url "baz-1.0"
+ end
+ formula_with_different_alias.build = Tab.empty
+ formula_with_different_alias.build.source["path"] = different_alias_path
+
+ formulae = [
+ formula_with_alias,
+ formula_without_alias,
+ formula_with_different_alias,
+ ]
+
+ allow(described_class).to receive(:installed).and_return(formulae)
+
+ expect(described_class.installed_with_alias_path(alias_path))
+ .to eq([formula_with_alias])
+ end
+ end
+
+ specify "spec integration" do
+ f = formula do
+ homepage "http://example.com"
+
+ url "http://example.com/test-0.1.tbz"
+ mirror "http://example.org/test-0.1.tbz"
+ sha256 TEST_SHA256
+
+ head "http://example.com/test.git", tag: "foo"
+
+ devel do
+ url "http://example.com/test-0.2.tbz"
+ mirror "http://example.org/test-0.2.tbz"
+ sha256 TEST_SHA256
+ end
+ end
+
+ expect(f.homepage).to eq("http://example.com")
+ expect(f.version).to eq(Version.create("0.1"))
+ expect(f).to be_stable
+ expect(f.stable.version).to eq(Version.create("0.1"))
+ expect(f.devel.version).to eq(Version.create("0.2"))
+ expect(f.head.version).to eq(Version.create("HEAD"))
+ end
+
+ specify "#active_spec=" do
+ f = formula do
+ url "foo"
+ version "1.0"
+ revision 1
+
+ devel do
+ url "foo"
+ version "1.0beta"
+ end
+ end
+
+ expect(f.active_spec_sym).to eq(:stable)
+ expect(f.send(:active_spec)).to eq(f.stable)
+ expect(f.pkg_version.to_s).to eq("1.0_1")
+
+ f.active_spec = :devel
+
+ expect(f.active_spec_sym).to eq(:devel)
+ expect(f.send(:active_spec)).to eq(f.devel)
+ expect(f.pkg_version.to_s).to eq("1.0beta_1")
+ expect { f.active_spec = :head }.to raise_error(FormulaSpecificationError)
+ end
+
+ specify "class specs are always initialized" do
+ f = formula do
+ url "foo-1.0"
+ end
+
+ expect(f.class.stable).to be_kind_of(SoftwareSpec)
+ expect(f.class.devel).to be_kind_of(SoftwareSpec)
+ expect(f.class.head).to be_kind_of(SoftwareSpec)
+ end
+
+ specify "incomplete instance specs are not accessible" do
+ f = formula do
+ url "foo-1.0"
+ end
+
+ expect(f.devel).to be nil
+ expect(f.head).to be nil
+ end
+
+ it "honors attributes declared before specs" do
+ f = formula do
+ url "foo-1.0"
+
+ depends_on "foo"
+
+ devel do
+ url "foo-1.1"
+ end
+ end
+
+ expect(f.class.stable.deps.first.name).to eq("foo")
+ expect(f.class.devel.deps.first.name).to eq("foo")
+ expect(f.class.head.deps.first.name).to eq("foo")
+ end
+
+ describe "#pkg_version" do
+ specify "simple version" do
+ f = formula do
+ url "foo-1.0.bar"
+ end
+
+ expect(f.pkg_version).to eq(PkgVersion.parse("1.0"))
+ end
+
+ specify "version with revision" do
+ f = formula do
+ url "foo-1.0.bar"
+ revision 1
+ end
+
+ expect(f.pkg_version).to eq(PkgVersion.parse("1.0_1"))
+ end
+
+ specify "head uses revisions" do
+ f = formula "test", spec: :head do
+ url "foo-1.0.bar"
+ revision 1
+
+ head "foo"
+ end
+
+ expect(f.pkg_version).to eq(PkgVersion.parse("HEAD_1"))
+ end
+ end
+
+ specify "#update_head_version" do
+ f = formula do
+ head "foo", using: :git
+ end
+
+ cached_location = f.head.downloader.cached_location
+ cached_location.mkpath
+ cached_location.cd do
+ FileUtils.touch "LICENSE"
+
+ shutup do
+ system("git", "init")
+ system("git", "add", "--all")
+ system("git", "commit", "-m", "Initial commit")
+ end
+ end
+
+ f.update_head_version
+
+ expect(f.head.version).to eq(Version.create("HEAD-5658946"))
+ end
+
+ specify "legacy options" do
+ f = formula do
+ url "foo-1.0"
+
+ def options
+ [
+ ["--foo", "desc"],
+ ["--bar", "desc"],
+ ]
+ end
+
+ option("baz")
+ end
+
+ expect(f).to have_option_defined("foo")
+ expect(f).to have_option_defined("bar")
+ expect(f).to have_option_defined("baz")
+ end
+
+ specify "#desc" do
+ f = formula do
+ desc "a formula"
+
+ url "foo-1.0"
+ end
+
+ expect(f.desc).to eq("a formula")
+ end
+
+ specify "#post_install_defined?" do
+ f1 = formula do
+ url "foo-1.0"
+
+ def post_install
+ # do nothing
+ end
+ end
+
+ f2 = formula do
+ url "foo-1.0"
+ end
+
+ expect(f1).to have_post_install_defined
+ expect(f2).not_to have_post_install_defined
+ end
+
+ specify "#test_defined?" do
+ f1 = formula do
+ url "foo-1.0"
+
+ def test
+ # do nothing
+ end
+ end
+
+ f2 = formula do
+ url "foo-1.0"
+ end
+
+ expect(f1).to have_test_defined
+ expect(f2).not_to have_test_defined
+ end
+
+ specify "test fixtures" do
+ f1 = formula do
+ url "foo-1.0"
+ end
+
+ expect(f1.test_fixtures("foo")).to eq(Pathname.new("#{HOMEBREW_LIBRARY_PATH}/test/support/fixtures/foo"))
+ end
+
+ specify "dependencies" do
+ f1 = formula "f1" do
+ url "f1-1.0"
+ end
+
+ f2 = formula "f2" do
+ url "f2-1.0"
+ end
+
+ f3 = formula "f3" do
+ url "f3-1.0"
+
+ depends_on "f1" => :build
+ depends_on "f2"
+ end
+
+ f4 = formula "f4" do
+ url "f4-1.0"
+
+ depends_on "f1"
+ end
+
+ stub_formula_loader(f1)
+ stub_formula_loader(f2)
+ stub_formula_loader(f3)
+ stub_formula_loader(f4)
+
+ f5 = formula "f5" do
+ url "f5-1.0"
+
+ depends_on "f3" => :build
+ depends_on "f4"
+ end
+
+ expect(f5.deps.map(&:name)).to eq(["f3", "f4"])
+ expect(f5.recursive_dependencies.map(&:name)).to eq(["f1", "f2", "f3", "f4"])
+ expect(f5.runtime_dependencies.map(&:name)).to eq(["f1", "f4"])
+ end
+
+ specify "runtime dependencies with optional deps from tap" do
+ tap_loader = double
+
+ allow(tap_loader).to receive(:get_formula).and_raise(RuntimeError, "tried resolving tap formula")
+ allow(Formulary).to receive(:loader_for).with("foo/bar/f1", from: nil).and_return(tap_loader)
+ stub_formula_loader(formula("f2") { url("f2-1.0") }, "baz/qux/f2")
+
+ f3 = formula "f3" do
+ url "f3-1.0"
+
+ depends_on "foo/bar/f1" => :optional
+ depends_on "baz/qux/f2"
+ end
+
+ expect(f3.runtime_dependencies.map(&:name)).to eq(["baz/qux/f2"])
+
+ stub_formula_loader(formula("f1") { url("f1-1.0") }, "foo/bar/f1")
+ f3.build = BuildOptions.new(Options.create(["--with-f1"]), f3.options)
+
+ expect(f3.runtime_dependencies.map(&:name)).to eq(["foo/bar/f1", "baz/qux/f2"])
+ end
+
+ specify "requirements" do
+ f1 = formula "f1" do
+ url "f1-1"
+
+ depends_on :python
+ depends_on x11: :recommended
+ depends_on xcode: ["1.0", :optional]
+ end
+ stub_formula_loader(f1)
+
+ python = PythonRequirement.new
+ x11 = X11Requirement.new("x11", [:recommended])
+ xcode = XcodeRequirement.new(["1.0", :optional])
+
+ expect(Set.new(f1.recursive_requirements)).to eq(Set[python, x11])
+
+ f1.build = BuildOptions.new(["--with-xcode", "--without-x11"], f1.options)
+
+ expect(Set.new(f1.recursive_requirements)).to eq(Set[python, xcode])
+
+ f1.build = f1.stable.build
+ f2 = formula "f2" do
+ url "f2-1"
+
+ depends_on "f1"
+ end
+
+ expect(Set.new(f2.recursive_requirements)).to eq(Set[python, x11])
+ expect(Set.new(f2.recursive_requirements {})).to eq(Set[python, x11, xcode])
+
+ requirements = f2.recursive_requirements do |_dependent, requirement|
+ Requirement.prune if requirement.is_a?(PythonRequirement)
+ end
+
+ expect(Set.new(requirements)).to eq(Set[x11, xcode])
+ end
+
+ specify "#to_hash" do
+ f1 = formula "foo" do
+ url "foo-1.0"
+
+ bottle do
+ cellar(:any)
+ sha256(TEST_SHA256 => Utils::Bottles.tag)
+ end
+ end
+
+ h = f1.to_hash
+
+ expect(h).to be_a(Hash)
+ expect(h["name"]).to eq("foo")
+ expect(h["full_name"]).to eq("foo")
+ expect(h["versions"]["stable"]).to eq("1.0")
+ expect(h["versions"]["bottle"]).to be_truthy
+ end
+
+ describe "#eligible_kegs_for_cleanup" do
+ it "returns Kegs eligible for cleanup" do
+ f1 = Class.new(Testball) do
+ version("1.0")
+ end.new
+
+ f2 = Class.new(Testball) do
+ version("0.2")
+ version_scheme(1)
+ end.new
+
+ f3 = Class.new(Testball) do
+ version("0.3")
+ version_scheme(1)
+ end.new
+
+ f4 = Class.new(Testball) do
+ version("0.1")
+ version_scheme(2)
+ end.new
+
+ shutup do
+ [f1, f2, f3, f4].each do |f|
+ f.brew { f.install }
+ Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
+ end
+ end
+
+ expect(f1).to be_installed
+ expect(f2).to be_installed
+ expect(f3).to be_installed
+ expect(f4).to be_installed
+ expect(f3.eligible_kegs_for_cleanup.sort_by(&:version))
+ .to eq([f2, f1].map { |f| Keg.new(f.prefix) })
+ end
+
+ specify "with pinned Keg" do
+ f1 = Class.new(Testball) { version("0.1") }.new
+ f2 = Class.new(Testball) { version("0.2") }.new
+ f3 = Class.new(Testball) { version("0.3") }.new
+
+ shutup do
+ f1.brew { f1.install }
+ f1.pin
+ f2.brew { f2.install }
+ f3.brew { f3.install }
+ end
+
+ expect(f1.prefix).to eq((HOMEBREW_PINNED_KEGS/f1.name).resolved_path)
+ expect(f1).to be_installed
+ expect(f2).to be_installed
+ expect(f3).to be_installed
+ expect(shutup { f3.eligible_kegs_for_cleanup }).to eq([Keg.new(f2.prefix)])
+ end
+
+ specify "with HEAD installed" do
+ f = formula do
+ version("0.1")
+ head("foo")
+ end
+
+ stable_prefix = f.installed_prefix
+ stable_prefix.mkpath
+
+ [["000000_1", 1], ["111111", 2], ["111111_1", 2]].each do |pkg_version_suffix, stamp|
+ prefix = f.prefix("HEAD-#{pkg_version_suffix}")
+ prefix.mkpath
+ tab = Tab.empty
+ tab.tabfile = prefix/Tab::FILENAME
+ tab.source_modified_time = stamp
+ tab.write
+ end
+
+ eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1"))]
+ expect(f.eligible_kegs_for_cleanup).to eq(eligible_kegs)
+ end
+ end
+
+ describe "#pour_bottle?" do
+ it "returns false if set to false" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ def pour_bottle?
+ false
+ end
+ end
+
+ expect(f).not_to pour_bottle
+ end
+
+ it "returns true if set to true" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ def pour_bottle?
+ true
+ end
+ end
+
+ expect(f).to pour_bottle
+ end
+
+ it "returns false if set to false via DSL" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ pour_bottle? do
+ reason "false reason"
+ satisfy { (var == etc) }
+ end
+ end
+
+ expect(f).not_to pour_bottle
+ end
+
+ it "returns true if set to true via DSL" do
+ f = formula "foo" do
+ url "foo-1.0"
+
+ pour_bottle? do
+ reason "true reason"
+ satisfy { true }
+ end
+ end
+
+ expect(f).to pour_bottle
+ end
+ end
+
+ describe "alias changes" do
+ let(:f) do
+ formula "formula_name", alias_path: alias_path do
+ url "foo-1.0"
+ end
+ end
+
+ let(:new_formula) do
+ formula "new_formula_name", alias_path: alias_path do
+ url "foo-1.1"
+ end
+ end
+
+ let(:tab) { Tab.empty }
+ let(:alias_path) { "#{CoreTap.instance.alias_dir}/bar" }
+
+ before(:each) do
+ allow(described_class).to receive(:installed).and_return([f])
+
+ f.build = tab
+ new_formula.build = tab
+ end
+
+ specify "alias changes when not installed with alias" do
+ tab.source["path"] = Formulary.core_path(f.name).to_s
+
+ expect(f.current_installed_alias_target).to be nil
+ expect(f.latest_formula).to eq(f)
+ expect(f).not_to have_changed_installed_alias_target
+ expect(f).not_to supersede_an_installed_formula
+ expect(f).not_to have_changed_alias
+ expect(f.old_installed_formulae).to be_empty
+ end
+
+ specify "alias changes when not changed" do
+ tab.source["path"] = alias_path
+ stub_formula_loader(f, alias_path)
+
+ expect(f.current_installed_alias_target).to eq(f)
+ expect(f.latest_formula).to eq(f)
+ expect(f).not_to have_changed_installed_alias_target
+ expect(f).not_to supersede_an_installed_formula
+ expect(f).not_to have_changed_alias
+ expect(f.old_installed_formulae).to be_empty
+ end
+
+ specify "alias changes when new alias target" do
+ tab.source["path"] = alias_path
+ stub_formula_loader(new_formula, alias_path)
+
+ expect(f.current_installed_alias_target).to eq(new_formula)
+ expect(f.latest_formula).to eq(new_formula)
+ expect(f).to have_changed_installed_alias_target
+ expect(f).not_to supersede_an_installed_formula
+ expect(f).to have_changed_alias
+ expect(f.old_installed_formulae).to be_empty
+ end
+
+ specify "alias changes when old formulae installed" do
+ tab.source["path"] = alias_path
+ stub_formula_loader(new_formula, alias_path)
+
+ expect(new_formula.current_installed_alias_target).to eq(new_formula)
+ expect(new_formula.latest_formula).to eq(new_formula)
+ expect(new_formula).not_to have_changed_installed_alias_target
+ expect(new_formula).to supersede_an_installed_formula
+ expect(new_formula).to have_changed_alias
+ expect(new_formula.old_installed_formulae).to eq([f])
+ end
+ end
+
+ describe "#outdated_kegs" do
+ let(:outdated_prefix) { (HOMEBREW_CELLAR/"#{f.name}/1.11") }
+ let(:same_prefix) { (HOMEBREW_CELLAR/"#{f.name}/1.20") }
+ let(:greater_prefix) { (HOMEBREW_CELLAR/"#{f.name}/1.21") }
+ let(:head_prefix) { (HOMEBREW_CELLAR/"#{f.name}/HEAD") }
+ let(:old_alias_target_prefix) { (HOMEBREW_CELLAR/"#{old_formula.name}/1.0") }
+
+ let(:f) do
+ formula do
+ url "foo"
+ version "1.20"
+ end
+ end
+
+ let(:old_formula) do
+ formula "foo@1" do
+ url "foo-1.0"
+ end
+ end
+
+ let(:new_formula) do
+ formula "foo@2" do
+ url "foo-2.0"
+ end
+ end
+
+ let(:alias_path) { "#{f.tap.alias_dir}/bar" }
+
+ def setup_tab_for_prefix(prefix, options = {})
+ prefix.mkpath
+ tab = Tab.empty
+ tab.tabfile = prefix/Tab::FILENAME
+ tab.source["path"] = options[:path].to_s if options[:path]
+ tab.source["tap"] = options[:tap] if options[:tap]
+ tab.source["versions"] = options[:versions] if options[:versions]
+ tab.source_modified_time = options[:source_modified_time].to_i
+ tab.write unless options[:no_write]
+ tab
+ end
+
+ def reset_outdated_kegs
+ f.instance_variable_set(:@outdated_kegs, nil)
+ end
+
+ example "greater different tap installed" do
+ setup_tab_for_prefix(greater_prefix, tap: "user/repo")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "greater same tap installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated different tap installed" do
+ setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated same tap installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated follow alias and alias unchanged" do
+ f.follow_installed_alias = true
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(f, alias_path)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated follow alias and alias changed and new target not installed" do
+ f.follow_installed_alias = true
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(new_formula, alias_path)
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated follow alias and alias changed and new target installed" do
+ f.follow_installed_alias = true
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(new_formula, alias_path)
+ setup_tab_for_prefix(new_formula.prefix)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated no follow alias and alias unchanged" do
+ f.follow_installed_alias = false
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+ stub_formula_loader(f, alias_path)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated no follow alias and alias changed" do
+ f.follow_installed_alias = false
+ f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
+
+ f2 = formula "foo@2" do
+ url "foo-2.0"
+ end
+
+ stub_formula_loader(f2, alias_path)
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated old alias targets installed" do
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+
+ tab = setup_tab_for_prefix(old_alias_target_prefix, path: alias_path)
+ old_formula.build = tab
+ allow(described_class).to receive(:installed).and_return([old_formula])
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated old alias targets not installed" do
+ f = formula alias_path: alias_path do
+ url "foo-1.0"
+ end
+
+ tab = setup_tab_for_prefix(old_alias_target_prefix, path: old_formula.path)
+ old_formula.build = tab
+ allow(described_class).to receive(:installed).and_return([old_formula])
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated same head installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(head_prefix, tap: "homebrew/core")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated different head installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(head_prefix, tap: "user/repo")
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated mixed taps greater version installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
+ setup_tab_for_prefix(greater_prefix, tap: "user/repo")
+
+ expect(f.outdated_kegs).to be_empty
+
+ setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated mixed taps outdated version installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+
+ extra_outdated_prefix = HOMEBREW_CELLAR/f.name/"1.0"
+
+ setup_tab_for_prefix(outdated_prefix)
+ setup_tab_for_prefix(extra_outdated_prefix, tap: "homebrew/core")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).not_to be_empty
+
+ setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).not_to be_empty
+ end
+
+ example "outdated same version tap installed" do
+ f.instance_variable_set(:@tap, CoreTap.instance)
+ setup_tab_for_prefix(same_prefix, tap: "homebrew/core")
+
+ expect(f.outdated_kegs).to be_empty
+
+ setup_tab_for_prefix(same_prefix, tap: "user/repo")
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ example "outdated installed head less than stable" do
+ tab = setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0" })
+
+ expect(f.outdated_kegs).not_to be_empty
+
+ tab.source["versions"] = { "stable" => f.version.to_s }
+ tab.write
+ reset_outdated_kegs
+
+ expect(f.outdated_kegs).to be_empty
+ end
+
+ describe ":fetch_head" do
+ let(:f) do
+ repo = testball_repo
+ formula "testball" do
+ url "foo"
+ version "2.10"
+ head "file://#{repo}", using: :git
+ end
+ end
+ let(:testball_repo) { HOMEBREW_PREFIX/"testball_repo" }
+
+ example do
+ begin
+ outdated_stable_prefix = HOMEBREW_CELLAR/"testball/1.0"
+ head_prefix_a = HOMEBREW_CELLAR/"testball/HEAD"
+ head_prefix_b = HOMEBREW_CELLAR/"testball/HEAD-aaaaaaa_1"
+ head_prefix_c = HOMEBREW_CELLAR/"testball/HEAD-18a7103"
+
+ setup_tab_for_prefix(outdated_stable_prefix)
+ tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
+ setup_tab_for_prefix(head_prefix_b)
+
+ testball_repo.mkdir
+ testball_repo.cd do
+ FileUtils.touch "LICENSE"
+
+ shutup do
+ system("git", "init")
+ system("git", "add", "--all")
+ system("git", "commit", "-m", "Initial commit")
+ end
+ end
+
+ expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
+
+ tab_a.source["versions"] = { "stable" => f.version.to_s }
+ tab_a.write
+ reset_outdated_kegs
+ expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
+
+ head_prefix_a.rmtree
+ reset_outdated_kegs
+ expect(f.outdated_kegs(fetch_head: true)).not_to be_empty
+
+ setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
+ reset_outdated_kegs
+ expect(f.outdated_kegs(fetch_head: true)).to be_empty
+ ensure
+ testball_repo.rmtree if testball_repo.exist?
+ end
+ end
+ end
+
+ describe "with changed version scheme" do
+ let(:f) do
+ formula "testball" do
+ url "foo"
+ version "20141010"
+ version_scheme 1
+ end
+ end
+
+ example do
+ prefix = HOMEBREW_CELLAR/"testball/0.1"
+ setup_tab_for_prefix(prefix, versions: { "stable" => "0.1" })
+
+ expect(f.outdated_kegs).not_to be_empty
+ end
+ end
+
+ describe "with mixed version schemes" do
+ let(:f) do
+ formula "testball" do
+ url "foo"
+ version "20141010"
+ version_scheme 3
+ end
+ end
+
+ example do
+ prefix_a = HOMEBREW_CELLAR/"testball/20141009"
+ setup_tab_for_prefix(prefix_a, versions: { "stable" => "20141009", "version_scheme" => 1 })
+
+ prefix_b = HOMEBREW_CELLAR/"testball/2.14"
+ setup_tab_for_prefix(prefix_b, versions: { "stable" => "2.14", "version_scheme" => 2 })
+
+ expect(f.outdated_kegs).not_to be_empty
+ reset_outdated_kegs
+
+ prefix_c = HOMEBREW_CELLAR/"testball/20141009"
+ setup_tab_for_prefix(prefix_c, versions: { "stable" => "20141009", "version_scheme" => 3 })
+
+ expect(f.outdated_kegs).not_to be_empty
+ reset_outdated_kegs
+
+ prefix_d = HOMEBREW_CELLAR/"testball/20141011"
+ setup_tab_for_prefix(prefix_d, versions: { "stable" => "20141009", "version_scheme" => 3 })
+ expect(f.outdated_kegs).to be_empty
+ end
+ end
+
+ describe "with version scheme" do
+ let(:f) do
+ formula "testball" do
+ url "foo"
+ version "1.0"
+ version_scheme 2
+ end
+ end
+
+ example do
+ head_prefix = HOMEBREW_CELLAR/"testball/HEAD"
+
+ setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 1 })
+ expect(f.outdated_kegs).not_to be_empty
+
+ reset_outdated_kegs
+ head_prefix.rmtree
+
+ setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 })
+ expect(f.outdated_kegs).to be_empty
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/formula_test.rb b/Library/Homebrew/test/formula_test.rb
deleted file mode 100644
index 81022d220..000000000
--- a/Library/Homebrew/test/formula_test.rb
+++ /dev/null
@@ -1,1210 +0,0 @@
-require "testing_env"
-require "test/support/fixtures/testball"
-require "formula"
-
-class FormulaTests < Homebrew::TestCase
- def test_formula_instantiation
- klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
- name = "formula_name"
- path = Formulary.core_path(name)
- spec = :stable
-
- f = klass.new(name, path, spec)
- assert_equal name, f.name
- assert_equal name, f.specified_name
- assert_equal name, f.full_name
- assert_equal name, f.full_specified_name
- assert_equal path, f.path
- assert_nil f.alias_path
- assert_nil f.alias_name
- assert_nil f.full_alias_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_formula_instantiation_with_alias
- klass = Class.new(Formula) { url "http://example.com/foo-1.0.tar.gz" }
- name = "formula_name"
- path = Formulary.core_path(name)
- spec = :stable
- alias_name = "baz@1"
- alias_path = CoreTap.instance.alias_dir/alias_name
-
- f = klass.new(name, path, spec, alias_path: alias_path)
- assert_equal name, f.name
- assert_equal name, f.full_name
- assert_equal path, f.path
- assert_equal alias_path, f.alias_path
- assert_equal alias_name, f.alias_name
- assert_equal alias_name, f.specified_name
- assert_equal alias_name, f.full_alias_name
- assert_equal alias_name, f.full_specified_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_tap_formula_instantiation
- tap = Tap.new("foo", "bar")
- klass = Class.new(Formula) { url "baz-1.0" }
- name = "baz"
- full_name = "#{tap.user}/#{tap.repo}/#{name}"
- path = tap.path/"Formula/#{name}.rb"
- spec = :stable
-
- f = klass.new(name, path, spec)
- assert_equal name, f.name
- assert_equal name, f.specified_name
- assert_equal full_name, f.full_name
- assert_equal full_name, f.full_specified_name
- assert_equal path, f.path
- assert_nil f.alias_path
- assert_nil f.alias_name
- assert_nil f.full_alias_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_tap_formula_instantiation_with_alias
- tap = Tap.new("foo", "bar")
- klass = Class.new(Formula) { url "baz-1.0" }
- name = "baz"
- full_name = "#{tap.user}/#{tap.repo}/#{name}"
- path = tap.path/"Formula/#{name}.rb"
- spec = :stable
- alias_name = "baz@1"
- full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
- alias_path = CoreTap.instance.alias_dir/alias_name
-
- f = klass.new(name, path, spec, alias_path: alias_path)
- assert_equal name, f.name
- assert_equal full_name, f.full_name
- assert_equal path, f.path
- assert_equal alias_path, f.alias_path
- assert_equal alias_name, f.alias_name
- assert_equal alias_name, f.specified_name
- assert_equal full_alias_name, f.full_alias_name
- assert_equal full_alias_name, f.full_specified_name
- assert_raises(ArgumentError) { klass.new }
- end
-
- def test_follow_installed_alias
- f = formula { url "foo-1.0" }
- assert_predicate f, :follow_installed_alias?
-
- f.follow_installed_alias = true
- assert_predicate f, :follow_installed_alias?
-
- f.follow_installed_alias = false
- refute_predicate f, :follow_installed_alias?
- end
-
- def test_installed_alias_with_core
- f = formula { url "foo-1.0" }
-
- build_values_with_no_installed_alias = [
- nil,
- BuildOptions.new({}, {}),
- Tab.new(source: { "path" => f.path.to_s }),
- ]
-
- build_values_with_no_installed_alias.each do |build|
- f.build = build
- assert_nil f.installed_alias_path
- assert_nil f.installed_alias_name
- assert_nil f.full_installed_alias_name
- assert_equal f.name, f.installed_specified_name
- assert_equal f.name, f.full_installed_specified_name
- end
-
- alias_name = "bar"
- alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
- f.build = Tab.new(source: { "path" => alias_path })
- assert_equal alias_path, f.installed_alias_path
- assert_equal alias_name, f.installed_alias_name
- assert_equal alias_name, f.full_installed_alias_name
- assert_equal alias_name, f.installed_specified_name
- assert_equal alias_name, f.full_installed_specified_name
- end
-
- def test_installed_alias_with_tap
- tap = Tap.new("user", "repo")
- name = "foo"
- path = "#{tap.path}/Formula/#{name}.rb"
- f = formula(name, path) { url "foo-1.0" }
-
- build_values_with_no_installed_alias = [
- nil,
- BuildOptions.new({}, {}),
- Tab.new(source: { "path" => f.path }),
- ]
-
- build_values_with_no_installed_alias.each do |build|
- f.build = build
- assert_nil f.installed_alias_path
- assert_nil f.installed_alias_name
- assert_nil f.full_installed_alias_name
- assert_equal f.name, f.installed_specified_name
- assert_equal f.full_name, f.full_installed_specified_name
- end
-
- alias_name = "bar"
- full_alias_name = "#{tap.user}/#{tap.repo}/#{alias_name}"
- alias_path = "#{tap.alias_dir}/#{alias_name}"
- f.build = Tab.new(source: { "path" => alias_path })
- assert_equal alias_path, f.installed_alias_path
- assert_equal alias_name, f.installed_alias_name
- assert_equal full_alias_name, f.full_installed_alias_name
- assert_equal alias_name, f.installed_specified_name
- assert_equal full_alias_name, f.full_installed_specified_name
- end
-
- def test_prefix
- f = Testball.new
- assert_equal HOMEBREW_CELLAR/f.name/"0.1", f.prefix
- assert_kind_of Pathname, f.prefix
- end
-
- def test_revised_prefix
- f = Class.new(Testball) { revision 1 }.new
- assert_equal HOMEBREW_CELLAR/f.name/"0.1_1", f.prefix
- end
-
- def test_any_version_installed?
- f = formula do
- url "foo"
- version "1.0"
- end
- refute_predicate f, :any_version_installed?
- prefix = HOMEBREW_CELLAR+f.name+"0.1"
- prefix.mkpath
- FileUtils.touch prefix+Tab::FILENAME
- assert_predicate f, :any_version_installed?
- ensure
- f.rack.rmtree
- end
-
- def test_migration_needed
- f = Testball.new("newname")
- f.instance_variable_set(:@oldname, "oldname")
- f.instance_variable_set(:@tap, CoreTap.instance)
-
- oldname_prefix = HOMEBREW_CELLAR/"oldname/2.20"
- newname_prefix = HOMEBREW_CELLAR/"newname/2.10"
- oldname_prefix.mkpath
- oldname_tab = Tab.empty
- oldname_tab.tabfile = oldname_prefix.join("INSTALL_RECEIPT.json")
- oldname_tab.write
-
- refute_predicate f, :migration_needed?
-
- oldname_tab.tabfile.unlink
- oldname_tab.source["tap"] = "homebrew/core"
- oldname_tab.write
-
- assert_predicate f, :migration_needed?
-
- newname_prefix.mkpath
-
- refute_predicate f, :migration_needed?
- ensure
- oldname_prefix.parent.rmtree
- newname_prefix.parent.rmtree
- end
-
- def test_installed?
- f = Testball.new
- f.stubs(:installed_prefix).returns(stub(directory?: false))
- refute_predicate f, :installed?
-
- f.stubs(:installed_prefix).returns(
- stub(directory?: true, children: [])
- )
- refute_predicate f, :installed?
-
- f.stubs(:installed_prefix).returns(
- stub(directory?: true, children: [stub])
- )
- assert_predicate f, :installed?
- end
-
- def test_installed_prefix
- f = Testball.new
- assert_equal f.prefix, f.installed_prefix
- end
-
- def test_installed_prefix_head_installed
- f = formula do
- head "foo"
- devel do
- url "foo"
- version "1.0"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.head.version
- prefix.mkpath
- assert_equal prefix, f.installed_prefix
- ensure
- f.rack.rmtree
- end
-
- def test_installed_prefix_devel_installed
- f = formula do
- head "foo"
- devel do
- url "foo"
- version "1.0"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.devel.version
- prefix.mkpath
- assert_equal prefix, f.installed_prefix
- ensure
- f.rack.rmtree
- end
-
- def test_installed_prefix_stable_installed
- f = formula do
- head "foo"
- devel do
- url "foo"
- version "1.0-devel"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.version
- prefix.mkpath
- assert_equal prefix, f.installed_prefix
- ensure
- f.rack.rmtree
- end
-
- def test_installed_prefix_outdated_stable_head_installed
- f = formula do
- url "foo"
- version "1.9"
- head "foo"
- end
-
- head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
- head_prefix.mkpath
- tab = Tab.empty
- tab.tabfile = head_prefix.join("INSTALL_RECEIPT.json")
- tab.source["versions"] = { "stable" => "1.0" }
- tab.write
-
- assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix
- ensure
- f.rack.rmtree
- end
-
- def test_installed_prefix_outdated_devel_head_installed
- f = formula do
- url "foo"
- version "1.9"
- devel do
- url "foo"
- version "2.1"
- end
- end
-
- head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
- head_prefix.mkpath
- tab = Tab.empty
- tab.tabfile = head_prefix.join("INSTALL_RECEIPT.json")
- tab.source["versions"] = { "stable" => "1.9", "devel" => "2.0" }
- tab.write
-
- assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix
- ensure
- f.rack.rmtree
- end
-
- def test_installed_prefix_head
- f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
- head "foo"
- devel do
- url "foo"
- version "1.0-devel"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.head.version
- assert_equal prefix, f.installed_prefix
- end
-
- def test_installed_prefix_devel
- f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do
- head "foo"
- devel do
- url "foo"
- version "1.0-devel"
- end
- end
- prefix = HOMEBREW_CELLAR+f.name+f.devel.version
- assert_equal prefix, f.installed_prefix
- end
-
- def test_latest_head_prefix
- f = Testball.new
-
- stamps_with_revisions = [[111111, 1], [222222, 1], [222222, 2], [222222, 0]]
-
- stamps_with_revisions.each do |stamp, revision|
- version = "HEAD-#{stamp}"
- version += "_#{revision}" if revision > 0
- prefix = f.rack.join(version)
- prefix.mkpath
-
- tab = Tab.empty
- tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
- tab.source_modified_time = stamp
- tab.write
- end
-
- prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD-222222_2"
- assert_equal prefix, f.latest_head_prefix
- ensure
- f.rack.rmtree
- end
-
- def test_equality
- x = Testball.new
- y = Testball.new
- assert_equal x, y
- assert_eql x, y
- assert_equal x.hash, y.hash
- end
-
- def test_inequality
- x = Testball.new("foo")
- y = Testball.new("bar")
- refute_equal x, y
- refute_eql x, y
- refute_equal x.hash, y.hash
- end
-
- def test_comparison_with_non_formula_objects_does_not_raise
- refute_equal Testball.new, Object.new
- end
-
- def test_sort_operator
- assert_nil Testball.new <=> Object.new
- end
-
- def test_alias_paths_with_build_options
- alias_path = CoreTap.instance.alias_dir/"another_name"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- f.build = BuildOptions.new({}, {})
- assert_equal alias_path, f.alias_path
- assert_nil f.installed_alias_path
- end
-
- def test_alias_paths_with_tab_with_non_alias_source_path
- alias_path = CoreTap.instance.alias_dir/"another_name"
- source_path = CoreTap.instance.formula_dir/"another_other_name"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- f.build = Tab.new(source: { "path" => source_path.to_s })
- assert_equal alias_path, f.alias_path
- assert_nil f.installed_alias_path
- end
-
- def test_alias_paths_with_tab_with_alias_source_path
- alias_path = CoreTap.instance.alias_dir/"another_name"
- source_path = CoreTap.instance.alias_dir/"another_other_name"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- f.build = Tab.new(source: { "path" => source_path.to_s })
- assert_equal alias_path, f.alias_path
- assert_equal source_path.to_s, f.installed_alias_path
- end
-
- def test_installed_with_alias_path_with_nil
- assert_predicate Formula.installed_with_alias_path(nil), :empty?
- end
-
- def test_installed_with_alias_path_with_a_path
- alias_path = "#{CoreTap.instance.alias_dir}/alias"
- different_alias_path = "#{CoreTap.instance.alias_dir}/another_alias"
-
- formula_with_alias = formula("foo") { url "foo-1.0" }
- formula_with_alias.build = Tab.empty
- formula_with_alias.build.source["path"] = alias_path
-
- formula_without_alias = formula("bar") { url "bar-1.0" }
- formula_without_alias.build = Tab.empty
- formula_without_alias.build.source["path"] = formula_without_alias.path.to_s
-
- formula_with_different_alias = formula("baz") { url "baz-1.0" }
- formula_with_different_alias.build = Tab.empty
- formula_with_different_alias.build.source["path"] = different_alias_path
-
- formulae = [
- formula_with_alias,
- formula_without_alias,
- formula_with_different_alias,
- ]
-
- Formula.stubs(:installed).returns(formulae)
- assert_equal [formula_with_alias], Formula.installed_with_alias_path(alias_path)
- end
-
- def test_formula_spec_integration
- f = formula do
- homepage "http://example.com"
- url "http://example.com/test-0.1.tbz"
- mirror "http://example.org/test-0.1.tbz"
- sha256 TEST_SHA256
-
- head "http://example.com/test.git", tag: "foo"
-
- devel do
- url "http://example.com/test-0.2.tbz"
- mirror "http://example.org/test-0.2.tbz"
- sha256 TEST_SHA256
- end
- end
-
- assert_equal "http://example.com", f.homepage
- assert_version_equal "0.1", f.version
- assert_predicate f, :stable?
-
- assert_version_equal "0.1", f.stable.version
- assert_version_equal "0.2", f.devel.version
- assert_version_equal "HEAD", f.head.version
- end
-
- def test_formula_active_spec=
- f = formula do
- url "foo"
- version "1.0"
- revision 1
-
- devel do
- url "foo"
- version "1.0beta"
- end
- end
- assert_equal :stable, f.active_spec_sym
- assert_equal f.stable, f.send(:active_spec)
- assert_equal "1.0_1", f.pkg_version.to_s
- f.active_spec = :devel
- assert_equal :devel, f.active_spec_sym
- assert_equal f.devel, f.send(:active_spec)
- assert_equal "1.0beta_1", f.pkg_version.to_s
- assert_raises(FormulaSpecificationError) { f.active_spec = :head }
- end
-
- def test_path
- name = "foo-bar"
- assert_equal Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb"), Formulary.core_path(name)
- end
-
- def test_class_specs_are_always_initialized
- f = formula { url "foo-1.0" }
-
- %w[stable devel head].each do |spec|
- assert_kind_of SoftwareSpec, f.class.send(spec)
- end
- end
-
- def test_incomplete_instance_specs_are_not_accessible
- f = formula { url "foo-1.0" }
-
- %w[devel head].each { |spec| assert_nil f.send(spec) }
- end
-
- def test_honors_attributes_declared_before_specs
- f = formula do
- url "foo-1.0"
- depends_on "foo"
- devel { url "foo-1.1" }
- end
-
- %w[stable devel head].each do |spec|
- assert_equal "foo", f.class.send(spec).deps.first.name
- end
- end
-
- def test_simple_version
- assert_equal PkgVersion.parse("1.0"), formula { url "foo-1.0.bar" }.pkg_version
- end
-
- def test_version_with_revision
- f = formula do
- url "foo-1.0.bar"
- revision 1
- end
-
- assert_equal PkgVersion.parse("1.0_1"), f.pkg_version
- end
-
- def test_head_uses_revisions
- f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
- url "foo-1.0.bar"
- revision 1
- head "foo"
- end
-
- assert_equal PkgVersion.parse("HEAD_1"), f.pkg_version
- end
-
- def test_update_head_version
- initial_env = ENV.to_hash
-
- f = formula do
- head "foo", using: :git
- end
-
- cached_location = f.head.downloader.cached_location
- cached_location.mkpath
-
- %w[AUTHOR COMMITTER].each do |role|
- ENV["GIT_#{role}_NAME"] = "brew tests"
- ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
- ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
- end
-
- cached_location.cd do
- FileUtils.touch "LICENSE"
- shutup do
- system "git", "init"
- system "git", "add", "--all"
- system "git", "commit", "-m", "Initial commit"
- end
- end
-
- f.update_head_version
- assert_equal Version.create("HEAD-5658946"), f.head.version
- ensure
- ENV.replace(initial_env)
- cached_location.rmtree
- end
-
- def test_legacy_options
- f = formula do
- url "foo-1.0"
-
- def options
- [["--foo", "desc"], ["--bar", "desc"]]
- end
-
- option "baz"
- end
-
- assert f.option_defined?("foo")
- assert f.option_defined?("bar")
- assert f.option_defined?("baz")
- end
-
- def test_desc
- f = formula do
- desc "a formula"
- url "foo-1.0"
- end
-
- assert_equal "a formula", f.desc
- end
-
- def test_post_install_defined
- f1 = formula do
- url "foo-1.0"
-
- def post_install; end
- end
-
- f2 = formula do
- url "foo-1.0"
- end
-
- assert f1.post_install_defined?
- refute f2.post_install_defined?
- end
-
- def test_test_defined
- f1 = formula do
- url "foo-1.0"
-
- def test; end
- end
-
- f2 = formula do
- url "foo-1.0"
- end
-
- assert f1.test_defined?
- refute f2.test_defined?
- end
-
- def test_test_fixtures
- f1 = formula do
- url "foo-1.0"
- end
-
- assert_equal Pathname.new("#{HOMEBREW_LIBRARY_PATH}/test/support/fixtures/foo"),
- f1.test_fixtures("foo")
- end
-
- def test_dependencies
- stub_formula_loader formula("f1") { url "f1-1.0" }
- stub_formula_loader formula("f2") { url "f2-1.0" }
-
- f3 = formula("f3") do
- url "f3-1.0"
- depends_on "f1" => :build
- depends_on "f2"
- end
- stub_formula_loader f3
-
- f4 = formula("f4") do
- url "f4-1.0"
- depends_on "f1"
- end
- stub_formula_loader f4
-
- f5 = formula("f5") do
- url "f5-1.0"
- depends_on "f3" => :build
- depends_on "f4"
- end
-
- assert_equal %w[f3 f4], f5.deps.map(&:name)
- assert_equal %w[f1 f2 f3 f4], f5.recursive_dependencies.map(&:name)
- assert_equal %w[f1 f4], f5.runtime_dependencies.map(&:name)
- end
-
- def test_runtime_dependencies_with_optional_deps_from_tap
- tap_loader = mock
- tap_loader.stubs(:get_formula).raises(RuntimeError, "tried resolving tap formula")
- Formulary.stubs(:loader_for).with("foo/bar/f1", from: nil).returns(tap_loader)
-
- stub_formula_loader formula("f2") { url "f2-1.0" }, "baz/qux/f2"
-
- f3 = formula("f3") do
- url "f3-1.0"
- depends_on "foo/bar/f1" => :optional
- depends_on "baz/qux/f2"
- end
-
- # f1 shouldn't be loaded by default.
- # If it is, an exception will be raised.
- assert_equal %w[baz/qux/f2], f3.runtime_dependencies.map(&:name)
-
- # If --with-f1, f1 should be loaded.
- stub_formula_loader formula("f1") { url "f1-1.0" }, "foo/bar/f1"
- f3.build = BuildOptions.new(Options.create(%w[--with-f1]), f3.options)
- assert_equal %w[foo/bar/f1 baz/qux/f2], f3.runtime_dependencies.map(&:name)
- end
-
- def test_to_hash
- f1 = formula("foo") do
- url "foo-1.0"
- end
-
- h = f1.to_hash
- assert h.is_a?(Hash), "Formula#to_hash should return a Hash"
- assert_equal "foo", h["name"]
- assert_equal "foo", h["full_name"]
- assert_equal "1.0", h["versions"]["stable"]
- end
-
- def test_to_hash_bottle
- f1 = formula("foo") do
- url "foo-1.0"
-
- bottle do
- cellar :any
- sha256 TEST_SHA256 => Utils::Bottles.tag
- end
- end
-
- h = f1.to_hash
- assert h.is_a?(Hash), "Formula#to_hash should return a Hash"
- assert h["versions"]["bottle"], "The hash should say the formula is bottled"
- end
-
- def test_eligible_kegs_for_cleanup
- f1 = Class.new(Testball) { version "0.1" }.new
- f2 = Class.new(Testball) { version "0.2" }.new
- f3 = Class.new(Testball) { version "0.3" }.new
-
- shutup do
- f1.brew { f1.install }
- f2.brew { f2.install }
- f3.brew { f3.install }
- end
-
- assert_predicate f1, :installed?
- assert_predicate f2, :installed?
- assert_predicate f3, :installed?
-
- assert_equal f3.installed_kegs.sort_by(&:version)[0..1],
- f3.eligible_kegs_for_cleanup.sort_by(&:version)
- ensure
- [f1, f2, f3].each(&:clear_cache)
- f3.rack.rmtree
- end
-
- def test_eligible_kegs_for_cleanup_keg_pinned
- f1 = Class.new(Testball) { version "0.1" }.new
- f2 = Class.new(Testball) { version "0.2" }.new
- f3 = Class.new(Testball) { version "0.3" }.new
-
- shutup do
- f1.brew { f1.install }
- f1.pin
- f2.brew { f2.install }
- f3.brew { f3.install }
- end
-
- assert_equal (HOMEBREW_PINNED_KEGS/f1.name).resolved_path, f1.prefix
-
- assert_predicate f1, :installed?
- assert_predicate f2, :installed?
- assert_predicate f3, :installed?
-
- assert_equal [Keg.new(f2.prefix)], shutup { f3.eligible_kegs_for_cleanup }
- ensure
- f1.unpin
- [f1, f2, f3].each(&:clear_cache)
- f3.rack.rmtree
- end
-
- def test_eligible_kegs_for_cleanup_head_installed
- f = formula do
- version "0.1"
- head "foo"
- end
-
- stable_prefix = f.installed_prefix
- stable_prefix.mkpath
-
- [["000000_1", 1], ["111111", 2], ["111111_1", 2]].each do |pkg_version_suffix, stamp|
- prefix = f.prefix("HEAD-#{pkg_version_suffix}")
- prefix.mkpath
- tab = Tab.empty
- tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
- tab.source_modified_time = stamp
- tab.write
- end
-
- eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1"))]
- assert_equal eligible_kegs, f.eligible_kegs_for_cleanup
- ensure
- f.rack.rmtree
- end
-
- def test_pour_bottle
- f_false = formula("foo") do
- url "foo-1.0"
- def pour_bottle?
- false
- end
- end
- refute f_false.pour_bottle?
-
- f_true = formula("foo") do
- url "foo-1.0"
- def pour_bottle?
- true
- end
- end
- assert f_true.pour_bottle?
- end
-
- def test_pour_bottle_dsl
- f_false = formula("foo") do
- url "foo-1.0"
- pour_bottle? do
- reason "false reason"
- satisfy { var == etc }
- end
- end
- refute f_false.pour_bottle?
-
- f_true = formula("foo") do
- url "foo-1.0"
- pour_bottle? do
- reason "true reason"
- satisfy { true }
- end
- end
- assert f_true.pour_bottle?
- end
-end
-
-class AliasChangeTests < Homebrew::TestCase
- attr_reader :f, :new_formula, :tab, :alias_path
-
- def make_formula(name, version)
- f = formula(name, alias_path: alias_path) { url "foo-#{version}" }
- f.build = tab
- f
- end
-
- def setup
- alias_name = "bar"
- @alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
-
- @tab = Tab.empty
-
- @f = make_formula("formula_name", "1.0")
- @new_formula = make_formula("new_formula_name", "1.1")
-
- Formula.stubs(:installed).returns([f])
- end
-
- def test_alias_changes_when_not_installed_with_alias
- tab.source["path"] = Formulary.core_path(f.name).to_s
-
- assert_nil f.current_installed_alias_target
- assert_equal f, f.latest_formula
- refute_predicate f, :installed_alias_target_changed?
- refute_predicate f, :supersedes_an_installed_formula?
- refute_predicate f, :alias_changed?
- assert_predicate f.old_installed_formulae, :empty?
- end
-
- def test_alias_changes_when_not_changed
- tab.source["path"] = alias_path
- stub_formula_loader(f, alias_path)
-
- assert_equal f, f.current_installed_alias_target
- assert_equal f, f.latest_formula
- refute_predicate f, :installed_alias_target_changed?
- refute_predicate f, :supersedes_an_installed_formula?
- refute_predicate f, :alias_changed?
- assert_predicate f.old_installed_formulae, :empty?
- end
-
- def test_alias_changes_when_new_alias_target
- tab.source["path"] = alias_path
- stub_formula_loader(new_formula, alias_path)
-
- assert_equal new_formula, f.current_installed_alias_target
- assert_equal new_formula, f.latest_formula
- assert_predicate f, :installed_alias_target_changed?
- refute_predicate f, :supersedes_an_installed_formula?
- assert_predicate f, :alias_changed?
- assert_predicate f.old_installed_formulae, :empty?
- end
-
- def test_alias_changes_when_old_formulae_installed
- tab.source["path"] = alias_path
- stub_formula_loader(new_formula, alias_path)
-
- assert_equal new_formula, new_formula.current_installed_alias_target
- assert_equal new_formula, new_formula.latest_formula
- refute_predicate new_formula, :installed_alias_target_changed?
- assert_predicate new_formula, :supersedes_an_installed_formula?
- assert_predicate new_formula, :alias_changed?
- assert_equal [f], new_formula.old_installed_formulae
- end
-end
-
-class OutdatedVersionsTests < Homebrew::TestCase
- attr_reader :outdated_prefix,
- :same_prefix,
- :greater_prefix,
- :head_prefix,
- :old_alias_target_prefix
- attr_reader :f, :old_formula, :new_formula
-
- def setup
- @f = formula do
- url "foo"
- version "1.20"
- end
-
- @old_formula = formula("foo@1") { url "foo-1.0" }
- @new_formula = formula("foo@2") { url "foo-2.0" }
-
- @outdated_prefix = HOMEBREW_CELLAR/"#{f.name}/1.11"
- @same_prefix = HOMEBREW_CELLAR/"#{f.name}/1.20"
- @greater_prefix = HOMEBREW_CELLAR/"#{f.name}/1.21"
- @head_prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD"
- @old_alias_target_prefix = HOMEBREW_CELLAR/"#{old_formula.name}/1.0"
- end
-
- def teardown
- formulae = [@f, @old_formula, @new_formula]
- formulae.map(&:rack).select(&:exist?).each(&:rmtree)
- end
-
- def alias_path
- "#{@f.tap.alias_dir}/bar"
- end
-
- def setup_tab_for_prefix(prefix, options = {})
- prefix.mkpath
- tab = Tab.empty
- tab.tabfile = prefix.join("INSTALL_RECEIPT.json")
- tab.source["path"] = options[:path].to_s if options[:path]
- tab.source["tap"] = options[:tap] if options[:tap]
- tab.source["versions"] = options[:versions] if options[:versions]
- tab.source_modified_time = options[:source_modified_time].to_i
- tab.write unless options[:no_write]
- tab
- end
-
- def reset_outdated_kegs
- f.instance_variable_set(:@outdated_kegs, nil)
- end
-
- def test_greater_different_tap_installed
- setup_tab_for_prefix(greater_prefix, tap: "user/repo")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_greater_same_tap_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_different_tap_installed
- setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_same_tap_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_follow_alias_and_alias_unchanged
- f.follow_installed_alias = true
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(f, alias_path)
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_follow_alias_and_alias_changed_and_new_target_not_installed
- f.follow_installed_alias = true
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(new_formula, alias_path)
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_follow_alias_and_alias_changed_and_new_target_installed
- f.follow_installed_alias = true
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(new_formula, alias_path)
- setup_tab_for_prefix(new_formula.prefix) # install new_formula
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_no_follow_alias_and_alias_unchanged
- f.follow_installed_alias = false
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(f, alias_path)
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_no_follow_alias_and_alias_changed
- f.follow_installed_alias = false
- f.build = setup_tab_for_prefix(same_prefix, path: alias_path)
- stub_formula_loader(formula("foo@2") { url "foo-2.0" }, alias_path)
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_old_alias_targets_installed
- @f = formula(alias_path: alias_path) { url "foo-1.0" }
- tab = setup_tab_for_prefix(old_alias_target_prefix, path: alias_path)
- old_formula.build = tab
- Formula.stubs(:installed).returns([old_formula])
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_old_alias_targets_not_installed
- @f = formula(alias_path: alias_path) { url "foo-1.0" }
- tab = setup_tab_for_prefix(old_alias_target_prefix, path: old_formula.path)
- old_formula.build = tab
- Formula.stubs(:installed).returns([old_formula])
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_same_head_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(head_prefix, tap: "homebrew/core")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_different_head_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(head_prefix, tap: "user/repo")
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_mixed_taps_greater_version_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(outdated_prefix, tap: "homebrew/core")
- setup_tab_for_prefix(greater_prefix, tap: "user/repo")
-
- assert_predicate f.outdated_kegs, :empty?
-
- setup_tab_for_prefix(greater_prefix, tap: "homebrew/core")
- reset_outdated_kegs
-
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_mixed_taps_outdated_version_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
-
- extra_outdated_prefix = HOMEBREW_CELLAR/"#{f.name}/1.0"
-
- setup_tab_for_prefix(outdated_prefix)
- setup_tab_for_prefix(extra_outdated_prefix, tap: "homebrew/core")
- reset_outdated_kegs
-
- refute_predicate f.outdated_kegs, :empty?
-
- setup_tab_for_prefix(outdated_prefix, tap: "user/repo")
- reset_outdated_kegs
-
- refute_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_same_version_tap_installed
- f.instance_variable_set(:@tap, CoreTap.instance)
- setup_tab_for_prefix(same_prefix, tap: "homebrew/core")
-
- assert_predicate f.outdated_kegs, :empty?
-
- setup_tab_for_prefix(same_prefix, tap: "user/repo")
- reset_outdated_kegs
-
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_installed_head_less_than_stable
- tab = setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0" })
- refute_predicate f.outdated_kegs, :empty?
-
- # Tab.for_keg(head_prefix) will be fetched from CACHE but we write it anyway
- tab.source["versions"] = { "stable" => f.version.to_s }
- tab.write
- reset_outdated_kegs
-
- assert_predicate f.outdated_kegs, :empty?
- end
-
- def test_outdated_fetch_head
- outdated_stable_prefix = HOMEBREW_CELLAR.join("testball/1.0")
- head_prefix_a = HOMEBREW_CELLAR.join("testball/HEAD")
- head_prefix_b = HOMEBREW_CELLAR.join("testball/HEAD-aaaaaaa_1")
- head_prefix_c = HOMEBREW_CELLAR.join("testball/HEAD-5658946")
-
- setup_tab_for_prefix(outdated_stable_prefix)
- tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
- setup_tab_for_prefix(head_prefix_b)
-
- initial_env = ENV.to_hash
- testball_repo = HOMEBREW_PREFIX.join("testball_repo")
- testball_repo.mkdir
-
- @f = formula("testball") do
- url "foo"
- version "2.10"
- head "file://#{testball_repo}", using: :git
- end
-
- %w[AUTHOR COMMITTER].each do |role|
- ENV["GIT_#{role}_NAME"] = "brew tests"
- ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
- ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
- end
-
- testball_repo.cd do
- FileUtils.touch "LICENSE"
- shutup do
- system "git", "init"
- system "git", "add", "--all"
- system "git", "commit", "-m", "Initial commit"
- end
- end
-
- refute_predicate f.outdated_kegs(fetch_head: true), :empty?
-
- tab_a.source["versions"] = { "stable" => f.version.to_s }
- tab_a.write
- reset_outdated_kegs
- refute_predicate f.outdated_kegs(fetch_head: true), :empty?
-
- head_prefix_a.rmtree
- reset_outdated_kegs
- refute_predicate f.outdated_kegs(fetch_head: true), :empty?
-
- setup_tab_for_prefix(head_prefix_c, source_modified_time: 1)
- reset_outdated_kegs
- assert_predicate f.outdated_kegs(fetch_head: true), :empty?
- ensure
- ENV.replace(initial_env)
- testball_repo.rmtree if testball_repo.exist?
- outdated_stable_prefix.rmtree if outdated_stable_prefix.exist?
- head_prefix_b.rmtree if head_prefix.exist?
- head_prefix_c.rmtree if head_prefix_c.exist?
- FileUtils.rm_rf HOMEBREW_CACHE/"testball--git"
- FileUtils.rm_rf HOMEBREW_CELLAR/"testball"
- end
-
- def test_outdated_kegs_version_scheme_changed
- @f = formula("testball") do
- url "foo"
- version "20141010"
- version_scheme 1
- end
-
- prefix = HOMEBREW_CELLAR.join("testball/0.1")
- setup_tab_for_prefix(prefix, versions: { "stable" => "0.1" })
-
- refute_predicate f.outdated_kegs, :empty?
- ensure
- prefix.rmtree
- end
-
- def test_outdated_kegs_mixed_version_schemes
- @f = formula("testball") do
- url "foo"
- version "20141010"
- version_scheme 3
- end
-
- prefix_a = HOMEBREW_CELLAR.join("testball/20141009")
- setup_tab_for_prefix(prefix_a, versions: { "stable" => "20141009", "version_scheme" => 1 })
-
- prefix_b = HOMEBREW_CELLAR.join("testball/2.14")
- setup_tab_for_prefix(prefix_b, versions: { "stable" => "2.14", "version_scheme" => 2 })
-
- refute_predicate f.outdated_kegs, :empty?
- reset_outdated_kegs
-
- prefix_c = HOMEBREW_CELLAR.join("testball/20141009")
- setup_tab_for_prefix(prefix_c, versions: { "stable" => "20141009", "version_scheme" => 3 })
-
- refute_predicate f.outdated_kegs, :empty?
- reset_outdated_kegs
-
- prefix_d = HOMEBREW_CELLAR.join("testball/20141011")
- setup_tab_for_prefix(prefix_d, versions: { "stable" => "20141009", "version_scheme" => 3 })
- assert_predicate f.outdated_kegs, :empty?
- ensure
- f.rack.rmtree
- end
-
- def test_outdated_kegs_head_with_version_scheme
- @f = formula("testball") do
- url "foo"
- version "1.0"
- version_scheme 2
- end
-
- head_prefix = HOMEBREW_CELLAR.join("testball/HEAD")
-
- setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 1 })
- refute_predicate f.outdated_kegs, :empty?
-
- reset_outdated_kegs
- head_prefix.rmtree
-
- setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 })
- assert_predicate f.outdated_kegs, :empty?
- ensure
- head_prefix.rmtree
- end
-end
diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb
new file mode 100644
index 000000000..213ad511d
--- /dev/null
+++ b/Library/Homebrew/test/formulary_spec.rb
@@ -0,0 +1,227 @@
+require "formula"
+require "formula_installer"
+require "utils/bottles"
+
+describe Formulary do
+ let(:formula_name) { "testball_bottle" }
+ let(:formula_path) { CoreTap.new.formula_dir/"#{formula_name}.rb" }
+ let(:formula_content) do
+ <<-EOS.undent
+ class #{subject.class_s(formula_name)} < Formula
+ url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
+ sha256 TESTBALL_SHA256
+
+ bottle do
+ cellar :any_skip_relocation
+ root_url "file://#{bottle_dir}"
+ sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => :#{Utils::Bottles.tag}
+ end
+
+ def install
+ prefix.install "bin"
+ prefix.install "libexec"
+ end
+ end
+ EOS
+ end
+ let(:bottle_dir) { Pathname.new("#{TEST_FIXTURE_DIR}/bottles") }
+ let(:bottle) { bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz" }
+
+ describe "::class_s" do
+ it "replaces '+' with 'x'" do
+ expect(subject.class_s("foo++")).to eq("Fooxx")
+ end
+
+ it "converts a string to PascalCase" do
+ expect(subject.class_s("shell.fm")).to eq("ShellFm")
+ expect(subject.class_s("s-lang")).to eq("SLang")
+ expect(subject.class_s("pkg-config")).to eq("PkgConfig")
+ expect(subject.class_s("foo_bar")).to eq("FooBar")
+ end
+
+ it "replaces '@' with 'AT'" do
+ expect(subject.class_s("openssl@1.1")).to eq("OpensslAT11")
+ end
+ end
+
+ describe "::factory" do
+ before(:each) do
+ formula_path.write formula_content
+ end
+
+ it "returns a Formula" do
+ expect(subject.factory(formula_name)).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula when given a fully qualified name" do
+ expect(subject.factory("homebrew/core/#{formula_name}")).to be_kind_of(Formula)
+ end
+
+ it "raises an error if the Formula cannot be found" do
+ expect {
+ subject.factory("not_existed_formula")
+ }.to raise_error(FormulaUnavailableError)
+ end
+
+ context "if the Formula has the wrong class" do
+ let(:formula_name) { "giraffe" }
+ let(:formula_content) do
+ <<-EOS.undent
+ class Wrong#{subject.class_s(formula_name)} < Formula
+ end
+ EOS
+ end
+
+ it "raises an error" do
+ expect {
+ subject.factory(formula_name)
+ }.to raise_error(FormulaClassUnavailableError)
+ end
+ end
+
+ it "returns a Formula when given a path" do
+ expect(subject.factory(formula_path)).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula when given a URL" do
+ formula = shutup do
+ subject.factory("file://#{formula_path}")
+ end
+
+ expect(formula).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula when given a bottle" do
+ formula = subject.factory(bottle)
+ expect(formula).to be_kind_of(Formula)
+ expect(formula.local_bottle_path).to eq(bottle.realpath)
+ end
+
+ it "returns a Formula when given an alias" do
+ alias_dir = CoreTap.instance.alias_dir
+ alias_dir.mkpath
+ alias_path = alias_dir/"foo"
+ FileUtils.ln_s formula_path, alias_path
+ result = subject.factory("foo")
+ expect(result).to be_kind_of(Formula)
+ expect(result.alias_path).to eq(alias_path.to_s)
+ end
+
+ context "with installed Formula" do
+ let(:formula) { subject.factory(formula_path) }
+ let(:installer) { FormulaInstaller.new(formula) }
+
+ it "returns a Formula when given a rack" do
+ shutup do
+ installer.install
+ end
+
+ f = subject.from_rack(formula.rack)
+ expect(f).to be_kind_of(Formula)
+ expect(f.build).to be_kind_of(Tab)
+ end
+
+ it "returns a Formula when given a Keg" do
+ shutup do
+ installer.install
+ end
+
+ keg = Keg.new(formula.prefix)
+ f = subject.from_keg(keg)
+ expect(f).to be_kind_of(Formula)
+ expect(f.build).to be_kind_of(Tab)
+ end
+ end
+
+ context "from Tap" do
+ let(:tap) { Tap.new("homebrew", "foo") }
+ let(:formula_path) { tap.path/"#{formula_name}.rb" }
+
+ it "returns a Formula when given a name" do
+ expect(subject.factory(formula_name)).to be_kind_of(Formula)
+ end
+
+ it "returns a Formula from an Alias path" do
+ alias_dir = tap.path/"Aliases"
+ alias_dir.mkpath
+ FileUtils.ln_s formula_path, alias_dir/"bar"
+ expect(subject.factory("bar")).to be_kind_of(Formula)
+ end
+
+ it "raises an error when the Formula cannot be found" do
+ expect {
+ subject.factory("#{tap}/not_existed_formula")
+ }.to raise_error(TapFormulaUnavailableError)
+ end
+
+ it "returns a Formula when given a fully qualified name" do
+ expect(subject.factory("#{tap}/#{formula_name}")).to be_kind_of(Formula)
+ end
+
+ it "raises an error if a Formula is in multiple Taps" do
+ begin
+ another_tap = Tap.new("homebrew", "bar")
+ (another_tap.path/"#{formula_name}.rb").write formula_content
+ expect {
+ subject.factory(formula_name)
+ }.to raise_error(TapFormulaAmbiguityError)
+ ensure
+ another_tap.path.rmtree
+ end
+ end
+ end
+ end
+
+ specify "::from_contents" do
+ expect(subject.from_contents(formula_name, formula_path, formula_content)).to be_kind_of(Formula)
+ end
+
+ specify "::to_rack" do
+ expect(subject.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name)
+
+ (HOMEBREW_CELLAR/formula_name).mkpath
+ expect(subject.to_rack(formula_name)).to eq(HOMEBREW_CELLAR/formula_name)
+
+ expect {
+ subject.to_rack("a/b/#{formula_name}")
+ }.to raise_error(TapFormulaUnavailableError)
+ end
+
+ describe "::find_with_priority" do
+ let(:core_path) { CoreTap.new.formula_dir/"#{formula_name}.rb" }
+ let(:tap) { Tap.new("homebrew", "foo") }
+ let(:tap_path) { tap.path/"#{formula_name}.rb" }
+
+ before(:each) do
+ core_path.write formula_content
+ tap_path.write formula_content
+ end
+
+ it "prioritizes core Formulae" do
+ formula = subject.find_with_priority(formula_name)
+ expect(formula).to be_kind_of(Formula)
+ expect(formula.path).to eq(core_path)
+ end
+
+ it "prioritizes Formulae from pinned Taps" do
+ begin
+ tap.pin
+ formula = shutup do
+ subject.find_with_priority(formula_name)
+ end
+ expect(formula).to be_kind_of(Formula)
+ expect(formula.path).to eq(tap_path.realpath)
+ ensure
+ tap.pinned_symlink_path.parent.parent.rmtree
+ end
+ end
+ end
+
+ describe "::core_path" do
+ it "returns the path to a Formula in the core tap" do
+ name = "foo-bar"
+ expect(subject.core_path(name))
+ .to eq(Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb"))
+ end
+ end
+end
diff --git a/Library/Homebrew/test/formulary_test.rb b/Library/Homebrew/test/formulary_test.rb
deleted file mode 100644
index 3d88c8407..000000000
--- a/Library/Homebrew/test/formulary_test.rb
+++ /dev/null
@@ -1,208 +0,0 @@
-require "testing_env"
-require "formula"
-require "formula_installer"
-require "utils/bottles"
-
-class FormularyTest < Homebrew::TestCase
- def test_class_naming
- assert_equal "ShellFm", Formulary.class_s("shell.fm")
- assert_equal "Fooxx", Formulary.class_s("foo++")
- assert_equal "SLang", Formulary.class_s("s-lang")
- assert_equal "PkgConfig", Formulary.class_s("pkg-config")
- assert_equal "FooBar", Formulary.class_s("foo_bar")
- assert_equal "OpensslAT11", Formulary.class_s("openssl@1.1")
- end
-end
-
-class FormularyFactoryTest < Homebrew::TestCase
- def setup
- @name = "testball_bottle"
- @path = CoreTap.new.formula_dir/"#{@name}.rb"
- @bottle_dir = Pathname.new("#{TEST_FIXTURE_DIR}/bottles")
- @bottle = @bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz"
- @path.write <<-EOS.undent
- class #{Formulary.class_s(@name)} < Formula
- url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
- sha256 TESTBALL_SHA256
-
- bottle do
- cellar :any_skip_relocation
- root_url "file://#{@bottle_dir}"
- sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => :#{Utils::Bottles.tag}
- end
-
- def install
- prefix.install "bin"
- prefix.install "libexec"
- end
- end
- EOS
- end
-
- def teardown
- @path.unlink
- end
-
- def test_factory
- assert_kind_of Formula, Formulary.factory(@name)
- end
-
- def test_factory_with_fully_qualified_name
- assert_kind_of Formula, Formulary.factory("homebrew/core/#{@name}")
- end
-
- def test_formula_unavailable_error
- assert_raises(FormulaUnavailableError) { Formulary.factory("not_existed_formula") }
- end
-
- def test_formula_class_unavailable_error
- name = "giraffe"
- path = CoreTap.new.formula_dir/"#{name}.rb"
- path.write "class Wrong#{Formulary.class_s(name)} < Formula\nend\n"
-
- assert_raises(FormulaClassUnavailableError) { Formulary.factory(name) }
- ensure
- path.unlink
- end
-
- def test_factory_from_path
- assert_kind_of Formula, Formulary.factory(@path)
- end
-
- def test_factory_from_url
- formula = shutup { Formulary.factory("file://#{@path}") }
- assert_kind_of Formula, formula
- ensure
- formula.path.unlink
- end
-
- def test_factory_from_bottle
- formula = Formulary.factory(@bottle)
- assert_kind_of Formula, formula
- assert_equal @bottle.realpath, formula.local_bottle_path
- end
-
- def test_factory_from_alias
- alias_dir = CoreTap.instance.alias_dir
- alias_dir.mkpath
- alias_path = alias_dir/"foo"
- FileUtils.ln_s @path, alias_path
- result = Formulary.factory("foo")
- assert_kind_of Formula, result
- assert_equal alias_path.to_s, result.alias_path
- ensure
- alias_dir.rmtree
- end
-
- def test_factory_from_rack_and_from_keg
- formula = Formulary.factory(@path)
- installer = FormulaInstaller.new(formula)
- shutup { installer.install }
- keg = Keg.new(formula.prefix)
- f = Formulary.from_rack(formula.rack)
- assert_kind_of Formula, f
- assert_kind_of Tab, f.build
- f = Formulary.from_keg(keg)
- assert_kind_of Formula, f
- assert_kind_of Tab, f.build
- ensure
- keg.unlink
- keg.uninstall
- formula.clear_cache
- formula.bottle.clear_cache
- end
-
- def test_load_from_contents
- assert_kind_of Formula, Formulary.from_contents(@name, @path, @path.read)
- end
-
- def test_to_rack
- assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
- (HOMEBREW_CELLAR/@name).mkpath
- assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name)
- assert_raises(TapFormulaUnavailableError) { Formulary.to_rack("a/b/#{@name}") }
- ensure
- FileUtils.rm_rf HOMEBREW_CELLAR/@name
- end
-end
-
-class FormularyTapFactoryTest < Homebrew::TestCase
- def setup
- @name = "foo"
- @tap = Tap.new "homebrew", "foo"
- @path = @tap.path/"#{@name}.rb"
- @code = <<-EOS.undent
- class #{Formulary.class_s(@name)} < Formula
- url "foo-1.0"
- end
- EOS
- @path.write @code
- end
-
- def teardown
- @tap.path.rmtree
- end
-
- def test_factory_tap_formula
- assert_kind_of Formula, Formulary.factory(@name)
- end
-
- def test_factory_tap_alias
- alias_dir = @tap.path/"Aliases"
- alias_dir.mkpath
- FileUtils.ln_s @path, alias_dir/"bar"
- assert_kind_of Formula, Formulary.factory("bar")
- end
-
- def test_tap_formula_unavailable_error
- assert_raises(TapFormulaUnavailableError) { Formulary.factory("#{@tap}/not_existed_formula") }
- end
-
- def test_factory_tap_formula_with_fully_qualified_name
- assert_kind_of Formula, Formulary.factory("#{@tap}/#{@name}")
- end
-
- def test_factory_ambiguity_tap_formulae
- another_tap = Tap.new "homebrew", "bar"
- (another_tap.path/"#{@name}.rb").write @code
- assert_raises(TapFormulaAmbiguityError) { Formulary.factory(@name) }
- ensure
- another_tap.path.rmtree
- end
-end
-
-class FormularyTapPriorityTest < Homebrew::TestCase
- def setup
- @name = "foo"
- @core_path = CoreTap.new.formula_dir/"#{@name}.rb"
- @tap = Tap.new "homebrew", "foo"
- @tap_path = @tap.path/"#{@name}.rb"
- code = <<-EOS.undent
- class #{Formulary.class_s(@name)} < Formula
- url "foo-1.0"
- end
- EOS
- @core_path.write code
- @tap_path.write code
- end
-
- def teardown
- @core_path.unlink
- @tap.path.rmtree
- end
-
- def test_find_with_priority_core_formula
- formula = Formulary.find_with_priority(@name)
- assert_kind_of Formula, formula
- assert_equal @core_path, formula.path
- end
-
- def test_find_with_priority_tap_formula
- @tap.pin
- formula = shutup { Formulary.find_with_priority(@name) }
- assert_kind_of Formula, formula
- assert_equal @tap_path.realpath, formula.path
- ensure
- @tap.pinned_symlink_path.parent.parent.rmtree
- end
-end
diff --git a/Library/Homebrew/test/gpg2_requirement_spec.rb b/Library/Homebrew/test/gpg2_requirement_spec.rb
new file mode 100644
index 000000000..f46b31196
--- /dev/null
+++ b/Library/Homebrew/test/gpg2_requirement_spec.rb
@@ -0,0 +1,23 @@
+require "requirements/gpg2_requirement"
+require "fileutils"
+
+describe GPG2Requirement do
+ let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
+
+ after(:each) do
+ FileUtils.rm_rf dir unless @dir.nil?
+ end
+
+ describe "#satisfied?" do
+ it "returns true if GPG2 is installed" do
+ ENV["PATH"] = dir/"bin"
+ (dir/"bin/gpg").write <<-EOS.undent
+ #!/bin/bash
+ echo 2.0.30
+ EOS
+ FileUtils.chmod 0755, dir/"bin/gpg"
+
+ expect(subject).to be_satisfied
+ end
+ end
+end
diff --git a/Library/Homebrew/test/gpg2_requirement_test.rb b/Library/Homebrew/test/gpg2_requirement_test.rb
deleted file mode 100644
index fa7fc9ea4..000000000
--- a/Library/Homebrew/test/gpg2_requirement_test.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require "testing_env"
-require "requirements/gpg2_requirement"
-require "fileutils"
-
-class GPG2RequirementTests < Homebrew::TestCase
- def setup
- @dir = Pathname.new(mktmpdir)
- (@dir/"bin/gpg").write <<-EOS.undent
- #!/bin/bash
- echo 2.0.30
- EOS
- FileUtils.chmod 0755, @dir/"bin/gpg"
- end
-
- def teardown
- FileUtils.rm_rf @dir
- end
-
- def test_satisfied
- with_environment("PATH" => @dir/"bin") do
- assert_predicate GPG2Requirement.new, :satisfied?
- end
- end
-end
diff --git a/Library/Homebrew/test/gpg_spec.rb b/Library/Homebrew/test/gpg_spec.rb
new file mode 100644
index 000000000..9809dccb5
--- /dev/null
+++ b/Library/Homebrew/test/gpg_spec.rb
@@ -0,0 +1,21 @@
+require "gpg"
+
+describe Gpg do
+ subject { described_class }
+
+ describe "::create_test_key" do
+ it "creates a test key in the home directory" do
+ skip "GPG Unavailable" unless subject.available?
+
+ Dir.mktmpdir do |dir|
+ ENV["HOME"] = dir
+ dir = Pathname.new(dir)
+
+ shutup do
+ subject.create_test_key(dir)
+ end
+ expect(dir/".gnupg/secring.gpg").to exist
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/gpg_test.rb b/Library/Homebrew/test/gpg_test.rb
deleted file mode 100644
index 0374bdab4..000000000
--- a/Library/Homebrew/test/gpg_test.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require "testing_env"
-require "gpg"
-
-class GpgTest < Homebrew::TestCase
- def setup
- skip "GPG Unavailable" unless Gpg.available?
- @dir = Pathname.new(mktmpdir)
- end
-
- def test_create_test_key
- Dir.chdir(@dir) do
- with_environment("HOME" => @dir) do
- shutup { Gpg.create_test_key(@dir) }
- assert_predicate @dir/".gnupg/secring.gpg", :exist?
- end
- end
- ensure
- @dir.rmtree
- end
-end
diff --git a/Library/Homebrew/test/hardware_spec.rb b/Library/Homebrew/test/hardware_spec.rb
new file mode 100644
index 000000000..c5f8daf4e
--- /dev/null
+++ b/Library/Homebrew/test/hardware_spec.rb
@@ -0,0 +1,40 @@
+require "hardware"
+
+module Hardware
+ describe CPU do
+ describe "::type" do
+ it "returns the current CPU's type as a symbol, or :dunno if it cannot be detected" do
+ expect(
+ [
+ :intel,
+ :ppc,
+ :dunno,
+ ],
+ ).to include(described_class.type)
+ end
+ end
+
+ describe "::family" do
+ it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do
+ skip "Needs an Intel CPU." unless described_class.intel?
+
+ expect(
+ [
+ :core,
+ :core2,
+ :penryn,
+ :nehalem,
+ :arrandale,
+ :sandybridge,
+ :ivybridge,
+ :haswell,
+ :broadwell,
+ :skylake,
+ :kabylake,
+ :dunno,
+ ],
+ ).to include(described_class.family)
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/hardware_test.rb b/Library/Homebrew/test/hardware_test.rb
deleted file mode 100644
index 69f881a60..000000000
--- a/Library/Homebrew/test/hardware_test.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require "testing_env"
-require "hardware"
-
-class HardwareTests < Homebrew::TestCase
- def test_hardware_cpu_type
- assert_includes [:intel, :ppc, :dunno], Hardware::CPU.type
- end
-
- if Hardware::CPU.intel?
- def test_hardware_intel_family
- families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :kabylake, :dunno]
- assert_includes families, Hardware::CPU.family
- end
- end
-end
diff --git a/Library/Homebrew/test/help_test.rb b/Library/Homebrew/test/help_test.rb
deleted file mode 100644
index 92dd99721..000000000
--- a/Library/Homebrew/test/help_test.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestHelp < IntegrationCommandTestCase
- def test_help
- assert_match "Example usage:\n",
- cmd_fail # Generic help (empty argument list).
- assert_match "Unknown command: command-that-does-not-exist",
- cmd_fail("help", "command-that-does-not-exist")
- assert_match(/^brew cat /,
- cmd_fail("cat")) # Missing formula argument triggers help.
-
- assert_match "Example usage:\n",
- cmd("help") # Generic help.
- assert_match(/^brew cat /,
- cmd("help", "cat")) # Internal command (documented, Ruby).
- assert_match(/^brew update /,
- cmd("help", "update")) # Internal command (documented, Shell).
- assert_match(/^brew update-test /,
- cmd("help", "update-test")) # Internal developer command (documented, Ruby).
- end
-end
diff --git a/Library/Homebrew/test/home_test.rb b/Library/Homebrew/test/home_test.rb
deleted file mode 100644
index ff06b72c1..000000000
--- a/Library/Homebrew/test/home_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestHome < IntegrationCommandTestCase
- def test_home
- setup_test_formula "testball"
-
- assert_equal HOMEBREW_WWW,
- cmd("home", "HOMEBREW_BROWSER" => "echo")
- assert_equal Formula["testball"].homepage,
- cmd("home", "testball", "HOMEBREW_BROWSER" => "echo")
- end
-end
diff --git a/Library/Homebrew/test/info_test.rb b/Library/Homebrew/test/info_test.rb
deleted file mode 100644
index f71044bf0..000000000
--- a/Library/Homebrew/test/info_test.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require "testing_env"
-require "cmd/info"
-require "formula"
-require "testing_env"
-
-class IntegrationCommandTestInfo < IntegrationCommandTestCase
- def test_info
- setup_test_formula "testball"
-
- assert_match "testball: stable 0.1",
- cmd("info", "testball")
- end
-end
-
-class InfoCommandTests < Homebrew::TestCase
- def test_github_remote_path
- remote = "https://github.com/Homebrew/homebrew-core"
- assert_equal "https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb",
- Homebrew.github_remote_path(remote, "Formula/git.rb")
- assert_equal "https://github.com/Homebrew/homebrew-core/blob/master/Formula/git.rb",
- Homebrew.github_remote_path("#{remote}.git", "Formula/git.rb")
-
- assert_equal "https://github.com/user/repo/blob/master/foo.rb",
- Homebrew.github_remote_path("git@github.com:user/repo", "foo.rb")
-
- assert_equal "https://mywebsite.com/foo/bar.rb",
- Homebrew.github_remote_path("https://mywebsite.com", "foo/bar.rb")
- end
-end
diff --git a/Library/Homebrew/test/inreplace_spec.rb b/Library/Homebrew/test/inreplace_spec.rb
new file mode 100644
index 000000000..5be44f50d
--- /dev/null
+++ b/Library/Homebrew/test/inreplace_spec.rb
@@ -0,0 +1,251 @@
+require "extend/string"
+require "tempfile"
+require "utils/inreplace"
+
+describe StringInreplaceExtension do
+ subject { string.extend(described_class) }
+
+ describe "#change_make_var!" do
+ context "flag" do
+ context "with spaces" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG = abc
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=def
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully appended" do
+ subject.change_make_var! "FLAG", "\\1 def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=abc def
+ FLAG2=abc
+ EOS
+ end
+ end
+
+ context "with tabs" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "CFLAGS", "-O3"
+ expect(subject).to eq <<-EOS.undent
+ CFLAGS=-O3
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+ end
+ end
+
+ context "empty flag between other flags" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG =
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=def
+ FLAG2=abc
+ EOS
+ end
+ end
+
+ context "empty flag" do
+ let(:string) do
+ <<-EOS.undent
+ FLAG =
+ mv file_a file_b
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ FLAG=def
+ mv file_a file_b
+ EOS
+ end
+ end
+
+ context "shell-style variable" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG=abc
+ FLAG2=abc
+ EOS
+ end
+
+ it "is successfully replaced" do
+ subject.change_make_var! "FLAG", "def"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG=def
+ FLAG2=abc
+ EOS
+ end
+ end
+ end
+
+ describe "#remove_make_var!" do
+ context "flag" do
+ context "with spaces" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG = abc
+ FLAG2 = def
+ EOS
+ end
+
+ it "is successfully removed" do
+ subject.remove_make_var! "FLAG"
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ FLAG2 = def
+ EOS
+ end
+ end
+
+ context "with tabs" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+
+ it "is successfully removed" do
+ subject.remove_make_var! "LDFLAGS"
+ expect(subject).to eq <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ EOS
+ end
+ end
+ end
+
+ context "multiple flags" do
+ let(:string) do
+ <<-EOS.undent
+ OTHER=def
+ FLAG = abc
+ FLAG2 = def
+ OTHER2=def
+ EOS
+ end
+
+ specify "are be successfully removed" do
+ subject.remove_make_var! ["FLAG", "FLAG2"]
+ expect(subject).to eq <<-EOS.undent
+ OTHER=def
+ OTHER2=def
+ EOS
+ end
+ end
+ end
+
+ describe "#get_make_var" do
+ context "with spaces" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS = -Wall -O2
+ LDFLAGS = -lcrypto -lssl
+ EOS
+ end
+
+ it "extracts the value for a given variable" do
+ expect(subject.get_make_var("CFLAGS")).to eq("-Wall -O2")
+ end
+ end
+
+ context "with tabs" do
+ let(:string) do
+ <<-EOS.undent
+ CFLAGS\t=\t-Wall -O2
+ LDFLAGS\t=\t-lcrypto -lssl
+ EOS
+ end
+
+ it "extracts the value for a given variable" do
+ expect(subject.get_make_var("CFLAGS")).to eq("-Wall -O2")
+ end
+ end
+ end
+
+ describe "#sub!" do
+ let(:string) { "foo" }
+
+ it "replaces the first occurence" do
+ subject.sub!("o", "e")
+ expect(subject).to eq("feo")
+ end
+ end
+
+ describe "#gsub!" do
+ let(:string) { "foo" }
+
+ it "replaces the all occurences" do
+ subject.gsub!("o", "e") # rubocop:disable Performance/StringReplacement
+ expect(subject).to eq("fee")
+ end
+ end
+end
+
+describe Utils::Inreplace do
+ let(:file) { Tempfile.new("test") }
+
+ before(:each) do
+ file.write <<-EOS.undent
+ a
+ b
+ c
+ EOS
+ end
+
+ after(:each) { file.unlink }
+
+ it "raises error if there is nothing to replace" do
+ expect {
+ described_class.inreplace file.path, "d", "f"
+ }.to raise_error(Utils::InreplaceError)
+ end
+
+ it "raises error if there is nothing to replace" do
+ expect {
+ described_class.inreplace(file.path) do |s|
+ s.gsub!("d", "f") # rubocop:disable Performance/StringReplacement
+ end
+ }.to raise_error(Utils::InreplaceError)
+ end
+
+ it "raises error if there is nothing to replace" do
+ expect {
+ described_class.inreplace(file.path) do |s|
+ s.change_make_var! "VAR", "value"
+ s.remove_make_var! "VAR2"
+ end
+ }.to raise_error(Utils::InreplaceError)
+ end
+end
diff --git a/Library/Homebrew/test/inreplace_test.rb b/Library/Homebrew/test/inreplace_test.rb
deleted file mode 100644
index 0e62f9d3f..000000000
--- a/Library/Homebrew/test/inreplace_test.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-require "testing_env"
-require "extend/string"
-require "utils/inreplace"
-
-class InreplaceTest < Homebrew::TestCase
- def test_change_make_var
- # Replace flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "OTHER=def\nFLAG=def\nFLAG2=abc", s1
- end
-
- def test_change_make_var_empty
- # Replace empty flag
- s1 = "OTHER=def\nFLAG = \nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "OTHER=def\nFLAG=def\nFLAG2=abc", s1
- end
-
- def test_change_make_var_empty_2
- # Replace empty flag
- s1 = "FLAG = \nmv file_a file_b"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "FLAG=def\nmv file_a file_b", s1
- end
-
- def test_change_make_var_append
- # Append to flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "\\1 def"
- assert_equal "OTHER=def\nFLAG=abc def\nFLAG2=abc", s1
- end
-
- def test_change_make_var_shell_style
- # Shell variables have no spaces around =
- s1 = "OTHER=def\nFLAG=abc\nFLAG2=abc"
- s1.extend(StringInreplaceExtension)
- s1.change_make_var! "FLAG", "def"
- assert_equal "OTHER=def\nFLAG=def\nFLAG2=abc", s1
- end
-
- def test_remove_make_var
- # Replace flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2 = def"
- s1.extend(StringInreplaceExtension)
- s1.remove_make_var! "FLAG"
- assert_equal "OTHER=def\nFLAG2 = def", s1
- end
-
- def test_remove_make_vars
- # Replace flag
- s1 = "OTHER=def\nFLAG = abc\nFLAG2 = def\nOTHER2=def"
- s1.extend(StringInreplaceExtension)
- s1.remove_make_var! ["FLAG", "FLAG2"]
- assert_equal "OTHER=def\nOTHER2=def", s1
- end
-
- def test_get_make_var
- s = "CFLAGS = -Wall -O2\nLDFLAGS = -lcrypto -lssl"
- s.extend(StringInreplaceExtension)
- assert_equal "-Wall -O2", s.get_make_var("CFLAGS")
- end
-
- def test_change_make_var_with_tabs
- s = "CFLAGS\t=\t-Wall -O2\nLDFLAGS\t=\t-lcrypto -lssl"
- s.extend(StringInreplaceExtension)
-
- assert_equal "-Wall -O2", s.get_make_var("CFLAGS")
-
- s.change_make_var! "CFLAGS", "-O3"
- assert_equal "CFLAGS=-O3\nLDFLAGS\t=\t-lcrypto -lssl", s
-
- s.remove_make_var! "LDFLAGS"
- assert_equal "CFLAGS=-O3\n", s
- end
-
- def test_sub_gsub
- s = "foo"
- s.extend(StringInreplaceExtension)
-
- s.sub!("f", "b")
- assert_equal "boo", s
-
- # Under current context, we are testing `String#gsub!`, so let's disable rubocop temporarily.
- s.gsub!("o", "e") # rubocop:disable Performance/StringReplacement
- assert_equal "bee", s
- end
-
- def test_inreplace_errors
- require "tempfile"
- extend(Utils::Inreplace)
-
- file = Tempfile.new("test")
-
- file.write "a\nb\nc\n"
-
- assert_raises(Utils::InreplaceError) do
- inreplace file.path, "d", "f"
- end
-
- assert_raises(Utils::InreplaceError) do
- # Under current context, we are testing `String#gsub!`, so let's disable rubocop temporarily.
- inreplace(file.path) { |s| s.gsub!("d", "f") } # rubocop:disable Performance/StringReplacement
- end
-
- assert_raises(Utils::InreplaceError) do
- inreplace(file.path) do |s|
- s.change_make_var! "VAR", "value"
- s.remove_make_var! "VAR2"
- end
- end
- ensure
- file.unlink
- end
-end
diff --git a/Library/Homebrew/test/install_test.rb b/Library/Homebrew/test/install_test.rb
deleted file mode 100644
index e047c0030..000000000
--- a/Library/Homebrew/test/install_test.rb
+++ /dev/null
@@ -1,147 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestInstall < IntegrationCommandTestCase
- def test_install
- setup_test_formula "testball1"
- assert_match "Specify `--HEAD`", cmd_fail("install", "testball1", "--head")
- assert_match "No head is defined", cmd_fail("install", "testball1", "--HEAD")
- assert_match "No devel block", cmd_fail("install", "testball1", "--devel")
- assert_match "#{HOMEBREW_CELLAR}/testball1/0.1", cmd("install", "testball1")
- assert_match "testball1-0.1 already installed", cmd("install", "testball1")
- assert_match "MacRuby is not packaged", cmd_fail("install", "macruby")
- assert_match "No available formula", cmd_fail("install", "formula")
- assert_match "This similarly named formula was found",
- cmd_fail("install", "testball")
-
- setup_test_formula "testball2"
- assert_match "These similarly named formulae were found",
- cmd_fail("install", "testball")
-
- install_and_rename_coretap_formula "testball1", "testball2"
- assert_match "testball1 already installed, it's just not migrated",
- cmd("install", "testball2")
- end
-
- def test_install_failures
- path = setup_test_formula "testball1", "version \"1.0\""
- devel_content = <<-EOS.undent
- version "3.0"
- devel do
- url "#{Formulary.factory("testball1").stable.url}"
- sha256 "#{TESTBALL_SHA256}"
- version "2.0"
- end
- EOS
-
- assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1")
-
- FileUtils.rm path
- setup_test_formula "testball1", devel_content
-
- assert_match "first `brew unlink testball1`", cmd_fail("install", "testball1")
- assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("unlink", "testball1")
- assert_match "#{HOMEBREW_CELLAR}/testball1/2.0", cmd("install", "testball1", "--devel")
- assert_match "#{HOMEBREW_CELLAR}/testball1/2.0", cmd("unlink", "testball1")
- assert_match "#{HOMEBREW_CELLAR}/testball1/3.0", cmd("install", "testball1")
-
- cmd("switch", "testball1", "2.0")
- assert_match "already installed, however linked version is",
- cmd("install", "testball1")
- assert_match "#{HOMEBREW_CELLAR}/testball1/2.0", cmd("unlink", "testball1")
- assert_match "just not linked", cmd("install", "testball1")
- end
-
- def test_install_keg_only_outdated
- path_keg_only = setup_test_formula "testball1", <<-EOS.undent
- version "1.0"
- keg_only "test reason"
- EOS
-
- assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1")
-
- FileUtils.rm path_keg_only
- setup_test_formula "testball1", <<-EOS.undent
- version "2.0"
- keg_only "test reason"
- EOS
-
- assert_match "keg-only and another version is linked to opt",
- cmd("install", "testball1")
-
- assert_match "#{HOMEBREW_CELLAR}/testball1/2.0",
- cmd("install", "testball1", "--force")
- end
-
- def test_install_head_installed
- initial_env = ENV.to_hash
- %w[AUTHOR COMMITTER].each do |role|
- ENV["GIT_#{role}_NAME"] = "brew tests"
- ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
- ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
- end
-
- repo_path = HOMEBREW_CACHE.join("repo")
- repo_path.join("bin").mkpath
-
- repo_path.cd do
- shutup do
- system "git", "init"
- system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
- FileUtils.touch "bin/something.bin"
- FileUtils.touch "README"
- system "git", "add", "--all"
- system "git", "commit", "-m", "Initial repo commit"
- end
- end
-
- setup_test_formula "testball1", <<-EOS.undent
- version "1.0"
- head "file://#{repo_path}", :using => :git
- def install
- prefix.install Dir["*"]
- end
- EOS
-
- # Ignore dependencies, because we'll try to resolve requirements in build.rb
- # and there will be the git requirement, but we cannot instantiate git
- # formula since we only have testball1 formula.
- assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-2ccdf4f", cmd("install", "testball1", "--HEAD", "--ignore-dependencies")
- assert_match "testball1-HEAD-2ccdf4f already installed",
- cmd("install", "testball1", "--HEAD", "--ignore-dependencies")
- assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-2ccdf4f", cmd("unlink", "testball1")
- assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1")
-
- ensure
- ENV.replace(initial_env)
- repo_path.rmtree
- end
-
- def test_install_with_invalid_option
- setup_test_formula "testball1"
- assert_match "testball1: this formula has no --with-fo option so it will be ignored!",
- cmd("install", "testball1", "--with-fo")
- end
-
- def test_install_with_nonfatal_requirement
- setup_test_formula "testball1", <<-EOS.undent
- class NonFatalRequirement < Requirement
- satisfy { false }
- end
- depends_on NonFatalRequirement
- EOS
- message = "NonFatalRequirement unsatisfied!"
- assert_equal 1, cmd("install", "testball1").scan(message).size
- end
-
- def test_install_with_fatal_requirement
- setup_test_formula "testball1", <<-EOS.undent
- class FatalRequirement < Requirement
- fatal true
- satisfy { false }
- end
- depends_on FatalRequirement
- EOS
- message = "FatalRequirement unsatisfied!"
- assert_equal 1, cmd_fail("install", "testball1").scan(message).size
- end
-end
diff --git a/Library/Homebrew/test/irb_test.rb b/Library/Homebrew/test/irb_test.rb
deleted file mode 100644
index 832ca39a5..000000000
--- a/Library/Homebrew/test/irb_test.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestIrb < IntegrationCommandTestCase
- def test_irb
- assert_match "'v8'.f # => instance of the v8 formula",
- cmd("irb", "--examples")
-
- setup_test_formula "testball"
-
- irb_test = HOMEBREW_TEMP/"irb-test.rb"
- irb_test.write <<-EOS.undent
- "testball".f
- :testball.f
- exit
- EOS
-
- assert_match "Interactive Homebrew Shell", cmd("irb", irb_test)
- end
-end
diff --git a/Library/Homebrew/test/java_requirement_spec.rb b/Library/Homebrew/test/java_requirement_spec.rb
new file mode 100644
index 000000000..5adf64c7c
--- /dev/null
+++ b/Library/Homebrew/test/java_requirement_spec.rb
@@ -0,0 +1,107 @@
+require "requirements/java_requirement"
+
+describe JavaRequirement do
+ subject { described_class.new([]) }
+
+ before(:each) do
+ ENV["JAVA_HOME"] = nil
+ end
+
+ describe "#message" do
+ its(:message) { is_expected.to match(/Java is required to install this formula./) }
+ end
+
+ describe "#inspect" do
+ subject { described_class.new(%w[1.7+]) }
+ its(:inspect) { is_expected.to eq('#<JavaRequirement: "java" [] version="1.7+">') }
+ end
+
+ describe "#display_s" do
+ context "without specific version" do
+ its(:display_s) { is_expected.to eq("java") }
+ end
+
+ context "with version 1.8" do
+ subject { described_class.new(%w[1.8]) }
+ its(:display_s) { is_expected.to eq("java = 1.8") }
+ end
+
+ context "with version 1.8+" do
+ subject { described_class.new(%w[1.8+]) }
+ its(:display_s) { is_expected.to eq("java >= 1.8") }
+ end
+ end
+
+ describe "#satisfied?" do
+ subject { described_class.new(%w[1.8]) }
+
+ it "returns false if no `java` executable can be found" do
+ allow(File).to receive(:executable?).and_return(false)
+ expect(subject).not_to be_satisfied
+ end
+
+ it "returns true if #preferred_java returns a path" do
+ allow(subject).to receive(:preferred_java).and_return(Pathname.new("/usr/bin/java"))
+ expect(subject).to be_satisfied
+ end
+
+ context "when #possible_javas contains paths" do
+ let(:path) { Pathname.new(Dir.mktmpdir) }
+ let(:java) { path/"java" }
+
+ def setup_java_with_version(version)
+ IO.write java, <<-EOS.undent
+ #!/bin/sh
+ echo 'java version "#{version}"'
+ EOS
+ FileUtils.chmod "+x", java
+ end
+
+ before(:each) do
+ allow(subject).to receive(:possible_javas).and_return([java])
+ end
+
+ after(:each) do
+ path.rmtree
+ end
+
+ context "and 1.7 is required" do
+ subject { described_class.new(%w[1.7]) }
+
+ it "returns false if all are lower" do
+ setup_java_with_version "1.6.0_5"
+ expect(subject).not_to be_satisfied
+ end
+
+ it "returns true if one is equal" do
+ setup_java_with_version "1.7.0_5"
+ expect(subject).to be_satisfied
+ end
+
+ it "returns false if all are higher" do
+ setup_java_with_version "1.8.0_5"
+ expect(subject).not_to be_satisfied
+ end
+ end
+
+ context "and 1.7+ is required" do
+ subject { described_class.new(%w[1.7+]) }
+
+ it "returns false if all are lower" do
+ setup_java_with_version "1.6.0_5"
+ expect(subject).not_to be_satisfied
+ end
+
+ it "returns true if one is equal" do
+ setup_java_with_version "1.7.0_5"
+ expect(subject).to be_satisfied
+ end
+
+ it "returns true if one is higher" do
+ setup_java_with_version "1.8.0_5"
+ expect(subject).to be_satisfied
+ end
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/json_test.rb b/Library/Homebrew/test/json_test.rb
deleted file mode 100644
index 7c4c3671d..000000000
--- a/Library/Homebrew/test/json_test.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require "testing_env"
-require "json"
-
-class JsonSmokeTest < Homebrew::TestCase
- def test_encode
- hash = { "foo" => ["bar", "baz"] }
- json = '{"foo":["bar","baz"]}'
- assert_equal json, JSON.generate(hash)
- end
-
- def test_decode
- hash = { "foo" => ["bar", "baz"], "qux" => 1 }
- json = '{"foo":["bar","baz"],"qux":1}'
- assert_equal hash, JSON.parse(json)
- end
-
- def test_decode_failure
- assert_raises(JSON::ParserError) { JSON.parse("nope") }
- end
-end
diff --git a/Library/Homebrew/test/keg_spec.rb b/Library/Homebrew/test/keg_spec.rb
new file mode 100644
index 000000000..f40002dd2
--- /dev/null
+++ b/Library/Homebrew/test/keg_spec.rb
@@ -0,0 +1,486 @@
+require "keg"
+require "stringio"
+
+describe Keg do
+ include FileUtils
+
+ def setup_test_keg(name, version)
+ path = HOMEBREW_CELLAR/name/version
+ (path/"bin").mkpath
+
+ %w[hiworld helloworld goodbye_cruel_world].each do |file|
+ touch path/"bin"/file
+ end
+
+ keg = described_class.new(path)
+ kegs << keg
+ keg
+ end
+
+ around(:each) do |example|
+ begin
+ @old_stdout = $stdout
+ $stdout = StringIO.new
+
+ example.run
+ ensure
+ $stdout = @old_stdout
+ end
+ end
+
+ let(:dst) { HOMEBREW_PREFIX/"bin"/"helloworld" }
+ let(:nonexistent) { Pathname.new("/some/nonexistent/path") }
+ let(:mode) { OpenStruct.new }
+ let!(:keg) { setup_test_keg("foo", "1.0") }
+ let(:kegs) { [] }
+
+ before(:each) do
+ (HOMEBREW_PREFIX/"bin").mkpath
+ (HOMEBREW_PREFIX/"lib").mkpath
+ end
+
+ after(:each) do
+ kegs.each(&:unlink)
+ rmtree HOMEBREW_PREFIX/"lib"
+ end
+
+ specify "::all" do
+ Formula.clear_racks_cache
+ expect(described_class.all).to eq([keg])
+ end
+
+ specify "#empty_installation?" do
+ %w[.DS_Store INSTALL_RECEIPT.json LICENSE.txt].each do |file|
+ touch keg/file
+ end
+
+ expect(keg).to exist
+ expect(keg).to be_a_directory
+ expect(keg).not_to be_an_empty_installation
+
+ (keg/"bin").rmtree
+ expect(keg).to be_an_empty_installation
+ end
+
+ specify "#oldname_opt_record" do
+ expect(keg.oldname_opt_record).to be nil
+ oldname_opt_record = HOMEBREW_PREFIX/"opt/oldfoo"
+ oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/1.0")
+ expect(keg.oldname_opt_record).to eq(oldname_opt_record)
+ end
+
+ specify "#remove_oldname_opt_record" do
+ oldname_opt_record = HOMEBREW_PREFIX/"opt/oldfoo"
+ oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/2.0")
+ keg.remove_oldname_opt_record
+ expect(oldname_opt_record).to be_a_symlink
+ oldname_opt_record.unlink
+ oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/1.0")
+ keg.remove_oldname_opt_record
+ expect(oldname_opt_record).not_to be_a_symlink
+ end
+
+ describe "#link" do
+ it "links a Keg" do
+ expect(keg.link).to eq(3)
+ (HOMEBREW_PREFIX/"bin").children.each do |c|
+ expect(c.readlink).to be_relative
+ end
+ end
+
+ context "with dry run set to true" do
+ it "only prints what would be done" do
+ mode.dry_run = true
+
+ expect(keg.link(mode)).to eq(0)
+ expect(keg).not_to be_linked
+
+ ["hiworld", "helloworld", "goodbye_cruel_world"].each do |file|
+ expect($stdout.string).to match("#{HOMEBREW_PREFIX}/bin/#{file}")
+ end
+ expect($stdout.string.lines.count).to eq(3)
+ end
+ end
+
+ it "fails when already linked" do
+ keg.link
+
+ expect { keg.link }.to raise_error(Keg::AlreadyLinkedError)
+ end
+
+ it "fails when files exist" do
+ touch dst
+
+ expect { keg.link }.to raise_error(Keg::ConflictError)
+ end
+
+ it "ignores broken symlinks at target" do
+ src = keg/"bin"/"helloworld"
+ dst.make_symlink(nonexistent)
+ keg.link
+ expect(dst.readlink).to eq(src.relative_path_from(dst.dirname))
+ end
+
+ context "with overwrite set to true" do
+ it "overwrite existing files" do
+ touch dst
+ mode.overwrite = true
+ expect(keg.link(mode)).to eq(3)
+ expect(keg).to be_linked
+ end
+
+ it "overwrites broken symlinks" do
+ dst.make_symlink "nowhere"
+ mode.overwrite = true
+ expect(keg.link(mode)).to eq(3)
+ expect(keg).to be_linked
+ end
+
+ it "still supports dryrun" do
+ touch dst
+ mode.overwrite = true
+ mode.dry_run = true
+
+ expect(keg.link(mode)).to eq(0)
+ expect(keg).not_to be_linked
+
+ expect($stdout.string).to eq("#{dst}\n")
+ end
+ end
+
+ it "also creates an opt link" do
+ expect(keg).not_to be_optlinked
+ keg.link
+ expect(keg).to be_optlinked
+ end
+
+ specify "pkgconfig directory is created" do
+ link = HOMEBREW_PREFIX/"lib"/"pkgconfig"
+ (keg/"lib"/"pkgconfig").mkpath
+ keg.link
+ expect(link.lstat).to be_a_directory
+ end
+
+ specify "cmake directory is created" do
+ link = HOMEBREW_PREFIX/"lib"/"cmake"
+ (keg/"lib"/"cmake").mkpath
+ keg.link
+ expect(link.lstat).to be_a_directory
+ end
+
+ specify "symlinks are linked directly" do
+ link = HOMEBREW_PREFIX/"lib"/"pkgconfig"
+
+ (keg/"lib"/"example").mkpath
+ (keg/"lib"/"pkgconfig").make_symlink "example"
+ keg.link
+
+ expect(link.resolved_path).to be_a_symlink
+ expect(link.lstat).to be_a_symlink
+ end
+ end
+
+ describe "#unlink" do
+ it "unlinks a Keg" do
+ keg.link
+ expect(dst).to be_a_symlink
+ expect(keg.unlink).to eq(3)
+ expect(dst).not_to be_a_symlink
+ end
+
+ it "prunes empty top-level directories" do
+ mkpath HOMEBREW_PREFIX/"lib/foo/bar"
+ mkpath keg/"lib/foo/bar"
+ touch keg/"lib/foo/bar/file1"
+
+ keg.unlink
+
+ expect(HOMEBREW_PREFIX/"lib/foo").not_to be_a_directory
+ end
+
+ it "ignores .DS_Store when pruning empty directories" do
+ mkpath HOMEBREW_PREFIX/"lib/foo/bar"
+ touch HOMEBREW_PREFIX/"lib/foo/.DS_Store"
+ mkpath keg/"lib/foo/bar"
+ touch keg/"lib/foo/bar/file1"
+
+ keg.unlink
+
+ expect(HOMEBREW_PREFIX/"lib/foo").not_to be_a_directory
+ expect(HOMEBREW_PREFIX/"lib/foo/.DS_Store").not_to exist
+ end
+
+ it "doesn't remove opt link" do
+ keg.link
+ keg.unlink
+ expect(keg).to be_optlinked
+ end
+
+ it "preverves broken symlinks pointing outside the Keg" do
+ keg.link
+ dst.delete
+ dst.make_symlink(nonexistent)
+ keg.unlink
+ expect(dst).to be_a_symlink
+ end
+
+ it "preverves broken symlinks pointing into the Keg" do
+ keg.link
+ dst.resolved_path.delete
+ keg.unlink
+ expect(dst).to be_a_symlink
+ end
+
+ it "preverves symlinks pointing outside the Keg" do
+ keg.link
+ dst.delete
+ dst.make_symlink(Pathname.new("/bin/sh"))
+ keg.unlink
+ expect(dst).to be_a_symlink
+ end
+
+ it "preserves real files" do
+ keg.link
+ dst.delete
+ touch dst
+ keg.unlink
+ expect(dst).to be_a_file
+ end
+
+ it "ignores nonexistent file" do
+ keg.link
+ dst.delete
+ expect(keg.unlink).to eq(2)
+ end
+
+ it "doesn't remove links to symlinks" do
+ a = HOMEBREW_CELLAR/"a"/"1.0"
+ b = HOMEBREW_CELLAR/"b"/"1.0"
+
+ (a/"lib"/"example").mkpath
+ (a/"lib"/"example2").make_symlink "example"
+ (b/"lib"/"example2").mkpath
+
+ a = described_class.new(a)
+ b = described_class.new(b)
+ a.link
+
+ lib = HOMEBREW_PREFIX/"lib"
+ expect(lib.children.length).to eq(2)
+ expect { b.link }.to raise_error(Keg::ConflictError)
+ expect(lib.children.length).to eq(2)
+ end
+
+ it "removes broken symlinks that conflict with directories" do
+ a = HOMEBREW_CELLAR/"a"/"1.0"
+ (a/"lib"/"foo").mkpath
+
+ keg = described_class.new(a)
+
+ link = HOMEBREW_PREFIX/"lib"/"foo"
+ link.parent.mkpath
+ link.make_symlink(nonexistent)
+
+ keg.link
+ end
+ end
+
+ describe "#optlink" do
+ it "creates an opt link" do
+ oldname_opt_record = HOMEBREW_PREFIX/"opt/oldfoo"
+ oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/1.0")
+ keg_record = HOMEBREW_CELLAR/"foo"/"2.0"
+ (keg_record/"bin").mkpath
+ keg = described_class.new(keg_record)
+ keg.optlink
+ expect(keg_record).to eq(oldname_opt_record.resolved_path)
+ keg.uninstall
+ expect(oldname_opt_record).not_to be_a_symlink
+ end
+
+ it "doesn't fail if already opt-linked" do
+ keg.opt_record.make_relative_symlink Pathname.new(keg)
+ keg.optlink
+ expect(keg).to be_optlinked
+ end
+
+ it "replaces an existing directory" do
+ keg.opt_record.mkpath
+ keg.optlink
+ expect(keg).to be_optlinked
+ end
+
+ it "replaces an existing file" do
+ keg.opt_record.parent.mkpath
+ keg.opt_record.write("foo")
+ keg.optlink
+ expect(keg).to be_optlinked
+ end
+ end
+
+ specify "#link and #unlink" do
+ expect(keg).not_to be_linked
+ keg.link
+ expect(keg).to be_linked
+ keg.unlink
+ expect(keg).not_to be_linked
+ end
+
+ describe "::find_some_installed_dependents" do
+ def stub_formula_name(name)
+ f = formula(name) { url "foo-1.0" }
+ stub_formula_loader f
+ stub_formula_loader f, "homebrew/core/#{f}"
+ f
+ end
+
+ def setup_test_keg(name, version)
+ f = stub_formula_name(name)
+ keg = super
+ Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
+ keg
+ end
+
+ before(:each) do
+ keg.link
+ end
+
+ def alter_tab(keg = dependent)
+ tab = Tab.for_keg(keg)
+ yield tab
+ tab.write
+ end
+
+ # 1.1.6 is the earliest version of Homebrew that generates correct runtime
+ # dependency lists in Tabs.
+ def dependencies(deps, homebrew_version: "1.1.6")
+ alter_tab do |tab|
+ tab.homebrew_version = homebrew_version
+ tab.tabfile = dependent/Tab::FILENAME
+ tab.runtime_dependencies = deps
+ end
+ end
+
+ def unreliable_dependencies(deps)
+ # 1.1.5 is (hopefully!) the last version of Homebrew that generates
+ # incorrect runtime dependency lists in Tabs.
+ dependencies(deps, homebrew_version: "1.1.5")
+ end
+
+ let(:dependent) { setup_test_keg("bar", "1.0") }
+
+ # Test with a keg whose formula isn't known.
+ # This can happen if e.g. a formula is installed
+ # from a file path or URL.
+ specify "unknown Formula" do
+ allow(Formulary).to receive(:loader_for).and_call_original
+ alter_tab(keg) do |t|
+ t.source["tap"] = "some/tap"
+ t.source["path"] = nil
+ end
+
+ dependencies [{ "full_name" => "some/tap/foo", "version" => "1.0" }]
+ expect(keg.installed_dependents).to eq([dependent])
+ expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar 1.0"]])
+
+ dependencies nil
+ # It doesn't make sense for a keg with no formula to have any dependents,
+ # so that can't really be tested.
+ expect(described_class.find_some_installed_dependents([keg])).to be nil
+ end
+
+ specify "a dependency with no Tap in Tab" do
+ tap_dep = setup_test_keg("baz", "1.0")
+
+ alter_tab(keg) { |t| t.source["tap"] = nil }
+
+ dependencies nil
+ Formula["bar"].class.depends_on "foo"
+ Formula["bar"].class.depends_on "baz"
+
+ result = described_class.find_some_installed_dependents([keg, tap_dep])
+ expect(result).to eq([[keg, tap_dep], ["bar"]])
+ end
+
+ specify "no dependencies anywhere" do
+ dependencies nil
+ expect(keg.installed_dependents).to be_empty
+ expect(described_class.find_some_installed_dependents([keg])).to be nil
+ end
+
+ specify "missing Formula dependency" do
+ dependencies nil
+ Formula["bar"].class.depends_on "foo"
+ expect(keg.installed_dependents).to be_empty
+ expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar"]])
+ end
+
+ specify "uninstalling dependent and dependency" do
+ dependencies nil
+ Formula["bar"].class.depends_on "foo"
+ expect(keg.installed_dependents).to be_empty
+ expect(described_class.find_some_installed_dependents([keg, dependent])).to be nil
+ end
+
+ specify "renamed dependency" do
+ dependencies nil
+
+ stub_formula_loader Formula["foo"], "homebrew/core/foo-old"
+ renamed_path = HOMEBREW_CELLAR/"foo-old"
+ (HOMEBREW_CELLAR/"foo").rename(renamed_path)
+ renamed_keg = described_class.new(renamed_path/"1.0")
+
+ Formula["bar"].class.depends_on "foo"
+
+ result = described_class.find_some_installed_dependents([renamed_keg])
+ expect(result).to eq([[renamed_keg], ["bar"]])
+ end
+
+ specify "empty dependencies in Tab" do
+ dependencies []
+ expect(keg.installed_dependents).to be_empty
+ expect(described_class.find_some_installed_dependents([keg])).to be nil
+ end
+
+ specify "same name but different version in Tab" do
+ dependencies [{ "full_name" => "foo", "version" => "1.1" }]
+ expect(keg.installed_dependents).to eq([dependent])
+ expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar 1.0"]])
+ end
+
+ specify "different name and same version in Tab" do
+ stub_formula_name("baz")
+ dependencies [{ "full_name" => "baz", "version" => keg.version.to_s }]
+ expect(keg.installed_dependents).to be_empty
+ expect(described_class.find_some_installed_dependents([keg])).to be nil
+ end
+
+ specify "same name and version in Tab" do
+ dependencies [{ "full_name" => "foo", "version" => "1.0" }]
+ expect(keg.installed_dependents).to eq([dependent])
+ expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar 1.0"]])
+ end
+
+ specify "fallback for old versions" do
+ unreliable_dependencies [{ "full_name" => "baz", "version" => "1.0" }]
+ Formula["bar"].class.depends_on "foo"
+ expect(keg.installed_dependents).to be_empty
+ expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar"]])
+ end
+
+ specify "non-opt-linked" do
+ keg.remove_opt_record
+ dependencies [{ "full_name" => "foo", "version" => "1.0" }]
+ expect(keg.installed_dependents).to be_empty
+ expect(described_class.find_some_installed_dependents([keg])).to be nil
+ end
+
+ specify "keg-only" do
+ keg.unlink
+ Formula["foo"].class.keg_only "a good reason"
+ dependencies [{ "full_name" => "foo", "version" => "1.1" }] # different version
+ expect(keg.installed_dependents).to eq([dependent])
+ expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar 1.0"]])
+ end
+ end
+end
diff --git a/Library/Homebrew/test/keg_test.rb b/Library/Homebrew/test/keg_test.rb
deleted file mode 100644
index 40b47b5e9..000000000
--- a/Library/Homebrew/test/keg_test.rb
+++ /dev/null
@@ -1,484 +0,0 @@
-require "testing_env"
-require "keg"
-require "stringio"
-
-class LinkTestCase < Homebrew::TestCase
- include FileUtils
-
- def setup_test_keg(name, version)
- path = HOMEBREW_CELLAR.join(name, version)
- path.join("bin").mkpath
-
- %w[hiworld helloworld goodbye_cruel_world].each do |file|
- touch path.join("bin", file)
- end
-
- keg = Keg.new(path)
- @kegs ||= []
- @kegs << keg
- keg
- end
-
- def setup
- @keg = setup_test_keg("foo", "1.0")
- @dst = HOMEBREW_PREFIX.join("bin", "helloworld")
- @nonexistent = Pathname.new("/some/nonexistent/path")
-
- @mode = OpenStruct.new
-
- @old_stdout = $stdout
- $stdout = StringIO.new
-
- mkpath HOMEBREW_PREFIX/"bin"
- mkpath HOMEBREW_PREFIX/"lib"
- end
-
- def teardown
- @kegs.each do |keg|
- keg.unlink
- keg.uninstall
- end
-
- $stdout = @old_stdout
-
- rmtree HOMEBREW_PREFIX/"bin"
- rmtree HOMEBREW_PREFIX/"lib"
- end
-end
-
-class LinkTests < LinkTestCase
- def test_all
- Formula.clear_racks_cache
- assert_equal [@keg], Keg.all
- end
-
- def test_empty_installation
- %w[.DS_Store INSTALL_RECEIPT.json LICENSE.txt].each do |file|
- touch @keg/file
- end
- assert_predicate @keg, :exist?
- assert_predicate @keg, :directory?
- refute_predicate @keg, :empty_installation?
-
- (@keg/"bin").rmtree
- assert_predicate @keg, :empty_installation?
- end
-
- def test_linking_keg
- assert_equal 3, @keg.link
- (HOMEBREW_PREFIX/"bin").children.each { |c| assert_predicate c.readlink, :relative? }
- end
-
- def test_unlinking_keg
- @keg.link
- assert_predicate @dst, :symlink?
- assert_equal 3, @keg.unlink
- refute_predicate @dst, :symlink?
- end
-
- def test_oldname_opt_record
- assert_nil @keg.oldname_opt_record
- oldname_opt_record = HOMEBREW_PREFIX/"opt/oldfoo"
- oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/1.0")
- assert_equal oldname_opt_record, @keg.oldname_opt_record
- end
-
- def test_optlink_relink
- oldname_opt_record = HOMEBREW_PREFIX/"opt/oldfoo"
- oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/1.0")
- keg_record = HOMEBREW_CELLAR.join("foo", "2.0")
- keg_record.join("bin").mkpath
- keg = Keg.new(keg_record)
- keg.optlink
- assert_equal keg_record, oldname_opt_record.resolved_path
- keg.uninstall
- refute_predicate oldname_opt_record, :symlink?
- end
-
- def test_remove_oldname_opt_record
- oldname_opt_record = HOMEBREW_PREFIX/"opt/oldfoo"
- oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/2.0")
- @keg.remove_oldname_opt_record
- assert_predicate oldname_opt_record, :symlink?
- oldname_opt_record.unlink
- oldname_opt_record.make_relative_symlink(HOMEBREW_CELLAR/"foo/1.0")
- @keg.remove_oldname_opt_record
- refute_predicate oldname_opt_record, :symlink?
- end
-
- def test_link_dry_run
- @mode.dry_run = true
-
- assert_equal 0, @keg.link(@mode)
- refute_predicate @keg, :linked?
-
- ["hiworld", "helloworld", "goodbye_cruel_world"].each do |file|
- assert_match "#{HOMEBREW_PREFIX}/bin/#{file}", $stdout.string
- end
- assert_equal 3, $stdout.string.lines.count
- end
-
- def test_linking_fails_when_already_linked
- @keg.link
- assert_raises(Keg::AlreadyLinkedError) { @keg.link }
- end
-
- def test_linking_fails_when_files_exist
- touch @dst
- assert_raises(Keg::ConflictError) { @keg.link }
- end
-
- def test_link_ignores_broken_symlinks_at_target
- src = @keg.join("bin", "helloworld")
- @dst.make_symlink(@nonexistent)
- @keg.link
- assert_equal src.relative_path_from(@dst.dirname), @dst.readlink
- end
-
- def test_link_overwrite
- touch @dst
- @mode.overwrite = true
- assert_equal 3, @keg.link(@mode)
- assert_predicate @keg, :linked?
- end
-
- def test_link_overwrite_broken_symlinks
- @dst.make_symlink "nowhere"
- @mode.overwrite = true
- assert_equal 3, @keg.link(@mode)
- assert_predicate @keg, :linked?
- end
-
- def test_link_overwrite_dryrun
- touch @dst
- @mode.overwrite = true
- @mode.dry_run = true
-
- assert_equal 0, @keg.link(@mode)
- refute_predicate @keg, :linked?
-
- assert_equal "#{@dst}\n", $stdout.string
- end
-
- def test_unlink_prunes_empty_toplevel_directories
- mkpath HOMEBREW_PREFIX/"lib/foo/bar"
- mkpath @keg/"lib/foo/bar"
- touch @keg/"lib/foo/bar/file1"
-
- @keg.unlink
-
- refute_predicate HOMEBREW_PREFIX/"lib/foo", :directory?
- end
-
- def test_unlink_ignores_ds_store_when_pruning_empty_dirs
- mkpath HOMEBREW_PREFIX/"lib/foo/bar"
- touch HOMEBREW_PREFIX/"lib/foo/.DS_Store"
- mkpath @keg/"lib/foo/bar"
- touch @keg/"lib/foo/bar/file1"
-
- @keg.unlink
-
- refute_predicate HOMEBREW_PREFIX/"lib/foo", :directory?
- refute_predicate HOMEBREW_PREFIX/"lib/foo/.DS_Store", :exist?
- end
-
- def test_linking_creates_opt_link
- refute_predicate @keg, :optlinked?
- @keg.link
- assert_predicate @keg, :optlinked?
- end
-
- def test_unlinking_does_not_remove_opt_link
- @keg.link
- @keg.unlink
- assert_predicate @keg, :optlinked?
- end
-
- def test_existing_opt_link
- @keg.opt_record.make_relative_symlink Pathname.new(@keg)
- @keg.optlink
- assert_predicate @keg, :optlinked?
- end
-
- def test_existing_opt_link_directory
- @keg.opt_record.mkpath
- @keg.optlink
- assert_predicate @keg, :optlinked?
- end
-
- def test_existing_opt_link_file
- @keg.opt_record.parent.mkpath
- @keg.opt_record.write("foo")
- @keg.optlink
- assert_predicate @keg, :optlinked?
- end
-
- def test_linked_keg
- refute_predicate @keg, :linked?
- @keg.link
- assert_predicate @keg, :linked?
- @keg.unlink
- refute_predicate @keg, :linked?
- end
-
- def test_unlink_preserves_broken_symlink_pointing_outside_the_keg
- @keg.link
- @dst.delete
- @dst.make_symlink(@nonexistent)
- @keg.unlink
- assert_predicate @dst, :symlink?
- end
-
- def test_unlink_preserves_broken_symlink_pointing_into_the_keg
- @keg.link
- @dst.resolved_path.delete
- @keg.unlink
- assert_predicate @dst, :symlink?
- end
-
- def test_unlink_preserves_symlink_pointing_outside_of_keg
- @keg.link
- @dst.delete
- @dst.make_symlink(Pathname.new("/bin/sh"))
- @keg.unlink
- assert_predicate @dst, :symlink?
- end
-
- def test_unlink_preserves_real_file
- @keg.link
- @dst.delete
- touch @dst
- @keg.unlink
- assert_predicate @dst, :file?
- end
-
- def test_unlink_ignores_nonexistent_file
- @keg.link
- @dst.delete
- assert_equal 2, @keg.unlink
- end
-
- def test_pkgconfig_is_mkpathed
- link = HOMEBREW_PREFIX.join("lib", "pkgconfig")
- @keg.join("lib", "pkgconfig").mkpath
- @keg.link
- assert_predicate link.lstat, :directory?
- end
-
- def test_cmake_is_mkpathed
- link = HOMEBREW_PREFIX.join("lib", "cmake")
- @keg.join("lib", "cmake").mkpath
- @keg.link
- assert_predicate link.lstat, :directory?
- end
-
- def test_symlinks_are_linked_directly
- link = HOMEBREW_PREFIX.join("lib", "pkgconfig")
-
- @keg.join("lib", "example").mkpath
- @keg.join("lib", "pkgconfig").make_symlink "example"
- @keg.link
-
- assert_predicate link.resolved_path, :symlink?
- assert_predicate link.lstat, :symlink?
- end
-
- def test_links_to_symlinks_are_not_removed
- a = HOMEBREW_CELLAR.join("a", "1.0")
- b = HOMEBREW_CELLAR.join("b", "1.0")
-
- a.join("lib", "example").mkpath
- a.join("lib", "example2").make_symlink "example"
- b.join("lib", "example2").mkpath
-
- a = Keg.new(a)
- b = Keg.new(b)
- a.link
-
- lib = HOMEBREW_PREFIX.join("lib")
- assert_equal 2, lib.children.length
- assert_raises(Keg::ConflictError) { b.link }
- assert_equal 2, lib.children.length
- ensure
- a.unlink
- a.uninstall
- b.uninstall
- end
-
- def test_removes_broken_symlinks_that_conflict_with_directories
- a = HOMEBREW_CELLAR.join("a", "1.0")
- a.join("lib", "foo").mkpath
-
- keg = Keg.new(a)
-
- link = HOMEBREW_PREFIX.join("lib", "foo")
- link.parent.mkpath
- link.make_symlink(@nonexistent)
-
- keg.link
- ensure
- keg.unlink
- keg.uninstall
- end
-end
-
-class InstalledDependantsTests < LinkTestCase
- def stub_formula_name(name)
- f = formula(name) { url "foo-1.0" }
- stub_formula_loader f
- stub_formula_loader f, "homebrew/core/#{f}"
- f
- end
-
- def setup_test_keg(name, version)
- f = stub_formula_name(name)
- keg = super
- Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
- keg
- end
-
- def setup
- super
- @dependent = setup_test_keg("bar", "1.0")
- @keg.link
- end
-
- def alter_tab(keg = @dependent)
- tab = Tab.for_keg(keg)
- yield tab
- tab.write
- end
-
- # 1.1.6 is the earliest version of Homebrew that generates correct runtime
- # dependency lists in tabs.
- def dependencies(deps, homebrew_version: "1.1.6")
- alter_tab do |tab|
- tab.homebrew_version = homebrew_version
- tab.tabfile = @dependent.join("INSTALL_RECEIPT.json")
- tab.runtime_dependencies = deps
- end
- end
-
- def unreliable_dependencies(deps)
- # 1.1.5 is (hopefully!) the last version of Homebrew that generates
- # incorrect runtime dependency lists in tabs.
- dependencies(deps, homebrew_version: "1.1.5")
- end
-
- # Test with a keg whose formula isn't known.
- # This can happen if e.g. a formula is installed
- # from a file path or URL.
- def test_unknown_formula
- Formulary.unstub(:loader_for)
- alter_tab(@keg) do |t|
- t.source["tap"] = "some/tap"
- t.source["path"] = nil
- end
-
- dependencies [{ "full_name" => "some/tap/foo", "version" => "1.0" }]
- assert_equal [@dependent], @keg.installed_dependents
- assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg])
-
- dependencies nil
- # It doesn't make sense for a keg with no formula to have any dependents,
- # so that can't really be tested.
- assert_nil Keg.find_some_installed_dependents([@keg])
- end
-
- def test_a_dependency_with_no_tap_in_tab
- @tap_dep = setup_test_keg("baz", "1.0")
-
- alter_tab(@keg) { |t| t.source["tap"] = nil }
-
- dependencies nil
- Formula["bar"].class.depends_on "foo"
- Formula["bar"].class.depends_on "baz"
-
- result = Keg.find_some_installed_dependents([@keg, @tap_dep])
- assert_equal [[@keg, @tap_dep], ["bar"]], result
- end
-
- def test_no_dependencies_anywhere
- dependencies nil
- assert_empty @keg.installed_dependents
- assert_nil Keg.find_some_installed_dependents([@keg])
- end
-
- def test_missing_formula_dependency
- dependencies nil
- Formula["bar"].class.depends_on "foo"
- assert_empty @keg.installed_dependents
- assert_equal [[@keg], ["bar"]], Keg.find_some_installed_dependents([@keg])
- end
-
- def test_uninstalling_dependent_and_dependency
- dependencies nil
- Formula["bar"].class.depends_on "foo"
- assert_empty @keg.installed_dependents
- assert_nil Keg.find_some_installed_dependents([@keg, @dependent])
- end
-
- def test_renamed_dependency
- dependencies nil
-
- stub_formula_loader Formula["foo"], "homebrew/core/foo-old"
- renamed_path = HOMEBREW_CELLAR/"foo-old"
- (HOMEBREW_CELLAR/"foo").rename(renamed_path)
- renamed_keg = Keg.new(renamed_path.join("1.0"))
-
- Formula["bar"].class.depends_on "foo"
-
- result = Keg.find_some_installed_dependents([renamed_keg])
- assert_equal [[renamed_keg], ["bar"]], result
- ensure
- # Move it back to where it was so it'll be cleaned up.
- (HOMEBREW_CELLAR/"foo-old").rename(HOMEBREW_CELLAR/"foo")
- end
-
- def test_empty_dependencies_in_tab
- dependencies []
- assert_empty @keg.installed_dependents
- assert_nil Keg.find_some_installed_dependents([@keg])
- end
-
- def test_same_name_different_version_in_tab
- dependencies [{ "full_name" => "foo", "version" => "1.1" }]
- assert_equal [@dependent], @keg.installed_dependents
- assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg])
- end
-
- def test_different_name_same_version_in_tab
- stub_formula_name("baz")
- dependencies [{ "full_name" => "baz", "version" => @keg.version.to_s }]
- assert_empty @keg.installed_dependents
- assert_nil Keg.find_some_installed_dependents([@keg])
- end
-
- def test_same_name_and_version_in_tab
- dependencies [{ "full_name" => "foo", "version" => "1.0" }]
- assert_equal [@dependent], @keg.installed_dependents
- assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg])
- end
-
- def test_fallback_for_old_versions
- unreliable_dependencies [{ "full_name" => "baz", "version" => "1.0" }]
- Formula["bar"].class.depends_on "foo"
- assert_empty @keg.installed_dependents
- assert_equal [[@keg], ["bar"]], Keg.find_some_installed_dependents([@keg])
- end
-
- def test_nonoptlinked
- @keg.remove_opt_record
- dependencies [{ "full_name" => "foo", "version" => "1.0" }]
- assert_empty @keg.installed_dependents
- assert_nil Keg.find_some_installed_dependents([@keg])
- end
-
- def test_keg_only
- @keg.unlink
- Formula["foo"].class.keg_only "a good reason"
- dependencies [{ "full_name" => "foo", "version" => "1.1" }] # different version
- assert_equal [@dependent], @keg.installed_dependents
- assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg])
- end
-end
diff --git a/Library/Homebrew/test/language/go_spec.rb b/Library/Homebrew/test/language/go_spec.rb
new file mode 100644
index 000000000..24db78594
--- /dev/null
+++ b/Library/Homebrew/test/language/go_spec.rb
@@ -0,0 +1,15 @@
+require "language/go"
+
+describe Language::Go do
+ specify "#stage_deps" do
+ ENV.delete("HOMEBREW_DEVELOPER")
+
+ expect(described_class).to receive(:opoo).once
+
+ Dir.mktmpdir do |path|
+ shutup do
+ described_class.stage_deps [], path
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/language/python_spec.rb b/Library/Homebrew/test/language/python_spec.rb
new file mode 100644
index 000000000..c78520897
--- /dev/null
+++ b/Library/Homebrew/test/language/python_spec.rb
@@ -0,0 +1,106 @@
+require "language/python"
+require "resource"
+
+describe Language::Python::Virtualenv::Virtualenv do
+ subject { described_class.new(formula, dir, "python") }
+
+ let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
+
+ let(:resource) { double("resource", stage: true) }
+ let(:formula_bin) { dir/"formula_bin" }
+ let(:formula) { double("formula", resource: resource, bin: formula_bin) }
+
+ after(:each) { dir.rmtree unless @dir.nil? }
+
+ describe "#create" do
+ it "creates a virtual environment" do
+ expect(formula).to receive(:resource).with("homebrew-virtualenv").and_return(resource)
+ subject.create
+ end
+
+ specify "virtual environment creation is idempotent" do
+ expect(formula).to receive(:resource).with("homebrew-virtualenv").and_return(resource)
+ subject.create
+ FileUtils.mkdir_p dir/"bin"
+ FileUtils.touch dir/"bin/python"
+ subject.create
+ FileUtils.rm dir/"bin/python"
+ end
+ end
+
+ describe "#pip_install" do
+ it "accepts a string" do
+ expect(formula).to receive(:system)
+ .with(dir/"bin/pip", "install", "-v", "--no-deps",
+ "--no-binary", ":all:", "--ignore-installed", "foo")
+ .and_return(true)
+ subject.pip_install "foo"
+ end
+
+ it "accepts a multi-line strings" do
+ expect(formula).to receive(:system)
+ .with(dir/"bin/pip", "install", "-v", "--no-deps",
+ "--no-binary", ":all:", "--ignore-installed", "foo", "bar")
+ .and_return(true)
+
+ subject.pip_install <<-EOS.undent
+ foo
+ bar
+ EOS
+ end
+
+ it "accepts an array" do
+ expect(formula).to receive(:system)
+ .with(dir/"bin/pip", "install", "-v", "--no-deps",
+ "--no-binary", ":all:", "--ignore-installed", "foo")
+ .and_return(true)
+
+ expect(formula).to receive(:system)
+ .with(dir/"bin/pip", "install", "-v", "--no-deps",
+ "--no-binary", ":all:", "--ignore-installed", "bar")
+ .and_return(true)
+
+ subject.pip_install ["foo", "bar"]
+ end
+
+ it "accepts a Resource" do
+ res = Resource.new("test")
+
+ expect(res).to receive(:stage).and_yield
+ expect(formula).to receive(:system)
+ .with(dir/"bin/pip", "install", "-v", "--no-deps",
+ "--no-binary", ":all:", "--ignore-installed", Pathname.pwd)
+ .and_return(true)
+
+ subject.pip_install res
+ end
+ end
+
+ describe "#pip_install_and_link" do
+ let(:src_bin) { dir/"bin" }
+ let(:dest_bin) { formula.bin }
+
+ it "can link scripts" do
+ src_bin.mkpath
+
+ expect(src_bin/"kilroy").not_to exist
+ expect(dest_bin/"kilroy").not_to exist
+
+ FileUtils.touch src_bin/"irrelevant"
+ bin_before = Dir.glob(src_bin/"*")
+ FileUtils.touch src_bin/"kilroy"
+ bin_after = Dir.glob(src_bin/"*")
+
+ expect(subject).to receive(:pip_install).with("foo")
+ expect(Dir).to receive(:[]).with(src_bin/"*").twice.and_return(bin_before, bin_after)
+
+ subject.pip_install_and_link "foo"
+
+ expect(src_bin/"kilroy").to exist
+ expect(dest_bin/"kilroy").to exist
+ expect(dest_bin/"kilroy").to be_a_symlink
+ expect((src_bin/"kilroy").realpath).to eq((dest_bin/"kilroy").realpath)
+ expect(dest_bin/"irrelevant").not_to exist
+ end
+ end
+end
diff --git a/Library/Homebrew/test/language_go_test.rb b/Library/Homebrew/test/language_go_test.rb
deleted file mode 100644
index 692a5d2cc..000000000
--- a/Library/Homebrew/test/language_go_test.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# -*- coding: UTF-8 -*-
-
-require "testing_env"
-require "language/go"
-
-class LanguageGoTests < Homebrew::TestCase
- def test_stage_deps_empty
- if ARGV.homebrew_developer?
- Language::Go.expects(:odie).once
- else
- Language::Go.expects(:opoo).once
- end
- mktmpdir do |path|
- shutup { Language::Go.stage_deps [], path }
- end
- end
-end
diff --git a/Library/Homebrew/test/language_module_requirement_spec.rb b/Library/Homebrew/test/language_module_requirement_spec.rb
new file mode 100644
index 000000000..7f2666855
--- /dev/null
+++ b/Library/Homebrew/test/language_module_requirement_spec.rb
@@ -0,0 +1,49 @@
+require "requirements/language_module_requirement"
+
+describe LanguageModuleRequirement do
+ specify "unique dependencies are not equal" do
+ x = described_class.new(:node, "less")
+ y = described_class.new(:node, "coffee-script")
+ expect(x).not_to eq(y)
+ expect(x.hash).not_to eq(y.hash)
+ end
+
+ context "when module and import name differ" do
+ subject { described_class.new(:python, mod_name, import_name) }
+ let(:mod_name) { "foo" }
+ let(:import_name) { "bar" }
+
+ its(:message) { is_expected.to include(mod_name) }
+ its(:the_test) { is_expected.to include("import #{import_name}") }
+ end
+
+ context "when the language is Perl" do
+ it "does not satisfy invalid dependencies" do
+ expect(described_class.new(:perl, "notapackage")).not_to be_satisfied
+ end
+
+ it "satisfies valid dependencies" do
+ expect(described_class.new(:perl, "Env")).to be_satisfied
+ end
+ end
+
+ context "when the language is Python", :needs_python do
+ it "does not satisfy invalid dependencies" do
+ expect(described_class.new(:python, "notapackage")).not_to be_satisfied
+ end
+
+ it "satisfies valid dependencies" do
+ expect(described_class.new(:python, "datetime")).to be_satisfied
+ end
+ end
+
+ context "when the language is Ruby" do
+ it "does not satisfy invalid dependencies" do
+ expect(described_class.new(:ruby, "notapackage")).not_to be_satisfied
+ end
+
+ it "satisfies valid dependencies" do
+ expect(described_class.new(:ruby, "date")).to be_satisfied
+ end
+ end
+end
diff --git a/Library/Homebrew/test/language_module_requirement_test.rb b/Library/Homebrew/test/language_module_requirement_test.rb
deleted file mode 100644
index dfa992287..000000000
--- a/Library/Homebrew/test/language_module_requirement_test.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-require "testing_env"
-require "requirements/language_module_requirement"
-
-class LanguageModuleRequirementTests < Homebrew::TestCase
- parallelize_me!
-
- def assert_deps_fail(spec)
- refute_predicate LanguageModuleRequirement.new(*spec.shift.reverse), :satisfied?
- end
-
- def assert_deps_pass(spec)
- assert_predicate LanguageModuleRequirement.new(*spec.shift.reverse), :satisfied?
- end
-
- def test_unique_deps_are_not_eql
- x = LanguageModuleRequirement.new(:node, "less")
- y = LanguageModuleRequirement.new(:node, "coffee-script")
- refute_eql x, y
- refute_equal x.hash, y.hash
- end
-
- def test_differing_module_and_import_name
- mod_name = "foo"
- import_name = "bar"
- l = LanguageModuleRequirement.new(:python, mod_name, import_name)
- assert_includes l.message, mod_name
- assert_includes l.the_test, "import #{import_name}"
- end
-
- def test_bad_perl_deps
- assert_deps_fail "notapackage" => :perl
- end
-
- def test_good_perl_deps
- assert_deps_pass "Env" => :perl
- end
-
- def test_bad_python_deps
- needs_python
- assert_deps_fail "notapackage" => :python
- end
-
- def test_good_python_deps
- needs_python
- assert_deps_pass "datetime" => :python
- end
-
- def test_bad_ruby_deps
- assert_deps_fail "notapackage" => :ruby
- end
-
- def test_good_ruby_deps
- assert_deps_pass "date" => :ruby
- end
-end
diff --git a/Library/Homebrew/test/language_python_test.rb b/Library/Homebrew/test/language_python_test.rb
deleted file mode 100644
index d1e3867f7..000000000
--- a/Library/Homebrew/test/language_python_test.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-require "testing_env"
-require "language/python"
-require "resource"
-
-class LanguagePythonTests < Homebrew::TestCase
- def setup
- @dir = Pathname.new(mktmpdir)
- resource = stub("resource", stage: true)
- formula_bin = @dir/"formula_bin"
- @formula = mock("formula") do
- stubs(:resource).returns(resource)
- stubs(:bin).returns(formula_bin)
- end
- @venv = Language::Python::Virtualenv::Virtualenv.new(@formula, @dir, "python")
- end
-
- def teardown
- FileUtils.rm_rf @dir
- end
-
- def test_virtualenv_creation
- @formula.expects(:resource).with("homebrew-virtualenv").returns(
- mock("resource", stage: true)
- )
- @venv.create
- end
-
- # or at least doesn't crash the second time
- def test_virtualenv_creation_is_idempotent
- @formula.expects(:resource).with("homebrew-virtualenv").returns(
- mock("resource", stage: true)
- )
- @venv.create
- FileUtils.mkdir_p @dir/"bin"
- FileUtils.touch @dir/"bin/python"
- @venv.create
- FileUtils.rm @dir/"bin/python"
- end
-
- def test_pip_install_accepts_string
- @formula.expects(:system).returns(true).with do |*params|
- params.first == @dir/"bin/pip" && params.last == "foo"
- end
- @venv.pip_install "foo"
- end
-
- def test_pip_install_accepts_multiline_string
- @formula.expects(:system).returns(true).with do |*params|
- params.first == @dir/"bin/pip" && params[-2..-1] == ["foo", "bar"]
- end
- @venv.pip_install <<-EOS.undent
- foo
- bar
- EOS
- end
-
- def test_pip_install_accepts_array
- @formula.expects(:system).returns(true).with do |*params|
- params.first == @dir/"bin/pip" && params.last == "foo"
- end
- @formula.expects(:system).returns(true).with do |*params|
- params.first == @dir/"bin/pip" && params.last == "bar"
- end
- @venv.pip_install ["foo", "bar"]
- end
-
- def test_pip_install_accepts_resource
- res = Resource.new "test"
- res.expects(:stage).yields(nil)
- @formula.expects(:system).returns(true).with do |*params|
- params.first == @dir/"bin/pip" && params.last == Pathname.pwd
- end
- @venv.pip_install res
- end
-
- def test_pip_install_and_link_links_scripts
- bin = @dir/"bin"
- bin.mkpath
- dest = @formula.bin
-
- refute_predicate bin/"kilroy", :exist?
- refute_predicate dest/"kilroy", :exist?
-
- FileUtils.touch bin/"irrelevant"
- bin_before = Dir[bin/"*"]
- FileUtils.touch bin/"kilroy"
- bin_after = Dir[bin/"*"]
- @venv.expects(:pip_install).with("foo")
- Dir.expects(:[]).twice.returns(bin_before, bin_after)
-
- @venv.pip_install_and_link "foo"
-
- assert_predicate bin/"kilroy", :exist?
- assert_predicate dest/"kilroy", :exist?
- assert_predicate dest/"kilroy", :symlink?
- assert_equal((bin/"kilroy").realpath, (dest/"kilroy").realpath)
- refute_predicate dest/"irrelevant", :exist?
- end
-end
diff --git a/Library/Homebrew/test/leaves_test.rb b/Library/Homebrew/test/leaves_test.rb
deleted file mode 100644
index f73fba1ea..000000000
--- a/Library/Homebrew/test/leaves_test.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestLeaves < IntegrationCommandTestCase
- def test_leaves
- setup_test_formula "foo"
- setup_test_formula "bar"
- assert_equal "", cmd("leaves")
-
- (HOMEBREW_CELLAR/"foo/0.1/somedir").mkpath
- assert_equal "foo", cmd("leaves")
-
- (HOMEBREW_CELLAR/"bar/0.1/somedir").mkpath
- assert_equal "bar", cmd("leaves")
- end
-end
diff --git a/Library/Homebrew/test/link_test.rb b/Library/Homebrew/test/link_test.rb
deleted file mode 100644
index 062caa0c0..000000000
--- a/Library/Homebrew/test/link_test.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestLink < IntegrationCommandTestCase
- def test_link
- assert_match "This command requires a keg argument", cmd_fail("link")
-
- setup_test_formula "testball1"
- cmd("install", "testball1")
- cmd("link", "testball1")
-
- cmd("unlink", "testball1")
- assert_match "Would link", cmd("link", "--dry-run", "testball1")
- assert_match "Would remove",
- cmd("link", "--dry-run", "--overwrite", "testball1")
- assert_match "Linking", cmd("link", "testball1")
-
- setup_test_formula "testball2", <<-EOS.undent
- keg_only "just because"
- EOS
- cmd("install", "testball2")
- assert_match "testball2 is keg-only", cmd("link", "testball2")
- end
-end
diff --git a/Library/Homebrew/test/linkapps_test.rb b/Library/Homebrew/test/linkapps_test.rb
deleted file mode 100644
index 4c5b8ec13..000000000
--- a/Library/Homebrew/test/linkapps_test.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestLinkapps < IntegrationCommandTestCase
- def test_linkapps
- home_dir = Pathname.new(mktmpdir)
- (home_dir/"Applications").mkpath
-
- setup_test_formula "testball"
-
- source_dir = HOMEBREW_CELLAR/"testball/0.1/TestBall.app"
- source_dir.mkpath
- assert_match "Linking: #{source_dir}",
- cmd("linkapps", "--local", "HOME" => home_dir)
- end
-end
diff --git a/Library/Homebrew/test/list_test.rb b/Library/Homebrew/test/list_test.rb
deleted file mode 100644
index 3c691e3ad..000000000
--- a/Library/Homebrew/test/list_test.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestList < IntegrationCommandTestCase
- def test_list
- formulae = %w[bar foo qux]
- formulae.each do |f|
- (HOMEBREW_CELLAR/"#{f}/1.0/somedir").mkpath
- end
-
- assert_equal formulae.join("\n"),
- cmd("list")
- end
-end
diff --git a/Library/Homebrew/test/log_formula_test.rb b/Library/Homebrew/test/log_formula_test.rb
deleted file mode 100644
index bb6a1f661..000000000
--- a/Library/Homebrew/test/log_formula_test.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestLogFormula < IntegrationCommandTestCase
- def test_log_formula
- core_tap = CoreTap.new
- setup_test_formula "testball"
-
- core_tap.path.cd do
- shutup do
- system "git", "init"
- system "git", "add", "--all"
- system "git", "commit", "-m", "This is a test commit for Testball"
- end
- end
-
- core_tap_url = "file://#{core_tap.path}"
- shallow_tap = Tap.fetch("homebrew", "shallow")
- shutup do
- system "git", "clone", "--depth=1", core_tap_url, shallow_tap.path
- end
-
- assert_match "This is a test commit for Testball",
- cmd("log", "#{shallow_tap}/testball")
- assert_predicate shallow_tap.path/".git/shallow", :exist?,
- "A shallow clone should have been created."
- end
-end
diff --git a/Library/Homebrew/test/log_test.rb b/Library/Homebrew/test/log_test.rb
deleted file mode 100644
index b2e150ccd..000000000
--- a/Library/Homebrew/test/log_test.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestLog < IntegrationCommandTestCase
- def test_log
- FileUtils.cd HOMEBREW_REPOSITORY do
- shutup do
- system "git", "init"
- system "git", "commit", "--allow-empty", "-m", "This is a test commit"
- end
- end
- assert_match "This is a test commit", cmd("log")
- end
-end
diff --git a/Library/Homebrew/test/migrate_test.rb b/Library/Homebrew/test/migrate_test.rb
deleted file mode 100644
index 17929d038..000000000
--- a/Library/Homebrew/test/migrate_test.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestMigrate < IntegrationCommandTestCase
- def test_migrate
- setup_test_formula "testball1"
- setup_test_formula "testball2"
- assert_match "Invalid usage", cmd_fail("migrate")
- assert_match "No available formula with the name \"testball\"",
- cmd_fail("migrate", "testball")
- assert_match "testball1 doesn't replace any formula",
- cmd_fail("migrate", "testball1")
-
- install_and_rename_coretap_formula "testball1", "testball2"
- assert_match "Migrating testball1 to testball2", cmd("migrate", "testball1")
- (HOMEBREW_CELLAR/"testball1").unlink
- assert_match "Error: No such keg", cmd_fail("migrate", "testball1")
- end
-end
diff --git a/Library/Homebrew/test/migrator_spec.rb b/Library/Homebrew/test/migrator_spec.rb
new file mode 100644
index 000000000..90ee9d8ff
--- /dev/null
+++ b/Library/Homebrew/test/migrator_spec.rb
@@ -0,0 +1,264 @@
+require "migrator"
+require "test/support/fixtures/testball"
+require "tab"
+require "keg"
+
+describe Migrator do
+ subject { described_class.new(new_formula) }
+
+ let(:new_formula) { Testball.new("newname") }
+ let(:old_formula) { Testball.new("oldname") }
+
+ let(:new_keg_record) { HOMEBREW_CELLAR/"newname/0.1" }
+ let(:old_keg_record) { HOMEBREW_CELLAR/"oldname/0.1" }
+
+ let(:old_tab) { Tab.empty }
+
+ let(:keg) { Keg.new(old_keg_record) }
+ let(:old_pin) { HOMEBREW_PINNED_KEGS/"oldname" }
+
+ before(:each) do |example|
+ allow(new_formula).to receive(:oldname).and_return("oldname")
+
+ # do not create directories for error tests
+ next if example.metadata[:description].start_with?("raises an error")
+
+ (old_keg_record/"bin").mkpath
+
+ %w[inside bindir].each do |file|
+ FileUtils.touch old_keg_record/"bin/#{file}"
+ end
+
+ old_tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ old_tab.source["path"] = "/oldname"
+ old_tab.write
+
+ keg.link
+ keg.optlink
+
+ old_pin.make_relative_symlink old_keg_record
+
+ subject # needs to be evaluated eagerly
+
+ (HOMEBREW_PREFIX/"bin").mkpath
+ end
+
+ after(:each) do
+ if !old_keg_record.parent.symlink? && old_keg_record.directory?
+ keg.unlink
+ end
+
+ if new_keg_record.directory?
+ new_keg = Keg.new(new_keg_record)
+ new_keg.unlink
+ end
+ end
+
+ describe "::new" do
+ it "raises an error if there is no old name" do
+ expect {
+ described_class.new(old_formula)
+ }.to raise_error(Migrator::MigratorNoOldnameError)
+ end
+
+ it "raises an error if there is no old path" do
+ expect {
+ described_class.new(new_formula)
+ }.to raise_error(Migrator::MigratorNoOldpathError)
+ end
+
+ it "raises an error if the Taps differ" do
+ keg = HOMEBREW_CELLAR/"oldname/0.1"
+ keg.mkpath
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ tab.source["tap"] = "homebrew/core"
+ tab.write
+
+ expect {
+ described_class.new(new_formula)
+ }.to raise_error(Migrator::MigratorDifferentTapsError)
+ end
+ end
+
+ specify "#move_to_new_directory" do
+ keg.unlink
+ shutup do
+ subject.move_to_new_directory
+ end
+
+ expect(new_keg_record).to be_a_directory
+ expect(new_keg_record/"bin").to be_a_directory
+ expect(new_keg_record/"bin/inside").to be_a_file
+ expect(new_keg_record/"bin/bindir").to be_a_file
+ expect(old_keg_record).not_to be_a_directory
+ end
+
+ specify "#backup_oldname_cellar" do
+ old_keg_record.parent.rmtree
+ (new_keg_record/"bin").mkpath
+
+ subject.backup_oldname_cellar
+
+ expect(old_keg_record/"bin").to be_a_directory
+ expect(old_keg_record/"bin").to be_a_directory
+ end
+
+ specify "#repin" do
+ (new_keg_record/"bin").mkpath
+ expected_relative = new_keg_record.relative_path_from HOMEBREW_PINNED_KEGS
+
+ subject.repin
+
+ expect(subject.new_pin_record).to be_a_symlink
+ expect(subject.new_pin_record.readlink).to eq(expected_relative)
+ expect(subject.old_pin_record).not_to exist
+ end
+
+ specify "#unlink_oldname" do
+ expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1)
+ expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1)
+
+ shutup do
+ subject.unlink_oldname
+ end
+
+ expect(HOMEBREW_LINKED_KEGS).not_to exist
+ expect(HOMEBREW_LIBRARY/"bin").not_to exist
+ end
+
+ specify "#link_newname" do
+ keg.unlink
+ keg.uninstall
+
+ (new_keg_record/"bin").mkpath
+ %w[inside bindir].each do |file|
+ FileUtils.touch new_keg_record/"bin"/file
+ end
+
+ shutup do
+ subject.link_newname
+ end
+
+ expect(HOMEBREW_LINKED_KEGS.children.count).to eq(1)
+ expect((HOMEBREW_PREFIX/"opt").children.count).to eq(1)
+ end
+
+ specify "#link_oldname_opt" do
+ new_keg_record.mkpath
+ subject.link_oldname_opt
+ expect((HOMEBREW_PREFIX/"opt/oldname").realpath).to eq(new_keg_record.realpath)
+ end
+
+ specify "#link_oldname_cellar" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ subject.link_oldname_cellar
+ expect((HOMEBREW_CELLAR/"oldname").realpath).to eq(new_keg_record.parent.realpath)
+ end
+
+ specify "#update_tabs" do
+ (new_keg_record/"bin").mkpath
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"newname/0.1/INSTALL_RECEIPT.json"
+ tab.source["path"] = "/path/that/must/be/changed/by/update_tabs"
+ tab.write
+ subject.update_tabs
+ expect(Tab.for_keg(new_keg_record).source["path"]).to eq(new_formula.path.to_s)
+ end
+
+ specify "#migrate" do
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ tab.source["path"] = old_formula.path.to_s
+ tab.write
+
+ shutup do
+ subject.migrate
+ end
+
+ expect(new_keg_record).to exist
+ expect(old_keg_record.parent).to be_a_symlink
+ expect(HOMEBREW_LINKED_KEGS/"oldname").not_to exist
+ expect((HOMEBREW_LINKED_KEGS/"newname").realpath).to eq(new_keg_record.realpath)
+ expect(old_keg_record.realpath).to eq(new_keg_record.realpath)
+ expect((HOMEBREW_PREFIX/"opt/oldname").realpath).to eq(new_keg_record.realpath)
+ expect((HOMEBREW_CELLAR/"oldname").realpath).to eq(new_keg_record.parent.realpath)
+ expect((HOMEBREW_PINNED_KEGS/"newname").realpath).to eq(new_keg_record.realpath)
+ expect(Tab.for_keg(new_keg_record).source["path"]).to eq(new_formula.path.to_s)
+ end
+
+ specify "#unlinik_oldname_opt" do
+ new_keg_record.mkpath
+ old_opt_record = HOMEBREW_PREFIX/"opt/oldname"
+ old_opt_record.unlink if old_opt_record.symlink?
+ old_opt_record.make_relative_symlink(new_keg_record)
+ subject.unlink_oldname_opt
+ expect(old_opt_record).not_to be_a_symlink
+ end
+
+ specify "#unlink_oldname_cellar" do
+ new_keg_record.mkpath
+ keg.unlink
+ keg.uninstall
+ old_keg_record.parent.make_relative_symlink(new_keg_record.parent)
+ subject.unlink_oldname_cellar
+ expect(old_keg_record.parent).not_to be_a_symlink
+ end
+
+ specify "#backup_oldname_cellar" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ subject.backup_oldname_cellar
+ expect(old_keg_record.subdirs).not_to be_empty
+ end
+
+ specify "#backup_old_tabs" do
+ tab = Tab.empty
+ tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
+ tab.source["path"] = "/should/be/the/same"
+ tab.write
+ migrator = Migrator.new(new_formula)
+ tab.tabfile.delete
+ migrator.backup_old_tabs
+ expect(Tab.for_keg(old_keg_record).source["path"]).to eq("/should/be/the/same")
+ end
+
+ describe "#backup_oldname" do
+ after(:each) do
+ expect(old_keg_record.parent).to be_a_directory
+ expect(old_keg_record.parent.subdirs).not_to be_empty
+ expect(HOMEBREW_LINKED_KEGS/"oldname").to exist
+ expect(HOMEBREW_PREFIX/"opt/oldname").to exist
+ expect(HOMEBREW_PINNED_KEGS/"oldname").to be_a_symlink
+ expect(keg).to be_linked
+ end
+
+ context "when cellar exists" do
+ it "backs up the old name" do
+ subject.backup_oldname
+ end
+ end
+
+ context "when cellar is removed" do
+ it "backs up the old name" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ subject.backup_oldname
+ end
+ end
+
+ context "when cellar is linked" do
+ it "backs up the old name" do
+ (new_keg_record/"bin").mkpath
+ keg.unlink
+ keg.uninstall
+ old_keg_record.parent.make_relative_symlink(new_keg_record.parent)
+ subject.backup_oldname
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/migrator_test.rb b/Library/Homebrew/test/migrator_test.rb
deleted file mode 100644
index 8a2b6ad63..000000000
--- a/Library/Homebrew/test/migrator_test.rb
+++ /dev/null
@@ -1,264 +0,0 @@
-require "testing_env"
-require "migrator"
-require "test/support/fixtures/testball"
-require "tab"
-require "keg"
-
-class Formula
- attr_writer :oldname
-end
-
-class MigratorErrorsTests < Homebrew::TestCase
- def setup
- @new_f = Testball.new("newname")
- @new_f.oldname = "oldname"
- @old_f = Testball.new("oldname")
- end
-
- def test_no_oldname
- assert_raises(Migrator::MigratorNoOldnameError) { Migrator.new(@old_f) }
- end
-
- def test_no_oldpath
- assert_raises(Migrator::MigratorNoOldpathError) { Migrator.new(@new_f) }
- end
-
- def test_different_taps
- keg = HOMEBREW_CELLAR/"oldname/0.1"
- keg.mkpath
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- tab.source["tap"] = "homebrew/core"
- tab.write
- assert_raises(Migrator::MigratorDifferentTapsError) { Migrator.new(@new_f) }
- ensure
- keg.parent.rmtree
- end
-end
-
-class MigratorTests < Homebrew::TestCase
- include FileUtils
-
- def setup
- @new_f = Testball.new("newname")
- @new_f.oldname = "oldname"
-
- @old_f = Testball.new("oldname")
-
- @old_keg_record = HOMEBREW_CELLAR/"oldname/0.1"
- @old_keg_record.join("bin").mkpath
- @new_keg_record = HOMEBREW_CELLAR/"newname/0.1"
-
- %w[inside bindir].each { |file| touch @old_keg_record.join("bin", file) }
-
- @old_tab = Tab.empty
- @old_tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- @old_tab.source["path"] = "/oldname"
- @old_tab.write
-
- @keg = Keg.new(@old_keg_record)
- @keg.link
- @keg.optlink
-
- @old_pin = HOMEBREW_PINNED_KEGS/"oldname"
- @old_pin.make_relative_symlink @old_keg_record
-
- @migrator = Migrator.new(@new_f)
-
- mkpath HOMEBREW_PREFIX/"bin"
- end
-
- def teardown
- @old_pin.unlink if @old_pin.symlink?
-
- if @old_keg_record.parent.symlink?
- @old_keg_record.parent.unlink
- elsif @old_keg_record.directory?
- @keg.unlink
- @keg.uninstall
- end
-
- if @new_keg_record.directory?
- new_keg = Keg.new(@new_keg_record)
- new_keg.unlink
- new_keg.uninstall
- end
-
- @old_keg_record.parent.rmtree if @old_keg_record.parent.directory?
- @new_keg_record.parent.rmtree if @new_keg_record.parent.directory?
-
- rmtree HOMEBREW_PREFIX/"bin"
- rmtree HOMEBREW_PREFIX/"opt" if (HOMEBREW_PREFIX/"opt").directory?
- # What to do with pin?
- @new_f.unpin
-
- HOMEBREW_LOCK_DIR.children.each(&:unlink)
- end
-
- def test_move_cellar
- @keg.unlink
- shutup { @migrator.move_to_new_directory }
- assert_predicate @new_keg_record, :directory?
- assert_predicate @new_keg_record/"bin", :directory?
- assert_predicate @new_keg_record/"bin/inside", :file?
- assert_predicate @new_keg_record/"bin/bindir", :file?
- refute_predicate @old_keg_record, :directory?
- end
-
- def test_backup_cellar
- @old_keg_record.parent.rmtree
- @new_keg_record.join("bin").mkpath
-
- @migrator.backup_oldname_cellar
-
- assert_predicate @old_keg_record, :directory?
- assert_predicate @old_keg_record/"bin", :directory?
- end
-
- def test_repin
- @new_keg_record.join("bin").mkpath
- expected_relative = @new_keg_record.relative_path_from HOMEBREW_PINNED_KEGS
-
- @migrator.repin
-
- assert_predicate @migrator.new_pin_record, :symlink?
- assert_equal expected_relative, @migrator.new_pin_record.readlink
- refute_predicate @migrator.old_pin_record, :exist?
- end
-
- def test_unlink_oldname
- assert_equal 1, HOMEBREW_LINKED_KEGS.children.size
- assert_equal 1, (HOMEBREW_PREFIX/"opt").children.size
-
- shutup { @migrator.unlink_oldname }
-
- refute_predicate HOMEBREW_LINKED_KEGS, :exist?
- refute_predicate HOMEBREW_LIBRARY/"bin", :exist?
- end
-
- def test_link_newname
- @keg.unlink
- @keg.uninstall
- @new_keg_record.join("bin").mkpath
- %w[inside bindir].each { |file| touch @new_keg_record.join("bin", file) }
-
- shutup { @migrator.link_newname }
-
- assert_equal 1, HOMEBREW_LINKED_KEGS.children.size
- assert_equal 1, (HOMEBREW_PREFIX/"opt").children.size
- end
-
- def test_link_oldname_opt
- @new_keg_record.mkpath
- @migrator.link_oldname_opt
- assert_equal @new_keg_record.realpath, (HOMEBREW_PREFIX/"opt/oldname").realpath
- end
-
- def test_link_oldname_cellar
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @migrator.link_oldname_cellar
- assert_equal @new_keg_record.parent.realpath, (HOMEBREW_CELLAR/"oldname").realpath
- end
-
- def test_update_tabs
- @new_keg_record.join("bin").mkpath
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"newname/0.1/INSTALL_RECEIPT.json"
- tab.source["path"] = "/path/that/must/be/changed/by/update_tabs"
- tab.write
- @migrator.update_tabs
- assert_equal @new_f.path.to_s, Tab.for_keg(@new_keg_record).source["path"]
- end
-
- def test_migrate
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- tab.source["path"] = @old_f.path.to_s
- tab.write
-
- shutup { @migrator.migrate }
-
- assert_predicate @new_keg_record, :exist?
- assert_predicate @old_keg_record.parent, :symlink?
- refute_predicate HOMEBREW_LINKED_KEGS/"oldname", :exist?
- assert_equal @new_keg_record.realpath, (HOMEBREW_LINKED_KEGS/"newname").realpath
- assert_equal @new_keg_record.realpath, @old_keg_record.realpath
- assert_equal @new_keg_record.realpath, (HOMEBREW_PREFIX/"opt/oldname").realpath
- assert_equal @new_keg_record.parent.realpath, (HOMEBREW_CELLAR/"oldname").realpath
- assert_equal @new_keg_record.realpath, (HOMEBREW_PINNED_KEGS/"newname").realpath
- assert_equal @new_f.path.to_s, Tab.for_keg(@new_keg_record).source["path"]
- end
-
- def test_unlinik_oldname_opt
- @new_keg_record.mkpath
- old_opt_record = HOMEBREW_PREFIX/"opt/oldname"
- old_opt_record.unlink if old_opt_record.symlink?
- old_opt_record.make_relative_symlink(@new_keg_record)
- @migrator.unlink_oldname_opt
- refute_predicate old_opt_record, :symlink?
- end
-
- def test_unlink_oldname_cellar
- @new_keg_record.mkpath
- @keg.unlink
- @keg.uninstall
- @old_keg_record.parent.make_relative_symlink(@new_keg_record.parent)
- @migrator.unlink_oldname_cellar
- refute_predicate @old_keg_record.parent, :symlink?
- end
-
- def test_backup_oldname_cellar
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @migrator.backup_oldname_cellar
- refute_predicate @old_keg_record.subdirs, :empty?
- end
-
- def test_backup_old_tabs
- tab = Tab.empty
- tab.tabfile = HOMEBREW_CELLAR/"oldname/0.1/INSTALL_RECEIPT.json"
- tab.source["path"] = "/should/be/the/same"
- tab.write
- migrator = Migrator.new(@new_f)
- tab.tabfile.delete
- migrator.backup_old_tabs
- assert_equal "/should/be/the/same", Tab.for_keg(@old_keg_record).source["path"]
- end
-
- # Backup tests are divided into three groups: when oldname Cellar is deleted
- # and when it still exists and when it's a symlink
-
- def check_after_backup
- assert_predicate @old_keg_record.parent, :directory?
- refute_predicate @old_keg_record.parent.subdirs, :empty?
- assert_predicate HOMEBREW_LINKED_KEGS/"oldname", :exist?
- assert_predicate HOMEBREW_PREFIX/"opt/oldname", :exist?
- assert_predicate HOMEBREW_PINNED_KEGS/"oldname", :symlink?
- assert_predicate @keg, :linked?
- end
-
- def test_backup_cellar_exist
- @migrator.backup_oldname
- check_after_backup
- end
-
- def test_backup_cellar_removed
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @migrator.backup_oldname
- check_after_backup
- end
-
- def test_backup_cellar_linked
- @new_keg_record.join("bin").mkpath
- @keg.unlink
- @keg.uninstall
- @old_keg_record.parent.make_relative_symlink(@new_keg_record.parent)
- @migrator.backup_oldname
- check_after_backup
- end
-end
diff --git a/Library/Homebrew/test/missing_test.rb b/Library/Homebrew/test/missing_test.rb
deleted file mode 100644
index 4f20d8a7a..000000000
--- a/Library/Homebrew/test/missing_test.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestMissing < IntegrationCommandTestCase
- def setup
- super
-
- setup_test_formula "foo"
- setup_test_formula "bar"
- end
-
- def make_prefix(name)
- (HOMEBREW_CELLAR/name/"1.0").mkpath
- end
-
- def test_missing_missing
- make_prefix "bar"
-
- assert_match "foo", cmd("missing")
- end
-
- def test_missing_not_missing
- make_prefix "foo"
- make_prefix "bar"
-
- assert_empty cmd("missing")
- end
-
- def test_missing_hide
- make_prefix "foo"
- make_prefix "bar"
-
- assert_match "foo", cmd("missing", "--hide=foo")
- end
-end
diff --git a/Library/Homebrew/test/mpi_requirement_spec.rb b/Library/Homebrew/test/mpi_requirement_spec.rb
new file mode 100644
index 000000000..f32b27993
--- /dev/null
+++ b/Library/Homebrew/test/mpi_requirement_spec.rb
@@ -0,0 +1,14 @@
+require "requirements/mpi_requirement"
+
+describe MPIRequirement do
+ describe "::new" do
+ subject { described_class.new(*(wrappers + tags)) }
+ let(:wrappers) { [:cc, :cxx, :f77] }
+ let(:tags) { [:optional, "some-other-tag"] }
+
+ it "untangles wrappers and tags" do
+ expect(subject.lang_list).to eq(wrappers)
+ expect(subject.tags).to eq(tags)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/mpi_requirement_test.rb b/Library/Homebrew/test/mpi_requirement_test.rb
deleted file mode 100644
index e0f97e8ee..000000000
--- a/Library/Homebrew/test/mpi_requirement_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "testing_env"
-require "requirements/mpi_requirement"
-
-class MPIRequirementTests < Homebrew::TestCase
- def test_initialize_untangles_tags_and_wrapper_symbols
- wrappers = [:cc, :cxx, :f77]
- tags = [:optional, "some-other-tag"]
- dep = MPIRequirement.new(*wrappers + tags)
- assert_equal wrappers, dep.lang_list
- assert_equal tags, dep.tags
- end
-end
diff --git a/Library/Homebrew/test/options_spec.rb b/Library/Homebrew/test/options_spec.rb
new file mode 100644
index 000000000..a05bb139e
--- /dev/null
+++ b/Library/Homebrew/test/options_spec.rb
@@ -0,0 +1,148 @@
+require "options"
+
+describe Option do
+ subject { described_class.new("foo") }
+
+ specify "#to_s" do
+ expect(subject.to_s).to eq("--foo")
+ end
+
+ specify "equality" do
+ foo = Option.new("foo")
+ bar = Option.new("bar")
+ expect(subject).to eq(foo)
+ expect(subject).not_to eq(bar)
+ expect(subject).to eql(foo)
+ expect(subject).not_to eql(bar)
+ end
+
+ specify "#description" do
+ expect(subject.description).to be_empty
+ expect(Option.new("foo", "foo").description).to eq("foo")
+ end
+
+ specify "#inspect" do
+ expect(subject.inspect).to eq("#<Option: \"--foo\">")
+ end
+end
+
+describe DeprecatedOption do
+ subject { described_class.new("foo", "bar") }
+
+ specify "#old" do
+ expect(subject.old).to eq("foo")
+ end
+
+ specify "#old_flag" do
+ expect(subject.old_flag).to eq("--foo")
+ end
+
+ specify "#current" do
+ expect(subject.current).to eq("bar")
+ end
+
+ specify "#current_flag" do
+ expect(subject.current_flag).to eq("--bar")
+ end
+
+ specify "equality" do
+ foobar = DeprecatedOption.new("foo", "bar")
+ boofar = DeprecatedOption.new("boo", "far")
+ expect(foobar).to eq(subject)
+ expect(subject).to eq(foobar)
+ expect(boofar).not_to eq(subject)
+ expect(subject).not_to eq(boofar)
+ end
+end
+
+describe Options do
+ it "removes duplicate options" do
+ subject << Option.new("foo")
+ subject << Option.new("foo")
+ expect(subject).to include("--foo")
+ expect(subject.count).to eq(1)
+ end
+
+ it "preserves existing member when adding a duplicate" do
+ a = Option.new("foo", "bar")
+ b = Option.new("foo", "qux")
+ subject << a << b
+ expect(subject.count).to eq(1)
+ expect(subject.first).to be(a)
+ expect(subject.first.description).to eq(a.description)
+ end
+
+ specify "#include?" do
+ subject << Option.new("foo")
+ expect(subject).to include("--foo")
+ expect(subject).to include("foo")
+ expect(subject).to include(Option.new("foo"))
+ end
+
+ describe "#+" do
+ it "returns options" do
+ expect(subject + Options.new).to be_an_instance_of(Options)
+ end
+ end
+
+ describe "#-" do
+ it "returns options" do
+ expect(subject - Options.new).to be_an_instance_of(Options)
+ end
+ end
+
+ specify "#&" do
+ foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
+ options = Options.new << foo << bar
+ subject << foo << baz
+ expect((subject & options).to_a).to eq([foo])
+ end
+
+ specify "#|" do
+ foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
+ options = Options.new << foo << bar
+ subject << foo << baz
+ expect((subject | options).sort).to eq([foo, bar, baz].sort)
+ end
+
+ specify "#*" do
+ subject << Option.new("aa") << Option.new("bb") << Option.new("cc")
+ expect((subject * "XX").split("XX").sort).to eq(%w[--aa --bb --cc])
+ end
+
+ describe "<<" do
+ it "returns itself" do
+ expect(subject << Option.new("foo")).to be subject
+ end
+ end
+
+ specify "#as_flags" do
+ subject << Option.new("foo")
+ expect(subject.as_flags).to eq(%w[--foo])
+ end
+
+ specify "#to_a" do
+ option = Option.new("foo")
+ subject << option
+ expect(subject.to_a).to eq([option])
+ end
+
+ specify "#to_ary" do
+ option = Option.new("foo")
+ subject << option
+ expect(subject.to_ary).to eq([option])
+ end
+
+ specify "::create_with_array" do
+ array = %w[--foo --bar]
+ option1 = Option.new("foo")
+ option2 = Option.new("bar")
+ expect(Options.create(array).sort).to eq([option1, option2].sort)
+ end
+
+ specify "#inspect" do
+ expect(subject.inspect).to eq("#<Options: []>")
+ subject << Option.new("foo")
+ expect(subject.inspect).to eq("#<Options: [#<Option: \"--foo\">]>")
+ end
+end
diff --git a/Library/Homebrew/test/options_test.rb b/Library/Homebrew/test/options_test.rb
deleted file mode 100644
index e7189a604..000000000
--- a/Library/Homebrew/test/options_test.rb
+++ /dev/null
@@ -1,157 +0,0 @@
-require "testing_env"
-require "options"
-require "testing_env"
-
-class IntegrationCommandTestOptions < IntegrationCommandTestCase
- def test_options
- setup_test_formula "testball", <<-EOS.undent
- depends_on "bar" => :recommended
- EOS
-
- assert_equal "--with-foo\n\tBuild with foo\n--without-bar\n\tBuild without bar support",
- cmd_output("options", "testball").chomp
- end
-end
-
-class OptionTests < Homebrew::TestCase
- def setup
- @option = Option.new("foo")
- end
-
- def test_to_s
- assert_equal "--foo", @option.to_s
- end
-
- def test_equality
- foo = Option.new("foo")
- bar = Option.new("bar")
- assert_equal foo, @option
- refute_equal bar, @option
- assert_eql @option, foo
- refute_eql @option, bar
- end
-
- def test_description
- assert_empty @option.description
- assert_equal "foo", Option.new("foo", "foo").description
- end
-
- def test_inspect
- assert_equal "#<Option: \"--foo\">", @option.inspect
- end
-end
-
-class DeprecatedOptionTests < Homebrew::TestCase
- def setup
- @deprecated_option = DeprecatedOption.new("foo", "bar")
- end
-
- def test_old
- assert_equal "foo", @deprecated_option.old
- assert_equal "--foo", @deprecated_option.old_flag
- end
-
- def test_current
- assert_equal "bar", @deprecated_option.current
- assert_equal "--bar", @deprecated_option.current_flag
- end
-
- def test_equality
- foobar = DeprecatedOption.new("foo", "bar")
- boofar = DeprecatedOption.new("boo", "far")
- assert_equal foobar, @deprecated_option
- refute_equal boofar, @deprecated_option
- assert_eql @deprecated_option, foobar
- refute_eql @deprecated_option, boofar
- end
-end
-
-class OptionsTests < Homebrew::TestCase
- def setup
- @options = Options.new
- end
-
- def test_no_duplicate_options
- @options << Option.new("foo")
- @options << Option.new("foo")
- assert_includes @options, "--foo"
- assert_equal 1, @options.count
- end
-
- def test_preserves_existing_member_when_pushing_duplicate
- a = Option.new("foo", "bar")
- b = Option.new("foo", "qux")
- @options << a << b
- assert_equal 1, @options.count
- assert_same a, @options.first
- assert_equal a.description, @options.first.description
- end
-
- def test_include
- @options << Option.new("foo")
- assert_includes @options, "--foo"
- assert_includes @options, "foo"
- assert_includes @options, Option.new("foo")
- end
-
- def test_union_returns_options
- assert_instance_of Options, @options + Options.new
- end
-
- def test_difference_returns_options
- assert_instance_of Options, @options - Options.new
- end
-
- def test_shovel_returns_self
- assert_same @options, @options << Option.new("foo")
- end
-
- def test_as_flags
- @options << Option.new("foo")
- assert_equal %w[--foo], @options.as_flags
- end
-
- def test_to_a
- option = Option.new("foo")
- @options << option
- assert_equal [option], @options.to_a
- end
-
- def test_to_ary
- option = Option.new("foo")
- @options << option
- assert_equal [option], @options.to_ary
- end
-
- def test_intersection
- foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
- options = Options.new << foo << bar
- @options << foo << baz
- assert_equal [foo], (@options & options).to_a
- end
-
- def test_set_union
- foo, bar, baz = %w[foo bar baz].map { |o| Option.new(o) }
- options = Options.new << foo << bar
- @options << foo << baz
- assert_equal [foo, bar, baz].sort, (@options | options).sort
- end
-
- def test_times
- @options << Option.new("aa") << Option.new("bb") << Option.new("cc")
- assert_equal %w[--aa --bb --cc], (@options * "XX").split("XX").sort
- end
-
- def test_create_with_array
- array = %w[--foo --bar]
- option1 = Option.new("foo")
- option2 = Option.new("bar")
- assert_equal [option1, option2].sort, Options.create(array).sort
- end
-
- def test_inspect
- assert_equal "#<Options: []>", @options.inspect
- @options << Option.new("foo")
- assert_equal "#<Options: [#<Option: \"--foo\">]>", @options.inspect
- end
-end
diff --git a/Library/Homebrew/test/os/mac/blacklist_test.rb b/Library/Homebrew/test/os/mac/blacklist_test.rb
deleted file mode 100644
index 26dd84ed9..000000000
--- a/Library/Homebrew/test/os/mac/blacklist_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "testing_env"
-require "blacklist"
-
-class OSMacBlacklistTests < Homebrew::TestCase
- def assert_blacklisted(s)
- assert blacklisted?(s), "'#{s}' should be blacklisted"
- end
-
- def test_xcode
- %w[xcode Xcode].each { |s| assert_blacklisted s }
- end
-end
diff --git a/Library/Homebrew/test/os/mac/bottle_collector_test.rb b/Library/Homebrew/test/os/mac/bottle_collector_test.rb
deleted file mode 100644
index 2f88050ae..000000000
--- a/Library/Homebrew/test/os/mac/bottle_collector_test.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require "testing_env"
-require "utils/bottles"
-
-class OSMacBottleCollectorTests < Homebrew::TestCase
- def setup
- @collector = Utils::Bottles::Collector.new
- end
-
- def checksum_for(tag)
- @collector.fetch_checksum_for(tag)
- end
-
- def test_collector_finds_or_later_tags
- @collector[:lion_or_later] = "foo"
- assert_equal ["foo", :lion_or_later], checksum_for(:mountain_lion)
- assert_nil checksum_for(:snow_leopard)
- end
-
- def test_collector_finds_altivec_tags
- @collector[:tiger_altivec] = "foo"
- assert_equal ["foo", :tiger_altivec], checksum_for(:tiger_g4)
- assert_equal ["foo", :tiger_altivec], checksum_for(:tiger_g4e)
- assert_equal ["foo", :tiger_altivec], checksum_for(:tiger_g5)
- assert_nil checksum_for(:tiger_g3)
- end
-end
diff --git a/Library/Homebrew/test/os/mac/bottle_tag_test.rb b/Library/Homebrew/test/os/mac/bottle_tag_test.rb
deleted file mode 100644
index 996bd4d53..000000000
--- a/Library/Homebrew/test/os/mac/bottle_tag_test.rb
+++ /dev/null
@@ -1,79 +0,0 @@
-require "testing_env"
-require "utils/bottles"
-
-class OSMacBottleTagTests < Homebrew::TestCase
- def test_tag_tiger_ppc
- MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
- Hardware::CPU.stubs(:type).returns(:ppc)
- Hardware::CPU.stubs(:family).returns(:foo)
- MacOS.stubs(:prefer_64_bit?).returns(false)
- assert_equal :tiger_foo, Utils::Bottles.tag
- end
-
- def test_tag_tiger_intel
- MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
- Hardware::CPU.stubs(:type).returns(:intel)
- MacOS.stubs(:prefer_64_bit?).returns(false)
- assert_equal :tiger, Utils::Bottles.tag
- end
-
- def test_tag_tiger_ppc_64
- MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
- Hardware::CPU.stubs(:type).returns(:ppc)
- Hardware::CPU.stubs(:family).returns(:g5)
- MacOS.stubs(:prefer_64_bit?).returns(true)
- assert_equal :tiger_g5_64, Utils::Bottles.tag
- end
-
- # Note that this will probably never be used
- def test_tag_tiger_intel_64
- MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
- Hardware::CPU.stubs(:type).returns(:intel)
- MacOS.stubs(:prefer_64_bit?).returns(true)
- assert_equal :tiger_64, Utils::Bottles.tag
- end
-
- def test_tag_leopard_intel
- MacOS.stubs(:version).returns(MacOS::Version.new("10.5"))
- Hardware::CPU.stubs(:type).returns(:intel)
- MacOS.stubs(:prefer_64_bit?).returns(false)
- assert_equal :leopard, Utils::Bottles.tag
- end
-
- def test_tag_leopard_ppc_64
- MacOS.stubs(:version).returns(MacOS::Version.new("10.5"))
- Hardware::CPU.stubs(:type).returns(:ppc)
- Hardware::CPU.stubs(:family).returns(:g5)
- MacOS.stubs(:prefer_64_bit?).returns(true)
- assert_equal :leopard_g5_64, Utils::Bottles.tag
- end
-
- def test_tag_leopard_intel_64
- MacOS.stubs(:version).returns(MacOS::Version.new("10.5"))
- Hardware::CPU.stubs(:type).returns(:intel)
- MacOS.stubs(:prefer_64_bit?).returns(true)
- assert_equal :leopard_64, Utils::Bottles.tag
- end
-
- def test_tag_snow_leopard_32
- MacOS.stubs(:version).returns(MacOS::Version.new("10.6"))
- Hardware::CPU.stubs(:is_64_bit?).returns(false)
- assert_equal :snow_leopard_32, Utils::Bottles.tag
- end
-
- def test_tag_snow_leopard_64
- MacOS.stubs(:version).returns(MacOS::Version.new("10.6"))
- Hardware::CPU.stubs(:is_64_bit?).returns(true)
- assert_equal :snow_leopard, Utils::Bottles.tag
- end
-
- def test_tag_lion
- MacOS.stubs(:version).returns(MacOS::Version.new("10.7"))
- assert_equal :lion, Utils::Bottles.tag
- end
-
- def test_tag_mountain_lion
- MacOS.stubs(:version).returns(MacOS::Version.new("10.8"))
- assert_equal :mountain_lion, Utils::Bottles.tag
- end
-end
diff --git a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb
new file mode 100644
index 000000000..21b15cd99
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb
@@ -0,0 +1,50 @@
+require "dependency_collector"
+
+RSpec::Matchers.alias_matcher :need_tar_xz_dependency, :be_tar_needs_xz_dependency
+
+describe DependencyCollector do
+ after(:each) do
+ described_class.clear_cache
+ end
+
+ specify "#tar_needs_xz_dependency?" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.9"))
+ expect(described_class).not_to need_tar_xz_dependency
+ end
+
+ specify "LD64 pre-Leopard dependency" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ expect(subject.build(:ld64)).to eq(LD64Dependency.new)
+ end
+
+ specify "LD64 Leopard or newer dependency" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
+ expect(subject.build(:ld64)).to be nil
+ end
+
+ specify "ant Mavericks or newer dependency" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.9"))
+ subject.add ant: :build
+ expect(subject.deps.find { |dep| dep.name == "ant" }).to eq(Dependency.new("ant", [:build]))
+ end
+
+ specify "ant pre-Mavericks dependency" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.7"))
+ subject.add ant: :build
+ expect(subject.deps.find { |dep| dep.name == "ant" }).to be nil
+ end
+
+ specify "Resource xz pre-Mavericks dependency" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.8"))
+ resource = Resource.new
+ resource.url("http://example.com/foo.tar.xz")
+ expect(subject.add(resource)).to eq(Dependency.new("xz", [:build]))
+ end
+
+ specify "Resource xz Mavericks or newer dependency" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.9"))
+ resource = Resource.new
+ resource.url("http://example.com/foo.tar.xz")
+ expect(subject.add(resource)).to be nil
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/dependency_collector_test.rb b/Library/Homebrew/test/os/mac/dependency_collector_test.rb
deleted file mode 100644
index 4fdf3ebe4..000000000
--- a/Library/Homebrew/test/os/mac/dependency_collector_test.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-require "testing_env"
-require "dependency_collector"
-
-class OSMacDependencyCollectorTests < Homebrew::TestCase
- def find_dependency(name)
- @d.deps.find { |dep| dep.name == name }
- end
-
- def setup
- @d = DependencyCollector.new
- end
-
- def teardown
- DependencyCollector.clear_cache
- end
-
- def test_tar_needs_xz_dependency
- MacOS.stubs(:version).returns(MacOS::Version.new("10.9"))
- refute DependencyCollector.tar_needs_xz_dependency?
- end
-
- def test_ld64_dep_pre_leopard
- MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
- assert_equal LD64Dependency.new, @d.build(:ld64)
- end
-
- def test_ld64_dep_leopard_or_newer
- MacOS.stubs(:version).returns(MacOS::Version.new("10.5"))
- assert_nil @d.build(:ld64)
- end
-
- def test_ant_dep_mavericks_or_newer
- MacOS.stubs(:version).returns(MacOS::Version.new("10.9"))
- @d.add ant: :build
- assert_equal find_dependency("ant"), Dependency.new("ant", [:build])
- end
-
- def test_ant_dep_pre_mavericks
- MacOS.stubs(:version).returns(MacOS::Version.new("10.7"))
- @d.add ant: :build
- assert_nil find_dependency("ant")
- end
-
- def test_resource_dep_xz_pre_mavericks
- MacOS.stubs(:version).returns(MacOS::Version.new("10.8"))
- resource = Resource.new
- resource.url("http://example.com/foo.tar.xz")
- assert_equal Dependency.new("xz", [:build]), @d.add(resource)
- end
-
- def test_resource_dep_xz_mavericks_or_newer
- MacOS.stubs(:version).returns(MacOS::Version.new("10.9"))
- resource = Resource.new
- resource.url("http://example.com/foo.tar.xz")
- assert_nil @d.add(resource)
- end
-end
diff --git a/Library/Homebrew/test/os/mac/diagnostic_spec.rb b/Library/Homebrew/test/os/mac/diagnostic_spec.rb
new file mode 100644
index 000000000..d2b38a332
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/diagnostic_spec.rb
@@ -0,0 +1,42 @@
+require "diagnostic"
+
+describe Homebrew::Diagnostic::Checks do
+ specify "#check_for_other_package_managers" do
+ allow(MacOS).to receive(:macports_or_fink).and_return(["fink"])
+ expect(subject.check_for_other_package_managers)
+ .to match("You have MacPorts or Fink installed:")
+ end
+
+ specify "#check_for_unsupported_macos" do
+ ENV.delete("HOMEBREW_DEVELOPER")
+ allow(OS::Mac).to receive(:prerelease?).and_return(true)
+
+ expect(subject.check_for_unsupported_macos)
+ .to match("We do not provide support for this pre-release version.")
+ end
+
+ specify "#check_for_unsupported_curl_vars" do
+ allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.10"))
+ ENV["SSL_CERT_DIR"] = "/some/path"
+
+ expect(subject.check_for_unsupported_curl_vars)
+ .to match("SSL_CERT_DIR support was removed from Apple's curl.")
+ end
+
+ specify "#check_for_beta_xquartz" do
+ allow(MacOS::XQuartz).to receive(:version).and_return("2.7.10_beta2")
+
+ expect(subject.check_for_beta_xquartz)
+ .to match("The following beta release of XQuartz is installed: 2.7.10_beta2")
+ end
+
+ specify "#check_xcode_8_without_clt_on_el_capitan" do
+ allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.11"))
+ allow(MacOS::Xcode).to receive(:installed?).and_return(true)
+ allow(MacOS::Xcode).to receive(:version).and_return("8.0")
+ allow(MacOS::Xcode).to receive(:without_clt?).and_return(true)
+
+ expect(subject.check_xcode_8_without_clt_on_el_capitan)
+ .to match("You have Xcode 8 installed without the CLT")
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/diagnostic_test.rb b/Library/Homebrew/test/os/mac/diagnostic_test.rb
deleted file mode 100644
index 655aa1d46..000000000
--- a/Library/Homebrew/test/os/mac/diagnostic_test.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require "testing_env"
-require "fileutils"
-require "pathname"
-require "diagnostic"
-
-class OSMacDiagnosticChecksTest < Homebrew::TestCase
- def setup
- @env = ENV.to_hash
- @checks = Homebrew::Diagnostic::Checks.new
- end
-
- def teardown
- ENV.replace(@env)
- end
-
- def test_check_for_other_package_managers
- MacOS.stubs(:macports_or_fink).returns ["fink"]
- assert_match "You have MacPorts or Fink installed:",
- @checks.check_for_other_package_managers
- end
-
- def test_check_for_unsupported_macos
- ARGV.stubs(:homebrew_developer?).returns false
- OS::Mac.stubs(:prerelease?).returns true
- assert_match "We do not provide support for this pre-release version.",
- @checks.check_for_unsupported_macos
- end
-
- def test_check_for_unsupported_curl_vars
- MacOS.stubs(:version).returns OS::Mac::Version.new("10.10")
- ENV["SSL_CERT_DIR"] = "/some/path"
-
- assert_match "SSL_CERT_DIR support was removed from Apple's curl.",
- @checks.check_for_unsupported_curl_vars
- end
-
- def test_check_for_beta_xquartz
- MacOS::XQuartz.stubs(:version).returns("2.7.10_beta2")
- assert_match "The following beta release of XQuartz is installed: 2.7.10_beta2", @checks.check_for_beta_xquartz
- end
-
- def test_check_xcode_8_without_clt_on_el_capitan
- MacOS.stubs(:version).returns OS::Mac::Version.new("10.11")
- MacOS::Xcode.stubs(:installed?).returns true
- MacOS::Xcode.stubs(:version).returns "8.0"
- MacOS::Xcode.stubs(:without_clt?).returns true
- assert_match "You have Xcode 8 installed without the CLT", @checks.check_xcode_8_without_clt_on_el_capitan
- end
-end
diff --git a/Library/Homebrew/test/os/mac/java_requirement_spec.rb b/Library/Homebrew/test/os/mac/java_requirement_spec.rb
new file mode 100644
index 000000000..f6404db92
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/java_requirement_spec.rb
@@ -0,0 +1,34 @@
+require "requirements/java_requirement"
+require "fileutils"
+
+describe JavaRequirement do
+ subject { described_class.new(%w[1.8]) }
+ let(:java_home) { Dir.mktmpdir }
+ let(:java_home_path) { Pathname.new(java_home) }
+
+ before(:each) do
+ FileUtils.mkdir java_home_path/"bin"
+ FileUtils.touch java_home_path/"bin/java"
+ allow(subject).to receive(:preferred_java).and_return(java_home_path/"bin/java")
+ expect(subject).to be_satisfied
+ end
+
+ after(:each) { java_home_path.rmtree }
+
+ specify "Apple Java environment" do
+ expect(ENV).to receive(:prepend_path)
+ expect(ENV).to receive(:append_to_cflags)
+
+ subject.modify_build_environment
+ expect(ENV["JAVA_HOME"]).to eq(java_home)
+ end
+
+ specify "Oracle Java environment" do
+ FileUtils.mkdir java_home_path/"include"
+ expect(ENV).to receive(:prepend_path)
+ expect(ENV).to receive(:append_to_cflags).twice
+
+ subject.modify_build_environment
+ expect(ENV["JAVA_HOME"]).to eq(java_home)
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/keg_spec.rb b/Library/Homebrew/test/os/mac/keg_spec.rb
new file mode 100644
index 000000000..562c2ba6a
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/keg_spec.rb
@@ -0,0 +1,32 @@
+require "keg"
+
+describe Keg do
+ include FileUtils
+
+ subject { described_class.new(keg_path) }
+
+ describe "#mach_o_files" do
+ let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" }
+
+ before(:each) { (keg_path/"lib").mkpath }
+
+ after(:each) { subject.unlink }
+
+ it "skips hardlinks" do
+ cp dylib_path("i386"), keg_path/"lib/i386.dylib"
+ ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib"
+
+ subject.link
+ expect(subject.mach_o_files.count).to eq(1)
+ end
+
+ it "isn't confused by symlinks" do
+ cp dylib_path("i386"), keg_path/"lib/i386.dylib"
+ ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib"
+ ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib"
+
+ subject.link
+ expect(subject.mach_o_files.count).to eq(1)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/keg_test.rb b/Library/Homebrew/test/os/mac/keg_test.rb
deleted file mode 100644
index e79cbc921..000000000
--- a/Library/Homebrew/test/os/mac/keg_test.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require "testing_env"
-require "keg"
-require "stringio"
-
-class OSMacLinkTests < Homebrew::TestCase
- include FileUtils
-
- def setup
- keg = HOMEBREW_CELLAR.join("foo", "1.0")
- keg.join("bin").mkpath
-
- %w[hiworld helloworld goodbye_cruel_world].each do |file|
- touch keg.join("bin", file)
- end
-
- @keg = Keg.new(keg)
- @dst = HOMEBREW_PREFIX.join("bin", "helloworld")
- @nonexistent = Pathname.new("/some/nonexistent/path")
-
- @mode = OpenStruct.new
-
- @old_stdout = $stdout
- $stdout = StringIO.new
-
- mkpath HOMEBREW_PREFIX/"bin"
- mkpath HOMEBREW_PREFIX/"lib"
- end
-
- def teardown
- @keg.unlink
- @keg.uninstall
-
- $stdout = @old_stdout
-
- rmtree HOMEBREW_PREFIX/"bin"
- rmtree HOMEBREW_PREFIX/"lib"
- end
-
- def test_mach_o_files_skips_hardlinks
- a = HOMEBREW_CELLAR/"a/1.0"
- (a/"lib").mkpath
- FileUtils.cp dylib_path("i386"), a/"lib/i386.dylib"
- FileUtils.ln a/"lib/i386.dylib", a/"lib/i386_link.dylib"
-
- keg = Keg.new(a)
- keg.link
-
- assert_equal 1, keg.mach_o_files.size
- ensure
- keg.unlink
- keg.uninstall
- end
-
- def test_mach_o_files_isnt_confused_by_symlinks
- a = HOMEBREW_CELLAR/"a/1.0"
- (a/"lib").mkpath
- FileUtils.cp dylib_path("i386"), a/"lib/i386.dylib"
- FileUtils.ln a/"lib/i386.dylib", a/"lib/i386_link.dylib"
- FileUtils.ln_s a/"lib/i386.dylib", a/"lib/1.dylib"
-
- keg = Keg.new(a)
- keg.link
-
- assert_equal 1, keg.mach_o_files.size
- ensure
- keg.unlink
- keg.uninstall
- end
-end
diff --git a/Library/Homebrew/test/os/mac/language_test.rb b/Library/Homebrew/test/os/mac/language_test.rb
deleted file mode 100644
index e328db5e0..000000000
--- a/Library/Homebrew/test/os/mac/language_test.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require "testing_env"
-require "locale"
-require "os/mac"
-
-class OSMacLanguageTests < Homebrew::TestCase
- def test_languages_format
- OS::Mac.languages.each do |language|
- assert_nothing_raised do
- Locale.parse(language)
- end
- end
- end
-
- def test_language_format
- assert_nothing_raised do
- Locale.parse(OS::Mac.language)
- end
- end
-end
diff --git a/Library/Homebrew/test/os/mac/mach_spec.rb b/Library/Homebrew/test/os/mac/mach_spec.rb
new file mode 100644
index 000000000..5c9aafcbb
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/mach_spec.rb
@@ -0,0 +1,198 @@
+describe "Mach-O Pathname tests" do
+ specify "fat dylib" do
+ pn = dylib_path("fat")
+ expect(pn).to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn.arch).to eq(:universal)
+ end
+
+ specify "i386 dylib" do
+ pn = dylib_path("i386")
+ expect(pn).not_to be_universal
+ expect(pn).to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn).not_to be_mach_o_bundle
+ end
+
+ specify "x86_64 dylib" do
+ pn = dylib_path("x86_64")
+ expect(pn).not_to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn).not_to be_mach_o_bundle
+ end
+
+ specify "Mach-O executable" do
+ pn = Pathname.new("#{TEST_FIXTURE_DIR}/mach/a.out")
+ expect(pn).to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn).not_to be_mach_o_bundle
+ end
+
+ specify "fat bundle" do
+ pn = bundle_path("fat")
+ expect(pn).to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn).to be_mach_o_bundle
+ end
+
+ specify "i386 bundle" do
+ pn = bundle_path("i386")
+ expect(pn).not_to be_universal
+ expect(pn).to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn).to be_mach_o_bundle
+ end
+
+ specify "x86_64 bundle" do
+ pn = bundle_path("x86_64")
+ expect(pn).not_to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn).to be_mach_o_bundle
+ end
+
+ specify "non-Mach-O" do
+ pn = Pathname.new("#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz")
+ expect(pn).not_to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn).not_to be_mach_o_bundle
+ expect(pn.arch).to eq(:dunno)
+ end
+end
+
+describe ArchitectureListExtension do
+ let(:archs) { [:i386, :x86_64, :ppc7400, :ppc64].extend(described_class) }
+
+ specify "universal checks" do
+ expect(archs).to be_universal
+ expect(archs).to be_intel_universal
+ expect(archs).to be_ppc_universal
+ expect(archs).to be_cross_universal
+ expect(archs).to be_fat
+
+ non_universal = [:i386].extend(described_class)
+ expect(non_universal).not_to be_universal
+
+ intel_only = [:i386, :x86_64].extend(described_class)
+ expect(intel_only).to be_universal
+ expect(intel_only).not_to be_ppc_universal
+ expect(intel_only).not_to be_cross_universal
+
+ ppc_only = [:ppc970, :ppc64].extend(described_class)
+ expect(ppc_only).to be_universal
+ expect(ppc_only).not_to be_intel_universal
+ expect(ppc_only).not_to be_cross_universal
+
+ cross = [:ppc7400, :i386].extend(described_class)
+ expect(cross).to be_universal
+ expect(cross).not_to be_intel_universal
+ expect(cross).not_to be_ppc_universal
+ end
+
+ specify "messaging flags" do
+ archs.remove_ppc!
+ expect(archs.length).to eq(2)
+ expect(archs.as_arch_flags).to match(/-arch i386/)
+ expect(archs.as_arch_flags).to match(/-arch x86_64/)
+ end
+
+ specify "architecture flags" do
+ pn = dylib_path("fat")
+ expect(pn.archs).to be_intel_universal
+ expect(pn.archs.as_arch_flags).to eq("-arch x86_64 -arch i386")
+ expect(pn.archs.as_cmake_arch_flags).to eq("x86_64;i386")
+ end
+end
+
+describe "text executables" do
+ let(:pn) { HOMEBREW_PREFIX/"an_executable" }
+
+ after(:each) { pn.unlink }
+
+ specify "simple shebang" do
+ pn.write "#!/bin/sh"
+ expect(pn).not_to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).to be_text_executable
+ expect(pn.archs).to eq([])
+ expect(pn.arch).to eq(:dunno)
+ end
+
+ specify "shebang with options" do
+ pn.write "#! /usr/bin/perl -w"
+ expect(pn).not_to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).to be_text_executable
+ expect(pn.archs).to eq([])
+ expect(pn.arch).to eq(:dunno)
+ end
+
+ specify "malformed shebang" do
+ pn.write " #!"
+ expect(pn).not_to be_universal
+ expect(pn).not_to be_i386
+ expect(pn).not_to be_x86_64
+ expect(pn).not_to be_ppc7400
+ expect(pn).not_to be_ppc64
+ expect(pn).not_to be_dylib
+ expect(pn).not_to be_mach_o_executable
+ expect(pn).not_to be_text_executable
+ expect(pn.archs).to eq([])
+ expect(pn.arch).to eq(:dunno)
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/mach_test.rb b/Library/Homebrew/test/os/mac/mach_test.rb
deleted file mode 100644
index a42f7316b..000000000
--- a/Library/Homebrew/test/os/mac/mach_test.rb
+++ /dev/null
@@ -1,208 +0,0 @@
-require "testing_env"
-
-class MachOPathnameTests < Homebrew::TestCase
- def test_fat_dylib
- pn = dylib_path("fat")
- assert_predicate pn, :universal?
- refute_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- assert_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- assert_equal :universal, pn.arch
- end
-
- def test_i386_dylib
- pn = dylib_path("i386")
- refute_predicate pn, :universal?
- assert_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- assert_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- refute_predicate pn, :mach_o_bundle?
- end
-
- def test_x86_64_dylib
- pn = dylib_path("x86_64")
- refute_predicate pn, :universal?
- refute_predicate pn, :i386?
- assert_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- assert_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- refute_predicate pn, :mach_o_bundle?
- end
-
- def test_mach_o_executable
- pn = Pathname.new("#{TEST_FIXTURE_DIR}/mach/a.out")
- assert_predicate pn, :universal?
- refute_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- assert_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- refute_predicate pn, :mach_o_bundle?
- end
-
- def test_fat_bundle
- pn = bundle_path("fat")
- assert_predicate pn, :universal?
- refute_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- assert_predicate pn, :mach_o_bundle?
- end
-
- def test_i386_bundle
- pn = bundle_path("i386")
- refute_predicate pn, :universal?
- assert_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- assert_predicate pn, :mach_o_bundle?
- end
-
- def test_x86_64_bundle
- pn = bundle_path("x86_64")
- refute_predicate pn, :universal?
- refute_predicate pn, :i386?
- assert_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- assert_predicate pn, :mach_o_bundle?
- end
-
- def test_non_mach_o
- pn = Pathname.new("#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz")
- refute_predicate pn, :universal?
- refute_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- refute_predicate pn, :mach_o_bundle?
- assert_equal :dunno, pn.arch
- end
-end
-
-class ArchitectureListExtensionTests < MachOPathnameTests
- def setup
- @archs = [:i386, :x86_64, :ppc7400, :ppc64].extend(ArchitectureListExtension)
- end
-
- def test_architecture_list_extension_universal_checks
- assert_predicate @archs, :universal?
- assert_predicate @archs, :intel_universal?
- assert_predicate @archs, :ppc_universal?
- assert_predicate @archs, :cross_universal?
- assert_predicate @archs, :fat?
-
- non_universal = [:i386].extend ArchitectureListExtension
- refute_predicate non_universal, :universal?
-
- intel_only = [:i386, :x86_64].extend ArchitectureListExtension
- assert_predicate intel_only, :universal?
- refute_predicate intel_only, :ppc_universal?
- refute_predicate intel_only, :cross_universal?
-
- ppc_only = [:ppc970, :ppc64].extend ArchitectureListExtension
- assert_predicate ppc_only, :universal?
- refute_predicate ppc_only, :intel_universal?
- refute_predicate ppc_only, :cross_universal?
-
- cross = [:ppc7400, :i386].extend ArchitectureListExtension
- assert_predicate cross, :universal?
- refute_predicate cross, :intel_universal?
- refute_predicate cross, :ppc_universal?
- end
-
- def test_architecture_list_extension_massaging_flags
- @archs.remove_ppc!
- assert_equal 2, @archs.length
- assert_match(/-arch i386/, @archs.as_arch_flags)
- assert_match(/-arch x86_64/, @archs.as_arch_flags)
- end
-
- def test_architecture_list_arch_flags_methods
- pn = dylib_path("fat")
- assert_predicate pn.archs, :intel_universal?
- assert_equal "-arch x86_64 -arch i386", pn.archs.as_arch_flags
- assert_equal "x86_64;i386", pn.archs.as_cmake_arch_flags
- end
-end
-
-class TextExecutableTests < Homebrew::TestCase
- attr_reader :pn
-
- def setup
- @pn = HOMEBREW_PREFIX.join("an_executable")
- end
-
- def teardown
- HOMEBREW_PREFIX.join("an_executable").unlink
- end
-
- def test_simple_shebang
- pn.write "#!/bin/sh"
- refute_predicate pn, :universal?
- refute_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- assert_predicate pn, :text_executable?
- assert_equal [], pn.archs
- assert_equal :dunno, pn.arch
- end
-
- def test_shebang_with_options
- pn.write "#! /usr/bin/perl -w"
- refute_predicate pn, :universal?
- refute_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- assert_predicate pn, :text_executable?
- assert_equal [], pn.archs
- assert_equal :dunno, pn.arch
- end
-
- def test_malformed_shebang
- pn.write " #!"
- refute_predicate pn, :universal?
- refute_predicate pn, :i386?
- refute_predicate pn, :x86_64?
- refute_predicate pn, :ppc7400?
- refute_predicate pn, :ppc64?
- refute_predicate pn, :dylib?
- refute_predicate pn, :mach_o_executable?
- refute_predicate pn, :text_executable?
- assert_equal [], pn.archs
- assert_equal :dunno, pn.arch
- end
-end
diff --git a/Library/Homebrew/test/os/mac/version_spec.rb b/Library/Homebrew/test/os/mac/version_spec.rb
new file mode 100644
index 000000000..797207b67
--- /dev/null
+++ b/Library/Homebrew/test/os/mac/version_spec.rb
@@ -0,0 +1,51 @@
+require "version"
+require "os/mac/version"
+
+describe OS::Mac::Version do
+ subject { described_class.new("10.7") }
+
+ specify "comparison with Symbol" do
+ expect(subject).to be > :snow_leopard
+ expect(subject).to be == :lion
+ expect(subject).to be === :lion # rubocop:disable Style/CaseEquality
+ expect(subject).to be < :mountain_lion
+ end
+
+ specify "comparison with Fixnum" do
+ expect(subject).to be > 10
+ expect(subject).to be < 11
+ end
+
+ specify "comparison with Float" do
+ expect(subject).to be > 10.6
+ expect(subject).to be == 10.7
+ expect(subject).to be === 10.7 # rubocop:disable Style/CaseEquality
+ expect(subject).to be < 10.8
+ end
+
+ specify "comparison with String" do
+ expect(subject).to be > "10.6"
+ expect(subject).to be == "10.7"
+ expect(subject).to be === "10.7" # rubocop:disable Style/CaseEquality
+ expect(subject).to be < "10.8"
+ end
+
+ specify "comparison with Version" do
+ expect(subject).to be > Version.create("10.6")
+ expect(subject).to be == Version.create("10.7")
+ expect(subject).to be === Version.create("10.7") # rubocop:disable Style/CaseEquality
+ expect(subject).to be < Version.create("10.8")
+ end
+
+ specify "#from_symbol" do
+ expect(described_class.from_symbol(:lion)).to eq(subject)
+ expect { described_class.from_symbol(:foo) }
+ .to raise_error(ArgumentError)
+ end
+
+ specify "#pretty_name" do
+ expect(described_class.new("10.11").pretty_name).to eq("El Capitan")
+ expect(described_class.new("10.8").pretty_name).to eq("Mountain Lion")
+ expect(described_class.new("10.10").pretty_name).to eq("Yosemite")
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/version_test.rb b/Library/Homebrew/test/os/mac/version_test.rb
deleted file mode 100644
index f702c7097..000000000
--- a/Library/Homebrew/test/os/mac/version_test.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require "testing_env"
-require "version"
-require "os/mac/version"
-
-class OSMacVersionTests < Homebrew::TestCase
- def setup
- @v = MacOS::Version.new("10.7")
- end
-
- def test_compare_with_symbol
- assert_operator @v, :>, :snow_leopard
- assert_operator @v, :==, :lion
- assert_operator @v, :===, :lion
- assert_operator @v, :<, :mountain_lion
- end
-
- def test_compare_with_fixnum
- assert_operator @v, :>, 10
- assert_operator @v, :<, 11
- end
-
- def test_compare_with_float
- assert_operator @v, :>, 10.6
- assert_operator @v, :==, 10.7
- assert_operator @v, :===, 10.7
- assert_operator @v, :<, 10.8
- end
-
- def test_compare_with_string
- assert_operator @v, :>, "10.6"
- assert_operator @v, :==, "10.7"
- assert_operator @v, :===, "10.7"
- assert_operator @v, :<, "10.8"
- end
-
- def test_compare_with_version
- assert_operator @v, :>, Version.create("10.6")
- assert_operator @v, :==, Version.create("10.7")
- assert_operator @v, :===, Version.create("10.7")
- assert_operator @v, :<, Version.create("10.8")
- end
-
- def test_from_symbol
- assert_equal @v, MacOS::Version.from_symbol(:lion)
- assert_raises(ArgumentError) { MacOS::Version.from_symbol(:foo) }
- end
-
- def test_pretty_name
- assert_equal "El Capitan", MacOS::Version.new("10.11").pretty_name
- assert_equal "Mountain Lion", MacOS::Version.new("10.8").pretty_name
- assert_equal "Yosemite", MacOS::Version.new("10.10").pretty_name
- end
-end
diff --git a/Library/Homebrew/test/os/mac_spec.rb b/Library/Homebrew/test/os/mac_spec.rb
new file mode 100644
index 000000000..641782451
--- /dev/null
+++ b/Library/Homebrew/test/os/mac_spec.rb
@@ -0,0 +1,22 @@
+require "locale"
+require "os/mac"
+
+describe OS::Mac do
+ describe "::languages" do
+ specify "all languages can be parsed by Locale::parse" do
+ subject.languages.each do |language|
+ expect { Locale.parse(language) }.not_to raise_error
+ end
+ end
+ end
+
+ describe "::language" do
+ it "returns the first item from #languages" do
+ expect(subject.language).to eq(subject.languages.first)
+ end
+
+ it "can be parsed by Locale::parse" do
+ expect { Locale.parse(subject.language) }.not_to raise_error
+ end
+ end
+end
diff --git a/Library/Homebrew/test/outdated_test.rb b/Library/Homebrew/test/outdated_test.rb
deleted file mode 100644
index 3e7148ded..000000000
--- a/Library/Homebrew/test/outdated_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestOutdated < IntegrationCommandTestCase
- def test_outdated
- setup_test_formula "testball"
- (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
-
- assert_equal "testball", cmd("outdated")
- end
-end
diff --git a/Library/Homebrew/test/patch_spec.rb b/Library/Homebrew/test/patch_spec.rb
new file mode 100644
index 000000000..22c103662
--- /dev/null
+++ b/Library/Homebrew/test/patch_spec.rb
@@ -0,0 +1,165 @@
+require "patch"
+
+describe Patch do
+ describe "#create" do
+ context "simple patch" do
+ subject { described_class.create(:p2, nil) }
+ it { is_expected.to be_kind_of ExternalPatch }
+ it { is_expected.to be_external }
+ its(:strip) { is_expected.to eq(:p2) }
+ end
+
+ context "string patch" do
+ subject { described_class.create(:p0, "foo") }
+ it { is_expected.to be_kind_of StringPatch }
+ its(:strip) { is_expected.to eq(:p0) }
+ end
+
+ context "string patch without strip" do
+ subject { described_class.create("foo", nil) }
+ it { is_expected.to be_kind_of StringPatch }
+ its(:strip) { is_expected.to eq(:p1) }
+ end
+
+ context "data patch" do
+ subject { described_class.create(:p0, :DATA) }
+ it { is_expected.to be_kind_of DATAPatch }
+ its(:strip) { is_expected.to eq(:p0) }
+ end
+
+ context "data patch without strip" do
+ subject { described_class.create(:DATA, nil) }
+ it { is_expected.to be_kind_of DATAPatch }
+ its(:strip) { is_expected.to eq(:p1) }
+ end
+
+ it "raises an error for unknown values" do
+ expect {
+ described_class.create(Object.new)
+ }.to raise_error(ArgumentError)
+
+ expect {
+ described_class.create(Object.new, Object.new)
+ }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "#patch_files" do
+ subject { described_class.create(:p2, nil) }
+
+ context "empty patch" do
+ its(:resource) { is_expected.to be_kind_of Resource::Patch }
+ its(:patch_files) { is_expected.to eq(subject.resource.patch_files) }
+ its(:patch_files) { is_expected.to eq([]) }
+ end
+
+ it "returns applied patch files" do
+ subject.resource.apply("patch1.diff")
+ expect(subject.patch_files).to eq(["patch1.diff"])
+
+ subject.resource.apply("patch2.diff", "patch3.diff")
+ expect(subject.patch_files).to eq(["patch1.diff", "patch2.diff", "patch3.diff"])
+
+ subject.resource.apply(["patch4.diff", "patch5.diff"])
+ expect(subject.patch_files.count).to eq(5)
+
+ subject.resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff")
+ expect(subject.patch_files.count).to eq(7)
+ end
+ end
+
+ describe "#normalize_legacy_patches" do
+ it "can create a patch from a single string" do
+ patches = described_class.normalize_legacy_patches("http://example.com/patch.diff")
+ expect(patches.length).to eq(1)
+ expect(patches.first.strip).to eq(:p1)
+ end
+
+ it "can create patches from an array" do
+ patches = described_class.normalize_legacy_patches(
+ %w[http://example.com/patch1.diff http://example.com/patch2.diff],
+ )
+
+ expect(patches.length).to eq(2)
+ expect(patches[0].strip).to eq(:p1)
+ expect(patches[1].strip).to eq(:p1)
+ end
+
+ it "can create patches from a :p0 hash" do
+ patches = Patch.normalize_legacy_patches(
+ p0: "http://example.com/patch.diff",
+ )
+
+ expect(patches.length).to eq(1)
+ expect(patches.first.strip).to eq(:p0)
+ end
+
+ it "can create patches from a :p1 hash" do
+ patches = Patch.normalize_legacy_patches(
+ p1: "http://example.com/patch.diff",
+ )
+
+ expect(patches.length).to eq(1)
+ expect(patches.first.strip).to eq(:p1)
+ end
+
+ it "can create patches from a mixed hash" do
+ patches = Patch.normalize_legacy_patches(
+ p1: "http://example.com/patch1.diff",
+ p0: "http://example.com/patch0.diff",
+ )
+
+ expect(patches.length).to eq(2)
+ expect(patches.count { |p| p.strip == :p0 }).to eq(1)
+ expect(patches.count { |p| p.strip == :p1 }).to eq(1)
+ end
+
+ it "can create patches from a mixed hash with array" do
+ patches = Patch.normalize_legacy_patches(
+ p1: [
+ "http://example.com/patch10.diff",
+ "http://example.com/patch11.diff",
+ ],
+ p0: [
+ "http://example.com/patch00.diff",
+ "http://example.com/patch01.diff",
+ ],
+ )
+
+ expect(patches.length).to eq(4)
+ expect(patches.count { |p| p.strip == :p0 }).to eq(2)
+ expect(patches.count { |p| p.strip == :p1 }).to eq(2)
+ end
+
+ it "returns an empty array if given nil" do
+ expect(Patch.normalize_legacy_patches(nil)).to be_empty
+ end
+ end
+end
+
+describe EmbeddedPatch do
+ describe "#new" do
+ subject { described_class.new(:p1) }
+ its(:inspect) { is_expected.to eq("#<EmbeddedPatch: :p1>") }
+ end
+end
+
+describe ExternalPatch do
+ subject { described_class.new(:p1) { url "file:///my.patch" } }
+
+ describe "#url" do
+ its(:url) { is_expected.to eq("file:///my.patch") }
+ end
+
+ describe "#inspect" do
+ its(:inspect) { is_expected.to eq('#<ExternalPatch: :p1 "file:///my.patch">') }
+ end
+
+ describe "#cached_download" do
+ before(:each) do
+ allow(subject.resource).to receive(:cached_download).and_return("/tmp/foo.tar.gz")
+ end
+
+ its(:cached_download) { is_expected.to eq("/tmp/foo.tar.gz") }
+ end
+end
diff --git a/Library/Homebrew/test/patch_test.rb b/Library/Homebrew/test/patch_test.rb
deleted file mode 100644
index 62624720e..000000000
--- a/Library/Homebrew/test/patch_test.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-require "testing_env"
-require "patch"
-
-class PatchTests < Homebrew::TestCase
- def test_create_simple
- patch = Patch.create(:p2, nil)
- assert_kind_of ExternalPatch, patch
- assert_predicate patch, :external?
- assert_equal :p2, patch.strip
- end
-
- def test_create_string
- patch = Patch.create(:p0, "foo")
- assert_kind_of StringPatch, patch
- assert_equal :p0, patch.strip
- end
-
- def test_create_string_without_strip
- patch = Patch.create("foo", nil)
- assert_kind_of StringPatch, patch
- assert_equal :p1, patch.strip
- end
-
- def test_create_data
- patch = Patch.create(:p0, :DATA)
- assert_kind_of DATAPatch, patch
- assert_equal :p0, patch.strip
- end
-
- def test_create_data_without_strip
- patch = Patch.create(:DATA, nil)
- assert_kind_of DATAPatch, patch
- assert_equal :p1, patch.strip
- end
-
- def test_raises_for_unknown_values
- assert_raises(ArgumentError) { Patch.create(Object.new) }
- assert_raises(ArgumentError) { Patch.create(Object.new, Object.new) }
- end
-end
-
-class LegacyPatchTests < Homebrew::TestCase
- def test_patch_single_string
- patches = Patch.normalize_legacy_patches("http://example.com/patch.diff")
- assert_equal 1, patches.length
- assert_equal :p1, patches.first.strip
- end
-
- def test_patch_array
- patches = Patch.normalize_legacy_patches(
- %w[http://example.com/patch1.diff http://example.com/patch2.diff]
- )
-
- assert_equal 2, patches.length
- assert_equal :p1, patches[0].strip
- assert_equal :p1, patches[1].strip
- end
-
- def test_p0_hash_to_string
- patches = Patch.normalize_legacy_patches(
- p0: "http://example.com/patch.diff"
- )
-
- assert_equal 1, patches.length
- assert_equal :p0, patches.first.strip
- end
-
- def test_p1_hash_to_string
- patches = Patch.normalize_legacy_patches(
- p1: "http://example.com/patch.diff"
- )
-
- assert_equal 1, patches.length
- assert_equal :p1, patches.first.strip
- end
-
- def test_mixed_hash_to_strings
- patches = Patch.normalize_legacy_patches(
- p1: "http://example.com/patch1.diff",
- p0: "http://example.com/patch0.diff"
- )
- assert_equal 2, patches.length
- assert_equal 1, patches.count { |p| p.strip == :p0 }
- assert_equal 1, patches.count { |p| p.strip == :p1 }
- end
-
- def test_mixed_hash_to_arrays
- patches = Patch.normalize_legacy_patches(
- p1: ["http://example.com/patch10.diff",
- "http://example.com/patch11.diff"],
- p0: ["http://example.com/patch00.diff",
- "http://example.com/patch01.diff"]
- )
-
- assert_equal 4, patches.length
- assert_equal 2, patches.count { |p| p.strip == :p0 }
- assert_equal 2, patches.count { |p| p.strip == :p1 }
- end
-
- def test_nil
- assert_empty Patch.normalize_legacy_patches(nil)
- end
-end
-
-class EmbeddedPatchTests < Homebrew::TestCase
- def test_inspect
- p = EmbeddedPatch.new :p1
- assert_equal "#<EmbeddedPatch: :p1>", p.inspect
- end
-end
-
-class ExternalPatchTests < Homebrew::TestCase
- def setup
- @p = ExternalPatch.new(:p1) { url "file:///my.patch" }
- end
-
- def test_url
- assert_equal "file:///my.patch", @p.url
- end
-
- def test_inspect
- assert_equal '#<ExternalPatch: :p1 "file:///my.patch">', @p.inspect
- end
-
- def test_cached_download
- @p.resource.stubs(:cached_download).returns "/tmp/foo.tar.gz"
- assert_equal "/tmp/foo.tar.gz", @p.cached_download
- end
-end
-
-class ApplyPatchTests < Homebrew::TestCase
- def test_empty_patch_files
- patch = Patch.create(:p2, nil)
- resource = patch.resource
- patch_files = patch.patch_files
- assert_kind_of Resource::Patch, resource
- assert_equal patch_files, resource.patch_files
- assert_equal patch_files, []
- end
-
- def test_resource_patch_apply_method
- patch = Patch.create(:p2, nil)
- resource = patch.resource
- patch_files = patch.patch_files
- resource.apply("patch1.diff")
- assert_equal patch_files, ["patch1.diff"]
- resource.apply("patch2.diff", "patch3.diff")
- assert_equal patch_files, ["patch1.diff", "patch2.diff", "patch3.diff"]
- resource.apply(["patch4.diff", "patch5.diff"])
- assert_equal patch_files.count, 5
- resource.apply("patch4.diff", ["patch5.diff", "patch6.diff"], "patch7.diff")
- assert_equal patch_files.count, 7
- end
-end
diff --git a/Library/Homebrew/test/patching_spec.rb b/Library/Homebrew/test/patching_spec.rb
new file mode 100644
index 000000000..dd849ca92
--- /dev/null
+++ b/Library/Homebrew/test/patching_spec.rb
@@ -0,0 +1,289 @@
+require "formula"
+
+describe "patching" do
+ TESTBALL_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz".freeze
+ TESTBALL_PATCHES_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1-patches.tgz".freeze
+ PATCH_URL_A = "file://#{TEST_FIXTURE_DIR}/patches/noop-a.diff".freeze
+ PATCH_URL_B = "file://#{TEST_FIXTURE_DIR}/patches/noop-b.diff".freeze
+ PATCH_A_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-a.diff"
+ PATCH_B_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-b.diff"
+ APPLY_A = "noop-a.diff".freeze
+ APPLY_B = "noop-b.diff".freeze
+ APPLY_C = "noop-c.diff".freeze
+
+ def formula(name = "formula_name", path: Formulary.core_path(name), spec: :stable, alias_path: nil, &block)
+ Class.new(Formula) {
+ url TESTBALL_URL
+ sha256 TESTBALL_SHA256
+ class_eval(&block)
+ }.new(name, path, spec, alias_path: alias_path)
+ end
+
+ matcher :be_patched do
+ match do |formula|
+ shutup do
+ formula.brew do
+ formula.patch
+ s = File.read("libexec/NOOP")
+ expect(s).not_to include("NOOP"), "libexec/NOOP was not patched as expected"
+ expect(s).to include("ABCD"), "libexec/NOOP was not patched as expected"
+ end
+ end
+ end
+ end
+
+ matcher :be_sequentially_patched do
+ match do |formula|
+ shutup do
+ formula.brew do
+ formula.patch
+ s = File.read("libexec/NOOP")
+ expect(s).not_to include("NOOP"), "libexec/NOOP was not patched as expected"
+ expect(s).not_to include("ABCD"), "libexec/NOOP was not patched as expected"
+ expect(s).to include("1234"), "libexec/NOOP was not patched as expected"
+ end
+ end
+ end
+ end
+
+ matcher :miss_apply do
+ match do |formula|
+ expect {
+ shutup do
+ formula.brew do
+ formula.patch
+ end
+ end
+ }.to raise_error(MissingApplyError)
+ end
+ end
+
+ specify "single_patch" do
+ expect(
+ formula do
+ def patches
+ PATCH_URL_A
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl" do
+ expect(
+ formula do
+ patch do
+ url PATCH_URL_A
+ sha256 PATCH_A_SHA256
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_apply" do
+ expect(
+ formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_sequential_apply" do
+ expect(
+ formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A, APPLY_C
+ end
+ end,
+ ).to be_sequentially_patched
+ end
+
+ specify "single_patch_dsl_with_strip" do
+ expect(
+ formula do
+ patch :p1 do
+ url PATCH_URL_A
+ sha256 PATCH_A_SHA256
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_strip_with_apply" do
+ expect(
+ formula do
+ patch :p1 do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_dsl_with_incorrect_strip" do
+ expect {
+ shutup do
+ f = formula do
+ patch :p0 do
+ url PATCH_URL_A
+ sha256 PATCH_A_SHA256
+ end
+ end
+
+ f.brew { |formula, _staging| formula.patch }
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+
+ specify "single_patch_dsl_with_incorrect_strip_with_apply" do
+ expect {
+ shutup do
+ f = formula do
+ patch :p0 do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_A
+ end
+ end
+
+ f.brew { |formula, _staging| formula.patch }
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+
+ specify "patch_p0_dsl" do
+ expect(
+ formula do
+ patch :p0 do
+ url PATCH_URL_B
+ sha256 PATCH_B_SHA256
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_p0_dsl_with_apply" do
+ expect(
+ formula do
+ patch :p0 do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply APPLY_B
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_p0" do
+ expect(
+ formula do
+ def patches
+ { p0: PATCH_URL_B }
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_array" do
+ expect(
+ formula do
+ def patches
+ [PATCH_URL_A]
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_hash" do
+ expect(
+ formula do
+ def patches
+ { p1: PATCH_URL_A }
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_hash_array" do
+ expect(
+ formula do
+ def patches
+ { p1: [PATCH_URL_A] }
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "patch_string" do
+ expect(formula { patch PATCH_A_CONTENTS }).to be_patched
+ end
+
+ specify "patch_string_with_strip" do
+ expect(formula { patch :p0, PATCH_B_CONTENTS }).to be_patched
+ end
+
+ specify "patch_data_constant" do
+ expect(
+ formula("test", path: Pathname.new(__FILE__).expand_path) do
+ def patches
+ :DATA
+ end
+ end,
+ ).to be_patched
+ end
+
+ specify "single_patch_missing_apply_fail" do
+ expect(
+ formula do
+ def patches
+ TESTBALL_PATCHES_URL
+ end
+ end,
+ ).to miss_apply
+ end
+
+ specify "single_patch_dsl_missing_apply_fail" do
+ expect(
+ formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ end
+ end,
+ ).to miss_apply
+ end
+
+ specify "single_patch_dsl_with_apply_enoent_fail" do
+ expect {
+ shutup do
+ f = formula do
+ patch do
+ url TESTBALL_PATCHES_URL
+ sha256 TESTBALL_PATCHES_SHA256
+ apply "patches/#{APPLY_A}"
+ end
+ end
+
+ f.brew { |formula, _staging| formula.patch }
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+end
+
+__END__
+diff --git a/libexec/NOOP b/libexec/NOOP
+index bfdda4c..e08d8f4 100755
+--- a/libexec/NOOP
++++ b/libexec/NOOP
+@@ -1,2 +1,2 @@
+ #!/bin/bash
+-echo NOOP
+\ No newline at end of file
++echo ABCD
+\ No newline at end of file
diff --git a/Library/Homebrew/test/patching_test.rb b/Library/Homebrew/test/patching_test.rb
deleted file mode 100644
index ac14c8e1e..000000000
--- a/Library/Homebrew/test/patching_test.rb
+++ /dev/null
@@ -1,253 +0,0 @@
-require "testing_env"
-require "formula"
-
-class PatchingTests < Homebrew::TestCase
- TESTBALL_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz".freeze
- TESTBALL_PATCHES_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1-patches.tgz".freeze
- PATCH_URL_A = "file://#{TEST_FIXTURE_DIR}/patches/noop-a.diff".freeze
- PATCH_URL_B = "file://#{TEST_FIXTURE_DIR}/patches/noop-b.diff".freeze
- PATCH_A_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-a.diff"
- PATCH_B_CONTENTS = File.read "#{TEST_FIXTURE_DIR}/patches/noop-b.diff"
- APPLY_A = "noop-a.diff".freeze
- APPLY_B = "noop-b.diff".freeze
- APPLY_C = "noop-c.diff".freeze
-
- def formula(*args, &block)
- super do
- url TESTBALL_URL
- sha256 TESTBALL_SHA256
- class_eval(&block)
- end
- end
-
- def teardown
- @_f.clear_cache
- @_f.patchlist.each { |p| p.clear_cache if p.external? }
- end
-
- def assert_patched(formula)
- shutup do
- formula.brew do
- formula.patch
- s = File.read("libexec/NOOP")
- refute_includes s, "NOOP", "libexec/NOOP was not patched as expected"
- assert_includes s, "ABCD", "libexec/NOOP was not patched as expected"
- end
- end
- end
-
- def assert_sequentially_patched(formula)
- shutup do
- formula.brew do
- formula.patch
- s = File.read("libexec/NOOP")
- refute_includes s, "NOOP", "libexec/NOOP was not patched as expected"
- refute_includes s, "ABCD", "libexec/NOOP was not patched as expected"
- assert_includes s, "1234", "libexec/NOOP was not patched as expected"
- end
- end
- end
-
- def assert_missing_apply_fail(formula)
- assert_raises(MissingApplyError) do
- shutup do
- formula.brew do
- formula.patch
- end
- end
- end
- end
-
- def test_single_patch
- assert_patched formula {
- def patches
- PATCH_URL_A
- end
- }
- end
-
- def test_single_patch_dsl
- assert_patched formula {
- patch do
- url PATCH_URL_A
- sha256 PATCH_A_SHA256
- end
- }
- end
-
- def test_single_patch_dsl_with_apply
- assert_patched formula {
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A
- end
- }
- end
-
- def test_single_patch_dsl_with_sequential_apply
- assert_sequentially_patched formula {
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A, APPLY_C
- end
- }
- end
-
- def test_single_patch_dsl_with_strip
- assert_patched formula {
- patch :p1 do
- url PATCH_URL_A
- sha256 PATCH_A_SHA256
- end
- }
- end
-
- def test_single_patch_dsl_with_strip_with_apply
- assert_patched formula {
- patch :p1 do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A
- end
- }
- end
-
- def test_single_patch_dsl_with_incorrect_strip
- assert_raises(ErrorDuringExecution) do
- shutup do
- formula do
- patch :p0 do
- url PATCH_URL_A
- sha256 PATCH_A_SHA256
- end
- end.brew { |f, _staging| f.patch }
- end
- end
- end
-
- def test_single_patch_dsl_with_incorrect_strip_with_apply
- assert_raises(ErrorDuringExecution) do
- shutup do
- formula do
- patch :p0 do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_A
- end
- end.brew { |f, _staging| f.patch }
- end
- end
- end
-
- def test_patch_p0_dsl
- assert_patched formula {
- patch :p0 do
- url PATCH_URL_B
- sha256 PATCH_B_SHA256
- end
- }
- end
-
- def test_patch_p0_dsl_with_apply
- assert_patched formula {
- patch :p0 do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply APPLY_B
- end
- }
- end
-
- def test_patch_p0
- assert_patched formula {
- def patches
- { p0: PATCH_URL_B }
- end
- }
- end
-
- def test_patch_array
- assert_patched formula {
- def patches
- [PATCH_URL_A]
- end
- }
- end
-
- def test_patch_hash
- assert_patched formula {
- def patches
- { p1: PATCH_URL_A }
- end
- }
- end
-
- def test_patch_hash_array
- assert_patched formula {
- def patches
- { p1: [PATCH_URL_A] }
- end
- }
- end
-
- def test_patch_string
- assert_patched formula { patch PATCH_A_CONTENTS }
- end
-
- def test_patch_string_with_strip
- assert_patched formula { patch :p0, PATCH_B_CONTENTS }
- end
-
- def test_patch_data_constant
- assert_patched formula("test", Pathname.new(__FILE__).expand_path) {
- def patches
- :DATA
- end
- }
- end
-
- def test_single_patch_missing_apply_fail
- assert_missing_apply_fail formula {
- def patches
- TESTBALL_PATCHES_URL
- end
- }
- end
-
- def test_single_patch_dsl_missing_apply_fail
- assert_missing_apply_fail formula {
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- end
- }
- end
-
- def test_single_patch_dsl_with_apply_enoent_fail
- assert_raises(ErrorDuringExecution) do
- shutup do
- formula do
- patch do
- url TESTBALL_PATCHES_URL
- sha256 TESTBALL_PATCHES_SHA256
- apply "patches/#{APPLY_A}"
- end
- end.brew { |f, _staging| f.patch }
- end
- end
- end
-end
-
-__END__
-diff --git a/libexec/NOOP b/libexec/NOOP
-index bfdda4c..e08d8f4 100755
---- a/libexec/NOOP
-+++ b/libexec/NOOP
-@@ -1,2 +1,2 @@
- #!/bin/bash
--echo NOOP
-\ No newline at end of file
-+echo ABCD
-\ No newline at end of file
diff --git a/Library/Homebrew/test/pathname_spec.rb b/Library/Homebrew/test/pathname_spec.rb
new file mode 100644
index 000000000..6e7dc34aa
--- /dev/null
+++ b/Library/Homebrew/test/pathname_spec.rb
@@ -0,0 +1,300 @@
+require "tmpdir"
+require "extend/pathname"
+require "install_renamed"
+
+describe Pathname do
+ include FileUtils
+
+ let(:src) { Pathname.new(Dir.mktmpdir) }
+ let(:dst) { Pathname.new(Dir.mktmpdir) }
+ let(:file) { src/"foo" }
+ let(:dir) { src/"bar" }
+
+ after(:each) { rm_rf [src, dst] }
+
+ describe DiskUsageExtension do
+ before(:each) do
+ mkdir_p dir/"a-directory"
+ touch [dir/".DS_Store", dir/"a-file"]
+ File.truncate(dir/"a-file", 1_048_576)
+ ln_s dir/"a-file", dir/"a-symlink"
+ ln dir/"a-file", dir/"a-hardlink"
+ end
+
+ describe "#file_count" do
+ it "returns the number of files in a directory" do
+ expect(dir.file_count).to eq(3)
+ end
+ end
+
+ describe "#abv" do
+ context "when called on a directory" do
+ it "returns a string with the file count and disk usage" do
+ expect(dir.abv).to eq("3 files, 1MB")
+ end
+ end
+
+ context "when called on a file" do
+ it "returns the disk usage" do
+ expect((dir/"a-file").abv).to eq("1MB")
+ end
+ end
+ end
+ end
+
+ describe "#rmdir_if_possible" do
+ before(:each) { mkdir_p dir }
+
+ it "returns true and removes a directory if it doesn't contain files" do
+ expect(dir.rmdir_if_possible).to be true
+ expect(dir).not_to exist
+ end
+
+ it "returns false and doesn't delete a directory if it contains files" do
+ touch dir/"foo"
+ expect(dir.rmdir_if_possible).to be false
+ expect(dir).to be_a_directory
+ end
+
+ it "ignores .DS_Store files" do
+ touch dir/".DS_Store"
+ expect(dir.rmdir_if_possible).to be true
+ expect(dir).not_to exist
+ end
+ end
+
+ describe "#write" do
+ it "creates a file and writes to it" do
+ expect(file).not_to exist
+ file.write("CONTENT")
+ expect(File.read(file)).to eq("CONTENT")
+ end
+
+ it "raises an error if the file already exists" do
+ touch file
+ expect { file.write("CONTENT") }.to raise_error(RuntimeError)
+ end
+ end
+
+ describe "#append_lines" do
+ it "appends lines to a file" do
+ touch file
+
+ file.append_lines("CONTENT")
+ expect(File.read(file)).to eq <<-EOS.undent
+ CONTENT
+ EOS
+
+ file.append_lines("CONTENTS")
+ expect(File.read(file)).to eq <<-EOS.undent
+ CONTENT
+ CONTENTS
+ EOS
+ end
+
+ it "raises an error if the file does not exist" do
+ expect(file).not_to exist
+ expect { file.append_lines("CONTENT") }.to raise_error(RuntimeError)
+ end
+ end
+
+ describe "#atomic_write" do
+ it "atomically replaces a file" do
+ touch file
+ file.atomic_write("CONTENT")
+ expect(File.read(file)).to eq("CONTENT")
+ end
+
+ it "preserves permissions" do
+ File.open(file, "w", 0100777).close
+ file.atomic_write("CONTENT")
+ expect(file.stat.mode).to eq(0100777 & ~File.umask)
+ end
+
+ it "preserves default permissions" do
+ file.atomic_write("CONTENT")
+ sentinel = file.parent.join("sentinel")
+ touch sentinel
+ expect(file.stat.mode).to eq(sentinel.stat.mode)
+ end
+ end
+
+ describe "#ensure_writable" do
+ it "makes a file writable and restores permissions afterwards" do
+ touch file
+ chmod 0555, file
+ expect(file).not_to be_writable
+ file.ensure_writable do
+ expect(file).to be_writable
+ end
+ expect(file).not_to be_writable
+ end
+ end
+
+ describe "#extname" do
+ it "supports common multi-level archives" do
+ expect(Pathname.new("foo-0.1.tar.gz").extname).to eq(".tar.gz")
+ expect(Pathname.new("foo-0.1.cpio.gz").extname).to eq(".cpio.gz")
+ end
+ end
+
+ describe "#stem" do
+ it "returns the basename without double extensions" do
+ expect(Pathname("foo-0.1.tar.gz").stem).to eq("foo-0.1")
+ expect(Pathname("foo-0.1.cpio.gz").stem).to eq("foo-0.1")
+ end
+ end
+
+ describe "#install" do
+ before(:each) do
+ (src/"a.txt").write "This is sample file a."
+ (src/"b.txt").write "This is sample file b."
+ end
+
+ it "raises an error if the file doesn't exist" do
+ expect { dst.install "non_existent_file" }.to raise_error(Errno::ENOENT)
+ end
+
+ it "installs a file to a directory with its basename" do
+ touch file
+ dst.install(file)
+ expect(dst/file.basename).to exist
+ expect(file).not_to exist
+ end
+
+ it "creates intermediate directories" do
+ touch file
+ expect(dir).not_to be_a_directory
+ dir.install(file)
+ expect(dir).to be_a_directory
+ end
+
+ it "can install a file" do
+ dst.install src/"a.txt"
+ expect(dst/"a.txt").to exist, "a.txt was not installed"
+ expect(dst/"b.txt").not_to exist, "b.txt was installed."
+ end
+
+ it "can install an array of files" do
+ dst.install [src/"a.txt", src/"b.txt"]
+
+ expect(dst/"a.txt").to exist, "a.txt was not installed"
+ expect(dst/"b.txt").to exist, "b.txt was not installed"
+ end
+
+ it "can install a directory" do
+ bin = src/"bin"
+ bin.mkpath
+ mv Dir[src/"*.txt"], bin
+ dst.install bin
+
+ expect(dst/"bin/a.txt").to exist, "a.txt was not installed"
+ expect(dst/"bin/b.txt").to exist, "b.txt was not installed"
+ end
+
+ it "supports renaming files" do
+ dst.install src/"a.txt" => "c.txt"
+
+ expect(dst/"c.txt").to exist, "c.txt was not installed"
+ expect(dst/"a.txt").not_to exist, "a.txt was installed but not renamed"
+ expect(dst/"b.txt").not_to exist, "b.txt was installed"
+ end
+
+ it "supports renaming multiple files" do
+ dst.install(src/"a.txt" => "c.txt", src/"b.txt" => "d.txt")
+
+ expect(dst/"c.txt").to exist, "c.txt was not installed"
+ expect(dst/"d.txt").to exist, "d.txt was not installed"
+ expect(dst/"a.txt").not_to exist, "a.txt was installed but not renamed"
+ expect(dst/"b.txt").not_to exist, "b.txt was installed but not renamed"
+ end
+
+ it "supports renaming directories" do
+ bin = src/"bin"
+ bin.mkpath
+ mv Dir[src/"*.txt"], bin
+ dst.install bin => "libexec"
+
+ expect(dst/"bin").not_to exist, "bin was installed but not renamed"
+ expect(dst/"libexec/a.txt").to exist, "a.txt was not installed"
+ expect(dst/"libexec/b.txt").to exist, "b.txt was not installed"
+ end
+
+ it "can install directories as relative symlinks" do
+ bin = src/"bin"
+ bin.mkpath
+ mv Dir[src/"*.txt"], bin
+ dst.install_symlink bin
+
+ expect(dst/"bin").to be_a_symlink
+ expect(dst/"bin").to be_a_directory
+ expect(dst/"bin/a.txt").to exist
+ expect(dst/"bin/b.txt").to exist
+ expect((dst/"bin").readlink).to be_relative
+ end
+
+ it "can install relative paths as symlinks" do
+ dst.install_symlink "foo" => "bar"
+ expect((dst/"bar").readlink).to eq(Pathname.new("foo"))
+ end
+ end
+
+ describe InstallRenamed do
+ before(:each) do
+ dst.extend(InstallRenamed)
+ end
+
+ it "renames the installed file if it already exists" do
+ file.write "a"
+ dst.install file
+
+ file.write "b"
+ dst.install file
+
+ expect(File.read(dst/file.basename)).to eq("a")
+ expect(File.read(dst/"#{file.basename}.default")).to eq("b")
+ end
+
+ it "renames the installed directory" do
+ file.write "a"
+ dst.install src
+ expect(File.read(dst/src.basename/file.basename)).to eq("a")
+ end
+
+ it "recursively renames directories" do
+ (dst/dir.basename).mkpath
+ (dst/dir.basename/"another_file").write "a"
+ dir.mkpath
+ (dir/"another_file").write "b"
+ dst.install dir
+ expect(File.read(dst/dir.basename/"another_file.default")).to eq("b")
+ end
+ end
+
+ describe "#cp_path_sub" do
+ it "copies a file and replaces the given pattern" do
+ file.write "a"
+ file.cp_path_sub src, dst
+ expect(File.read(dst/file.basename)).to eq("a")
+ end
+
+ it "copies a directory and replaces the given pattern" do
+ dir.mkpath
+ dir.cp_path_sub src, dst
+ expect(dst/dir.basename).to be_a_directory
+ end
+ end
+end
+
+describe FileUtils do
+ let(:dst) { Pathname.new(Dir.mktmpdir) }
+
+ describe "#mkdir" do
+ it "creates indermediate directories" do
+ described_class.mkdir dst/"foo/bar/baz" do
+ expect(dst/"foo/bar/baz").to exist, "foo/bar/baz was not created"
+ expect(dst/"foo/bar/baz").to be_a_directory, "foo/bar/baz was not a directory structure"
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/pathname_test.rb b/Library/Homebrew/test/pathname_test.rb
deleted file mode 100644
index 2f6360719..000000000
--- a/Library/Homebrew/test/pathname_test.rb
+++ /dev/null
@@ -1,267 +0,0 @@
-require "testing_env"
-require "tmpdir"
-require "extend/pathname"
-require "install_renamed"
-
-module PathnameTestExtension
- include FileUtils
-
- def setup
- @src = Pathname.new(mktmpdir)
- @dst = Pathname.new(mktmpdir)
- @file = @src/"foo"
- @dir = @src/"bar"
- end
-
- def teardown
- rmtree(@src)
- rmtree(@dst)
- end
-end
-
-class PathnameTests < Homebrew::TestCase
- include PathnameTestExtension
-
- def test_disk_usage_extension
- mkdir_p @dir/"a-directory"
- touch @dir/".DS_Store"
- touch @dir/"a-file"
- File.truncate(@dir/"a-file", 1_048_576)
- ln_s @dir/"a-file", @dir/"a-symlink"
- ln @dir/"a-file", @dir/"a-hardlink"
- assert_equal 3, @dir.file_count
- assert_equal "3 files, 1M", @dir.abv
- assert_equal "1M", (@dir/"a-file").abv
- end
-
- def test_rmdir_if_possible
- mkdir_p @dir
- touch @dir/"foo"
-
- assert !@dir.rmdir_if_possible
- assert_predicate @dir, :directory?
-
- rm_f @dir/"foo"
- assert @dir.rmdir_if_possible
- refute_predicate @dir, :exist?
- end
-
- def test_rmdir_if_possible_ignore_ds_store
- mkdir_p @dir
- touch @dir/".DS_Store"
- assert @dir.rmdir_if_possible
- refute_predicate @dir, :exist?
- end
-
- def test_write
- @file.write("CONTENT")
- assert_equal "CONTENT", File.read(@file)
- end
-
- def test_write_does_not_overwrite
- touch @file
- assert_raises(RuntimeError) { @file.write("CONTENT") }
- end
-
- def test_append_lines
- touch @file
- @file.append_lines("CONTENT")
- assert_equal "CONTENT\n", File.read(@file)
- @file.append_lines("CONTENTS")
- assert_equal "CONTENT\nCONTENTS\n", File.read(@file)
- end
-
- def test_append_lines_does_not_create
- assert_raises(RuntimeError) { @file.append_lines("CONTENT") }
- end
-
- def test_atomic_write
- touch @file
- @file.atomic_write("CONTENT")
- assert_equal "CONTENT", File.read(@file)
- end
-
- def test_atomic_write_preserves_permissions
- File.open(@file, "w", 0100777) {}
- @file.atomic_write("CONTENT")
- assert_equal 0100777 & ~File.umask, @file.stat.mode
- end
-
- def test_atomic_write_preserves_default_permissions
- @file.atomic_write("CONTENT")
- sentinel = @file.parent.join("sentinel")
- touch sentinel
- assert_equal sentinel.stat.mode, @file.stat.mode
- end
-
- def test_ensure_writable
- touch @file
- chmod 0555, @file
- @file.ensure_writable { assert_predicate @file, :writable? }
- refute_predicate @file, :writable?
- end
-
- def test_extname
- assert_equal ".tar.gz", Pathname("foo-0.1.tar.gz").extname
- assert_equal ".cpio.gz", Pathname("foo-0.1.cpio.gz").extname
- end
-
- def test_stem
- assert_equal "foo-0.1", Pathname("foo-0.1.tar.gz").stem
- assert_equal "foo-0.1", Pathname("foo-0.1.cpio.gz").stem
- end
-
- def test_install_missing_file
- assert_raises(Errno::ENOENT) { @dst.install "non_existent_file" }
- end
-
- def test_install_removes_original
- touch @file
- @dst.install(@file)
-
- assert_predicate @dst/@file.basename, :exist?
- refute_predicate @file, :exist?
- end
-
- def test_install_creates_intermediate_directories
- touch @file
- refute_predicate @dir, :directory?
- @dir.install(@file)
- assert_predicate @dir, :directory?
- end
-
- def test_install_renamed
- @dst.extend(InstallRenamed)
-
- @file.write "a"
- @dst.install @file
- @file.write "b"
- @dst.install @file
-
- assert_equal "a", File.read(@dst/@file.basename)
- assert_equal "b", File.read(@dst/"#{@file.basename}.default")
- end
-
- def test_install_renamed_directory
- @dst.extend(InstallRenamed)
- @file.write "a"
- @dst.install @src
- assert_equal "a", File.read(@dst/@src.basename/@file.basename)
- end
-
- def test_install_renamed_directory_recursive
- @dst.extend(InstallRenamed)
- (@dst/@dir.basename).mkpath
- (@dst/@dir.basename/"another_file").write "a"
- @dir.mkpath
- (@dir/"another_file").write "b"
- @dst.install @dir
- assert_equal "b", File.read(@dst/@dir.basename/"another_file.default")
- end
-
- def test_cp_path_sub_file
- @file.write "a"
- @file.cp_path_sub @src, @dst
- assert_equal "a", File.read(@dst/"foo")
- end
-
- def test_cp_path_sub_directory
- @dir.mkpath
- @dir.cp_path_sub @src, @dst
- assert_predicate @dst/@dir.basename, :directory?
- end
-end
-
-class PathnameInstallTests < Homebrew::TestCase
- include PathnameTestExtension
-
- def setup
- super
- (@src/"a.txt").write "This is sample file a."
- (@src/"b.txt").write "This is sample file b."
- end
-
- def test_install
- @dst.install @src/"a.txt"
-
- assert_predicate @dst/"a.txt", :exist?, "a.txt was not installed"
- refute_predicate @dst/"b.txt", :exist?, "b.txt was installed."
- end
-
- def test_install_list
- @dst.install [@src/"a.txt", @src/"b.txt"]
-
- assert_predicate @dst/"a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_glob
- @dst.install Dir[@src/"*.txt"]
-
- assert_predicate @dst/"a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_directory
- bin = @src/"bin"
- bin.mkpath
- mv Dir[@src/"*.txt"], bin
- @dst.install bin
-
- assert_predicate @dst/"bin/a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"bin/b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_rename
- @dst.install @src/"a.txt" => "c.txt"
-
- assert_predicate @dst/"c.txt", :exist?, "c.txt was not installed"
- refute_predicate @dst/"a.txt", :exist?, "a.txt was installed but not renamed"
- refute_predicate @dst/"b.txt", :exist?, "b.txt was installed"
- end
-
- def test_install_rename_more
- @dst.install(@src/"a.txt" => "c.txt", @src/"b.txt" => "d.txt")
-
- assert_predicate @dst/"c.txt", :exist?, "c.txt was not installed"
- assert_predicate @dst/"d.txt", :exist?, "d.txt was not installed"
- refute_predicate @dst/"a.txt", :exist?, "a.txt was installed but not renamed"
- refute_predicate @dst/"b.txt", :exist?, "b.txt was installed but not renamed"
- end
-
- def test_install_rename_directory
- bin = @src/"bin"
- bin.mkpath
- mv Dir[@src/"*.txt"], bin
- @dst.install bin => "libexec"
-
- refute_predicate @dst/"bin", :exist?, "bin was installed but not renamed"
- assert_predicate @dst/"libexec/a.txt", :exist?, "a.txt was not installed"
- assert_predicate @dst/"libexec/b.txt", :exist?, "b.txt was not installed"
- end
-
- def test_install_symlink
- bin = @src/"bin"
- bin.mkpath
- mv Dir[@src/"*.txt"], bin
- @dst.install_symlink bin
-
- assert_predicate @dst/"bin", :symlink?
- assert_predicate @dst/"bin", :directory?
- assert_predicate @dst/"bin/a.txt", :exist?
- assert_predicate @dst/"bin/b.txt", :exist?
- assert_predicate((@dst/"bin").readlink, :relative?)
- end
-
- def test_install_relative_symlink
- @dst.install_symlink "foo" => "bar"
- assert_equal Pathname.new("foo"), (@dst/"bar").readlink
- end
-
- def test_mkdir_creates_intermediate_directories
- mkdir @dst/"foo/bar/baz" do
- assert_predicate @dst/"foo/bar/baz", :exist?, "foo/bar/baz was not created"
- assert_predicate @dst/"foo/bar/baz", :directory?, "foo/bar/baz was not a directory structure"
- end
- end
-end
diff --git a/Library/Homebrew/test/pin_unpin_test.rb b/Library/Homebrew/test/pin_unpin_test.rb
deleted file mode 100644
index 65fb9e4da..000000000
--- a/Library/Homebrew/test/pin_unpin_test.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestPinUnpin < IntegrationCommandTestCase
- def test_pin_unpin
- setup_test_formula "testball"
- (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
-
- cmd("pin", "testball")
- cmd("upgrade")
- refute((HOMEBREW_CELLAR/"testball/0.1").directory?,
- "The latest version directory should NOT be created")
-
- cmd("unpin", "testball")
- cmd("upgrade")
- assert((HOMEBREW_CELLAR/"testball/0.1").directory?,
- "The latest version directory should be created")
- end
-end
diff --git a/Library/Homebrew/test/pkg_version_spec.rb b/Library/Homebrew/test/pkg_version_spec.rb
new file mode 100644
index 000000000..b1cceb32c
--- /dev/null
+++ b/Library/Homebrew/test/pkg_version_spec.rb
@@ -0,0 +1,81 @@
+require "pkg_version"
+
+describe PkgVersion do
+ describe "::parse" do
+ it "parses versions from a string" do
+ expect(described_class.parse("1.0_1")).to eq(described_class.new(Version.create("1.0"), 1))
+ expect(described_class.parse("1.0_1")).to eq(described_class.new(Version.create("1.0"), 1))
+ expect(described_class.parse("1.0")).to eq(described_class.new(Version.create("1.0"), 0))
+ expect(described_class.parse("1.0_0")).to eq(described_class.new(Version.create("1.0"), 0))
+ expect(described_class.parse("2.1.4_0")).to eq(described_class.new(Version.create("2.1.4"), 0))
+ expect(described_class.parse("1.0.1e_1")).to eq(described_class.new(Version.create("1.0.1e"), 1))
+ end
+ end
+
+ specify "#==" do
+ expect(described_class.parse("1.0_0")).to be == described_class.parse("1.0")
+ expect(described_class.parse("1.0_1")).to be == described_class.parse("1.0_1")
+ end
+
+ describe "#>" do
+ it "returns true if the left version is bigger than the right" do
+ expect(described_class.parse("1.1")).to be > described_class.parse("1.0_1")
+ end
+
+ it "returns true if the left version is HEAD" do
+ expect(described_class.parse("HEAD")).to be > described_class.parse("1.0")
+ end
+
+ it "raises an error if the other side isn't of the same class" do
+ expect {
+ described_class.new(Version.create("1.0"), 0) > Object.new
+ }.to raise_error(ArgumentError)
+ end
+
+ it "is not compatible with Version" do
+ expect {
+ described_class.new(Version.create("1.0"), 0) > Version.create("1.0")
+ }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "#<" do
+ it "returns true if the left version is smaller than the right" do
+ expect(described_class.parse("1.0_1")).to be < described_class.parse("2.0_1")
+ end
+
+ it "returns true if the right version is HEAD" do
+ expect(described_class.parse("1.0")).to be < described_class.parse("HEAD")
+ end
+ end
+
+ describe "#<=>" do
+ it "returns nil if the comparison fails" do
+ expect(described_class.new(Version.create("1.0"), 0) <=> Object.new).to be nil
+ end
+ end
+
+ describe "#to_s" do
+ it "returns a string of the form 'version_revision'" do
+ expect(described_class.new(Version.create("1.0"), 0).to_s).to eq("1.0")
+ expect(described_class.new(Version.create("1.0"), 1).to_s).to eq("1.0_1")
+ expect(described_class.new(Version.create("1.0"), 0).to_s).to eq("1.0")
+ expect(described_class.new(Version.create("1.0"), 0).to_s).to eq("1.0")
+ expect(described_class.new(Version.create("HEAD"), 1).to_s).to eq("HEAD_1")
+ expect(described_class.new(Version.create("HEAD-ffffff"), 1).to_s).to eq("HEAD-ffffff_1")
+ end
+ end
+
+ describe "#hash" do
+ let(:p1) { described_class.new(Version.create("1.0"), 1) }
+ let(:p2) { described_class.new(Version.create("1.0"), 1) }
+ let(:p3) { described_class.new(Version.create("1.1"), 1) }
+ let(:p4) { described_class.new(Version.create("1.0"), 0) }
+
+ it "returns a hash based on the version and revision" do
+ expect(p1.hash).to eq(p2.hash)
+ expect(p1.hash).not_to eq(p3.hash)
+ expect(p1.hash).not_to eq(p4.hash)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/pkg_version_test.rb b/Library/Homebrew/test/pkg_version_test.rb
deleted file mode 100644
index ff7896f8b..000000000
--- a/Library/Homebrew/test/pkg_version_test.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require "testing_env"
-require "pkg_version"
-
-class PkgVersionTests < Homebrew::TestCase
- def v(version)
- PkgVersion.parse(version)
- end
-
- def test_parse
- assert_equal PkgVersion.new(Version.create("1.0"), 1), PkgVersion.parse("1.0_1")
- assert_equal PkgVersion.new(Version.create("1.0"), 1), PkgVersion.parse("1.0_1")
- assert_equal PkgVersion.new(Version.create("1.0"), 0), PkgVersion.parse("1.0")
- assert_equal PkgVersion.new(Version.create("1.0"), 0), PkgVersion.parse("1.0_0")
- assert_equal PkgVersion.new(Version.create("2.1.4"), 0), PkgVersion.parse("2.1.4_0")
- assert_equal PkgVersion.new(Version.create("1.0.1e"), 1), PkgVersion.parse("1.0.1e_1")
- end
-
- def test_comparison
- assert_operator v("1.0_0"), :==, v("1.0")
- assert_operator v("1.0_1"), :==, v("1.0_1")
- assert_operator v("1.1"), :>, v("1.0_1")
- assert_operator v("1.0_0"), :==, v("1.0")
- assert_operator v("1.0_1"), :<, v("2.0_1")
- assert_operator v("HEAD"), :>, v("1.0")
- assert_operator v("1.0"), :<, v("HEAD")
-
- v = PkgVersion.new(Version.create("1.0"), 0)
- assert_nil v <=> Object.new
- assert_raises(ArgumentError) { v > Object.new }
- assert_raises(ArgumentError) { v > Version.create("1.0") }
- end
-
- def test_to_s
- assert_equal "1.0", PkgVersion.new(Version.create("1.0"), 0).to_s
- assert_equal "1.0_1", PkgVersion.new(Version.create("1.0"), 1).to_s
- assert_equal "1.0", PkgVersion.new(Version.create("1.0"), 0).to_s
- assert_equal "1.0", PkgVersion.new(Version.create("1.0"), 0).to_s
- assert_equal "HEAD_1", PkgVersion.new(Version.create("HEAD"), 1).to_s
- assert_equal "HEAD-ffffff_1", PkgVersion.new(Version.create("HEAD-ffffff"), 1).to_s
- end
-
- def test_hash
- p1 = PkgVersion.new(Version.create("1.0"), 1)
- p2 = PkgVersion.new(Version.create("1.0"), 1)
- p3 = PkgVersion.new(Version.create("1.1"), 1)
- p4 = PkgVersion.new(Version.create("1.0"), 0)
- assert_equal p1.hash, p2.hash
- refute_equal p1.hash, p3.hash
- refute_equal p1.hash, p4.hash
- end
-end
diff --git a/Library/Homebrew/test/prefix_formula_test.rb b/Library/Homebrew/test/prefix_formula_test.rb
deleted file mode 100644
index eb5970d3e..000000000
--- a/Library/Homebrew/test/prefix_formula_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestPrefixFormula < IntegrationCommandTestCase
- def test_prefix_formula
- assert_match "#{HOMEBREW_CELLAR}/testball",
- cmd("--prefix", testball)
- end
-end
diff --git a/Library/Homebrew/test/prefix_test.rb b/Library/Homebrew/test/prefix_test.rb
deleted file mode 100644
index a3ae75542..000000000
--- a/Library/Homebrew/test/prefix_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestPrefix < IntegrationCommandTestCase
- def test_prefix
- assert_equal HOMEBREW_PREFIX.to_s,
- cmd("--prefix")
- end
-end
diff --git a/Library/Homebrew/test/prune_test.rb b/Library/Homebrew/test/prune_test.rb
deleted file mode 100644
index 8fa5df7b7..000000000
--- a/Library/Homebrew/test/prune_test.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestPrune < IntegrationCommandTestCase
- def test_prune
- share = (HOMEBREW_PREFIX/"share")
-
- (share/"pruneable/directory/here").mkpath
- (share/"notpruneable/file").write "I'm here"
- FileUtils.ln_s "/i/dont/exist/no/really/i/dont", share/"pruneable_symlink"
-
- assert_match %r{Would remove \(empty directory\): .*/pruneable/directory/here},
- cmd("prune", "--dry-run")
- assert_match "Pruned 1 symbolic links and 3 directories",
- cmd("prune")
- refute((share/"pruneable").directory?)
- assert((share/"notpruneable").directory?)
- refute((share/"pruneable_symlink").symlink?)
-
- assert_match "Nothing pruned", cmd("prune", "--verbose")
- end
-end
diff --git a/Library/Homebrew/test/pull_offline_test.rb b/Library/Homebrew/test/pull_offline_test.rb
deleted file mode 100644
index c9d46cd74..000000000
--- a/Library/Homebrew/test/pull_offline_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestPullOffline < IntegrationCommandTestCase
- def test_pull_offline
- assert_match "You meant `git pull --rebase`.", cmd_fail("pull", "--rebase")
- assert_match "This command requires at least one argument", cmd_fail("pull")
- assert_match "Not a GitHub pull request or commit",
- cmd_fail("pull", "0")
- end
-end
diff --git a/Library/Homebrew/test/pull_test.rb b/Library/Homebrew/test/pull_test.rb
deleted file mode 100644
index 445d73cb1..000000000
--- a/Library/Homebrew/test/pull_test.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestPull < IntegrationCommandTestCase
- def test_pull
- skip "Requires network connection" if ENV["HOMEBREW_NO_GITHUB_API"]
-
- core_tap = CoreTap.new
- core_tap.path.cd do
- shutup do
- system "git", "init"
- system "git", "checkout", "-b", "new-branch"
- end
- end
-
- assert_match "Testing URLs require `--bottle`!",
- cmd_fail("pull", "https://bot.brew.sh/job/Homebrew\%20Testing/1028/")
- assert_match "Current branch is new-branch",
- cmd_fail("pull", "1")
- assert_match "No changed formulae found to bump",
- cmd_fail("pull", "--bump", "8")
- assert_match "Can only bump one changed formula",
- cmd_fail("pull", "--bump",
- "https://api.github.com/repos/Homebrew/homebrew-core/pulls/122")
- assert_match "Patch failed to apply",
- cmd_fail("pull", "https://github.com/Homebrew/homebrew-core/pull/1")
- end
-end
diff --git a/Library/Homebrew/test/readall_test.rb b/Library/Homebrew/test/readall_test.rb
deleted file mode 100644
index 3eec79dd8..000000000
--- a/Library/Homebrew/test/readall_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestReadall < IntegrationCommandTestCase
- def test_readall
- formula_file = setup_test_formula "testball"
- alias_file = CoreTap.new.alias_dir/"foobar"
- alias_file.parent.mkpath
- FileUtils.ln_s formula_file, alias_file
- cmd("readall", "--aliases", "--syntax")
- cmd("readall", "homebrew/core")
- end
-end
diff --git a/Library/Homebrew/test/reinstall_pinned_test.rb b/Library/Homebrew/test/reinstall_pinned_test.rb
deleted file mode 100644
index 80f5518ea..000000000
--- a/Library/Homebrew/test/reinstall_pinned_test.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestReinstallPinned < IntegrationCommandTestCase
- def test_reinstall_pinned
- setup_test_formula "testball"
-
- HOMEBREW_CELLAR.join("testball/0.1").mkpath
- HOMEBREW_PINNED_KEGS.mkpath
- FileUtils.ln_s HOMEBREW_CELLAR.join("testball/0.1"), HOMEBREW_PINNED_KEGS/"testball"
-
- assert_match "testball is pinned. You must unpin it to reinstall.", cmd("reinstall", "testball")
-
- HOMEBREW_PINNED_KEGS.rmtree
- end
-end
diff --git a/Library/Homebrew/test/reinstall_test.rb b/Library/Homebrew/test/reinstall_test.rb
deleted file mode 100644
index 613c06188..000000000
--- a/Library/Homebrew/test/reinstall_test.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestReinstall < IntegrationCommandTestCase
- def test_reinstall
- setup_test_formula "testball"
-
- cmd("install", "testball", "--with-foo")
- foo_dir = HOMEBREW_CELLAR/"testball/0.1/foo"
- assert foo_dir.exist?
- foo_dir.rmtree
- assert_match "Reinstalling testball --with-foo",
- cmd("reinstall", "testball")
- assert foo_dir.exist?
- end
-end
diff --git a/Library/Homebrew/test/repository_test.rb b/Library/Homebrew/test/repository_test.rb
deleted file mode 100644
index 77967a58d..000000000
--- a/Library/Homebrew/test/repository_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestRepository < IntegrationCommandTestCase
- def test_repository
- assert_match HOMEBREW_REPOSITORY.to_s,
- cmd("--repository")
- assert_match "#{HOMEBREW_LIBRARY}/Taps/foo/homebrew-bar",
- cmd("--repository", "foo/bar")
- end
-end
diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb
new file mode 100644
index 000000000..110a7ac4f
--- /dev/null
+++ b/Library/Homebrew/test/requirement_spec.rb
@@ -0,0 +1,288 @@
+require "extend/ENV"
+require "requirement"
+
+RSpec::Matchers.alias_matcher :have_a_default_formula, :be_a_default_formula
+RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_a_build
+
+describe Requirement do
+ subject { klass.new }
+
+ let(:klass) { Class.new(described_class) }
+
+ describe "#tags" do
+ subject { described_class.new(tags) }
+
+ context "single tag" do
+ let(:tags) { ["bar"] }
+
+ its(:tags) { are_expected.to eq(tags) }
+ end
+
+ context "multiple tags" do
+ let(:tags) { ["bar", "baz"] }
+
+ its(:tags) { are_expected.to eq(tags) }
+ end
+
+ context "symbol tags" do
+ let(:tags) { [:build] }
+
+ its(:tags) { are_expected.to eq(tags) }
+ end
+
+ context "symbol and string tags" do
+ let(:tags) { [:build, "bar"] }
+
+ its(:tags) { are_expected.to eq(tags) }
+ end
+ end
+
+ describe "#fatal?" do
+ context "#fatal true is specified" do
+ let(:klass) do
+ Class.new(described_class) do
+ fatal true
+ end
+ end
+
+ it { is_expected.to be_fatal }
+ end
+
+ context "#fatal is ommitted" do
+ it { is_expected.not_to be_fatal }
+ end
+ end
+
+ describe "#satisfied?" do
+ context "#satisfy with block and build_env returns true" do
+ let(:klass) do
+ Class.new(described_class) do
+ satisfy(build_env: false) do
+ true
+ end
+ end
+ end
+
+ it { is_expected.to be_satisfied }
+ end
+
+ context "#satisfy with block and build_env returns false" do
+ let(:klass) do
+ Class.new(described_class) do
+ satisfy(build_env: false) do
+ false
+ end
+ end
+ end
+
+ it { is_expected.not_to be_satisfied }
+ end
+
+ context "#satisfy returns true" do
+ let(:klass) do
+ Class.new(described_class) do
+ satisfy true
+ end
+ end
+
+ it { is_expected.to be_satisfied }
+ end
+
+ context "#satisfy returns false" do
+ let(:klass) do
+ Class.new(described_class) do
+ satisfy false
+ end
+ end
+
+ it { is_expected.not_to be_satisfied }
+ end
+
+ context "#satisfy with block returning true and without :build_env" do
+ let(:klass) do
+ Class.new(described_class) do
+ satisfy do
+ true
+ end
+ end
+ end
+
+ it "sets up build environment" do
+ expect(ENV).to receive(:with_build_environment).and_call_original
+ subject.satisfied?
+ end
+ end
+
+ context "#satisfy with block returning true and :build_env set to false" do
+ let(:klass) do
+ Class.new(described_class) do
+ satisfy(build_env: false) do
+ true
+ end
+ end
+ end
+
+ it "skips setting up build environment" do
+ expect(ENV).not_to receive(:with_build_environment)
+ subject.satisfied?
+ end
+ end
+
+ context "#satisfy with block returning path and without :build_env" do
+ let(:klass) do
+ Class.new(described_class) do
+ satisfy do
+ Pathname.new("/foo/bar/baz")
+ end
+ end
+ end
+
+ it "infers path from #satisfy result" do
+ expect(ENV).to receive(:append_path).with("PATH", Pathname.new("/foo/bar"))
+ subject.satisfied?
+ subject.modify_build_environment
+ end
+ end
+ end
+
+ describe "#build?" do
+ context "#build true is specified" do
+ let(:klass) do
+ Class.new(described_class) do
+ build true
+ end
+ end
+
+ it { is_expected.to be_a_build_requirement }
+ end
+
+ context "#build ommitted" do
+ it { is_expected.not_to be_a_build_requirement }
+ end
+ end
+
+ describe "#name and #option_names" do
+ let(:const) { :FooRequirement }
+ let(:klass) { self.class.const_get(const) }
+
+ before(:each) do
+ self.class.const_set(const, Class.new(described_class))
+ end
+
+ after(:each) do
+ self.class.send(:remove_const, const)
+ end
+
+ its(:name) { is_expected.to eq("foo") }
+ its(:option_names) { are_expected.to eq(["foo"]) }
+ end
+
+ describe "#default_formula?" do
+ context "#default_formula specified" do
+ let(:klass) do
+ Class.new(described_class) do
+ default_formula "foo"
+ end
+ end
+
+ it { is_expected.to have_a_default_formula }
+ end
+
+ context "#default_formula ommitted" do
+ it { is_expected.not_to have_a_default_formula }
+ end
+ end
+
+ describe "#to_dependency" do
+ let(:klass) do
+ Class.new(described_class) do
+ default_formula "foo"
+ end
+ end
+
+ it "returns a Dependency for its default Formula" do
+ expect(subject.to_dependency).to eq(Dependency.new("foo"))
+ end
+
+ context "#modify_build_environment" do
+ context "with error" do
+ let(:klass) do
+ Class.new(described_class) do
+ class ModifyBuildEnvironmentError < StandardError; end
+
+ default_formula "foo"
+
+ satisfy do
+ true
+ end
+
+ env do
+ raise ModifyBuildEnvironmentError
+ end
+ end
+ end
+
+ it "raises an error" do
+ expect {
+ subject.to_dependency.modify_build_environment
+ }.to raise_error(klass.const_get(:ModifyBuildEnvironmentError))
+ end
+ end
+ end
+ end
+
+ describe "#modify_build_environment" do
+ context "without env proc" do
+ let(:klass) { Class.new(described_class) }
+
+ it "returns nil" do
+ expect(subject.modify_build_environment).to be nil
+ end
+ end
+ end
+
+ describe "#eql? and #==" do
+ subject { described_class.new }
+
+ it "returns true if the names and tags are equal" do
+ other = described_class.new
+
+ expect(subject).to eql(other)
+ expect(subject).to eq(other)
+ end
+
+ it "returns false if names differ" do
+ other = described_class.new
+ allow(other).to receive(:name).and_return("foo")
+ expect(subject).not_to eql(other)
+ expect(subject).not_to eq(other)
+ end
+
+ it "returns false if tags differ" do
+ other = described_class.new([:optional])
+
+ expect(subject).not_to eql(other)
+ expect(subject).not_to eq(other)
+ end
+ end
+
+ describe "#hash" do
+ subject { described_class.new }
+
+ it "is equal if names and tags are equal" do
+ other = described_class.new
+ expect(subject.hash).to eq(other.hash)
+ end
+
+ it "differs if names differ" do
+ other = described_class.new
+ allow(other).to receive(:name).and_return("foo")
+ expect(subject.hash).not_to eq(other.hash)
+ end
+
+ it "differs if tags differ" do
+ other = described_class.new([:optional])
+ expect(subject.hash).not_to eq(other.hash)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/requirement_test.rb b/Library/Homebrew/test/requirement_test.rb
deleted file mode 100644
index 580d42bfa..000000000
--- a/Library/Homebrew/test/requirement_test.rb
+++ /dev/null
@@ -1,152 +0,0 @@
-require "testing_env"
-require "requirement"
-
-class RequirementTests < Homebrew::TestCase
- class TestRequirement < Requirement; end
-
- def test_accepts_single_tag
- dep = Requirement.new(%w[bar])
- assert_equal %w[bar], dep.tags
- end
-
- def test_accepts_multiple_tags
- dep = Requirement.new(%w[bar baz])
- assert_equal %w[bar baz].sort, dep.tags.sort
- end
-
- def test_option_names
- dep = TestRequirement.new
- assert_equal %w[test], dep.option_names
- end
-
- def test_preserves_symbol_tags
- dep = Requirement.new([:build])
- assert_equal [:build], dep.tags
- end
-
- def test_accepts_symbol_and_string_tags
- dep = Requirement.new([:build, "bar"])
- assert_equal [:build, "bar"], dep.tags
- end
-
- def test_dsl_fatal
- req = Class.new(Requirement) { fatal true }.new
- assert_predicate req, :fatal?
- end
-
- def test_satisfy_true
- req = Class.new(Requirement) do
- satisfy(build_env: false) { true }
- end.new
- assert_predicate req, :satisfied?
- end
-
- def test_satisfy_false
- req = Class.new(Requirement) do
- satisfy(build_env: false) { false }
- end.new
- refute_predicate req, :satisfied?
- end
-
- def test_satisfy_with_boolean
- req = Class.new(Requirement) do
- satisfy true
- end.new
- assert_predicate req, :satisfied?
- end
-
- def test_satisfy_sets_up_build_env_by_default
- req = Class.new(Requirement) do
- satisfy { true }
- end.new
-
- ENV.expects(:with_build_environment).yields.returns(true)
-
- assert_predicate req, :satisfied?
- end
-
- def test_satisfy_build_env_can_be_disabled
- req = Class.new(Requirement) do
- satisfy(build_env: false) { true }
- end.new
-
- ENV.expects(:with_build_environment).never
-
- assert_predicate req, :satisfied?
- end
-
- def test_infers_path_from_satisfy_result
- which_path = Pathname.new("/foo/bar/baz")
- req = Class.new(Requirement) do
- satisfy { which_path }
- end.new
-
- ENV.expects(:with_build_environment).yields.returns(which_path)
- ENV.expects(:append_path).with("PATH", which_path.parent)
-
- req.satisfied?
- req.modify_build_environment
- end
-
- def test_dsl_build
- req = Class.new(Requirement) { build true }.new
- assert_predicate req, :build?
- end
-
- def test_infer_name_from_class
- const = :FooRequirement
- klass = self.class
-
- klass.const_set(const, Class.new(Requirement))
-
- begin
- assert_equal "foo", klass.const_get(const).new.name
- ensure
- klass.send(:remove_const, const)
- end
- end
-
- def test_dsl_default_formula
- req = Class.new(Requirement) { default_formula "foo" }.new
- assert_predicate req, :default_formula?
- end
-
- def test_to_dependency
- req = Class.new(Requirement) { default_formula "foo" }.new
- assert_equal Dependency.new("foo"), req.to_dependency
- end
-
- def test_to_dependency_calls_requirement_modify_build_environment
- error = Class.new(StandardError)
-
- req = Class.new(Requirement) do
- default_formula "foo"
- satisfy { true }
- env { raise error }
- end.new
-
- assert_raises(error) do
- req.to_dependency.modify_build_environment
- end
- end
-
- def test_modify_build_environment_without_env_proc
- assert_nil Class.new(Requirement).new.modify_build_environment
- end
-
- def test_eql
- a = Requirement.new
- b = Requirement.new
- assert_equal a, b
- assert_eql a, b
- assert_equal a.hash, b.hash
- end
-
- def test_not_eql
- a = Requirement.new([:optional])
- b = Requirement.new
- refute_equal a, b
- refute_eql a, b
- refute_equal a.hash, b.hash
- end
-end
diff --git a/Library/Homebrew/test/resource_spec.rb b/Library/Homebrew/test/resource_spec.rb
new file mode 100644
index 000000000..6a0419538
--- /dev/null
+++ b/Library/Homebrew/test/resource_spec.rb
@@ -0,0 +1,147 @@
+require "resource"
+
+describe Resource do
+ subject { described_class.new("test") }
+
+ describe "#url" do
+ it "sets the URL" do
+ subject.url("foo")
+ expect(subject.url).to eq("foo")
+ end
+
+ it "can set the URL with specifications" do
+ subject.url("foo", branch: "master")
+ expect(subject.url).to eq("foo")
+ expect(subject.specs).to eq(branch: "master")
+ end
+
+ it "can set the URL with a custom download strategy class" do
+ strategy = Class.new(AbstractDownloadStrategy)
+ subject.url("foo", using: strategy)
+ expect(subject.url).to eq("foo")
+ expect(subject.download_strategy).to eq(strategy)
+ end
+
+ it "can set the URL with specifications and a custom download strategy class" do
+ strategy = Class.new(AbstractDownloadStrategy)
+ subject.url("foo", using: strategy, branch: "master")
+ expect(subject.url).to eq("foo")
+ expect(subject.specs).to eq(branch: "master")
+ expect(subject.download_strategy).to eq(strategy)
+ end
+
+ it "can set the URL with a custom download strategy symbol" do
+ subject.url("foo", using: :git)
+ expect(subject.url).to eq("foo")
+ expect(subject.download_strategy).to eq(GitDownloadStrategy)
+ end
+
+ it "raises an error if the download strategy class is unkown" do
+ expect { subject.url("foo", using: Class.new) }.to raise_error(TypeError)
+ end
+
+ it "does not mutate the specifications hash" do
+ specs = { using: :git, branch: "master" }
+ subject.url("foo", specs)
+ expect(subject.specs).to eq(branch: "master")
+ expect(subject.using).to eq(:git)
+ expect(specs).to eq(using: :git, branch: "master")
+ end
+ end
+
+ describe "#version" do
+ it "sets the version" do
+ subject.version("1.0")
+ expect(subject.version).to eq(Version.parse("1.0"))
+ expect(subject.version).not_to be_detected_from_url
+ end
+
+ it "can detect the version from a URL" do
+ subject.url("http://example.com/foo-1.0.tar.gz")
+ expect(subject.version).to eq(Version.parse("1.0"))
+ expect(subject.version).to be_detected_from_url
+ end
+
+ it "can set the version with a scheme" do
+ klass = Class.new(Version)
+ subject.version klass.new("1.0")
+ expect(subject.version).to eq(Version.parse("1.0"))
+ expect(subject.version).to be_a(klass)
+ end
+
+ it "can set the version from a tag" do
+ subject.url("http://example.com/foo-1.0.tar.gz", tag: "v1.0.2")
+ expect(subject.version).to eq(Version.parse("1.0.2"))
+ expect(subject.version).to be_detected_from_url
+ end
+
+ it "rejects non-string versions" do
+ expect { subject.version(1) }.to raise_error(TypeError)
+ expect { subject.version(2.0) }.to raise_error(TypeError)
+ expect { subject.version(Object.new) }.to raise_error(TypeError)
+ end
+
+ it "returns nil if unset" do
+ expect(subject.version).to be nil
+ end
+ end
+
+ describe "#mirrors" do
+ it "is empty by defaults" do
+ expect(subject.mirrors).to be_empty
+ end
+
+ it "returns an array of mirrors added with #mirror" do
+ subject.mirror("foo")
+ subject.mirror("bar")
+ expect(subject.mirrors).to eq(%w[foo bar])
+ end
+ end
+
+ describe "#checksum" do
+ it "returns nil if unset" do
+ expect(subject.checksum).to be nil
+ end
+
+ it "returns the checksum set with #sha256" do
+ subject.sha256(TEST_SHA256)
+ expect(subject.checksum).to eq(Checksum.new(:sha256, TEST_SHA256))
+ end
+ end
+
+ describe "#download_strategy" do
+ it "returns the download strategy" do
+ strategy = Object.new
+ expect(DownloadStrategyDetector)
+ .to receive(:detect).with("foo", nil).and_return(strategy)
+ subject.url("foo")
+ expect(subject.download_strategy).to eq(strategy)
+ end
+ end
+
+ specify "#verify_download_integrity_missing" do
+ fn = Pathname.new("test")
+
+ allow(fn).to receive(:file?).and_return(true)
+ expect(fn).to receive(:verify_checksum).and_raise(ChecksumMissingError)
+ expect(fn).to receive(:sha256)
+
+ shutup do
+ subject.verify_download_integrity(fn)
+ end
+ end
+
+ specify "#verify_download_integrity_mismatch" do
+ fn = double(file?: true)
+ checksum = subject.sha256(TEST_SHA256)
+
+ expect(fn).to receive(:verify_checksum).with(checksum)
+ .and_raise(ChecksumMismatchError.new(fn, checksum, Object.new))
+
+ shutup do
+ expect {
+ subject.verify_download_integrity(fn)
+ }.to raise_error(ChecksumMismatchError)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/resource_test.rb b/Library/Homebrew/test/resource_test.rb
deleted file mode 100644
index c1b526cb2..000000000
--- a/Library/Homebrew/test/resource_test.rb
+++ /dev/null
@@ -1,132 +0,0 @@
-require "testing_env"
-require "resource"
-
-class ResourceTests < Homebrew::TestCase
- def setup
- @resource = Resource.new("test")
- end
-
- def test_url
- @resource.url("foo")
- assert_equal "foo", @resource.url
- end
-
- def test_url_with_specs
- @resource.url("foo", branch: "master")
- assert_equal "foo", @resource.url
- assert_equal({ branch: "master" }, @resource.specs)
- end
-
- def test_url_with_custom_download_strategy_class
- strategy = Class.new(AbstractDownloadStrategy)
- @resource.url("foo", using: strategy)
- assert_equal "foo", @resource.url
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_url_with_specs_and_download_strategy
- strategy = Class.new(AbstractDownloadStrategy)
- @resource.url("foo", using: strategy, branch: "master")
- assert_equal "foo", @resource.url
- assert_equal({ branch: "master" }, @resource.specs)
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_url_with_custom_download_strategy_symbol
- @resource.url("foo", using: :git)
- assert_equal "foo", @resource.url
- assert_equal GitDownloadStrategy, @resource.download_strategy
- end
-
- def test_raises_for_unknown_download_strategy_class
- assert_raises(TypeError) { @resource.url("foo", using: Class.new) }
- end
-
- def test_does_not_mutate_specs_hash
- specs = { using: :git, branch: "master" }
- @resource.url("foo", specs)
- assert_equal({ branch: "master" }, @resource.specs)
- assert_equal(:git, @resource.using)
- assert_equal({ using: :git, branch: "master" }, specs)
- end
-
- def test_version
- @resource.version("1.0")
- assert_version_equal "1.0", @resource.version
- refute_predicate @resource.version, :detected_from_url?
- end
-
- def test_version_from_url
- @resource.url("http://example.com/foo-1.0.tar.gz")
- assert_version_equal "1.0", @resource.version
- assert_predicate @resource.version, :detected_from_url?
- end
-
- def test_version_with_scheme
- klass = Class.new(Version)
- @resource.version klass.new("1.0")
- assert_version_equal "1.0", @resource.version
- assert_instance_of klass, @resource.version
- end
-
- def test_version_from_tag
- @resource.url("http://example.com/foo-1.0.tar.gz", tag: "v1.0.2")
- assert_version_equal "1.0.2", @resource.version
- assert_predicate @resource.version, :detected_from_url?
- end
-
- def test_rejects_non_string_versions
- assert_raises(TypeError) { @resource.version(1) }
- assert_raises(TypeError) { @resource.version(2.0) }
- assert_raises(TypeError) { @resource.version(Object.new) }
- end
-
- def test_version_when_url_is_not_set
- assert_nil @resource.version
- end
-
- def test_mirrors
- assert_empty @resource.mirrors
- @resource.mirror("foo")
- @resource.mirror("bar")
- assert_equal %w[foo bar], @resource.mirrors
- end
-
- def test_checksum_setters
- assert_nil @resource.checksum
- @resource.sha256(TEST_SHA256)
- assert_equal Checksum.new(:sha256, TEST_SHA256), @resource.checksum
- end
-
- def test_download_strategy
- strategy = Object.new
- DownloadStrategyDetector
- .expects(:detect).with("foo", nil).returns(strategy)
- @resource.url("foo")
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_verify_download_integrity_missing
- fn = Pathname.new("test")
-
- fn.stubs(file?: true)
- fn.expects(:verify_checksum).raises(ChecksumMissingError)
- fn.expects(:sha256)
-
- shutup { @resource.verify_download_integrity(fn) }
- end
-
- def test_verify_download_integrity_mismatch
- fn = stub(file?: true)
- checksum = @resource.sha256(TEST_SHA256)
-
- fn.expects(:verify_checksum).with(checksum)
- .raises(ChecksumMismatchError.new(fn, checksum, Object.new))
-
- shutup do
- assert_raises(ChecksumMismatchError) do
- @resource.verify_download_integrity(fn)
- end
- end
- end
-end
diff --git a/Library/Homebrew/test/sandbox_test.rb b/Library/Homebrew/test/sandbox_test.rb
index 2a062cb10..a633defce 100644
--- a/Library/Homebrew/test/sandbox_test.rb
+++ b/Library/Homebrew/test/sandbox_test.rb
@@ -3,26 +3,23 @@ require "sandbox"
class SandboxTest < Homebrew::TestCase
def setup
+ super
skip "sandbox not implemented" unless Sandbox.available?
@sandbox = Sandbox.new
@dir = Pathname.new(mktmpdir)
@file = @dir/"foo"
end
- def teardown
- @dir.rmtree
- end
-
def test_formula?
f = formula { url "foo-1.0" }
f2 = formula { url "bar-1.0" }
f2.stubs(:tap).returns(Tap.fetch("test/tap"))
- ARGV.stubs(:sandbox?).returns true
+ ENV["HOMEBREW_SANDBOX"] = "1"
assert Sandbox.formula?(f),
"Formulae should be sandboxed if --sandbox was passed."
- ARGV.stubs(:sandbox?).returns false
+ ENV.delete("HOMEBREW_SANDBOX")
assert Sandbox.formula?(f),
"Formulae should be sandboxed if in a sandboxed tap."
refute Sandbox.formula?(f2),
@@ -30,7 +27,7 @@ class SandboxTest < Homebrew::TestCase
end
def test_test?
- ARGV.stubs(:no_sandbox?).returns false
+ ENV.delete("HOMEBREW_NO_SANDBOX")
assert Sandbox.test?,
"Tests should be sandboxed unless --no-sandbox was passed."
end
@@ -50,7 +47,7 @@ class SandboxTest < Homebrew::TestCase
def test_complains_on_failure
Utils.expects(popen_read: "foo")
- ARGV.stubs(verbose?: true)
+ ENV["HOMEBREW_VERBOSE"] = "1"
out, _err = capture_io do
assert_raises(ErrorDuringExecution) { @sandbox.exec "false" }
end
@@ -64,7 +61,7 @@ class SandboxTest < Homebrew::TestCase
bar
EOS
Utils.expects(popen_read: with_bogus_error)
- ARGV.stubs(verbose?: true)
+ ENV["HOMEBREW_VERBOSE"] = "1"
out, _err = capture_io do
assert_raises(ErrorDuringExecution) { @sandbox.exec "false" }
end
diff --git a/Library/Homebrew/test/search_remote_tap_test.rb b/Library/Homebrew/test/search_remote_tap_test.rb
deleted file mode 100644
index 9dd9ee654..000000000
--- a/Library/Homebrew/test/search_remote_tap_test.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require "testing_env"
-require "cmd/search"
-
-class SearchRemoteTapTests < Homebrew::TestCase
- def test_search_remote_tap
- json_response = {
- "tree" => [
- {
- "path" => "Formula/not-a-formula.rb",
- "type" => "blob",
- },
- ],
- }
-
- GitHub.stubs(:open).yields(json_response)
-
- assert_equal ["homebrew/not-a-tap/not-a-formula"], Homebrew.search_tap("homebrew", "not-a-tap", "not-a-formula")
- end
-end
diff --git a/Library/Homebrew/test/search_test.rb b/Library/Homebrew/test/search_test.rb
deleted file mode 100644
index 70b6f01fb..000000000
--- a/Library/Homebrew/test/search_test.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestSearch < IntegrationCommandTestCase
- def test_search
- setup_test_formula "testball"
- desc_cache = HOMEBREW_CACHE/"desc_cache.json"
- refute_predicate desc_cache, :exist?, "Cached file should not exist"
-
- assert_match "testball", cmd("search")
- assert_match "testball", cmd("search", "testball")
- assert_match "testball", cmd("search", "homebrew/homebrew-core/testball")
- assert_match "testball", cmd("search", "--desc", "Some test")
-
- flags = {
- "macports" => "https://www.macports.org/ports.php?by=name&substr=testball",
- "fink" => "http://pdb.finkproject.org/pdb/browse.php?summary=testball",
- "debian" => "https://packages.debian.org/search?keywords=testball&searchon=names&suite=all&section=all",
- "opensuse" => "https://software.opensuse.org/search?q=testball",
- "fedora" => "https://admin.fedoraproject.org/pkgdb/packages/%2Atestball%2A/",
- "ubuntu" => "http://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all&section=all",
- }
-
- flags.each do |flag, url|
- assert_equal url, cmd("search", "--#{flag}",
- "testball", "HOMEBREW_BROWSER" => "echo")
- end
-
- assert_predicate desc_cache, :exist?, "Cached file should exist"
- end
-end
diff --git a/Library/Homebrew/test/services_test.rb b/Library/Homebrew/test/services_test.rb
deleted file mode 100644
index 280aeb9f4..000000000
--- a/Library/Homebrew/test/services_test.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestServices < IntegrationCommandTestCase
- def test_services
- needs_test_cmd_taps
- needs_macos
- setup_remote_tap("homebrew/services")
- assert_equal "Warning: No services available to control with `brew services`",
- cmd("services", "list")
- end
-end
diff --git a/Library/Homebrew/test/sh_test.rb b/Library/Homebrew/test/sh_test.rb
deleted file mode 100644
index 48fcdc54a..000000000
--- a/Library/Homebrew/test/sh_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestSh < IntegrationCommandTestCase
- def test_sh
- assert_match "Your shell has been configured",
- cmd("sh", "SHELL" => which("true"))
- end
-end
diff --git a/Library/Homebrew/test/shell_test.rb b/Library/Homebrew/test/shell_test.rb
deleted file mode 100644
index 877acb5c8..000000000
--- a/Library/Homebrew/test/shell_test.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require "testing_env"
-require "utils/shell"
-
-class ShellSmokeTest < Homebrew::TestCase
- def test_path_to_shell
- # raw command name
- assert_equal :bash, Utils::Shell.path_to_shell("bash")
- # full path
- assert_equal :bash, Utils::Shell.path_to_shell("/bin/bash")
- # versions
- assert_equal :zsh, Utils::Shell.path_to_shell("zsh-5.2")
- # strip newline too
- assert_equal :zsh, Utils::Shell.path_to_shell("zsh-5.2\n")
- end
-
- def test_path_to_shell_failure
- assert_equal nil, Utils::Shell.path_to_shell("")
- assert_equal nil, Utils::Shell.path_to_shell("@@@@@@")
- assert_equal nil, Utils::Shell.path_to_shell("invalid_shell-4.2")
- end
-
- def test_sh_quote
- assert_equal "''", Utils::Shell.sh_quote("")
- assert_equal "\\\\", Utils::Shell.sh_quote("\\")
- assert_equal "'\n'", Utils::Shell.sh_quote("\n")
- assert_equal "\\$", Utils::Shell.sh_quote("$")
- assert_equal "word", Utils::Shell.sh_quote("word")
- end
-
- def test_csh_quote
- assert_equal "''", Utils::Shell.csh_quote("")
- assert_equal "\\\\", Utils::Shell.csh_quote("\\")
- # note this test is different than for sh
- assert_equal "'\\\n'", Utils::Shell.csh_quote("\n")
- assert_equal "\\$", Utils::Shell.csh_quote("$")
- assert_equal "word", Utils::Shell.csh_quote("word")
- end
-
- def prepend_path_shell(shell, path, fragment)
- original_shell = ENV["SHELL"]
- ENV["SHELL"] = shell
-
- prepend_message = Utils::Shell.prepend_path_in_shell_profile(path)
- assert(
- prepend_message.start_with?(fragment),
- "#{shell}: expected #{prepend_message} to match #{fragment}"
- )
-
- ENV["SHELL"] = original_shell
- end
-
- def test_prepend_path_in_shell_profile
- prepend_path_shell "/bin/tcsh", "/path", "echo 'setenv PATH /path"
-
- prepend_path_shell "/bin/bash", "/path", "echo 'export PATH=\"/path"
-
- prepend_path_shell "/usr/local/bin/fish", "/path", "echo 'set -g fish_user_paths \"/path\" $fish_user_paths' >>"
- end
-end
diff --git a/Library/Homebrew/test/software_spec_spec.rb b/Library/Homebrew/test/software_spec_spec.rb
new file mode 100644
index 000000000..5fd4f598a
--- /dev/null
+++ b/Library/Homebrew/test/software_spec_spec.rb
@@ -0,0 +1,184 @@
+require "software_spec"
+
+RSpec::Matchers.alias_matcher :have_defined_resource, :be_resource_defined
+RSpec::Matchers.alias_matcher :have_defined_option, :be_option_defined
+
+describe SoftwareSpec do
+ let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") }
+
+ describe "#resource" do
+ it "defines a resource" do
+ subject.resource("foo") { url "foo-1.0" }
+ expect(subject).to have_defined_resource("foo")
+ end
+
+ it "sets itself to be the resource's owner" do
+ subject.resource("foo") { url "foo-1.0" }
+ subject.owner = owner
+ subject.resources.each_value do |r|
+ expect(r.owner).to eq(subject)
+ end
+ end
+
+ it "receives the owner's version if it has no own version" do
+ subject.url("foo-42")
+ subject.resource("bar") { url "bar" }
+ subject.owner = owner
+
+ expect(subject.resource("bar").version).to eq("42")
+ end
+
+ it "raises an error when duplicate resources are defined" do
+ subject.resource("foo") { url "foo-1.0" }
+ expect {
+ subject.resource("foo") { url "foo-1.0" }
+ }.to raise_error(DuplicateResourceError)
+ end
+
+ it "raises an error when accessing missing resources" do
+ subject.owner = owner
+ expect {
+ subject.resource("foo")
+ }.to raise_error(ResourceMissingError)
+ end
+ end
+
+ describe "#owner" do
+ it "sets the owner" do
+ subject.owner = owner
+ expect(subject.owner).to eq(owner)
+ end
+
+ it "sets the name" do
+ subject.owner = owner
+ expect(subject.name).to eq(owner.name)
+ end
+ end
+
+ describe "#option" do
+ it "defines an option" do
+ subject.option("foo")
+ expect(subject).to have_defined_option("foo")
+ end
+
+ it "raises an error when it begins with dashes" do
+ expect {
+ subject.option("--foo")
+ }.to raise_error(ArgumentError)
+ end
+
+ it "raises an error when name is empty" do
+ expect {
+ subject.option("")
+ }.to raise_error(ArgumentError)
+ end
+
+ it "special cases the cxx11 option" do
+ subject.option(:cxx11)
+ expect(subject).to have_defined_option("c++11")
+ expect(subject).not_to have_defined_option("cxx11")
+ end
+
+ it "supports options with descriptions" do
+ subject.option("bar", "description")
+ expect(subject.options.first.description).to eq("description")
+ end
+
+ it "defaults to an empty string when no description is given" do
+ subject.option("foo")
+ expect(subject.options.first.description).to eq("")
+ end
+ end
+
+ describe "#deprecated_option" do
+ it "allows specifying deprecated options" do
+ subject.deprecated_option("foo" => "bar")
+ expect(subject.deprecated_options).not_to be_empty
+ expect(subject.deprecated_options.first.old).to eq("foo")
+ expect(subject.deprecated_options.first.current).to eq("bar")
+ end
+
+ it "allows specifying deprecated options as a Hash from an Array/String to an Array/String" do
+ subject.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"])
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo1", "bar1"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo2", "bar1"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar2"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar3"))
+ end
+
+ it "raises an error when empty" do
+ expect {
+ subject.deprecated_option({})
+ }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "#depends_on" do
+ it "allows specifying dependencies" do
+ subject.depends_on("foo")
+ expect(subject.deps.first.name).to eq("foo")
+ end
+
+ it "allows specifying optional dependencies" do
+ subject.depends_on "foo" => :optional
+ expect(subject).to have_defined_option("with-foo")
+ end
+
+ it "allows specifying recommended dependencies" do
+ subject.depends_on "bar" => :recommended
+ expect(subject).to have_defined_option("without-bar")
+ end
+ end
+
+ specify "explicit options override defaupt depends_on option description" do
+ subject.option("with-foo", "blah")
+ subject.depends_on("foo" => :optional)
+ expect(subject.options.first.description).to eq("blah")
+ end
+
+ describe "#patch" do
+ it "adds a patch" do
+ subject.patch(:p1, :DATA)
+ expect(subject.patches.count).to eq(1)
+ expect(subject.patches.first.strip).to eq(:p1)
+ end
+ end
+end
+
+describe HeadSoftwareSpec do
+ specify "#version" do
+ expect(subject.version).to eq(Version.create("HEAD"))
+ end
+
+ specify "#verify_download_integrity" do
+ expect(subject.verify_download_integrity(Object.new)).to be nil
+ end
+end
+
+describe BottleSpecification do
+ specify "#sha256" do
+ checksums = {
+ snow_leopard_32: "deadbeef" * 8,
+ snow_leopard: "faceb00c" * 8,
+ lion: "baadf00d" * 8,
+ mountain_lion: "8badf00d" * 8,
+ }
+
+ checksums.each_pair do |cat, digest|
+ subject.sha256(digest => cat)
+ end
+
+ checksums.each_pair do |cat, digest|
+ checksum, = subject.checksum_for(cat)
+ expect(Checksum.new(:sha256, digest)).to eq(checksum)
+ end
+ end
+
+ %w[root_url prefix cellar rebuild].each do |method|
+ specify "##{method}" do
+ object = Object.new
+ subject.public_send(method, object)
+ expect(subject.public_send(method)).to eq(object)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/software_spec_test.rb b/Library/Homebrew/test/software_spec_test.rb
deleted file mode 100644
index d9226f8c3..000000000
--- a/Library/Homebrew/test/software_spec_test.rb
+++ /dev/null
@@ -1,181 +0,0 @@
-require "testing_env"
-require "software_spec"
-
-class SoftwareSpecTests < Homebrew::TestCase
- def setup
- @spec = SoftwareSpec.new
- end
-
- def test_resource
- @spec.resource("foo") { url "foo-1.0" }
- assert @spec.resource_defined?("foo")
- end
-
- def test_raises_when_duplicate_resources_are_defined
- @spec.resource("foo") { url "foo-1.0" }
- assert_raises(DuplicateResourceError) do
- @spec.resource("foo") { url "foo-1.0" }
- end
- end
-
- def test_raises_when_accessing_missing_resources
- @spec.owner = Class.new do
- def name
- "test"
- end
-
- def full_name
- "test"
- end
-
- def tap
- "homebrew/core"
- end
- end.new
- assert_raises(ResourceMissingError) { @spec.resource("foo") }
- end
-
- def test_set_owner
- owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- @spec.owner = owner
- assert_equal owner, @spec.owner
- end
-
- def test_resource_owner
- @spec.resource("foo") { url "foo-1.0" }
- @spec.owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- assert_equal "some_name", @spec.name
- @spec.resources.each_value { |r| assert_equal @spec, r.owner }
- end
-
- def test_resource_without_version_receives_owners_version
- @spec.url("foo-42")
- @spec.resource("bar") { url "bar" }
- @spec.owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- assert_version_equal "42", @spec.resource("bar").version
- end
-
- def test_option
- @spec.option("foo")
- assert @spec.option_defined?("foo")
- end
-
- def test_option_raises_when_begins_with_dashes
- assert_raises(ArgumentError) { @spec.option("--foo") }
- end
-
- def test_option_raises_when_name_empty
- assert_raises(ArgumentError) { @spec.option("") }
- end
-
- def test_cxx11_option_special_case
- @spec.option(:cxx11)
- assert @spec.option_defined?("c++11")
- refute @spec.option_defined?("cxx11")
- end
-
- def test_option_description
- @spec.option("bar", "description")
- assert_equal "description", @spec.options.first.description
- end
-
- def test_option_description_defaults_to_empty_string
- @spec.option("foo")
- assert_equal "", @spec.options.first.description
- end
-
- def test_deprecated_option
- @spec.deprecated_option("foo" => "bar")
- refute_empty @spec.deprecated_options
- assert_equal "foo", @spec.deprecated_options.first.old
- assert_equal "bar", @spec.deprecated_options.first.current
- end
-
- def test_deprecated_options
- @spec.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"])
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo1", "bar1")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo2", "bar1")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar2")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar3")
- end
-
- def test_deprecated_option_raises_when_empty
- assert_raises(ArgumentError) { @spec.deprecated_option({}) }
- end
-
- def test_depends_on
- @spec.depends_on("foo")
- assert_equal "foo", @spec.deps.first.name
- end
-
- def test_dependency_option_integration
- @spec.depends_on "foo" => :optional
- @spec.depends_on "bar" => :recommended
- assert @spec.option_defined?("with-foo")
- assert @spec.option_defined?("without-bar")
- end
-
- def test_explicit_options_override_default_dep_option_description
- @spec.option("with-foo", "blah")
- @spec.depends_on("foo" => :optional)
- assert_equal "blah", @spec.options.first.description
- end
-
- def test_patch
- @spec.patch :p1, :DATA
- assert_equal 1, @spec.patches.length
- assert_equal :p1, @spec.patches.first.strip
- end
-end
-
-class HeadSoftwareSpecTests < Homebrew::TestCase
- def setup
- @spec = HeadSoftwareSpec.new
- end
-
- def test_version
- assert_version_equal "HEAD", @spec.version
- end
-
- def test_verify_download_integrity
- assert_nil @spec.verify_download_integrity(Object.new)
- end
-end
-
-class BottleSpecificationTests < Homebrew::TestCase
- def setup
- @spec = BottleSpecification.new
- end
-
- def test_checksum_setters
- checksums = {
- snow_leopard_32: "deadbeef"*8,
- snow_leopard: "faceb00c"*8,
- lion: "baadf00d"*8,
- mountain_lion: "8badf00d"*8,
- }
-
- checksums.each_pair do |cat, digest|
- @spec.sha256(digest => cat)
- end
-
- checksums.each_pair do |cat, digest|
- checksum, = @spec.checksum_for(cat)
- assert_equal Checksum.new(:sha256, digest), checksum
- end
- end
-
- def test_other_setters
- double = Object.new
- %w[root_url prefix cellar rebuild].each do |method|
- @spec.send(method, double)
- assert_equal double, @spec.send(method)
- end
- end
-end
diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb
new file mode 100644
index 000000000..9a4dbe026
--- /dev/null
+++ b/Library/Homebrew/test/spec_helper.rb
@@ -0,0 +1,101 @@
+require "find"
+require "pathname"
+require "rspec/its"
+require "rspec/wait"
+require "set"
+
+if ENV["HOMEBREW_TESTS_COVERAGE"]
+ require "simplecov"
+end
+
+$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew"))
+$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib"))
+
+require "global"
+require "tap"
+
+require "test/support/helper/shutup"
+require "test/support/helper/fixtures"
+require "test/support/helper/formula"
+require "test/support/helper/spec/shared_context/integration_test"
+
+TEST_DIRECTORIES = [
+ CoreTap.instance.path/"Formula",
+ HOMEBREW_CACHE,
+ HOMEBREW_CACHE_FORMULA,
+ HOMEBREW_CELLAR,
+ HOMEBREW_LOCK_DIR,
+ HOMEBREW_LOGS,
+ HOMEBREW_TEMP,
+].freeze
+
+RSpec.configure do |config|
+ config.order = :random
+ config.include(Test::Helper::Shutup)
+ config.include(Test::Helper::Fixtures)
+ config.include(Test::Helper::Formula)
+ config.before(:each) do |example|
+ if example.metadata[:needs_macos]
+ skip "Not on macOS." unless OS.mac?
+ end
+
+ if example.metadata[:needs_official_cmd_taps]
+ skip "Needs official command Taps." unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
+ end
+
+ if example.metadata[:needs_python]
+ skip "Python not installed." unless which("python")
+ end
+ end
+ config.around(:each) do |example|
+ begin
+ TEST_DIRECTORIES.each(&:mkpath)
+
+ @__homebrew_failed = Homebrew.failed?
+
+ @__files_before_test = Find.find(TEST_TMPDIR).map { |f| f.sub(TEST_TMPDIR, "") }
+
+ @__argv = ARGV.dup
+ @__env = ENV.to_hash # dup doesn't work on ENV
+
+ example.run
+ ensure
+ ARGV.replace(@__argv)
+ ENV.replace(@__env)
+
+ Tab.clear_cache
+
+ FileUtils.rm_rf [
+ TEST_DIRECTORIES.map(&:children),
+ HOMEBREW_LINKED_KEGS,
+ HOMEBREW_PINNED_KEGS,
+ HOMEBREW_PREFIX/".git",
+ HOMEBREW_PREFIX/"bin",
+ HOMEBREW_PREFIX/"share",
+ HOMEBREW_PREFIX/"opt",
+ HOMEBREW_PREFIX/"Caskroom",
+ HOMEBREW_LIBRARY/"Taps/caskroom",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bundle",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-shallow",
+ HOMEBREW_REPOSITORY/".git",
+ CoreTap.instance.path/".git",
+ CoreTap.instance.alias_dir,
+ CoreTap.instance.path/"formula_renames.json",
+ ]
+
+ files_after_test = Find.find(TEST_TMPDIR).map { |f| f.sub(TEST_TMPDIR, "") }
+
+ diff = Set.new(@__files_before_test) ^ Set.new(files_after_test)
+ expect(diff).to be_empty, <<-EOS.undent
+ file leak detected:
+ #{diff.map { |f| " #{f}" }.join("\n")}
+ EOS
+
+ Homebrew.failed = @__homebrew_failed
+ end
+ end
+end
+
+RSpec::Matchers.alias_matcher :have_failed, :be_failed
diff --git a/Library/Homebrew/test/stdlib_test.rb b/Library/Homebrew/test/stdlib_test.rb
deleted file mode 100644
index 3babfd58a..000000000
--- a/Library/Homebrew/test/stdlib_test.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-require "testing_env"
-require "formula"
-require "cxxstdlib"
-
-class CxxStdlibTests < Homebrew::TestCase
- def setup
- @clang = CxxStdlib.create(:libstdcxx, :clang)
- @gcc = CxxStdlib.create(:libstdcxx, :gcc)
- @gcc40 = CxxStdlib.create(:libstdcxx, :gcc_4_0)
- @gcc42 = CxxStdlib.create(:libstdcxx, :gcc_4_2)
- @gcc48 = CxxStdlib.create(:libstdcxx, "gcc-4.8")
- @gcc49 = CxxStdlib.create(:libstdcxx, "gcc-4.9")
- @lcxx = CxxStdlib.create(:libcxx, :clang)
- @purec = CxxStdlib.create(nil, :clang)
- end
-
- def test_apple_libstdcxx_intercompatibility
- assert @clang.compatible_with?(@gcc)
- assert @clang.compatible_with?(@gcc42)
- end
-
- def test_compatibility_same_compilers_and_type
- assert @gcc.compatible_with?(@gcc)
- assert @gcc48.compatible_with?(@gcc48)
- assert @clang.compatible_with?(@clang)
- end
-
- def test_apple_gnu_libstdcxx_incompatibility
- assert !@clang.compatible_with?(@gcc48)
- assert !@gcc48.compatible_with?(@clang)
- end
-
- def test_gnu_cross_version_incompatibility
- assert !@gcc48.compatible_with?(@gcc49)
- assert !@gcc49.compatible_with?(@gcc48)
- end
-
- def test_libstdcxx_libcxx_incompatibility
- assert !@clang.compatible_with?(@lcxx)
- assert !@lcxx.compatible_with?(@clang)
- end
-
- def test_apple_compiler_reporting
- assert_predicate @clang, :apple_compiler?
- assert_predicate @gcc, :apple_compiler?
- assert_predicate @gcc42, :apple_compiler?
- refute_predicate @gcc48, :apple_compiler?
- end
-
- def test_type_string_formatting
- assert_equal "libstdc++", @clang.type_string
- assert_equal "libc++", @lcxx.type_string
- end
-
- def test_compatibility_for_non_cxx_software
- assert @purec.compatible_with?(@clang)
- assert @clang.compatible_with?(@purec)
- assert @purec.compatible_with?(@purec)
- assert @purec.compatible_with?(@gcc48)
- assert @gcc48.compatible_with?(@purec)
- end
-end
diff --git a/Library/Homebrew/test/string_spec.rb b/Library/Homebrew/test/string_spec.rb
new file mode 100644
index 000000000..d1b820b66
--- /dev/null
+++ b/Library/Homebrew/test/string_spec.rb
@@ -0,0 +1,49 @@
+require "extend/string"
+
+describe String do
+ describe "#undent" do
+ it "removes leading whitespace, taking the first line as reference" do
+ string = <<-EOS.undent
+ hi
+........my friend over
+ there
+ EOS
+
+ expect(string).to eq("hi\n........my friend over\n there\n")
+ end
+
+ it "removes nothing if the text is not indented" do
+ string = <<-EOS.undent
+hi
+I'm not indented
+ EOS
+
+ expect(string).to eq("hi\nI'm not indented\n")
+ end
+
+ it "can be nested" do
+ nested_string = <<-EOS.undent
+ goodbye
+ EOS
+
+ string = <<-EOS.undent
+ hello
+ #{nested_string}
+ EOS
+
+ expect(string).to eq("hello\ngoodbye\n\n")
+ end
+ end
+end
+
+describe StringInreplaceExtension do
+ subject { string.extend(described_class) }
+ let(:string) { "foobar" }
+
+ describe "#sub!" do
+ it "adds an error to #errors when no replacement was made" do
+ subject.sub! "not here", "test"
+ expect(subject.errors).to eq(['expected replacement of "not here" with "test"'])
+ end
+ end
+end
diff --git a/Library/Homebrew/test/string_test.rb b/Library/Homebrew/test/string_test.rb
deleted file mode 100644
index 497c4badb..000000000
--- a/Library/Homebrew/test/string_test.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require "testing_env"
-require "extend/string"
-
-class StringTest < Homebrew::TestCase
- def test_undent
- undented = <<-EOS.undent
- hi
-....my friend over
- there
- EOS
- assert_equal "hi\n....my friend over\nthere\n", undented
- end
-
- def test_undent_not_indented
- undented = <<-EOS.undent
-hi
-I'm not indented
- EOS
- assert_equal "hi\nI'm not indented\n", undented
- end
-
- def test_undent_nested
- nest = <<-EOS.undent
- goodbye
- EOS
-
- undented = <<-EOS.undent
- hello
- #{nest}
- EOS
-
- assert_equal "hello\ngoodbye\n\n", undented
- end
-
- def test_inreplace_sub_failure
- s = "foobar".extend StringInreplaceExtension
- s.sub! "not here", "test"
- assert_equal ['expected replacement of "not here" with "test"'], s.errors
- end
-end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-checkpoint-sha256-for-empty-string.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-checkpoint-sha256-for-empty-string.rb
new file mode 100644
index 000000000..4e74d728d
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-checkpoint-sha256-for-empty-string.rb
@@ -0,0 +1,4 @@
+cask 'appcast-checkpoint-sha256-for-empty-string' do
+ appcast 'http://localhost/appcast.xml',
+ checkpoint: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-invalid-checkpoint.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-invalid-checkpoint.rb
new file mode 100644
index 000000000..8b6934148
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-invalid-checkpoint.rb
@@ -0,0 +1,4 @@
+cask 'appcast-invalid-checkpoint' do
+ appcast 'http://localhost/appcast.xml',
+ checkpoint: 'not a valid shasum'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-missing-checkpoint.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-missing-checkpoint.rb
new file mode 100644
index 000000000..fefdbcb3a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-missing-checkpoint.rb
@@ -0,0 +1,3 @@
+cask 'appcast-missing-checkpoint' do
+ appcast 'http://localhost/appcast.xml'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-valid-checkpoint.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-valid-checkpoint.rb
new file mode 100644
index 000000000..84c9ca512
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/appcast-valid-checkpoint.rb
@@ -0,0 +1,4 @@
+cask 'appcast-valid-checkpoint' do
+ appcast 'http://localhost/appcast.xml',
+ checkpoint: 'd5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/appdir-interpolation.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/appdir-interpolation.rb
new file mode 100644
index 000000000..e4b3e79e6
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/appdir-interpolation.rb
@@ -0,0 +1,9 @@
+cask 'appdir-interpolation' do
+ version '2.61'
+ sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
+ homepage 'http://example.com/appdir-interpolation'
+
+ binary "#{appdir}/some/path"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/auto-updates.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/auto-updates.rb
new file mode 100644
index 000000000..1cada2561
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/auto-updates.rb
@@ -0,0 +1,11 @@
+cask 'auto-updates' do
+ version '2.61'
+ sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
+ homepage 'http://example.com/auto-updates'
+
+ auto_updates true
+
+ app 'Transmission.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/bad-checksum.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/bad-checksum.rb
new file mode 100644
index 000000000..254ee59fd
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/bad-checksum.rb
@@ -0,0 +1,9 @@
+cask 'bad-checksum' do
+ version '1.2.3'
+ sha256 'badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/basic-cask.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/basic-cask.rb
new file mode 100644
index 000000000..ff1d90003
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/basic-cask.rb
@@ -0,0 +1,9 @@
+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/test/support/fixtures/cask/Casks/booby-trap.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/booby-trap.rb
new file mode 100644
index 000000000..21bd97952
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/booby-trap.rb
@@ -0,0 +1,8 @@
+cask 'booby-trap' do
+ version '0.0.7'
+
+ url do
+ # to be lazily evaluated
+ fail 'Boom'
+ end
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-7z.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-7z.rb
new file mode 100644
index 000000000..5b043a75e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-7z.rb
@@ -0,0 +1,11 @@
+cask 'container-7z' do
+ version '1.2.3'
+ sha256 '3f9542ace85ed5f88549e2d0ea82210f8ddc87e0defbb78469d3aed719b3c964'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.7z"
+ homepage 'https://example.com/container-7z'
+
+ depends_on formula: 'unar'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-air.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-air.rb
new file mode 100644
index 000000000..5aaf3d53e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-air.rb
@@ -0,0 +1,9 @@
+cask 'container-air' do
+ version '0.1'
+ sha256 '554472e163f8a028629b12b468e29acda9f16b223dff74fcd218bba73cc2365a'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.air"
+ homepage 'https://example.com/container-air'
+
+ app 'container.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-bzip2.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-bzip2.rb
new file mode 100644
index 000000000..60f834b7f
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-bzip2.rb
@@ -0,0 +1,9 @@
+cask 'container-bzip2' do
+ version '1.2.3'
+ sha256 'eaf67b3a62cb9275f96e45d05c70b94bef9ef1dae344083e93eda6b0b388a61c'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.bz2"
+ homepage 'https://example.com/container-bzip2'
+
+ app 'container-bzip2--1.2.3'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-cab.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-cab.rb
new file mode 100644
index 000000000..e57131567
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-cab.rb
@@ -0,0 +1,11 @@
+cask 'container-cab' do
+ version '1.2.3'
+ sha256 'c267f5cebb14814c8e612a8b7d2bda02aec913f869509b6f1d3883427c0f552b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.cab"
+ homepage 'https://example.com/container-cab'
+
+ depends_on formula: 'cabextract'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-dmg.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-dmg.rb
new file mode 100644
index 000000000..e9974b5d2
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-dmg.rb
@@ -0,0 +1,9 @@
+cask 'container-dmg' do
+ version '1.2.3'
+ sha256 '74d89d4fa5cef175cf43666ce11fefa3741aa1522114042ac75e656be37141a1'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.dmg"
+ homepage 'https://example.com/container-dmg'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-gzip.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gzip.rb
new file mode 100644
index 000000000..0bfc4108f
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gzip.rb
@@ -0,0 +1,9 @@
+cask 'container-gzip' do
+ version '1.2.3'
+ sha256 'fa4ebb5246583c4b6e62e1df4e3b71b4e38a1d7d91c025665827195d36214b20'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.gz"
+ homepage 'https://example.com/container-gzip'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-lzma.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-lzma.rb
new file mode 100644
index 000000000..92d2c253e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-lzma.rb
@@ -0,0 +1,11 @@
+cask 'container-lzma' do
+ version '1.2.3'
+ sha256 '9d7edb32d02ab9bd9749a5bde8756595ea4cfcb1da02ca11c30fb591d4c1ed85'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.lzma"
+ homepage 'https://example.com/container-lzma'
+
+ depends_on formula: 'lzma'
+
+ app 'container-lzma--1.2.3'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-pkg.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-pkg.rb
new file mode 100644
index 000000000..2ff4cca1e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-pkg.rb
@@ -0,0 +1,7 @@
+cask 'container-pkg' do
+ version '1.2.3'
+ sha256 '611c50c8a2a2098951d2cd0fd54787ed81b92cd97b4b08bd7cba17f1e1d8e40b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.pkg"
+ homepage 'https://example.com/container-pkg'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-rar.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-rar.rb
new file mode 100644
index 000000000..33ea670d1
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-rar.rb
@@ -0,0 +1,11 @@
+cask 'container-rar' do
+ version '1.2.3'
+ sha256 '419af7864c0e1f125515c49b08bd22e0f7de39f5285897c440fe03c714871763'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.rar"
+ homepage 'https://example.com/container-rar'
+
+ depends_on formula: 'unar'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-sit.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-sit.rb
new file mode 100644
index 000000000..5715795a7
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-sit.rb
@@ -0,0 +1,11 @@
+cask 'container-sit' do
+ version '1.2.3'
+ sha256 '0d21a64dce625044345c8ecca888e5439feaf254dac7f884917028a744f93cf3'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.sit"
+ homepage 'https://example.com/container-sit'
+
+ depends_on formula: 'unar'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-tar-gz.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-tar-gz.rb
new file mode 100644
index 000000000..e32931c89
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-tar-gz.rb
@@ -0,0 +1,9 @@
+cask 'container-tar-gz' do
+ version '1.2.3'
+ sha256 'fab685fabf73d5a9382581ce8698fce9408f5feaa49fa10d9bc6c510493300f5'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.gz"
+ homepage 'https://example.com/container-tar-gz'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-xar.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-xar.rb
new file mode 100644
index 000000000..82a751d5d
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-xar.rb
@@ -0,0 +1,9 @@
+cask 'container-xar' do
+ version '1.2.3'
+ sha256 '5bb8e09a6fc630ebeaf266b1fd2d15e2ae7d32d7e4da6668a8093426fa1ba509'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.xar"
+ homepage 'https://example.com/container-xar'
+
+ app 'container'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-xz.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-xz.rb
new file mode 100644
index 000000000..3f844af04
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/container-xz.rb
@@ -0,0 +1,11 @@
+cask 'container-xz' do
+ version '1.2.3'
+ sha256 '839263f474edde1d54a9101606e6f0dc9d963acc93f6dcc5af8d10ebc3187c02'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/container.xz"
+ homepage 'https://example.com/container-xz'
+
+ depends_on formula: 'xz'
+
+ app 'container-xz--1.2.3'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb
new file mode 100644
index 000000000..a1844a9c9
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb
@@ -0,0 +1,3 @@
+cask 'generic-artifact-absolute-target' do
+ artifact 'Caffeine.app', target: "#{Hbc.appdir}/Caffeine.app"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb
new file mode 100644
index 000000000..a3e65caab
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-no-target.rb
@@ -0,0 +1,3 @@
+cask 'generic-artifact-no-target' do
+ artifact 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-relative-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-relative-target.rb
new file mode 100644
index 000000000..eb521e35a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-relative-target.rb
@@ -0,0 +1,3 @@
+cask 'generic-artifact-relative-target' do
+ artifact 'Caffeine.app', target: 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid-sha256.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid-sha256.rb
new file mode 100644
index 000000000..2804da7c3
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid-sha256.rb
@@ -0,0 +1,4 @@
+cask 'invalid-sha256' do
+ version '1.2.3'
+ sha256 'not a valid shasum'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-multiple.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-multiple.rb
new file mode 100644
index 000000000..37634f619
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-multiple.rb
@@ -0,0 +1,13 @@
+cask 'invalid-appcast-multiple' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ appcast 'http://example.com/appcast1.xml',
+ checkpoint: '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+ appcast 'http://example.com/appcast2.xml',
+ checkpoint: '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+ homepage 'http://example.com/invalid-appcast-multiple'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-url.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-url.rb
new file mode 100644
index 000000000..7b51ffb53
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-appcast-url.rb
@@ -0,0 +1,11 @@
+cask 'invalid-appcast-url' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ appcast 1,
+ checkpoint: '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+ homepage 'http://example.com/invalid-appcast-url'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-conflicts-with-key.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-conflicts-with-key.rb
new file mode 100644
index 000000000..b066139ce
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-conflicts-with-key.rb
@@ -0,0 +1,11 @@
+cask 'invalid-conflicts-with-key' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-arch-value.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-arch-value.rb
new file mode 100644
index 000000000..b21912a6e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-arch-value.rb
@@ -0,0 +1,11 @@
+cask 'invalid-depends-on-arch-value' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-key.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-key.rb
new file mode 100644
index 000000000..24a912893
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-key.rb
@@ -0,0 +1,11 @@
+cask 'invalid-depends-on-key' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-bad-release.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-bad-release.rb
new file mode 100644
index 000000000..723ceacbb
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-bad-release.rb
@@ -0,0 +1,11 @@
+cask 'invalid-depends-on-macos-bad-release' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb
new file mode 100644
index 000000000..689e24b67
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-macos-conflicting-forms.rb
@@ -0,0 +1,12 @@
+cask 'invalid-depends-on-macos-conflicting-forms' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-x11-value.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-x11-value.rb
new file mode 100644
index 000000000..5c3faec35
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-depends-on-x11-value.rb
@@ -0,0 +1,11 @@
+cask 'invalid-depends-on-x11-value' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-gpg-conflicting-keys.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-conflicting-keys.rb
new file mode 100644
index 000000000..baf124b7a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-conflicting-keys.rb
@@ -0,0 +1,12 @@
+cask 'invalid-gpg-conflicting-keys' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-id.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-id.rb
new file mode 100644
index 000000000..386593b06
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-id.rb
@@ -0,0 +1,11 @@
+cask 'invalid-gpg-key-id' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-url.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-url.rb
new file mode 100644
index 000000000..4108380d2
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-key-url.rb
@@ -0,0 +1,11 @@
+cask 'invalid-gpg-key-url' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-gpg-missing-key.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-missing-key.rb
new file mode 100644
index 000000000..3375801c9
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-missing-key.rb
@@ -0,0 +1,10 @@
+cask 'invalid-gpg-missing-key' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-gpg-multiple-stanzas.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-multiple-stanzas.rb
new file mode 100644
index 000000000..b420f74d5
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-multiple-stanzas.rb
@@ -0,0 +1,13 @@
+cask 'invalid-gpg-multiple-stanzas' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-gpg-parameter.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-parameter.rb
new file mode 100644
index 000000000..40f6a9dae
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-parameter.rb
@@ -0,0 +1,11 @@
+cask 'invalid-gpg-parameter' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-gpg-signature-url.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-signature-url.rb
new file mode 100644
index 000000000..43cc27b08
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-signature-url.rb
@@ -0,0 +1,11 @@
+cask 'invalid-gpg-signature-url' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/invalid-gpg-signature-url'
+ gpg 1,
+ key_id: '01234567'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-type.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-type.rb
new file mode 100644
index 000000000..a369ef875
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-gpg-type.rb
@@ -0,0 +1,11 @@
+cask 'invalid-gpg-type' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/invalid/invalid-header-format.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-format.rb
new file mode 100644
index 000000000..c8c613767
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-format.rb
@@ -0,0 +1,9 @@
+cask => 'invalid-header-format' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-token-mismatch.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-token-mismatch.rb
new file mode 100644
index 000000000..af15a13ef
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-token-mismatch.rb
@@ -0,0 +1,9 @@
+cask 'invalid-header-token-mismatch-this-text-does-not-belong' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-version.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-version.rb
new file mode 100644
index 000000000..7e37e61df
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-header-version.rb
@@ -0,0 +1,9 @@
+cask 'invalid-header-version' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-stage-only-conflict.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-stage-only-conflict.rb
new file mode 100644
index 000000000..5a0ccadf6
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-stage-only-conflict.rb
@@ -0,0 +1,10 @@
+cask 'invalid-stage-only-conflict' do
+ version '2.61'
+ sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
+ homepage 'http://example.com/invalid-stage-only-conflict'
+
+ app 'Transmission.app'
+ stage_only true
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-homepage.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-homepage.rb
new file mode 100644
index 000000000..5170a9c0f
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-homepage.rb
@@ -0,0 +1,10 @@
+cask 'invalid-two-homepage' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+ homepage 'http://www.example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-url.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-url.rb
new file mode 100644
index 000000000..f548400a4
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-url.rb
@@ -0,0 +1,10 @@
+cask 'invalid-two-url' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ url 'http://example.com/caffeine.zip'
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-version.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-version.rb
new file mode 100644
index 000000000..fbffa8a1e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/invalid/invalid-two-version.rb
@@ -0,0 +1,10 @@
+cask 'invalid-two-version' do
+ version '1.2.3'
+ version '2.0'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/local-caffeine.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/local-caffeine.rb
new file mode 100644
index 000000000..934d22463
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/local-caffeine.rb
@@ -0,0 +1,9 @@
+cask 'local-caffeine' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/local-transmission.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/local-transmission.rb
new file mode 100644
index 000000000..6709ac12e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/local-transmission.rb
@@ -0,0 +1,9 @@
+cask 'local-transmission' do
+ version '2.61'
+ sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
+ homepage 'http://example.com/local-transmission'
+
+ app 'Transmission.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/missing-checksum.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-checksum.rb
new file mode 100644
index 000000000..907b1375f
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-checksum.rb
@@ -0,0 +1,8 @@
+cask 'missing-checksum' do
+ version '1.2.3'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/missing-homepage.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-homepage.rb
new file mode 100644
index 000000000..cf06d6c33
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-homepage.rb
@@ -0,0 +1,5 @@
+cask 'missing-homepage' do
+ version '1.2.3'
+
+ url 'http://localhost/something.dmg'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/missing-name.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-name.rb
new file mode 100644
index 000000000..0801f4abb
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-name.rb
@@ -0,0 +1,5 @@
+cask 'missing-name' do
+ version '1.2.3'
+
+ url 'http://localhost/something.dmg'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/missing-sha256.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-sha256.rb
new file mode 100644
index 000000000..e6e6d9d20
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-sha256.rb
@@ -0,0 +1,5 @@
+cask 'missing-sha256' do
+ version '1.2.3'
+
+ url 'http://localhost/something.dmg'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/missing-url.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-url.rb
new file mode 100644
index 000000000..0bfaec332
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-url.rb
@@ -0,0 +1,5 @@
+cask 'missing-url' do
+ version '1.2.3'
+
+ homepage 'http://example.com'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/missing-version.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-version.rb
new file mode 100644
index 000000000..88e13d8bb
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/missing-version.rb
@@ -0,0 +1,4 @@
+cask 'missing-version' do
+ url 'http://localhost/something.dmg'
+ homepage 'http://example.com'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/naked-executable.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/naked-executable.rb
new file mode 100644
index 000000000..2f4e30dc1
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/naked-executable.rb
@@ -0,0 +1,9 @@
+cask 'naked-executable' do
+ version '1.2.3'
+ sha256 '306c6ca7407560340797866e077e053627ad409277d1b9da58106fce4cf717cb'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/naked_executable"
+ homepage 'http://example.com/naked-executable'
+
+ container type: :naked
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/nested-app.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/nested-app.rb
new file mode 100644
index 000000000..6061f7bff
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/nested-app.rb
@@ -0,0 +1,11 @@
+cask 'nested-app' do
+ version '1.2.3'
+ sha256 '1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/NestedApp.dmg.zip"
+ homepage 'http://example.com/nested-app'
+
+ container nested: 'NestedApp.dmg'
+
+ app 'MyNestedApp.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/no-checksum.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/no-checksum.rb
new file mode 100644
index 000000000..1e06c6168
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/no-checksum.rb
@@ -0,0 +1,9 @@
+cask 'no-checksum' do
+ version '1.2.3'
+ sha256 :no_check
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/no-dsl-version.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/no-dsl-version.rb
new file mode 100644
index 000000000..3bafa171d
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/no-dsl-version.rb
@@ -0,0 +1,9 @@
+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/test/support/fixtures/cask/Casks/osdn-correct-url-format.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/osdn-correct-url-format.rb
new file mode 100644
index 000000000..7e60fc179
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/osdn-correct-url-format.rb
@@ -0,0 +1,6 @@
+cask 'osdn-correct-url-format' do
+ version '1.2.3'
+
+ url 'http://user.dl.osdn.jp/something/id/Something-1.2.3.dmg'
+ homepage 'http://osdn.jp/projects/something/'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/osdn-incorrect-url-format.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/osdn-incorrect-url-format.rb
new file mode 100644
index 000000000..68b4ecd4c
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/osdn-incorrect-url-format.rb
@@ -0,0 +1,6 @@
+cask 'osdn-incorrect-url-format' do
+ version '1.2.3'
+
+ url 'http://osdn.jp/projects/something/files/Something-1.2.3.dmg/download'
+ homepage 'http://osdn.jp/projects/something/'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/sha256-for-empty-string.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/sha256-for-empty-string.rb
new file mode 100644
index 000000000..0bf3ee9b5
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/sha256-for-empty-string.rb
@@ -0,0 +1,4 @@
+cask 'sha256-for-empty-string' do
+ version '1.2.3'
+ sha256 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-correct-url-format.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-correct-url-format.rb
new file mode 100644
index 000000000..439eb8998
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-correct-url-format.rb
@@ -0,0 +1,6 @@
+cask 'sourceforge-correct-url-format' do
+ version '1.2.3'
+
+ url 'https://downloads.sourceforge.net/something/Something-1.2.3.dmg'
+ homepage 'https://sourceforge.net/projects/something/'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-incorrect-url-format.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-incorrect-url-format.rb
new file mode 100644
index 000000000..39ac52414
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-incorrect-url-format.rb
@@ -0,0 +1,6 @@
+cask 'sourceforge-incorrect-url-format' do
+ version '1.2.3'
+
+ url 'http://sourceforge.net/projects/something/files/Something-1.2.3.dmg/download'
+ homepage 'http://sourceforge.net/projects/something/'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-version-latest-correct-url-format.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-version-latest-correct-url-format.rb
new file mode 100644
index 000000000..07b068f70
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/sourceforge-version-latest-correct-url-format.rb
@@ -0,0 +1,6 @@
+cask 'sourceforge-version-latest-correct-url-format' do
+ version :latest
+
+ url 'https://sourceforge.net/projects/something/files/latest/download'
+ homepage 'https://sourceforge.net/projects/something/'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/stage-only.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/stage-only.rb
new file mode 100644
index 000000000..941e2084f
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/stage-only.rb
@@ -0,0 +1,9 @@
+cask 'stage-only' do
+ version '2.61'
+ sha256 'e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/transmission-2.61.dmg"
+ homepage 'http://example.com/stage-only'
+
+ stage_only true
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/test-opera-mail.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/test-opera-mail.rb
new file mode 100644
index 000000000..3e2c76e67
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/test-opera-mail.rb
@@ -0,0 +1,9 @@
+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/test/support/fixtures/cask/Casks/test-opera.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/test-opera.rb
new file mode 100644
index 000000000..7ca0157d9
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/test-opera.rb
@@ -0,0 +1,9 @@
+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/test/support/fixtures/cask/Casks/version-latest-string.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest-string.rb
new file mode 100644
index 000000000..6bd090c28
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest-string.rb
@@ -0,0 +1,4 @@
+cask 'version-latest-string' do
+ version 'latest'
+ sha256 :no_check
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest-with-checksum.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest-with-checksum.rb
new file mode 100644
index 000000000..040cfc76e
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/version-latest-with-checksum.rb
@@ -0,0 +1,4 @@
+cask 'version-latest-with-checksum' do
+ version :latest
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-accessibility-access.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-accessibility-access.rb
new file mode 100644
index 000000000..4c1c9897a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-accessibility-access.rb
@@ -0,0 +1,11 @@
+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/test/support/fixtures/cask/Casks/with-alt-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-alt-target.rb
new file mode 100644
index 000000000..7a6d75a9c
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-alt-target.rb
@@ -0,0 +1,9 @@
+cask 'with-alt-target' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app', target: 'AnotherName.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-appcast.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-appcast.rb
new file mode 100644
index 000000000..fc57e5e65
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-appcast.rb
@@ -0,0 +1,11 @@
+cask 'with-appcast' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ appcast 'http://example.com/appcast.xml',
+ checkpoint: '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+ homepage 'http://example.com/with-appcast'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-binary.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-binary.rb
new file mode 100644
index 000000000..38be2e772
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-binary.rb
@@ -0,0 +1,10 @@
+cask 'with-binary' do
+ version '1.2.3'
+ sha256 'd5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/AppWithBinary.zip"
+ homepage 'http://example.com/with-binary'
+
+ app 'App.app'
+ binary 'binary'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-caveats.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-caveats.rb
new file mode 100644
index 000000000..d5d90114a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-caveats.rb
@@ -0,0 +1,23 @@
+cask 'with-caveats' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-choices.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-choices.rb
new file mode 100644
index 000000000..640a3bbb3
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-choices.rb
@@ -0,0 +1,16 @@
+cask 'with-choices' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'MyFancyPkg/Fancy.pkg',
+ choices: [
+ {
+ 'choiceIdentifier' => 'choice1',
+ 'choiceAttribute' => 'selected',
+ 'attributeSetting' => 1,
+ },
+ ]
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-caveats.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-caveats.rb
new file mode 100644
index 000000000..e3c666834
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-caveats.rb
@@ -0,0 +1,14 @@
+cask 'with-conditional-caveats' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-conflicts-with.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb
new file mode 100644
index 000000000..ab3631743
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb
@@ -0,0 +1,11 @@
+cask 'with-conflicts-with' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-conflicts-with'
+
+ conflicts_with formula: 'unar'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-arch.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-arch.rb
new file mode 100644
index 000000000..9fe0d043b
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-arch.rb
@@ -0,0 +1,12 @@
+cask 'with-depends-on-arch' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-depends-on-arch'
+
+ # covers all known hardware; always succeeds
+ depends_on arch: :intel
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic-helper.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic-helper.rb
new file mode 100644
index 000000000..3a90295e5
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic-helper.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-cask-cyclic-helper' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic.rb
new file mode 100644
index 000000000..776351568
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-cyclic.rb
@@ -0,0 +1,12 @@
+cask 'with-depends-on-cask-cyclic' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-cask-multiple.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-multiple.rb
new file mode 100644
index 000000000..74e1c2747
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask-multiple.rb
@@ -0,0 +1,12 @@
+cask 'with-depends-on-cask-multiple' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-cask.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask.rb
new file mode 100644
index 000000000..52daec865
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-cask.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-cask' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-depends-on-cask'
+
+ depends_on cask: 'local-transmission'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-formula-multiple.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-formula-multiple.rb
new file mode 100644
index 000000000..07d7bb86a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-formula-multiple.rb
@@ -0,0 +1,12 @@
+cask 'with-depends-on-formula-multiple' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-formula.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-formula.rb
new file mode 100644
index 000000000..ac980f890
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-formula.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-formula' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-depends-on-formula'
+
+ depends_on formula: 'unar'
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-array.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-array.rb
new file mode 100644
index 000000000..7fb1a9016
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-array.rb
@@ -0,0 +1,12 @@
+cask 'with-depends-on-macos-array' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-macos-comparison.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-comparison.rb
new file mode 100644
index 000000000..1483bcf74
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-comparison.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-macos-comparison' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-macos-failure.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-failure.rb
new file mode 100644
index 000000000..483d75814
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-failure.rb
@@ -0,0 +1,12 @@
+cask 'with-depends-on-macos-failure' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-macos-string.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-string.rb
new file mode 100644
index 000000000..887771fe2
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-string.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-macos-string' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-macos-symbol.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-symbol.rb
new file mode 100644
index 000000000..e5aa05d23
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-macos-symbol.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-macos-symbol' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-depends-on-x11-false.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-x11-false.rb
new file mode 100644
index 000000000..d5107edc5
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-x11-false.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-x11-false' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-depends-on-x11-false'
+
+ depends_on x11: false
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-x11.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-x11.rb
new file mode 100644
index 000000000..bcb781637
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-depends-on-x11.rb
@@ -0,0 +1,11 @@
+cask 'with-depends-on-x11' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-depends-on-x11'
+
+ depends_on x11: true
+
+ app 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-dsl-version.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-dsl-version.rb
new file mode 100644
index 000000000..15f0319c5
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-dsl-version.rb
@@ -0,0 +1,9 @@
+cask :v1 => 'with-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/test/support/fixtures/cask/Casks/with-embedded-binary.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-embedded-binary.rb
new file mode 100644
index 000000000..5987bbfe6
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-embedded-binary.rb
@@ -0,0 +1,10 @@
+cask 'with-embedded-binary' do
+ version '1.2.3'
+ sha256 'fe052d3e77d92676775fd916ddb8942e72a565b844ea7f6d055474c99bb4e47b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/AppWithEmbeddedBinary.zip"
+ homepage 'http://example.com/with-binary'
+
+ app 'App.app'
+ binary "#{appdir}/App.app/Contents/MacOS/App/binary"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact-no-target.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact-no-target.rb
new file mode 100644
index 000000000..f7f1ddc22
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact-no-target.rb
@@ -0,0 +1,9 @@
+cask 'with-generic-artifact-no-target' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-generic-artifact'
+
+ artifact 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb
new file mode 100644
index 000000000..d6ce0ce8d
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb
@@ -0,0 +1,9 @@
+cask 'with-generic-artifact' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/with-generic-artifact'
+
+ artifact 'Caffeine.app', target: "#{Hbc.appdir}/Caffeine.app"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-gpg-key-url.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-gpg-key-url.rb
new file mode 100644
index 000000000..fc0c9ddfc
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-gpg-key-url.rb
@@ -0,0 +1,11 @@
+cask 'with-gpg-key-url' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-gpg.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-gpg.rb
new file mode 100644
index 000000000..e07546b94
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-gpg.rb
@@ -0,0 +1,11 @@
+cask 'with-gpg' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-installable.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb
new file mode 100644
index 000000000..8416f3f88
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb
@@ -0,0 +1,21 @@
+cask 'with-installable' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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: [
+ "#{TEST_TMPDIR}/absolute_path",
+ '~/path_with_tilde',
+ "#{TEST_TMPDIR}/glob_path*",
+ 'impermissible/relative/path',
+ '/another/impermissible/../relative/path',
+ ],
+ rmdir: "#{TEST_TMPDIR}/empty_directory_path"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-manual.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-manual.rb
new file mode 100644
index 000000000..a857b6900
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-manual.rb
@@ -0,0 +1,9 @@
+cask 'with-installer-manual' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ installer manual: 'Caffeine.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-script.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-script.rb
new file mode 100644
index 000000000..b32d131e0
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installer-script.rb
@@ -0,0 +1,15 @@
+cask 'with-installer-script' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-macosx-dir.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-macosx-dir.rb
new file mode 100644
index 000000000..505e9f5a7
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-macosx-dir.rb
@@ -0,0 +1,9 @@
+cask 'with-macosx-dir' do
+ version '1.2.3'
+ sha256 '5633c3a0f2e572cbf021507dec78c50998b398c343232bdfc7e26221d0a5db4d'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
+ homepage 'http://example.com/MyFancyApp'
+
+ app 'MyFancyApp/MyFancyApp.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb
new file mode 100644
index 000000000..d86d47126
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb
@@ -0,0 +1,13 @@
+cask 'with-pkgutil-zap' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-suite.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-suite.rb
new file mode 100644
index 000000000..88158e10d
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-suite.rb
@@ -0,0 +1,10 @@
+cask 'with-suite' do
+ version '1.2.3'
+ sha256 'd95dcc12d4e5be0bc3cb9793c4b7e7f69a25f0b3c7418494b0c883957e6eeae4'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine-suite.zip"
+ name 'Caffeine'
+ homepage 'http://example.com/with-suite'
+
+ suite 'Caffeine'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-correct.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-correct.rb
new file mode 100644
index 000000000..3963d7790
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-correct.rb
@@ -0,0 +1,10 @@
+cask 'with-two-apps-correct' do
+ version '1.2.3'
+ sha256 '3178fbfd1ea5d87a2a0662a4eb599ebc9a03888e73f37538d9f3f6ee69d2368e'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeines.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine Mini.app'
+ app 'Caffeine Pro.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb
new file mode 100644
index 000000000..c3ca473bd
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-incorrect.rb
@@ -0,0 +1,9 @@
+cask 'with-two-apps-incorrect' do
+ version '1.2.3'
+ sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeine.app', 'Caffeine.app/Contents/MacOS/Caffeine'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-subdir.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-subdir.rb
new file mode 100644
index 000000000..879e6e4ce
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-two-apps-subdir.rb
@@ -0,0 +1,10 @@
+cask 'with-two-apps-subdir' do
+ version '1.2.3'
+ sha256 'd687c22a21c02bd8f07da9302c8292b93a04df9a929e3f04d09aea6c76f75c65'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/caffeines-subdir.zip"
+ homepage 'http://example.com/local-caffeine'
+
+ app 'Caffeines/Caffeine Mini.app'
+ app 'Caffeines/Caffeine Pro.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-delete.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-delete.rb
new file mode 100644
index 000000000..c7d2e4767
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-delete.rb
@@ -0,0 +1,17 @@
+cask 'with-uninstall-delete' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ uninstall delete: [
+ "#{TEST_TMPDIR}/absolute_path",
+ '~/path_with_tilde',
+ "#{TEST_TMPDIR}/glob_path*",
+ 'impermissible/relative/path',
+ '/another/impermissible/../relative/path',
+ ]
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-early-script.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-early-script.rb
new file mode 100644
index 000000000..a9cec5b97
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-early-script.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-early-script' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-uninstall-kext.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-kext.rb
new file mode 100644
index 000000000..9b27a1f36
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-kext.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-kext' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ uninstall kext: 'my.fancy.package.kernelextension'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-launchctl.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-launchctl.rb
new file mode 100644
index 000000000..e5aa2b2d7
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-launchctl.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-launchctl' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
+ homepage 'http://example.com/fancy'
+
+ app 'Fancy.app'
+
+ uninstall launchctl: 'my.fancy.package.service'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-login-item.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-login-item.rb
new file mode 100644
index 000000000..46f1f9704
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-login-item.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-login-item' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'MyFancyPkg/Fancy.pkg'
+
+ uninstall login_item: 'Fancy'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-pkgutil.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-pkgutil.rb
new file mode 100644
index 000000000..00157322d
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-pkgutil.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-pkgutil' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ uninstall pkgutil: 'my.fancy.package.*'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-quit.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-quit.rb
new file mode 100644
index 000000000..7f9515578
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-quit.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-quit' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'MyFancyPkg/Fancy.pkg'
+
+ uninstall quit: 'my.fancy.package.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-rmdir.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-rmdir.rb
new file mode 100644
index 000000000..8ded5b835
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-rmdir.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-rmdir' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'MyFancyPkg/Fancy.pkg'
+
+ uninstall rmdir: "#{TEST_TMPDIR}/empty_directory_path"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script-app.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script-app.rb
new file mode 100644
index 000000000..f5f3ae5dd
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script-app.rb
@@ -0,0 +1,21 @@
+cask 'with-uninstall-script-app' do
+ version '1.2.3'
+ sha256 '5633c3a0f2e572cbf021507dec78c50998b398c343232bdfc7e26221d0a5db4d'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
+ homepage 'http://example.com/MyFancyApp'
+
+ app 'MyFancyApp/MyFancyApp.app'
+
+ postflight do
+ IO.write "#{appdir}/MyFancyApp.app/uninstall.sh", <<-EOS.undent
+ #!/bin/sh
+ /bin/rm -r "#{appdir}/MyFancyApp.app"
+ EOS
+ end
+
+ uninstall script: {
+ executable: "#{appdir}/MyFancyApp.app/uninstall.sh",
+ sudo: false
+ }
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script.rb
new file mode 100644
index 000000000..3e2dd0bb9
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-script.rb
@@ -0,0 +1,11 @@
+cask 'with-uninstall-script' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-uninstall-signal.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-signal.rb
new file mode 100644
index 000000000..850055c3c
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-signal.rb
@@ -0,0 +1,14 @@
+cask 'with-uninstall-signal' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-uninstall-trash.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-trash.rb
new file mode 100644
index 000000000..b085b3e32
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-trash.rb
@@ -0,0 +1,17 @@
+cask 'with-uninstall-trash' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ uninstall trash: [
+ "#{TEST_TMPDIR}/absolute_path",
+ '~/path_with_tilde',
+ "#{TEST_TMPDIR}/glob_path*",
+ 'impermissible/relative/path',
+ '/another/impermissible/../relative/path',
+ ]
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb
new file mode 100644
index 000000000..d81a387f9
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb
@@ -0,0 +1,17 @@
+cask 'with-zap-delete' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ zap delete: [
+ "#{TEST_TMPDIR}/absolute_path",
+ '~/path_with_tilde',
+ "#{TEST_TMPDIR}/glob_path*",
+ 'impermissible/relative/path',
+ '/another/impermissible/../relative/path',
+ ]
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-early-script.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-early-script.rb
new file mode 100644
index 000000000..9375d2cc7
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-early-script.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-early-script' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-zap-kext.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-kext.rb
new file mode 100644
index 000000000..e9c29f619
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-kext.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-kext' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ zap kext: 'my.fancy.package.kernelextension'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-launchctl.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-launchctl.rb
new file mode 100644
index 000000000..6d17ccfb0
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-launchctl.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-launchctl' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
+ homepage 'http://example.com/fancy'
+
+ app 'Fancy.app'
+
+ zap launchctl: 'my.fancy.package.service'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-login-item.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-login-item.rb
new file mode 100644
index 000000000..2715892ef
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-login-item.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-login-item' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'MyFancyPkg/Fancy.pkg'
+
+ zap login_item: 'Fancy'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-pkgutil.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-pkgutil.rb
new file mode 100644
index 000000000..c7f08b76d
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-pkgutil.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-pkgutil' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ zap pkgutil: 'my.fancy.package.*'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-quit.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-quit.rb
new file mode 100644
index 000000000..4e4ab3a85
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-quit.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-quit' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'MyFancyPkg/Fancy.pkg'
+
+ zap quit: 'my.fancy.package.app'
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-rmdir.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-rmdir.rb
new file mode 100644
index 000000000..a67c4ca9a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-rmdir.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-rmdir' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'MyFancyPkg/Fancy.pkg'
+
+ zap rmdir: "#{TEST_TMPDIR}/empty_directory_path"
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-script.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-script.rb
new file mode 100644
index 000000000..5e033301a
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-script.rb
@@ -0,0 +1,11 @@
+cask 'with-zap-script' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-zap-signal.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-signal.rb
new file mode 100644
index 000000000..47870cf05
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-signal.rb
@@ -0,0 +1,14 @@
+cask 'with-zap-signal' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/Casks/with-zap-trash.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-trash.rb
new file mode 100644
index 000000000..ea2bc2a01
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-trash.rb
@@ -0,0 +1,17 @@
+cask 'with-zap-trash' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
+ homepage 'http://example.com/fancy-pkg'
+
+ pkg 'Fancy.pkg'
+
+ zap trash: [
+ "#{TEST_TMPDIR}/absolute_path",
+ '~/path_with_tilde',
+ "#{TEST_TMPDIR}/glob_path*",
+ 'impermissible/relative/path',
+ '/another/impermissible/../relative/path',
+ ]
+end
diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb
new file mode 100644
index 000000000..275516fba
--- /dev/null
+++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb
@@ -0,0 +1,19 @@
+cask 'with-zap' do
+ version '1.2.3'
+ sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
+
+ url "file://#{TEST_FIXTURE_DIR}/cask/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/test/support/fixtures/cask/empty_directory/.gitignore b/Library/Homebrew/test/support/fixtures/cask/empty_directory/.gitignore
deleted file mode 100644
index e69de29bb..000000000
--- a/Library/Homebrew/test/support/fixtures/cask/empty_directory/.gitignore
+++ /dev/null
diff --git a/Library/Homebrew/test/support/helper/env.rb b/Library/Homebrew/test/support/helper/env.rb
deleted file mode 100644
index 904a1d4c7..000000000
--- a/Library/Homebrew/test/support/helper/env.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-module Test
- module Helper
- module Env
- def with_environment(partial_env)
- old = ENV.to_hash
- ENV.update partial_env
- begin
- yield
- ensure
- ENV.replace old
- end
- end
- end
- end
-end
diff --git a/Library/Homebrew/test/support/helper/fixtures.rb b/Library/Homebrew/test/support/helper/fixtures.rb
new file mode 100644
index 000000000..716fe2008
--- /dev/null
+++ b/Library/Homebrew/test/support/helper/fixtures.rb
@@ -0,0 +1,13 @@
+module Test
+ module Helper
+ module Fixtures
+ def dylib_path(name)
+ Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.dylib")
+ end
+
+ def bundle_path(name)
+ Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.bundle")
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/support/helper/formula.rb b/Library/Homebrew/test/support/helper/formula.rb
new file mode 100644
index 000000000..7f55f4b66
--- /dev/null
+++ b/Library/Homebrew/test/support/helper/formula.rb
@@ -0,0 +1,19 @@
+require "formulary"
+
+module Test
+ module Helper
+ module Formula
+ def formula(name = "formula_name", path: Formulary.core_path(name), spec: :stable, alias_path: nil, &block)
+ Class.new(::Formula, &block).new(name, path, spec, alias_path: alias_path)
+ end
+
+ # Use a stubbed {Formulary::FormulaLoader} to make a given formula be found
+ # when loading from {Formulary} with `ref`.
+ def stub_formula_loader(formula, ref = formula.full_name)
+ loader = double(get_formula: formula)
+ allow(Formulary).to receive(:loader_for).with(ref, from: :keg).and_return(loader)
+ allow(Formulary).to receive(:loader_for).with(ref, from: nil).and_return(loader)
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/support/helper/fs_leak_logger.rb b/Library/Homebrew/test/support/helper/fs_leak_logger.rb
index 774ccda04..3fbb148fa 100644
--- a/Library/Homebrew/test/support/helper/fs_leak_logger.rb
+++ b/Library/Homebrew/test/support/helper/fs_leak_logger.rb
@@ -9,13 +9,13 @@ module Test
klass.make_my_diffs_pretty!
end
- def before_setup
+ def setup
@__files_before_test = []
Find.find(TEST_TMPDIR) { |f| @__files_before_test << f.sub(TEST_TMPDIR, "") }
super
end
- def after_teardown
+ def teardown
super
files_after_test = []
Find.find(TEST_TMPDIR) { |f| files_after_test << f.sub(TEST_TMPDIR, "") }
diff --git a/Library/Homebrew/test/support/helper/integration_command_test_case.rb b/Library/Homebrew/test/support/helper/integration_command_test_case.rb
index b79fdd6e0..7ba094645 100644
--- a/Library/Homebrew/test/support/helper/integration_command_test_case.rb
+++ b/Library/Homebrew/test/support/helper/integration_command_test_case.rb
@@ -3,43 +3,16 @@ require "fileutils"
require "pathname"
require "formula"
require "test/support/helper/test_case"
+require "open3"
class IntegrationCommandTestCase < Homebrew::TestCase
def setup
+ super
@cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`.
(HOMEBREW_PREFIX/"bin").mkpath
FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
end
- def teardown
- coretap = CoreTap.new
- paths_to_delete = [
- HOMEBREW_LINKED_KEGS,
- HOMEBREW_PINNED_KEGS,
- HOMEBREW_CELLAR.children,
- HOMEBREW_CACHE.children,
- HOMEBREW_LOCK_DIR.children,
- HOMEBREW_LOGS.children,
- HOMEBREW_TEMP.children,
- HOMEBREW_PREFIX/".git",
- HOMEBREW_PREFIX/"bin",
- HOMEBREW_PREFIX/"share",
- HOMEBREW_PREFIX/"opt",
- HOMEBREW_PREFIX/"Caskroom",
- HOMEBREW_LIBRARY/"Taps/caskroom",
- HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bundle",
- HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo",
- HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services",
- HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-shallow",
- HOMEBREW_REPOSITORY/".git",
- coretap.path/".git",
- coretap.alias_dir,
- coretap.formula_dir.children,
- coretap.path/"formula_renames.json",
- ].flatten
- FileUtils.rm_rf paths_to_delete
- end
-
def needs_test_cmd_taps
return if ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"]
skip "HOMEBREW_TEST_OFFICIAL_CMD_TAPS is not set"
@@ -56,66 +29,46 @@ class IntegrationCommandTestCase < Homebrew::TestCase
end
def cmd_output(*args)
- # 1.8-compatible way of writing def cmd_output(*args, **env)
env = args.last.is_a?(Hash) ? args.pop : {}
- cmd_args = %W[
- -W0
- -I#{HOMEBREW_LIBRARY_PATH}/test/support/lib
- -I#{HOMEBREW_LIBRARY_PATH}
- -rconfig
+
+ env.merge!(
+ "HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
+ "HOMEBREW_INTEGRATION_TEST" => cmd_id_from_args(args),
+ "HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,
+ "HOMEBREW_DEVELOPER" => ENV["HOMEBREW_DEVELOPER"],
+ )
+
+ ruby_args = [
+ "-W0",
+ "-I", "#{HOMEBREW_LIBRARY_PATH}/test/support/lib",
+ "-I", HOMEBREW_LIBRARY_PATH.to_s,
+ "-rconfig"
]
- if ENV["HOMEBREW_TESTS_COVERAGE"]
- # This is needed only because we currently use a patched version of
- # simplecov, and gems installed through git are not available without
- # requiring bundler/setup first. See also the comment in test/Gemfile.
- # Remove this line when we'll switch back to a stable simplecov release.
- cmd_args << "-rbundler/setup"
- cmd_args << "-rsimplecov"
- end
- cmd_args << "-rtest/support/helper/integration_mocks"
- cmd_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
- cmd_args += args
- developer = ENV["HOMEBREW_DEVELOPER"]
- Bundler.with_original_env do
- ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew"
- ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args)
- ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR
- ENV["HOMEBREW_DEVELOPER"] = developer
- env.each_pair do |k, v|
- ENV[k] = v
- end
+ ruby_args << "-rsimplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
+ ruby_args << "-rtest/support/helper/integration_mocks"
+ ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
- read, write = IO.pipe
- begin
- pid = fork do
- read.close
- $stdout.reopen(write)
- $stderr.reopen(write)
- write.close
- exec RUBY_PATH, *cmd_args
- end
- write.close
- read.read.chomp
- ensure
- Process.wait(pid)
- read.close
- end
+ Bundler.with_original_env do
+ output, status = Open3.capture2e(env, RUBY_PATH, *ruby_args, *args)
+ [output.chomp, status]
end
end
def cmd(*args)
- output = cmd_output(*args)
- status = $?.exitstatus
- puts "\n'brew #{args.join " "}' output: #{output}" if status.nonzero?
- assert_equal 0, status
+ output, status = cmd_output(*args)
+ assert status.success?, <<-EOS.undent
+ `brew #{args.join " "}` exited with non-zero status!
+ #{output}
+ EOS
output
end
def cmd_fail(*args)
- output = cmd_output(*args)
- status = $?.exitstatus
- $stderr.puts "\n'brew #{args.join " "}'" if status.zero?
- refute_equal 0, status
+ output, status = cmd_output(*args)
+ refute status.success?, <<-EOS.undent
+ `brew #{args.join " "}` exited with zero status!
+ #{output}
+ EOS
output
end
diff --git a/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb b/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb
new file mode 100644
index 000000000..413f8b11e
--- /dev/null
+++ b/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb
@@ -0,0 +1,22 @@
+module Test
+ module Helper
+ module LifecycleEnforcer
+ def setup
+ @__setup_called = true
+ super
+ end
+
+ def teardown
+ @__teardown_called = true
+ super
+ end
+
+ def after_teardown
+ assert @__setup_called, "Expected setup to call `super` but didn't"
+ assert @__teardown_called, "Expected teardown to call `super` but didn't"
+
+ super
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
new file mode 100644
index 000000000..2eb98826a
--- /dev/null
+++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
@@ -0,0 +1,176 @@
+require "rspec"
+require "open3"
+
+RSpec::Matchers.define_negated_matcher :not_to_output, :output
+RSpec::Matchers.define_negated_matcher :be_a_failure, :be_a_success
+
+RSpec.shared_context "integration test" do
+ extend RSpec::Matchers::DSL
+
+ matcher :be_a_success do
+ match do |actual|
+ status = actual.is_a?(Proc) ? actual.call : actual
+ status.respond_to?(:success?) && status.success?
+ end
+
+ def supports_block_expectations?
+ true
+ end
+
+ # It needs to be nested like this:
+ #
+ # expect {
+ # expect {
+ # # command
+ # }.to be_a_success
+ # }.to output(something).to_stdout
+ #
+ # rather than this:
+ #
+ # expect {
+ # expect {
+ # # command
+ # }.to output(something).to_stdout
+ # }.to be_a_success
+ #
+ def expects_call_stack_jump?
+ true
+ end
+ end
+
+ before(:each) do
+ (HOMEBREW_PREFIX/"bin").mkpath
+ FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
+ end
+
+ after(:each) do
+ FileUtils.rm HOMEBREW_PREFIX/"bin/brew"
+ FileUtils.rmdir HOMEBREW_PREFIX/"bin"
+ end
+
+ # Generate unique ID to be able to
+ # properly merge coverage results.
+ def command_id_from_args(args)
+ @command_count ||= 0
+ pretty_args = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
+ file_and_line = caller[1].sub(/(.*\d+):.*/, '\1')
+ .sub("#{HOMEBREW_LIBRARY_PATH}/test/", "")
+ "#{file_and_line}:brew #{pretty_args}:#{@command_count += 1}"
+ end
+
+ # Runs a `brew` command with the test configuration
+ # and with coverage reporting enabled.
+ def brew(*args)
+ env = args.last.is_a?(Hash) ? args.pop : {}
+
+ # Avoid warnings when HOMEBREW_PREFIX/bin is not in PATH.
+ path = [
+ env["PATH"],
+ (HOMEBREW_PREFIX/"bin").realpath.to_s,
+ ENV["PATH"],
+ ].compact.join(File::PATH_SEPARATOR)
+
+ env.merge!(
+ "PATH" => path,
+ "HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew",
+ "HOMEBREW_INTEGRATION_TEST" => command_id_from_args(args),
+ "HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR,
+ "HOMEBREW_DEVELOPER" => ENV["HOMEBREW_DEVELOPER"],
+ )
+
+ ruby_args = [
+ "-W0",
+ "-I", "#{HOMEBREW_LIBRARY_PATH}/test/support/lib",
+ "-I", HOMEBREW_LIBRARY_PATH.to_s,
+ "-rconfig"
+ ]
+ ruby_args << "-rsimplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
+ ruby_args << "-rtest/support/helper/integration_mocks"
+ ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
+
+ Bundler.with_original_env do
+ stdout, stderr, status = Open3.capture3(env, RUBY_PATH, *ruby_args, *args)
+ $stdout.print stdout
+ $stderr.print stderr
+ status
+ end
+ end
+
+ def setup_test_formula(name, content = nil)
+ case name
+ when /^testball/
+ content = <<-EOS.undent
+ desc "Some test"
+ homepage "https://example.com/#{name}"
+ url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
+ sha256 "#{TESTBALL_SHA256}"
+
+ option "with-foo", "Build with foo"
+
+ def install
+ (prefix/"foo"/"test").write("test") if build.with? "foo"
+ prefix.install Dir["*"]
+ (buildpath/"test.c").write \
+ "#include <stdio.h>\\nint main(){return printf(\\"test\\");}"
+ bin.mkpath
+ system ENV.cc, "test.c", "-o", bin/"test"
+ end
+
+ #{content}
+
+ # something here
+ EOS
+ when "foo"
+ content = <<-EOS.undent
+ url "https://example.com/#{name}-1.0"
+ EOS
+ when "bar"
+ content = <<-EOS.undent
+ url "https://example.com/#{name}-1.0"
+ depends_on "foo"
+ EOS
+ end
+
+ Formulary.core_path(name).tap do |formula_path|
+ formula_path.write <<-EOS.undent
+ class #{Formulary.class_s(name)} < Formula
+ #{content}
+ end
+ EOS
+ end
+ end
+
+ def setup_remote_tap(name)
+ Tap.fetch(name).tap do |tap|
+ tap.install(full_clone: false, quiet: true) unless tap.installed?
+ end
+ end
+
+ def install_and_rename_coretap_formula(old_name, new_name)
+ shutup do
+ CoreTap.instance.path.cd do |tap_path|
+ system "git", "init"
+ system "git", "add", "--all"
+ system "git", "commit", "-m",
+ "#{old_name.capitalize} has not yet been renamed"
+
+ brew "install", old_name
+
+ (tap_path/"Formula/#{old_name}.rb").unlink
+ (tap_path/"formula_renames.json").write JSON.generate(old_name => new_name)
+
+ system "git", "add", "--all"
+ system "git", "commit", "-m",
+ "#{old_name.capitalize} has been renamed to #{new_name.capitalize}"
+ end
+ end
+ end
+
+ def testball
+ "#{TEST_FIXTURE_DIR}/testball.rb"
+ end
+end
+
+RSpec.configure do |config|
+ config.include_context "integration test", :integration_test
+end
diff --git a/Library/Homebrew/test/support/helper/test_case.rb b/Library/Homebrew/test/support/helper/test_case.rb
index 60c91e7bb..568beb947 100644
--- a/Library/Homebrew/test/support/helper/test_case.rb
+++ b/Library/Homebrew/test/support/helper/test_case.rb
@@ -1,16 +1,66 @@
+require "formulary"
+require "tap"
+
module Homebrew
class TestCase < ::Minitest::Test
- require "test/support/helper/env"
require "test/support/helper/fs_leak_logger"
+ require "test/support/helper/lifecycle_enforcer"
require "test/support/helper/shutup"
require "test/support/helper/version_assertions"
- include Test::Helper::Env
include Test::Helper::FSLeakLogger
+ include Test::Helper::LifecycleEnforcer
include Test::Helper::Shutup
include Test::Helper::VersionAssertions
- TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
- TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
+ TEST_DIRECTORIES = [
+ CoreTap.instance.path/"Formula",
+ HOMEBREW_CACHE,
+ HOMEBREW_CACHE_FORMULA,
+ HOMEBREW_CELLAR,
+ HOMEBREW_LOCK_DIR,
+ HOMEBREW_LOGS,
+ HOMEBREW_TEMP,
+ ].freeze
+
+ def setup
+ # These directories need to be created before
+ # `FSLeakLogger` is called with `super`.
+ TEST_DIRECTORIES.each(&:mkpath)
+
+ super
+
+ @__argv = ARGV.dup
+ @__env = ENV.to_hash # dup doesn't work on ENV
+ end
+
+ def teardown
+ ARGV.replace(@__argv)
+ ENV.replace(@__env)
+
+ Tab.clear_cache
+
+ FileUtils.rm_rf [
+ TEST_DIRECTORIES.map(&:children),
+ HOMEBREW_LINKED_KEGS,
+ HOMEBREW_PINNED_KEGS,
+ HOMEBREW_PREFIX/".git",
+ HOMEBREW_PREFIX/"bin",
+ HOMEBREW_PREFIX/"share",
+ HOMEBREW_PREFIX/"opt",
+ HOMEBREW_PREFIX/"Caskroom",
+ HOMEBREW_LIBRARY/"Taps/caskroom",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bundle",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services",
+ HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-shallow",
+ HOMEBREW_REPOSITORY/".git",
+ CoreTap.instance.path/".git",
+ CoreTap.instance.alias_dir,
+ CoreTap.instance.path/"formula_renames.json",
+ ]
+
+ super
+ end
def formula(name = "formula_name", path = Formulary.core_path(name), spec = :stable, alias_path: nil, &block)
@_f = Class.new(Formula, &block).new(name, path, spec, alias_path: alias_path)
diff --git a/Library/Homebrew/test/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb
index f6fdb4ecb..3a0a76722 100644
--- a/Library/Homebrew/test/support/lib/config.rb
+++ b/Library/Homebrew/test/support/lib/config.rb
@@ -2,6 +2,8 @@ unless ENV["HOMEBREW_BREW_FILE"]
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!"
end
+require "constants"
+
require "tmpdir"
require "pathname"
@@ -38,3 +40,6 @@ TESTBALL_SHA256 = "91e3f7930c98d7ccfb288e115ed52d06b0e5bc16fec7dce8bdda865300270
TESTBALL_PATCHES_SHA256 = "799c2d551ac5c3a5759bea7796631a7906a6a24435b52261a317133a0bfb34d9".freeze
PATCH_A_SHA256 = "83404f4936d3257e65f176c4ffb5a5b8d6edd644a21c8d8dcc73e22a6d28fcfa".freeze
PATCH_B_SHA256 = "57958271bb802a59452d0816e0670d16c8b70bdf6530bcf6f78726489ad89b90".freeze
+
+TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
+TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
diff --git a/Library/Homebrew/test/switch_test.rb b/Library/Homebrew/test/switch_test.rb
deleted file mode 100644
index af1926c39..000000000
--- a/Library/Homebrew/test/switch_test.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestSwitch < IntegrationCommandTestCase
- def test_switch
- assert_match "Usage: brew switch <name> <version>", cmd_fail("switch")
- assert_match "testball not found", cmd_fail("switch", "testball", "0.1")
-
- setup_test_formula "testball", <<-EOS.undent
- keg_only "just because"
- EOS
-
- cmd("install", "testball")
- testball_rack = HOMEBREW_CELLAR/"testball"
- FileUtils.cp_r testball_rack/"0.1", testball_rack/"0.2"
-
- cmd("switch", "testball", "0.2")
- assert_match "testball does not have a version \"0.3\"",
- cmd_fail("switch", "testball", "0.3")
- end
-end
diff --git a/Library/Homebrew/test/tab_spec.rb b/Library/Homebrew/test/tab_spec.rb
new file mode 100644
index 000000000..01dbeb67c
--- /dev/null
+++ b/Library/Homebrew/test/tab_spec.rb
@@ -0,0 +1,341 @@
+require "tab"
+require "formula"
+
+RSpec::Matchers.alias_matcher :be_built_with, :be_with
+
+describe Tab do
+ matcher :be_poured_from_bottle do
+ match do |actual|
+ actual.poured_from_bottle == true
+ end
+ end
+
+ matcher :be_built_as_bottle do
+ match do |actual|
+ actual.built_as_bottle == true
+ end
+ end
+
+ subject {
+ described_class.new(
+ "homebrew_version" => HOMEBREW_VERSION,
+ "used_options" => used_options.as_flags,
+ "unused_options" => unused_options.as_flags,
+ "built_as_bottle" => false,
+ "poured_from_bottle" => true,
+ "changed_files" => [],
+ "time" => time,
+ "source_modified_time" => 0,
+ "HEAD" => TEST_SHA1,
+ "compiler" => "clang",
+ "stdlib" => "libcxx",
+ "runtime_dependencies" => [],
+ "source" => {
+ "tap" => CoreTap.instance.to_s,
+ "path" => CoreTap.instance.path.to_s,
+ "spec" => "stable",
+ "versions" => {
+ "stable" => "0.10",
+ "devel" => "0.14",
+ "head" => "HEAD-1111111",
+ },
+ },
+ )
+ }
+ let(:time) { Time.now.to_i }
+ let(:unused_options) { Options.create(%w[--with-baz --without-qux]) }
+ let(:used_options) { Options.create(%w[--with-foo --without-bar]) }
+
+ let(:f) { formula { url "foo-1.0" } }
+ let(:f_tab_path) { f.prefix/"INSTALL_RECEIPT.json" }
+ let(:f_tab_content) { (TEST_FIXTURE_DIR/"receipt.json").read }
+
+ specify "defaults" do
+ tab = described_class.empty
+
+ expect(tab.homebrew_version).to eq(HOMEBREW_VERSION)
+ expect(tab.unused_options).to be_empty
+ expect(tab.used_options).to be_empty
+ expect(tab.changed_files).to be nil
+ expect(tab).not_to be_built_as_bottle
+ expect(tab).not_to be_poured_from_bottle
+ expect(tab).to be_stable
+ expect(tab).not_to be_devel
+ expect(tab).not_to be_head
+ expect(tab.tap).to be nil
+ expect(tab.time).to be nil
+ expect(tab.HEAD).to be nil
+ expect(tab.runtime_dependencies).to be_empty
+ expect(tab.stable_version).to be nil
+ expect(tab.devel_version).to be nil
+ expect(tab.head_version).to be nil
+ expect(tab.cxxstdlib.compiler).to eq(DevelopmentTools.default_compiler)
+ expect(tab.cxxstdlib.type).to be nil
+ expect(tab.source["path"]).to be nil
+ end
+
+ specify "#include?" do
+ expect(subject).to include("with-foo")
+ expect(subject).to include("without-bar")
+ end
+
+ specify "#with?" do
+ expect(subject).to be_built_with("foo")
+ expect(subject).to be_built_with("qux")
+ expect(subject).not_to be_built_with("bar")
+ expect(subject).not_to be_built_with("baz")
+ end
+
+ specify "#universal?" do
+ tab = described_class.new(used_options: %w[--universal])
+ expect(tab).to be_universal
+ end
+
+ specify "#parsed_homebrew_version" do
+ tab = described_class.new
+ expect(tab.parsed_homebrew_version).to be Version::NULL
+
+ tab = described_class.new(homebrew_version: "1.2.3")
+ expect(tab.parsed_homebrew_version).to eq("1.2.3")
+ expect(tab.parsed_homebrew_version).to be < "1.2.3-1-g12789abdf"
+ expect(tab.parsed_homebrew_version).to be_kind_of(Version)
+
+ tab.homebrew_version = "1.2.4-567-g12789abdf"
+ expect(tab.parsed_homebrew_version).to be > "1.2.4"
+ expect(tab.parsed_homebrew_version).to be > "1.2.4-566-g21789abdf"
+ expect(tab.parsed_homebrew_version).to be < "1.2.4-568-g01789abdf"
+
+ tab = described_class.new(homebrew_version: "2.0.0-134-gabcdefabc-dirty")
+ expect(tab.parsed_homebrew_version).to be > "2.0.0"
+ expect(tab.parsed_homebrew_version).to be > "2.0.0-133-g21789abdf"
+ expect(tab.parsed_homebrew_version).to be < "2.0.0-135-g01789abdf"
+ end
+
+ specify "#runtime_dependencies" do
+ tab = described_class.new
+ expect(tab.runtime_dependencies).to be nil
+
+ tab.homebrew_version = "1.1.6"
+ expect(tab.runtime_dependencies).to be nil
+
+ tab.runtime_dependencies = []
+ expect(tab.runtime_dependencies).not_to be nil
+
+ tab.homebrew_version = "1.1.5"
+ expect(tab.runtime_dependencies).to be nil
+
+ tab.homebrew_version = "1.1.7"
+ expect(tab.runtime_dependencies).not_to be nil
+
+ tab.homebrew_version = "1.1.10"
+ expect(tab.runtime_dependencies).not_to be nil
+
+ tab.runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
+ expect(tab.runtime_dependencies).not_to be nil
+ end
+
+ specify "#cxxstdlib" do
+ expect(subject.cxxstdlib.compiler).to eq(:clang)
+ expect(subject.cxxstdlib.type).to eq(:libcxx)
+ end
+
+ specify "other attributes" do
+ expect(subject.HEAD).to eq(TEST_SHA1)
+ expect(subject.tap.name).to eq("homebrew/core")
+ expect(subject.time).to eq(time)
+ expect(subject).not_to be_built_as_bottle
+ expect(subject).to be_poured_from_bottle
+ end
+
+ describe "::from_file" do
+ it "parses a Tab from a file" do
+ path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt.json")
+ tab = described_class.from_file(path)
+ source_path = "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb"
+ runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
+ changed_files = %w[INSTALL_RECEIPT.json bin/foo]
+
+ expect(tab.used_options.sort).to eq(used_options.sort)
+ expect(tab.unused_options.sort).to eq(unused_options.sort)
+ expect(tab.changed_files).to eq(changed_files)
+ expect(tab).not_to be_built_as_bottle
+ expect(tab).to be_poured_from_bottle
+ expect(tab).to be_stable
+ expect(tab).not_to be_devel
+ expect(tab).not_to be_head
+ expect(tab.tap.name).to eq("homebrew/core")
+ expect(tab.spec).to eq(:stable)
+ expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
+ expect(tab.HEAD).to eq(TEST_SHA1)
+ expect(tab.cxxstdlib.compiler).to eq(:clang)
+ expect(tab.cxxstdlib.type).to eq(:libcxx)
+ expect(tab.runtime_dependencies).to eq(runtime_dependencies)
+ expect(tab.stable_version.to_s).to eq("2.14")
+ expect(tab.devel_version.to_s).to eq("2.15")
+ expect(tab.head_version.to_s).to eq("HEAD-0000000")
+ expect(tab.source["path"]).to eq(source_path)
+ end
+
+ it "can parse an old Tab file" do
+ path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt_old.json")
+ tab = described_class.from_file(path)
+
+ expect(tab.used_options.sort).to eq(used_options.sort)
+ expect(tab.unused_options.sort).to eq(unused_options.sort)
+ expect(tab).not_to be_built_as_bottle
+ expect(tab).to be_poured_from_bottle
+ expect(tab).to be_stable
+ expect(tab).not_to be_devel
+ expect(tab).not_to be_head
+ expect(tab.tap.name).to eq("homebrew/core")
+ expect(tab.spec).to eq(:stable)
+ expect(tab.time).to eq(Time.at(1_403_827_774).to_i)
+ expect(tab.HEAD).to eq(TEST_SHA1)
+ expect(tab.cxxstdlib.compiler).to eq(:clang)
+ expect(tab.cxxstdlib.type).to eq(:libcxx)
+ expect(tab.runtime_dependencies).to be nil
+ end
+ end
+
+ describe "::create" do
+ it "creates a Tab" do
+ f = formula do
+ url "foo-1.0"
+ depends_on "bar"
+ depends_on "user/repo/from_tap"
+ depends_on "baz" => :build
+ end
+
+ tap = Tap.new("user", "repo")
+ from_tap = formula("from_tap", path: tap.path/"Formula/from_tap.rb") do
+ url "from_tap-1.0"
+ end
+ stub_formula_loader from_tap
+
+ stub_formula_loader formula("bar") { url "bar-2.0" }
+ stub_formula_loader formula("baz") { url "baz-3.0" }
+
+ compiler = DevelopmentTools.default_compiler
+ stdlib = :libcxx
+ tab = described_class.create(f, compiler, stdlib)
+
+ runtime_dependencies = [
+ { "full_name" => "bar", "version" => "2.0" },
+ { "full_name" => "user/repo/from_tap", "version" => "1.0" },
+ ]
+
+ expect(tab.runtime_dependencies).to eq(runtime_dependencies)
+ expect(tab.source["path"]).to eq(f.path.to_s)
+ end
+
+ it "can create a Tab from an alias" do
+ alias_path = CoreTap.instance.alias_dir/"bar"
+ f = formula(alias_path: alias_path) { url "foo-1.0" }
+ compiler = DevelopmentTools.default_compiler
+ stdlib = :libcxx
+ tab = described_class.create(f, compiler, stdlib)
+
+ expect(tab.source["path"]).to eq(f.alias_path.to_s)
+ end
+ end
+
+ describe "::for_keg" do
+ subject { described_class.for_keg(f.prefix) }
+
+ it "creates a Tab for a given Keg" do
+ f.prefix.mkpath
+ f_tab_path.write f_tab_content
+
+ expect(subject.tabfile).to eq(f_tab_path)
+ end
+
+ it "can create a Tab for a non-existant Keg" do
+ f.prefix.mkpath
+
+ expect(subject.tabfile).to be nil
+ end
+ end
+
+ describe "::for_formula" do
+ it "creates a Tab for a given Formula" do
+ tab = described_class.for_formula(f)
+ expect(tab.source["path"]).to eq(f.path.to_s)
+ end
+
+ it "can create a Tab for for a Formula from an alias" do
+ alias_path = CoreTap.instance.alias_dir/"bar"
+ f = formula(alias_path: alias_path) { url "foo-1.0" }
+
+ tab = described_class.for_formula(f)
+ expect(tab.source["path"]).to eq(alias_path.to_s)
+ end
+
+ it "creates a Tab for a given Formula" do
+ f.prefix.mkpath
+ f_tab_path.write f_tab_content
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to eq(f_tab_path)
+ end
+
+ it "can create a Tab for a non-existant Formula" do
+ f.prefix.mkpath
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to be nil
+ end
+
+ it "can create a Tab for a Formula with multiple Kegs" do
+ f.prefix.mkpath
+ f_tab_path.write f_tab_content
+
+ f2 = formula { url "foo-2.0" }
+ f2.prefix.mkpath
+
+ expect(f2.rack).to eq(f.rack)
+ expect(f.installed_prefixes.length).to eq(2)
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to eq(f_tab_path)
+ end
+
+ it "can create a Tab for a Formula with an outdated Kegs" do
+ f_tab_path.write f_tab_content
+
+ f2 = formula { url "foo-2.0" }
+
+ expect(f2.rack).to eq(f.rack)
+ expect(f.installed_prefixes.length).to eq(1)
+
+ tab = described_class.for_formula(f)
+ expect(tab.tabfile).to eq(f_tab_path)
+ end
+ end
+
+ specify "#to_json" do
+ tab = described_class.new(JSON.parse(subject.to_json))
+ expect(tab.used_options.sort).to eq(subject.used_options.sort)
+ expect(tab.unused_options.sort).to eq(subject.unused_options.sort)
+ expect(tab.built_as_bottle).to eq(subject.built_as_bottle)
+ expect(tab.poured_from_bottle).to eq(subject.poured_from_bottle)
+ expect(tab.changed_files).to eq(subject.changed_files)
+ expect(tab.tap).to eq(subject.tap)
+ expect(tab.spec).to eq(subject.spec)
+ expect(tab.time).to eq(subject.time)
+ expect(tab.HEAD).to eq(subject.HEAD)
+ expect(tab.compiler).to eq(subject.compiler)
+ expect(tab.stdlib).to eq(subject.stdlib)
+ expect(tab.runtime_dependencies).to eq(subject.runtime_dependencies)
+ expect(tab.stable_version).to eq(subject.stable_version)
+ expect(tab.devel_version).to eq(subject.devel_version)
+ expect(tab.head_version).to eq(subject.head_version)
+ expect(tab.source["path"]).to eq(subject.source["path"])
+ end
+
+ specify "::remap_deprecated_options" do
+ deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")]
+ remapped_options = described_class.remap_deprecated_options(deprecated_options, subject.used_options)
+ expect(remapped_options).to include(Option.new("without-bar"))
+ expect(remapped_options).to include(Option.new("with-foo-new"))
+ end
+end
diff --git a/Library/Homebrew/test/tab_test.rb b/Library/Homebrew/test/tab_test.rb
deleted file mode 100644
index f9824ba2a..000000000
--- a/Library/Homebrew/test/tab_test.rb
+++ /dev/null
@@ -1,315 +0,0 @@
-require "testing_env"
-require "tab"
-require "formula"
-
-class TabTests < Homebrew::TestCase
- def setup
- @used = Options.create(%w[--with-foo --without-bar])
- @unused = Options.create(%w[--with-baz --without-qux])
-
- @tab = Tab.new("used_options" => @used.as_flags,
- "unused_options" => @unused.as_flags,
- "built_as_bottle" => false,
- "poured_from_bottle" => true,
- "changed_files" => [],
- "time" => nil,
- "source_modified_time" => 0,
- "HEAD" => TEST_SHA1,
- "compiler" => "clang",
- "stdlib" => "libcxx",
- "runtime_dependencies" => [],
- "source" => {
- "tap" => "homebrew/core",
- "path" => nil,
- "spec" => "stable",
- "versions" => {
- "stable" => "0.10",
- "devel" => "0.14",
- "head" => "HEAD-1111111",
- },
- })
- end
-
- def test_defaults
- tab = Tab.empty
-
- assert_equal HOMEBREW_VERSION, tab.homebrew_version
- assert_empty tab.unused_options
- assert_empty tab.used_options
- assert_nil tab.changed_files
- refute_predicate tab, :built_as_bottle
- refute_predicate tab, :poured_from_bottle
- assert_predicate tab, :stable?
- refute_predicate tab, :devel?
- refute_predicate tab, :head?
- assert_nil tab.tap
- assert_nil tab.time
- assert_nil tab.HEAD
- assert_empty tab.runtime_dependencies
- assert_nil tab.stable_version
- assert_nil tab.devel_version
- assert_nil tab.head_version
- assert_equal DevelopmentTools.default_compiler, tab.cxxstdlib.compiler
- assert_nil tab.cxxstdlib.type
- assert_nil tab.source["path"]
- end
-
- def test_include?
- assert_includes @tab, "with-foo"
- assert_includes @tab, "without-bar"
- end
-
- def test_with?
- assert @tab.with?("foo")
- assert @tab.with?("qux")
- refute @tab.with?("bar")
- refute @tab.with?("baz")
- end
-
- def test_universal?
- tab = Tab.new(used_options: %w[--universal])
- assert_predicate tab, :universal?
- end
-
- def test_parsed_homebrew_version
- tab = Tab.new
- assert_same Version::NULL, tab.parsed_homebrew_version
-
- tab = Tab.new(homebrew_version: "1.2.3")
- assert_equal "1.2.3", tab.parsed_homebrew_version
- assert tab.parsed_homebrew_version < "1.2.3-1-g12789abdf"
- assert_kind_of Version, tab.parsed_homebrew_version
-
- tab.homebrew_version = "1.2.4-567-g12789abdf"
- assert tab.parsed_homebrew_version > "1.2.4"
- assert tab.parsed_homebrew_version > "1.2.4-566-g21789abdf"
- assert tab.parsed_homebrew_version < "1.2.4-568-g01789abdf"
-
- tab = Tab.new(homebrew_version: "2.0.0-134-gabcdefabc-dirty")
- assert tab.parsed_homebrew_version > "2.0.0"
- assert tab.parsed_homebrew_version > "2.0.0-133-g21789abdf"
- assert tab.parsed_homebrew_version < "2.0.0-135-g01789abdf"
- end
-
- def test_runtime_dependencies
- tab = Tab.new
- assert_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.6"
- assert_nil tab.runtime_dependencies
-
- tab.runtime_dependencies = []
- refute_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.5"
- assert_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.7"
- refute_nil tab.runtime_dependencies
-
- tab.homebrew_version = "1.1.10"
- refute_nil tab.runtime_dependencies
-
- tab.runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
- refute_nil tab.runtime_dependencies
- end
-
- def test_cxxstdlib
- assert_equal :clang, @tab.cxxstdlib.compiler
- assert_equal :libcxx, @tab.cxxstdlib.type
- end
-
- def test_other_attributes
- assert_equal TEST_SHA1, @tab.HEAD
- assert_equal "homebrew/core", @tab.tap.name
- assert_nil @tab.time
- refute_predicate @tab, :built_as_bottle
- assert_predicate @tab, :poured_from_bottle
- end
-
- def test_from_old_version_file
- path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt_old.json")
- tab = Tab.from_file(path)
-
- assert_equal @used.sort, tab.used_options.sort
- assert_equal @unused.sort, tab.unused_options.sort
- refute_predicate tab, :built_as_bottle
- assert_predicate tab, :poured_from_bottle
- assert_predicate tab, :stable?
- refute_predicate tab, :devel?
- refute_predicate tab, :head?
- assert_equal "homebrew/core", tab.tap.name
- assert_equal :stable, tab.spec
- refute_nil tab.time
- assert_equal TEST_SHA1, tab.HEAD
- assert_equal :clang, tab.cxxstdlib.compiler
- assert_equal :libcxx, tab.cxxstdlib.type
- assert_nil tab.runtime_dependencies
- end
-
- def test_from_file
- path = Pathname.new("#{TEST_FIXTURE_DIR}/receipt.json")
- tab = Tab.from_file(path)
- source_path = "/usr/local/Library/Taps/homebrew/homebrew-core/Formula/foo.rb"
- runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }]
- changed_files = %w[INSTALL_RECEIPT.json bin/foo]
-
- assert_equal @used.sort, tab.used_options.sort
- assert_equal @unused.sort, tab.unused_options.sort
- assert_equal changed_files, tab.changed_files
- refute_predicate tab, :built_as_bottle
- assert_predicate tab, :poured_from_bottle
- assert_predicate tab, :stable?
- refute_predicate tab, :devel?
- refute_predicate tab, :head?
- assert_equal "homebrew/core", tab.tap.name
- assert_equal :stable, tab.spec
- refute_nil tab.time
- assert_equal TEST_SHA1, tab.HEAD
- assert_equal :clang, tab.cxxstdlib.compiler
- assert_equal :libcxx, tab.cxxstdlib.type
- assert_equal runtime_dependencies, tab.runtime_dependencies
- assert_equal "2.14", tab.stable_version.to_s
- assert_equal "2.15", tab.devel_version.to_s
- assert_equal "HEAD-0000000", tab.head_version.to_s
- assert_equal source_path, tab.source["path"]
- end
-
- def test_create
- f = formula do
- url "foo-1.0"
- depends_on "bar"
- depends_on "user/repo/from_tap"
- depends_on "baz" => :build
- end
-
- tap = Tap.new("user", "repo")
- from_tap = formula("from_tap", tap.path/"Formula/from_tap.rb") do
- url "from_tap-1.0"
- end
- stub_formula_loader from_tap
-
- stub_formula_loader formula("bar") { url "bar-2.0" }
- stub_formula_loader formula("baz") { url "baz-3.0" }
-
- compiler = DevelopmentTools.default_compiler
- stdlib = :libcxx
- tab = Tab.create(f, compiler, stdlib)
-
- runtime_dependencies = [
- { "full_name" => "bar", "version" => "2.0" },
- { "full_name" => "user/repo/from_tap", "version" => "1.0" },
- ]
-
- assert_equal runtime_dependencies, tab.runtime_dependencies
- assert_equal f.path.to_s, tab.source["path"]
- end
-
- def test_create_from_alias
- alias_path = CoreTap.instance.alias_dir/"bar"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- compiler = DevelopmentTools.default_compiler
- stdlib = :libcxx
- tab = Tab.create(f, compiler, stdlib)
-
- assert_equal f.alias_path.to_s, tab.source["path"]
- end
-
- def test_for_formula
- f = formula { url "foo-1.0" }
- tab = Tab.for_formula(f)
-
- assert_equal f.path.to_s, tab.source["path"]
- end
-
- def test_for_formula_from_alias
- alias_path = CoreTap.instance.alias_dir/"bar"
- f = formula(alias_path: alias_path) { url "foo-1.0" }
- tab = Tab.for_formula(f)
-
- assert_equal alias_path.to_s, tab.source["path"]
- end
-
- def test_to_json
- tab = Tab.new(JSON.parse(@tab.to_json))
- assert_equal @tab.used_options.sort, tab.used_options.sort
- assert_equal @tab.unused_options.sort, tab.unused_options.sort
- assert_equal @tab.built_as_bottle, tab.built_as_bottle
- assert_equal @tab.poured_from_bottle, tab.poured_from_bottle
- assert_equal @tab.changed_files, tab.changed_files
- assert_equal @tab.tap, tab.tap
- assert_equal @tab.spec, tab.spec
- assert_equal @tab.time, tab.time
- assert_equal @tab.HEAD, tab.HEAD
- assert_equal @tab.compiler, tab.compiler
- assert_equal @tab.stdlib, tab.stdlib
- assert_equal @tab.runtime_dependencies, tab.runtime_dependencies
- assert_equal @tab.stable_version, tab.stable_version
- assert_equal @tab.devel_version, tab.devel_version
- assert_equal @tab.head_version, tab.head_version
- assert_equal @tab.source["path"], tab.source["path"]
- end
-
- def test_remap_deprecated_options
- deprecated_options = [DeprecatedOption.new("with-foo", "with-foo-new")]
- remapped_options = Tab.remap_deprecated_options(deprecated_options, @tab.used_options)
- assert_includes remapped_options, Option.new("without-bar")
- assert_includes remapped_options, Option.new("with-foo-new")
- end
-end
-
-class TabLoadingTests < Homebrew::TestCase
- def setup
- @f = formula { url "foo-1.0" }
- @f.prefix.mkpath
- @path = @f.prefix.join(Tab::FILENAME)
- @path.write TEST_FIXTURE_DIR.join("receipt.json").read
- end
-
- def teardown
- @f.rack.rmtree
- end
-
- def test_for_keg
- tab = Tab.for_keg(@f.prefix)
- assert_equal @path, tab.tabfile
- end
-
- def test_for_keg_nonexistent_path
- @path.unlink
- tab = Tab.for_keg(@f.prefix)
- assert_nil tab.tabfile
- end
-
- def test_for_formula
- tab = Tab.for_formula(@f)
- assert_equal @path, tab.tabfile
- end
-
- def test_for_formula_nonexistent_path
- @path.unlink
- tab = Tab.for_formula(@f)
- assert_nil tab.tabfile
- end
-
- def test_for_formula_multiple_kegs
- f2 = formula { url "foo-2.0" }
- f2.prefix.mkpath
-
- assert_equal @f.rack, f2.rack
- assert_equal 2, @f.installed_prefixes.length
-
- tab = Tab.for_formula(@f)
- assert_equal @path, tab.tabfile
- end
-
- def test_for_formula_outdated_keg
- f2 = formula { url "foo-2.0" }
-
- assert_equal @f.rack, f2.rack
- assert_equal 1, @f.installed_prefixes.length
-
- tab = Tab.for_formula(f2)
- assert_equal @path, tab.tabfile
- end
-end
diff --git a/Library/Homebrew/test/tap_new_test.rb b/Library/Homebrew/test/tap_new_test.rb
deleted file mode 100644
index 261a334f0..000000000
--- a/Library/Homebrew/test/tap_new_test.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestTapNew < IntegrationCommandTestCase
- def test_tap_readme
- assert_equal "", cmd("tap-new", "homebrew/foo", "--verbose")
- readme = HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo/README.md"
- assert readme.exist?, "The README should be created"
- end
-end
diff --git a/Library/Homebrew/test/tap_test.rb b/Library/Homebrew/test/tap_test.rb
index 7114cdf22..729fc8198 100644
--- a/Library/Homebrew/test/tap_test.rb
+++ b/Library/Homebrew/test/tap_test.rb
@@ -1,39 +1,10 @@
require "testing_env"
-require "testing_env"
-
-class IntegrationCommandTestTap < IntegrationCommandTestCase
- def test_tap
- path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
- path.mkpath
- path.cd do
- shutup do
- system "git", "init"
- system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
- FileUtils.touch "readme"
- system "git", "add", "--all"
- system "git", "commit", "-m", "init"
- end
- end
-
- assert_match "homebrew/foo", cmd("tap")
- assert_match "homebrew/science", cmd("tap", "--list-official")
- assert_match "2 taps", cmd("tap-info")
- assert_match "https://github.com/Homebrew/homebrew-foo", cmd("tap-info", "homebrew/foo")
- assert_match "https://github.com/Homebrew/homebrew-foo", cmd("tap-info", "--json=v1", "--installed")
- assert_match "Pinned homebrew/foo", cmd("tap-pin", "homebrew/foo")
- assert_match "homebrew/foo", cmd("tap", "--list-pinned")
- assert_match "Unpinned homebrew/foo", cmd("tap-unpin", "homebrew/foo")
- assert_match "Tapped", cmd("tap", "homebrew/bar", path/".git")
- assert_match "Untapped", cmd("untap", "homebrew/bar")
- assert_equal "", cmd("tap", "homebrew/bar", path/".git", "-q", "--full")
- assert_match "Untapped", cmd("untap", "homebrew/bar")
- end
-end
class TapTest < Homebrew::TestCase
include FileUtils
def setup
+ super
@path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
@path.mkpath
@tap = Tap.new("Homebrew", "foo")
@@ -65,13 +36,6 @@ class TapTest < Homebrew::TestCase
end
def setup_git_repo
- env = ENV.to_hash
- %w[AUTHOR COMMITTER].each do |role|
- ENV["GIT_#{role}_NAME"] = "brew tests"
- ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
- ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
- end
-
@path.cd do
shutup do
system "git", "init"
@@ -80,12 +44,6 @@ class TapTest < Homebrew::TestCase
system "git", "commit", "-m", "init"
end
end
- ensure
- ENV.replace(env)
- end
-
- def teardown
- @path.rmtree
end
def test_fetch
@@ -171,8 +129,6 @@ class TapTest < Homebrew::TestCase
end
end
refute_predicate services_tap, :private?
- ensure
- services_tap.path.rmtree if services_tap
end
def test_remote_not_git_repo
@@ -189,10 +145,10 @@ class TapTest < Homebrew::TestCase
touch @path/"README"
setup_git_repo
- assert_equal "e1893a6bd191ba895c71b652ff8376a6114c7fa7", @tap.git_head
- assert_equal "e189", @tap.git_short_head
- assert_match "years ago", @tap.git_last_commit
- assert_equal "2009-05-21", @tap.git_last_commit_date
+ assert_equal "0453e16c8e3fac73104da50927a86221ca0740c2", @tap.git_head
+ assert_equal "0453", @tap.git_short_head
+ assert_match(/\A\d+ .+ ago\Z/, @tap.git_last_commit)
+ assert_equal "2017-01-22", @tap.git_last_commit_date
end
def test_private_remote
@@ -256,8 +212,6 @@ class TapTest < Homebrew::TestCase
refute_predicate tap, :installed?
refute_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :exist?
refute_predicate HOMEBREW_PREFIX/"share/man/man1", :exist?
- ensure
- (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist?
end
def test_pin_and_unpin
@@ -285,6 +239,7 @@ class CoreTapTest < Homebrew::TestCase
include FileUtils
def setup
+ super
@repo = CoreTap.new
end
@@ -322,8 +277,5 @@ class CoreTapTest < Homebrew::TestCase
assert_equal ["bar"], @repo.aliases
assert_equal @repo.alias_table, "bar" => "foo"
assert_equal @repo.alias_reverse_table, "foo" => ["bar"]
- ensure
- @formula_file.unlink
- @repo.alias_dir.rmtree
end
end
diff --git a/Library/Homebrew/test/test_formula_test.rb b/Library/Homebrew/test/test_formula_test.rb
deleted file mode 100644
index 5ad2db9e9..000000000
--- a/Library/Homebrew/test/test_formula_test.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestTestFormula < IntegrationCommandTestCase
- def test_test_formula
- assert_match "This command requires a formula argument", cmd_fail("test")
- assert_match "Testing requires the latest version of testball",
- cmd_fail("test", testball)
-
- cmd("install", testball)
- assert_match "testball defines no test", cmd_fail("test", testball)
-
- setup_test_formula "testball_copy", <<-EOS.undent
- head "https://github.com/example/testball2.git"
-
- devel do
- url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
- sha256 "#{TESTBALL_SHA256}"
- end
-
- keg_only "just because"
-
- test do
- end
- EOS
-
- cmd("install", "testball_copy")
- assert_match "Testing testball_copy", cmd("test", "--HEAD", "testball_copy")
- assert_match "Testing testball_copy", cmd("test", "--devel", "testball_copy")
- end
-end
diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb
index e2ba2e4e4..999fa1013 100644
--- a/Library/Homebrew/test/testing_env.rb
+++ b/Library/Homebrew/test/testing_env.rb
@@ -1,21 +1,18 @@
-$:.unshift File.expand_path("../..", __FILE__)
-$:.unshift File.expand_path("../support/lib", __FILE__)
-
-require "simplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
-require "global"
-require "formulary"
-
-# Test environment setup
-(HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-core/Formula").mkpath
-%w[cache formula_cache locks cellar logs temp].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath }
-
begin
require "minitest/autorun"
- require "parallel_tests/test/runtime_logger"
+ require "minitest/reporters"
+ Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
require "mocha/setup"
+ require "parallel_tests/test/runtime_logger"
+ require "simplecov" if ENV["HOMEBREW_TESTS_COVERAGE"]
rescue LoadError
- abort "Run `bundle install` or install the mocha and minitest gems before running the tests"
+ abort "Run `bundle install` before running the tests."
end
+$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew"))
+$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib"))
+
+require "global"
+
require "test/support/helper/test_case"
require "test/support/helper/integration_command_test_case"
diff --git a/Library/Homebrew/test/uninstall_test.rb b/Library/Homebrew/test/uninstall_test.rb
index 597e77e40..a9230ffac 100644
--- a/Library/Homebrew/test/uninstall_test.rb
+++ b/Library/Homebrew/test/uninstall_test.rb
@@ -3,6 +3,8 @@ require "cmd/uninstall"
class UninstallTests < Homebrew::TestCase
def setup
+ super
+
@dependency = formula("dependency") { url "f-1" }
@dependent = formula("dependent") do
url "f-1"
@@ -28,10 +30,7 @@ class UninstallTests < Homebrew::TestCase
def teardown
Homebrew.failed = false
- [@dependency, @dependent].each do |f|
- f.installed_kegs.each(&:remove_opt_record)
- f.rack.rmtree
- end
+ super
end
def handle_unsatisfied_dependents
@@ -59,14 +58,5 @@ class UninstallTests < Homebrew::TestCase
assert_empty handle_unsatisfied_dependents
refute_predicate Homebrew, :failed?
end
- ensure
- ARGV.delete("--ignore-dependencies")
- end
-end
-
-class IntegrationCommandTestUninstall < IntegrationCommandTestCase
- def test_uninstall
- cmd("install", testball)
- assert_match "Uninstalling testball", cmd("uninstall", "--force", testball)
end
end
diff --git a/Library/Homebrew/test/unlink_test.rb b/Library/Homebrew/test/unlink_test.rb
deleted file mode 100644
index 6d5cefc67..000000000
--- a/Library/Homebrew/test/unlink_test.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestUnlink < IntegrationCommandTestCase
- def test_unlink
- setup_test_formula "testball"
-
- cmd("install", "testball")
- assert_match "Would remove", cmd("unlink", "--dry-run", "testball")
- end
-end
diff --git a/Library/Homebrew/test/unlinkapps_test.rb b/Library/Homebrew/test/unlinkapps_test.rb
deleted file mode 100644
index 9d9672199..000000000
--- a/Library/Homebrew/test/unlinkapps_test.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestUnlinkapps < IntegrationCommandTestCase
- def test_unlinkapps
- home_dir = Pathname.new(mktmpdir)
- apps_dir = home_dir/"Applications"
- apps_dir.mkpath
-
- setup_test_formula "testball"
-
- source_app = (HOMEBREW_CELLAR/"testball/0.1/TestBall.app")
- source_app.mkpath
-
- FileUtils.ln_s source_app, "#{apps_dir}/TestBall.app"
-
- assert_match "Unlinking: #{apps_dir}/TestBall.app",
- cmd("unlinkapps", "--local", "HOME" => home_dir)
- end
-end
diff --git a/Library/Homebrew/test/unpack_test.rb b/Library/Homebrew/test/unpack_test.rb
deleted file mode 100644
index bbff6ad1c..000000000
--- a/Library/Homebrew/test/unpack_test.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestUnpack < IntegrationCommandTestCase
- def test_unpack
- setup_test_formula "testball"
-
- mktmpdir do |path|
- cmd "unpack", "testball", "--destdir=#{path}"
- assert File.directory?("#{path}/testball-0.1"),
- "The tarball should be unpacked"
- end
- end
-end
diff --git a/Library/Homebrew/test/update_report_test.rb b/Library/Homebrew/test/update_report_test.rb
deleted file mode 100644
index 6b6cec6ce..000000000
--- a/Library/Homebrew/test/update_report_test.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-require "testing_env"
-require "cmd/update-report"
-require "formula_versions"
-require "yaml"
-
-class ReportTests < Homebrew::TestCase
- class ReporterMock < ::Reporter
- attr_accessor :diff
-
- def initialize(tap)
- @tap = tap
- ENV["HOMEBREW_UPDATE_BEFORE#{repo_var}"] = "12345678"
- ENV["HOMEBREW_UPDATE_AFTER#{repo_var}"] = "abcdef12"
- super(tap)
- end
- end
-
- def fixture(name)
- self.class.fixture_data[name] || ""
- end
-
- def self.fixture_data
- @fixture_data ||= YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")
- end
-
- def setup
- @tap = CoreTap.new
- @reporter = ReporterMock.new(@tap)
- @hub = ReporterHub.new
- end
-
- def perform_update(fixture_name = "")
- Formulary.stubs(:factory).returns(stub(pkg_version: "1.0"))
- FormulaVersions.stubs(:new).returns(stub(formula_at_revision: "2.0"))
- @reporter.diff = fixture(fixture_name)
- @hub.add(@reporter) if @reporter.updated?
- end
-
- def test_update_report_without_revision_var
- ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" }
- assert_raises(Reporter::ReporterRevisionUnsetError) { Reporter.new(@tap) }
- end
-
- def test_update_homebrew_without_any_changes
- perform_update
- assert_empty @hub
- end
-
- def test_update_homebrew_without_formulae_changes
- perform_update("update_git_diff_output_without_formulae_changes")
- assert_empty @hub.select_formula(:M)
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- end
-
- def test_update_homebrew_with_formulae_changes
- perform_update("update_git_diff_output_with_formulae_changes")
- assert_equal %w[xar yajl], @hub.select_formula(:M)
- assert_equal %w[antiword bash-completion ddrescue dict lua], @hub.select_formula(:A)
- end
-
- def test_update_homebrew_with_removed_formulae
- perform_update("update_git_diff_output_with_removed_formulae")
- assert_equal %w[libgsasl], @hub.select_formula(:D)
- end
-
- def test_update_homebrew_with_changed_filetype
- perform_update("update_git_diff_output_with_changed_filetype")
- assert_equal %w[elixir], @hub.select_formula(:M)
- assert_equal %w[libbson], @hub.select_formula(:A)
- assert_equal %w[libgsasl], @hub.select_formula(:D)
- end
-
- def test_update_homebrew_with_formula_rename
- @tap.stubs(:formula_renames).returns("cv" => "progress")
- perform_update("update_git_diff_output_with_formula_rename")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_equal [["cv", "progress"]], @hub.select_formula(:R)
- end
-
- def test_update_homebrew_with_restructured_tap
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
-
- perform_update("update_git_diff_output_with_restructured_tap")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_empty @hub.select_formula(:R)
- ensure
- tap.path.parent.rmtree
- end
-
- def test_update_homebrew_with_formula_rename_and_restructuring
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
- tap.stubs(:formula_renames).returns("xchat" => "xchat2")
-
- perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_equal [%w[foo/bar/xchat foo/bar/xchat2]], @hub.select_formula(:R)
- ensure
- tap.path.parent.rmtree
- end
-
- def test_update_homebrew_simulate_homebrew_php_restructuring
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
-
- perform_update("update_git_diff_simulate_homebrew_php_restructuring")
- assert_empty @hub.select_formula(:A)
- assert_empty @hub.select_formula(:D)
- assert_empty @hub.select_formula(:R)
- ensure
- tap.path.parent.rmtree
- end
-
- def test_update_homebrew_with_tap_formulae_changes
- tap = Tap.new("foo", "bar")
- @reporter = ReporterMock.new(tap)
- tap.path.join("Formula").mkpath
-
- perform_update("update_git_diff_output_with_tap_formulae_changes")
- assert_equal %w[foo/bar/lua], @hub.select_formula(:A)
- assert_equal %w[foo/bar/git], @hub.select_formula(:M)
- assert_empty @hub.select_formula(:D)
- ensure
- tap.path.parent.rmtree
- end
-end
diff --git a/Library/Homebrew/test/upgrade_test.rb b/Library/Homebrew/test/upgrade_test.rb
deleted file mode 100644
index f3f5dccc7..000000000
--- a/Library/Homebrew/test/upgrade_test.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestUpgrade < IntegrationCommandTestCase
- def test_upgrade
- setup_test_formula "testball"
- (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
-
- cmd("upgrade")
- assert((HOMEBREW_CELLAR/"testball/0.1").directory?,
- "The latest version directory should be created")
- end
-end
diff --git a/Library/Homebrew/test/uses_test.rb b/Library/Homebrew/test/uses_test.rb
deleted file mode 100644
index 1fad0da28..000000000
--- a/Library/Homebrew/test/uses_test.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestUses < IntegrationCommandTestCase
- def test_uses
- setup_test_formula "foo"
- setup_test_formula "bar"
- setup_test_formula "baz", <<-EOS.undent
- url "https://example.com/baz-1.0"
- depends_on "bar"
- EOS
-
- assert_equal "", cmd("uses", "baz")
- assert_equal "baz", cmd("uses", "bar")
- assert_match(/(bar\nbaz|baz\nbar)/, cmd("uses", "--recursive", "foo"))
- end
-end
diff --git a/Library/Homebrew/test/utils/bottles/bintray_spec.rb b/Library/Homebrew/test/utils/bottles/bintray_spec.rb
new file mode 100644
index 000000000..a7dfc00ea
--- /dev/null
+++ b/Library/Homebrew/test/utils/bottles/bintray_spec.rb
@@ -0,0 +1,18 @@
+require "utils/bottles"
+
+describe Utils::Bottles::Bintray do
+ describe "::package" do
+ it "converts a Formula name to a package name" do
+ expect(described_class.package("openssl@1.1")).to eq("openssl:1.1")
+ expect(described_class.package("gtk+")).to eq("gtkx")
+ expect(described_class.package("llvm")).to eq("llvm")
+ end
+ end
+
+ describe "::repository" do
+ it "returns the repository for a given Tap" do
+ expect(described_class.repository(Tap.new("homebrew", "bintray-test")))
+ .to eq("bottles-bintray-test")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/bottles/bottles_spec.rb b/Library/Homebrew/test/utils/bottles/bottles_spec.rb
new file mode 100644
index 000000000..8b54b0b34
--- /dev/null
+++ b/Library/Homebrew/test/utils/bottles/bottles_spec.rb
@@ -0,0 +1,80 @@
+require "utils/bottles"
+
+describe Utils::Bottles do
+ describe "#tag", :needs_macos do
+ it "returns :tiger_foo on Tiger PowerPC" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:ppc)
+ allow(Hardware::CPU).to receive(:family).and_return(:foo)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:tiger_foo)
+ end
+
+ it "returns :tiger on Tiger Intel" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:tiger)
+ end
+
+ it "returns :tiger_g5_64 on Tiger PowerPC 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:ppc)
+ allow(Hardware::CPU).to receive(:family).and_return(:g5)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:tiger_g5_64)
+ end
+
+ # Note that this will probably never be used
+ it "returns :tiger_64 on Tiger Intel 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:tiger_64)
+ end
+
+ it "returns :leopard on Leopard Intel" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:leopard)
+ end
+
+ it "returns :leopard_g5_64 on Leopard PowerPC 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
+ allow(Hardware::CPU).to receive(:type).and_return(:ppc)
+ allow(Hardware::CPU).to receive(:family).and_return(:g5)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:leopard_g5_64)
+ end
+
+ it "returns :leopard_64 on Leopard Intel 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
+ allow(Hardware::CPU).to receive(:type).and_return(:intel)
+ allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:leopard_64)
+ end
+
+ it "returns :snow_leopard_32 on Snow Leopard 32-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.6"))
+ allow(Hardware::CPU).to receive(:is_64_bit?).and_return(false)
+ expect(described_class.tag).to eq(:snow_leopard_32)
+ end
+
+ it "returns :snow_leopard on Snow Leopard 64-bit" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.6"))
+ allow(Hardware::CPU).to receive(:is_64_bit?).and_return(true)
+ expect(described_class.tag).to eq(:snow_leopard)
+ end
+
+ it "returns :lion on Lion" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.7"))
+ expect(described_class.tag).to eq(:lion)
+ end
+
+ it "returns :mountain_lion on Mountain Lion" do
+ allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.8"))
+ expect(described_class.tag).to eq(:mountain_lion)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/bottles/collector_spec.rb b/Library/Homebrew/test/utils/bottles/collector_spec.rb
new file mode 100644
index 000000000..08484e545
--- /dev/null
+++ b/Library/Homebrew/test/utils/bottles/collector_spec.rb
@@ -0,0 +1,45 @@
+require "utils/bottles"
+
+describe Utils::Bottles::Collector do
+ describe "#fetch_checksum_for" do
+ it "returns passed tags" do
+ subject[:lion] = "foo"
+ subject[:mountain_lion] = "bar"
+ expect(subject.fetch_checksum_for(:mountain_lion)).to eq(["bar", :mountain_lion])
+ end
+
+ it "returns nil if empty" do
+ expect(subject.fetch_checksum_for(:foo)).to be nil
+ end
+
+ it "returns nil when there is no match" do
+ subject[:lion] = "foo"
+ expect(subject.fetch_checksum_for(:foo)).to be nil
+ end
+
+ it "returns nil when there is no match and later tag is present" do
+ subject[:lion_or_later] = "foo"
+ expect(subject.fetch_checksum_for(:foo)).to be nil
+ end
+
+ it "prefers exact matches" do
+ subject[:lion_or_later] = "foo"
+ subject[:mountain_lion] = "bar"
+ expect(subject.fetch_checksum_for(:mountain_lion)).to eq(["bar", :mountain_lion])
+ end
+
+ it "finds '_or_later' tags", :needs_macos do
+ subject[:lion_or_later] = "foo"
+ expect(subject.fetch_checksum_for(:mountain_lion)).to eq(["foo", :lion_or_later])
+ expect(subject.fetch_checksum_for(:snow_leopard)).to be nil
+ end
+
+ it "finds '_altivec' tags", :needs_macos do
+ subject[:tiger_altivec] = "foo"
+ expect(subject.fetch_checksum_for(:tiger_g4)).to eq(["foo", :tiger_altivec])
+ expect(subject.fetch_checksum_for(:tiger_g4e)).to eq(["foo", :tiger_altivec])
+ expect(subject.fetch_checksum_for(:tiger_g5)).to eq(["foo", :tiger_altivec])
+ expect(subject.fetch_checksum_for(:tiger_g3)).to be nil
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/popen_spec.rb b/Library/Homebrew/test/utils/popen_spec.rb
new file mode 100644
index 000000000..e3704a876
--- /dev/null
+++ b/Library/Homebrew/test/utils/popen_spec.rb
@@ -0,0 +1,28 @@
+require "utils/popen"
+
+describe Utils do
+ describe "::popen_read" do
+ it "reads the standard output of a given command" do
+ expect(subject.popen_read("sh", "-c", "echo success").chomp).to eq("success")
+ expect($?).to be_a_success
+ end
+
+ it "can be given a block to manually read from the pipe" do
+ expect(
+ subject.popen_read("sh", "-c", "echo success") do |pipe|
+ pipe.read.chomp
+ end,
+ ).to eq("success")
+ expect($?).to be_a_success
+ end
+ end
+
+ describe "::popen_write" do
+ it "with supports writing to a command's standard input" do
+ subject.popen_write("grep", "-q", "success") do |pipe|
+ pipe.write("success\n")
+ end
+ expect($?).to be_a_success
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/shell_spec.rb b/Library/Homebrew/test/utils/shell_spec.rb
new file mode 100644
index 000000000..c44bd8253
--- /dev/null
+++ b/Library/Homebrew/test/utils/shell_spec.rb
@@ -0,0 +1,93 @@
+require "utils/shell"
+
+describe Utils::Shell do
+ describe "::shell_profile" do
+ it "returns ~/.bash_profile by default" do
+ ENV["SHELL"] = "/bin/another_shell"
+ expect(subject.shell_profile).to eq("~/.bash_profile")
+ end
+
+ it "returns ~/.bash_profile for Sh" do
+ ENV["SHELL"] = "/bin/another_shell"
+ expect(subject.shell_profile).to eq("~/.bash_profile")
+ end
+
+ it "returns ~/.bash_profile for Bash" do
+ ENV["SHELL"] = "/bin/bash"
+ expect(subject.shell_profile).to eq("~/.bash_profile")
+ end
+
+ it "returns ~/.zshrc for Zsh" do
+ ENV["SHELL"] = "/bin/zsh"
+ expect(subject.shell_profile).to eq("~/.zshrc")
+ end
+
+ it "returns ~/.kshrc for Ksh" do
+ ENV["SHELL"] = "/bin/ksh"
+ expect(subject.shell_profile).to eq("~/.kshrc")
+ end
+ end
+
+ describe "::path_to_shell" do
+ it "supports a raw command name" do
+ expect(subject.path_to_shell("bash")).to eq(:bash)
+ end
+
+ it "supports full paths" do
+ expect(subject.path_to_shell("/bin/bash")).to eq(:bash)
+ end
+
+ it "supports versions" do
+ expect(subject.path_to_shell("zsh-5.2")).to eq(:zsh)
+ end
+
+ it "strips newlines" do
+ expect(subject.path_to_shell("zsh-5.2\n")).to eq(:zsh)
+ end
+
+ it "returns nil when input is invalid" do
+ expect(subject.path_to_shell("")).to be nil
+ expect(subject.path_to_shell("@@@@@@")).to be nil
+ expect(subject.path_to_shell("invalid_shell-4.2")).to be nil
+ end
+ end
+
+ specify "::sh_quote" do
+ expect(subject.sh_quote("")).to eq("''")
+ expect(subject.sh_quote("\\")).to eq("\\\\")
+ expect(subject.sh_quote("\n")).to eq("'\n'")
+ expect(subject.sh_quote("$")).to eq("\\$")
+ expect(subject.sh_quote("word")).to eq("word")
+ end
+
+ specify "::csh_quote" do
+ expect(subject.csh_quote("")).to eq("''")
+ expect(subject.csh_quote("\\")).to eq("\\\\")
+ # note this test is different than for sh
+ expect(subject.csh_quote("\n")).to eq("'\\\n'")
+ expect(subject.csh_quote("$")).to eq("\\$")
+ expect(subject.csh_quote("word")).to eq("word")
+ end
+
+ describe "::prepend_path_in_shell_profile" do
+ let(:path) { "/my/path" }
+
+ it "supports Tcsh" do
+ ENV["SHELL"] = "/bin/tcsh"
+ expect(subject.prepend_path_in_shell_profile(path))
+ .to start_with("echo 'setenv PATH #{path}:$")
+ end
+
+ it "supports Bash" do
+ ENV["SHELL"] = "/bin/bash"
+ expect(subject.prepend_path_in_shell_profile(path))
+ .to start_with("echo 'export PATH=\"#{path}:$")
+ end
+
+ it "supports Fish" do
+ ENV["SHELL"] = "/usr/local/bin/fish"
+ expect(subject.prepend_path_in_shell_profile(path))
+ .to start_with("echo 'set -g fish_user_paths \"#{path}\" $fish_user_paths' >>")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/tty_spec.rb b/Library/Homebrew/test/utils/tty_spec.rb
new file mode 100644
index 000000000..3ba89b6fd
--- /dev/null
+++ b/Library/Homebrew/test/utils/tty_spec.rb
@@ -0,0 +1,67 @@
+require "utils"
+
+describe Tty do
+ describe "::strip_ansi" do
+ it "removes ANSI escape codes from a string" do
+ expect(subject.strip_ansi("\033\[36;7mhello\033\[0m")).to eq("hello")
+ end
+ end
+
+ describe "::width" do
+ it "returns an Integer" do
+ expect(subject.width).to be_kind_of(Integer)
+ end
+
+ it "cannot be negative" do
+ expect(subject.width).to be >= 0
+ end
+ end
+
+ describe "::truncate" do
+ it "truncates the text to the terminal width, minus 4, to account for '==> '" do
+ allow(subject).to receive(:width).and_return(15)
+
+ expect(subject.truncate("foobar something very long")).to eq("foobar some")
+ expect(subject.truncate("truncate")).to eq("truncate")
+ end
+
+ it "doesn't truncate the text if the terminal is unsupported, i.e. the width is 0" do
+ allow(subject).to receive(:width).and_return(0)
+ expect(subject.truncate("foobar something very long")).to eq("foobar something very long")
+ end
+ end
+
+ context "when $stdout is not a TTY" do
+ before(:each) do
+ allow($stdout).to receive(:tty?).and_return(false)
+ end
+
+ it "returns an empty string for all colors" do
+ expect(subject.to_s).to eq("")
+ expect(subject.red.to_s).to eq("")
+ expect(subject.green.to_s).to eq("")
+ expect(subject.yellow.to_s).to eq("")
+ expect(subject.blue.to_s).to eq("")
+ expect(subject.magenta.to_s).to eq("")
+ expect(subject.cyan.to_s).to eq("")
+ expect(subject.default.to_s).to eq("")
+ end
+ end
+
+ context "when $stdout is a TTY" do
+ before(:each) do
+ allow($stdout).to receive(:tty?).and_return(true)
+ end
+
+ it "returns an empty string for all colors" do
+ expect(subject.to_s).to eq("")
+ expect(subject.red.to_s).to eq("\033[31m")
+ expect(subject.green.to_s).to eq("\033[32m")
+ expect(subject.yellow.to_s).to eq("\033[33m")
+ expect(subject.blue.to_s).to eq("\033[34m")
+ expect(subject.magenta.to_s).to eq("\033[35m")
+ expect(subject.cyan.to_s).to eq("\033[36m")
+ expect(subject.default.to_s).to eq("\033[39m")
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils/tty_test.rb b/Library/Homebrew/test/utils/tty_test.rb
deleted file mode 100644
index 09f092cbd..000000000
--- a/Library/Homebrew/test/utils/tty_test.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require "testing_env"
-require "utils"
-
-class TtyTests < Homebrew::TestCase
- def test_strip_ansi
- assert_equal "hello", Tty.strip_ansi("\033\[36;7mhello\033\[0m")
- end
-
- def test_width
- assert_kind_of Integer, Tty.width
- end
-
- def test_truncate
- Tty.stubs(:width).returns 15
- assert_equal "foobar some", Tty.truncate("foobar something very long")
- assert_equal "truncate", Tty.truncate("truncate")
-
- # When the terminal is unsupported, we report 0 width
- Tty.stubs(:width).returns 0
- assert_equal "foobar something very long", Tty.truncate("foobar something very long")
- end
-
- def test_no_tty_formatting
- $stdout.stubs(:tty?).returns false
- assert_equal "", Tty.to_s
- assert_equal "", Tty.red.to_s
- assert_equal "", Tty.green.to_s
- assert_equal "", Tty.yellow.to_s
- assert_equal "", Tty.blue.to_s
- assert_equal "", Tty.magenta.to_s
- assert_equal "", Tty.cyan.to_s
- assert_equal "", Tty.default.to_s
- end
-
- def test_formatting
- $stdout.stubs(:tty?).returns(true)
- assert_equal "", Tty.to_s
- assert_equal "\033[31m", Tty.red.to_s
- assert_equal "\033[32m", Tty.green.to_s
- assert_equal "\033[33m", Tty.yellow.to_s
- assert_equal "\033[34m", Tty.blue.to_s
- assert_equal "\033[35m", Tty.magenta.to_s
- assert_equal "\033[36m", Tty.cyan.to_s
- assert_equal "\033[39m", Tty.default.to_s
- end
-end
diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb
new file mode 100644
index 000000000..b3fdedcb9
--- /dev/null
+++ b/Library/Homebrew/test/utils_spec.rb
@@ -0,0 +1,277 @@
+require "utils"
+
+describe "globally-scoped helper methods" do
+ let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
+
+ after(:each) { dir.rmtree unless @dir.nil? }
+
+ def esc(code)
+ /(\e\[\d+m)*\e\[#{code}m/
+ end
+
+ describe "#ofail" do
+ it "sets Homebrew.failed to true" do
+ expect {
+ ofail "foo"
+ }.to output("Error: foo\n").to_stderr
+
+ expect(Homebrew).to have_failed
+ end
+ end
+
+ describe "#odie" do
+ it "exits with 1" do
+ expect(self).to receive(:exit).and_return(1)
+ expect {
+ odie "foo"
+ }.to output("Error: foo\n").to_stderr
+ end
+ end
+
+ describe "#pretty_installed" do
+ subject { pretty_installed("foo") }
+
+ context "when $stdout is a TTY" do
+ before(:each) { allow($stdout).to receive(:tty?).and_return(true) }
+
+ context "with HOMEBREW_NO_EMOJI unset" do
+ before(:each) { ENV.delete("HOMEBREW_NO_EMOJI") }
+
+ it "returns a string with a colored checkmark" do
+ expect(subject)
+ .to match(/#{esc 1}foo #{esc 32}✔#{esc 0}/)
+ end
+ end
+
+ context "with HOMEBREW_NO_EMOJI set" do
+ before(:each) { ENV["HOMEBREW_NO_EMOJI"] = "1" }
+
+ it "returns a string with colored info" do
+ expect(subject)
+ .to match(/#{esc 1}foo \(installed\)#{esc 0}/)
+ end
+ end
+ end
+
+ context "when $stdout is not a TTY" do
+ before(:each) { allow($stdout).to receive(:tty?).and_return(false) }
+
+ it "returns plain text" do
+ expect(subject).to eq("foo")
+ end
+ end
+ end
+
+ describe "#pretty_uninstalled" do
+ subject { pretty_uninstalled("foo") }
+
+ context "when $stdout is a TTY" do
+ before(:each) { allow($stdout).to receive(:tty?).and_return(true) }
+
+ context "with HOMEBREW_NO_EMOJI unset" do
+ before(:each) { ENV.delete("HOMEBREW_NO_EMOJI") }
+
+ it "returns a string with a colored checkmark" do
+ expect(subject)
+ .to match(/#{esc 1}foo #{esc 31}✘#{esc 0}/)
+ end
+ end
+
+ context "with HOMEBREW_NO_EMOJI set" do
+ before(:each) { ENV["HOMEBREW_NO_EMOJI"] = "1" }
+
+ it "returns a string with colored info" do
+ expect(subject)
+ .to match(/#{esc 1}foo \(uninstalled\)#{esc 0}/)
+ end
+ end
+ end
+
+ context "when $stdout is not a TTY" do
+ before(:each) { allow($stdout).to receive(:tty?).and_return(false) }
+
+ it "returns plain text" do
+ expect(subject).to eq("foo")
+ end
+ end
+ end
+
+ describe "#interactive_shell" do
+ let(:shell) { dir/"myshell" }
+
+ it "starts an interactive shell session" do
+ IO.write shell, <<-EOS.undent
+ #!/bin/sh
+ echo called > "#{dir}/called"
+ EOS
+
+ FileUtils.chmod 0755, shell
+
+ ENV["SHELL"] = shell
+
+ expect { interactive_shell }.not_to raise_error
+ expect(dir/"called").to exist
+ end
+ end
+
+ describe "#with_custom_locale" do
+ it "temporarily overrides the system locale" do
+ ENV["LC_ALL"] = "en_US.UTF-8"
+
+ with_custom_locale("C") do
+ expect(ENV["LC_ALL"]).to eq("C")
+ end
+
+ expect(ENV["LC_ALL"]).to eq("en_US.UTF-8")
+ end
+ end
+
+ describe "#run_as_not_developer" do
+ it "temporarily unsets HOMEBREW_DEVELOPER" do
+ ENV["HOMEBREW_DEVELOPER"] = "foo"
+
+ run_as_not_developer do
+ expect(ENV["HOMEBREW_DEVELOPER"]).to be nil
+ end
+
+ expect(ENV["HOMEBREW_DEVELOPER"]).to eq("foo")
+ end
+ end
+
+ describe "#which" do
+ let(:cmd) { dir/"foo" }
+
+ before(:each) { FileUtils.touch cmd }
+
+ it "returns the first executable that is found" do
+ cmd.chmod 0744
+ expect(which(File.basename(cmd), File.dirname(cmd))).to eq(cmd)
+ end
+
+ it "skips non-executables" do
+ expect(which(File.basename(cmd), File.dirname(cmd))).to be nil
+ end
+
+ it "skips malformed path and doesn't fail" do
+ # 'which' should not fail if a path is malformed
+ # see https://github.com/Homebrew/legacy-homebrew/issues/32789 for an example
+ cmd.chmod 0744
+
+ # ~~ will fail because ~foo resolves to foo's home and there is no '~' user
+ path = ["~~", File.dirname(cmd)].join(File::PATH_SEPARATOR)
+ expect(which(File.basename(cmd), path)).to eq(cmd)
+ end
+ end
+
+ describe "#which_all" do
+ let(:cmd1) { dir/"foo" }
+ let(:cmd2) { dir/"bar/foo" }
+ let(:cmd3) { dir/"bar/baz/foo" }
+
+ before(:each) do
+ (dir/"bar/baz").mkpath
+
+ FileUtils.touch cmd2
+
+ [cmd1, cmd3].each do |cmd|
+ FileUtils.touch cmd
+ cmd.chmod 0744
+ end
+ end
+
+ it "returns an array of all executables that are found" do
+ path = [
+ "#{dir}/bar/baz",
+ "#{dir}/baz:#{dir}",
+ "~baduserpath",
+ ].join(File::PATH_SEPARATOR)
+ expect(which_all("foo", path)).to eq([cmd3, cmd1])
+ end
+ end
+
+ specify "#which_editor" do
+ ENV["HOMEBREW_EDITOR"] = "vemate"
+ expect(which_editor).to eq("vemate")
+ end
+
+ specify "#gzip" do
+ Dir.mktmpdir do |path|
+ path = Pathname.new(path)
+ somefile = path/"somefile"
+ FileUtils.touch somefile
+ expect(gzip(somefile)[0].to_s).to eq("#{somefile}.gz")
+ expect(Pathname.new("#{somefile}.gz")).to exist
+ end
+ end
+
+ specify "#capture_stderr" do
+ err = capture_stderr do
+ $stderr.print "test"
+ end
+
+ expect(err).to eq("test")
+ end
+
+ describe "#pretty_duration" do
+ it "converts seconds to a human-readable string" do
+ expect(pretty_duration(1)).to eq("1 second")
+ expect(pretty_duration(2.5)).to eq("2 seconds")
+ expect(pretty_duration(42)).to eq("42 seconds")
+ expect(pretty_duration(240)).to eq("4 minutes")
+ expect(pretty_duration(252.45)).to eq("4 minutes 12 seconds")
+ end
+ end
+
+ specify "#plural" do
+ expect(plural(1)).to eq("")
+ expect(plural(0)).to eq("s")
+ expect(plural(42)).to eq("s")
+ expect(plural(42, "")).to eq("")
+ end
+
+ specify "#disk_usage_readable" do
+ expect(disk_usage_readable(1)).to eq("1B")
+ expect(disk_usage_readable(1000)).to eq("1000B")
+ expect(disk_usage_readable(1024)).to eq("1KB")
+ expect(disk_usage_readable(1025)).to eq("1KB")
+ expect(disk_usage_readable(4_404_020)).to eq("4.2MB")
+ expect(disk_usage_readable(4_509_715_660)).to eq("4.2GB")
+ end
+
+ describe "#number_readable" do
+ it "returns a string with thousands separators" do
+ expect(number_readable(1)).to eq("1")
+ expect(number_readable(1_000)).to eq("1,000")
+ expect(number_readable(1_000_000)).to eq("1,000,000")
+ end
+ end
+
+ specify "#truncate_text_to_approximate_size" do
+ glue = "\n[...snip...]\n" # hard-coded copy from truncate_text_to_approximate_size
+ n = 20
+ long_s = "x" * 40
+
+ s = truncate_text_to_approximate_size(long_s, n)
+ expect(s.length).to eq(n)
+ expect(s).to match(/^x+#{Regexp.escape(glue)}x+$/)
+
+ s = truncate_text_to_approximate_size(long_s, n, front_weight: 0.0)
+ expect(s).to eq(glue + ("x" * (n - glue.length)))
+
+ s = truncate_text_to_approximate_size(long_s, n, front_weight: 1.0)
+ expect(s).to eq(("x" * (n - glue.length)) + glue)
+ end
+
+ describe "#odeprecated" do
+ it "raises a MethodDeprecatedError" do
+ ENV.delete("HOMEBREW_DEVELOPER")
+ expect {
+ odeprecated(
+ "method", "replacement",
+ caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"],
+ disable: true
+ )
+ }.to raise_error(MethodDeprecatedError, %r{method.*replacement.*homebrew/homebrew-core.*homebrew/core}m)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/utils_test.rb b/Library/Homebrew/test/utils_test.rb
deleted file mode 100644
index d7c25683d..000000000
--- a/Library/Homebrew/test/utils_test.rb
+++ /dev/null
@@ -1,235 +0,0 @@
-require "testing_env"
-require "utils"
-require "tempfile"
-require "utils/shell"
-
-class UtilTests < Homebrew::TestCase
- def setup
- @dir = Pathname.new(mktmpdir)
- @env = ENV.to_hash
- end
-
- def teardown
- @dir.rmtree
- ENV.replace @env
- end
-
- def test_ofail
- shutup { ofail "foo" }
- assert Homebrew.failed?
- ensure
- Homebrew.failed = false
- end
-
- def test_odie
- expects(:exit).returns 1
- shutup { odie "foo" }
- end
-
- def test_pretty_installed
- $stdout.stubs(:tty?).returns false
- assert_equal "foo", pretty_installed("foo")
- end
-
- def test_pretty_uninstalled
- $stdout.stubs(:tty?).returns false
- assert_equal "foo", pretty_uninstalled("foo")
- end
-
- def test_interactive_shell
- mktmpdir do |path|
- shell = "#{path}/myshell"
- File.open(shell, "w") do |file|
- file.write "#!/bin/sh\necho called > #{path}/called\n"
- end
- FileUtils.chmod 0755, shell
- ENV["SHELL"] = shell
- assert_nothing_raised { interactive_shell }
- assert File.exist? "#{path}/called"
- end
- end
-
- def test_with_custom_locale
- ENV["LC_ALL"] = "en_US.UTF-8"
- with_custom_locale("C") do
- assert_equal "C", ENV["LC_ALL"]
- end
- assert_equal "en_US.UTF-8", ENV["LC_ALL"]
- end
-
- def test_run_as_not_developer
- ENV["HOMEBREW_DEVELOPER"] = "foo"
- run_as_not_developer do
- assert_nil ENV["HOMEBREW_DEVELOPER"]
- end
- assert_equal "foo", ENV["HOMEBREW_DEVELOPER"]
- end
-
- def test_put_columns_empty
- out, err = capture_io do
- puts Formatter.columns([])
- end
-
- assert_equal out, "\n"
- assert_equal err, ""
- end
-
- def test_which
- cmd = @dir/"foo"
- FileUtils.touch cmd
- cmd.chmod 0744
- assert_equal Pathname.new(cmd),
- which(File.basename(cmd), File.dirname(cmd))
- end
-
- def test_which_skip_non_executables
- cmd = @dir/"foo"
- FileUtils.touch cmd
- assert_nil which(File.basename(cmd), File.dirname(cmd))
- end
-
- def test_which_skip_malformed_path
- # 'which' should not fail if a path is malformed
- # see https://github.com/Homebrew/legacy-homebrew/issues/32789 for an example
- cmd = @dir/"foo"
- FileUtils.touch cmd
- cmd.chmod 0744
-
- # ~~ will fail because ~foo resolves to foo's home and there is no '~' user
- # here
- assert_equal Pathname.new(cmd),
- which(File.basename(cmd), "~~#{File::PATH_SEPARATOR}#{File.dirname(cmd)}")
- end
-
- def test_which_all
- (@dir/"bar/baz").mkpath
- cmd1 = @dir/"foo"
- cmd2 = @dir/"bar/foo"
- cmd3 = @dir/"bar/baz/foo"
- FileUtils.touch cmd2
- [cmd1, cmd3].each do |cmd|
- FileUtils.touch cmd
- cmd.chmod 0744
- end
- assert_equal [cmd3, cmd1],
- which_all("foo", "#{@dir}/bar/baz:#{@dir}/baz:#{@dir}:~baduserpath")
- end
-
- def test_which_editor
- ENV["HOMEBREW_EDITOR"] = "vemate"
- assert_equal "vemate", which_editor
- end
-
- def test_gzip
- mktmpdir do |path|
- somefile = "#{path}/somefile"
- FileUtils.touch somefile
- assert_equal "#{somefile}.gz",
- gzip(somefile)[0].to_s
- assert File.exist?("#{somefile}.gz")
- end
- end
-
- def test_capture_stderr
- assert_equal "test\n", capture_stderr { $stderr.puts "test" }
- end
-
- def test_shell_profile
- ENV["SHELL"] = "/bin/sh"
- assert_equal "~/.bash_profile", Utils::Shell.shell_profile
- ENV["SHELL"] = "/bin/bash"
- assert_equal "~/.bash_profile", Utils::Shell.shell_profile
- ENV["SHELL"] = "/bin/another_shell"
- assert_equal "~/.bash_profile", Utils::Shell.shell_profile
- ENV["SHELL"] = "/bin/zsh"
- assert_equal "~/.zshrc", Utils::Shell.shell_profile
- ENV["SHELL"] = "/bin/ksh"
- assert_equal "~/.kshrc", Utils::Shell.shell_profile
- end
-
- def test_popen_read
- out = Utils.popen_read("sh", "-c", "echo success").chomp
- assert_equal "success", out
- assert_predicate $?, :success?
- end
-
- def test_popen_read_with_block
- out = Utils.popen_read("sh", "-c", "echo success") do |pipe|
- pipe.read.chomp
- end
- assert_equal "success", out
- assert_predicate $?, :success?
- end
-
- def test_popen_write_with_block
- Utils.popen_write("grep", "-q", "success") do |pipe|
- pipe.write("success\n")
- end
- assert_predicate $?, :success?
- end
-
- def test_pretty_duration
- assert_equal "1 second", pretty_duration(1)
- assert_equal "2 seconds", pretty_duration(2.5)
- assert_equal "42 seconds", pretty_duration(42)
- assert_equal "4 minutes", pretty_duration(240)
- assert_equal "4 minutes 12 seconds", pretty_duration(252.45)
- end
-
- def test_plural
- assert_equal "", plural(1)
- assert_equal "s", plural(0)
- assert_equal "s", plural(42)
- assert_equal "", plural(42, "")
- end
-
- def test_disk_usage_readable
- assert_equal "1B", disk_usage_readable(1)
- assert_equal "1000B", disk_usage_readable(1000)
- assert_equal "1K", disk_usage_readable(1024)
- assert_equal "1K", disk_usage_readable(1025)
- assert_equal "4.2M", disk_usage_readable(4_404_020)
- assert_equal "4.2G", disk_usage_readable(4_509_715_660)
- end
-
- def test_number_readable
- assert_equal "1", number_readable(1)
- assert_equal "1,000", number_readable(1_000)
- assert_equal "1,000,000", number_readable(1_000_000)
- end
-
- def test_truncate_text_to_approximate_size
- glue = "\n[...snip...]\n" # hard-coded copy from truncate_text_to_approximate_size
- n = 20
- long_s = "x" * 40
- s = truncate_text_to_approximate_size(long_s, n)
- assert_equal n, s.length
- assert_match(/^x+#{Regexp.escape(glue)}x+$/, s)
- s = truncate_text_to_approximate_size(long_s, n, front_weight: 0.0)
- assert_equal glue + ("x" * (n - glue.length)), s
- s = truncate_text_to_approximate_size(long_s, n, front_weight: 1.0)
- assert_equal(("x" * (n - glue.length)) + glue, s)
- end
-
- def test_odeprecated
- ARGV.stubs(:homebrew_developer?).returns false
- e = assert_raises(MethodDeprecatedError) do
- odeprecated("method", "replacement",
- caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"],
- disable: true)
- end
- assert_match "method", e.message
- assert_match "replacement", e.message
- assert_match "homebrew/homebrew-core", e.message
- assert_match "homebrew/core", e.message
- end
-
- def test_bottles_bintray
- assert_equal "openssl:1.1", Utils::Bottles::Bintray.package("openssl@1.1")
- assert_equal "gtkx", Utils::Bottles::Bintray.package("gtk+")
- assert_equal "llvm", Utils::Bottles::Bintray.package("llvm")
-
- tap = Tap.new("homebrew", "bintray-test")
- assert_equal "bottles-bintray-test", Utils::Bottles::Bintray.repository(tap)
- end
-end
diff --git a/Library/Homebrew/test/version_test.rb b/Library/Homebrew/test/version_test.rb
deleted file mode 100644
index e7ffbc4f6..000000000
--- a/Library/Homebrew/test/version_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require "testing_env"
-
-class IntegrationCommandTestVersion < IntegrationCommandTestCase
- def test_version
- assert_match HOMEBREW_VERSION.to_s,
- cmd("--version")
- end
-end
diff --git a/Library/Homebrew/test/versions_test.rb b/Library/Homebrew/test/versions_test.rb
index a6e922178..b6814b1d1 100644
--- a/Library/Homebrew/test/versions_test.rb
+++ b/Library/Homebrew/test/versions_test.rb
@@ -185,8 +185,6 @@ class VersionParsingTests < Homebrew::TestCase
d = HOMEBREW_CELLAR/"foo-0.1.9"
d.mkpath
assert_equal version("0.1.9"), d.version
- ensure
- d.unlink
end
def test_no_version
diff --git a/Library/Homebrew/test/x11_requirement_spec.rb b/Library/Homebrew/test/x11_requirement_spec.rb
new file mode 100644
index 000000000..f60c8bffe
--- /dev/null
+++ b/Library/Homebrew/test/x11_requirement_spec.rb
@@ -0,0 +1,36 @@
+require "requirements/x11_requirement"
+
+describe X11Requirement do
+ let(:default_name) { "x11" }
+
+ describe "#name" do
+ it "defaults to x11" do
+ expect(subject.name).to eq(default_name)
+ end
+ end
+
+ describe "#eql?" do
+ it "returns true if the names are equal" do
+ other = described_class.new(default_name)
+ expect(subject).to eql(other)
+ end
+
+ it "and returns false if the names differ" do
+ other = described_class.new("foo")
+ expect(subject).not_to eql(other)
+ end
+
+ it "returns false if the minimum version differs" do
+ other = described_class.new(default_name, ["2.5"])
+ expect(subject).not_to eql(other)
+ end
+ end
+
+ describe "#modify_build_environment" do
+ it "calls ENV#x11" do
+ allow(subject).to receive(:satisfied?).and_return(true)
+ expect(ENV).to receive(:x11)
+ subject.modify_build_environment
+ end
+ end
+end
diff --git a/Library/Homebrew/test/x11_requirement_test.rb b/Library/Homebrew/test/x11_requirement_test.rb
deleted file mode 100644
index b82a59e53..000000000
--- a/Library/Homebrew/test/x11_requirement_test.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require "testing_env"
-require "requirements/x11_requirement"
-
-class X11RequirementTests < Homebrew::TestCase
- def test_eql_instances_are_eql
- x = X11Requirement.new
- y = X11Requirement.new
- assert_eql x, y
- assert_equal x.hash, y.hash
- end
-
- def test_not_eql_when_hashes_differ
- x = X11Requirement.new("foo")
- y = X11Requirement.new
- refute_eql x, y
- refute_equal x.hash, y.hash
- end
-
- def test_different_min_version
- x = X11Requirement.new
- y = X11Requirement.new("x11", %w[2.5])
- refute_eql x, y
- end
-
- def test_x_env
- x = X11Requirement.new
- x.stubs(:satisfied?).returns(true)
- ENV.expects(:x11)
- x.modify_build_environment
- end
-end