From 6b6b27126d7ecc1dde9a6bc166a7e1daa3af35d2 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 21 Oct 2016 08:57:39 +0200 Subject: Reorder and rename test files. --- Library/Homebrew/dev-cmd/tests.rb | 14 +- Library/Homebrew/test/test/ARGV_test.rb | 80 ++ Library/Homebrew/test/test/ENV_test.rb | 201 ++++ Library/Homebrew/test/test/analytics_test.rb | 26 + Library/Homebrew/test/test/audit_test.rb | 472 ++++++++ Library/Homebrew/test/test/bash_test.rb | 34 + Library/Homebrew/test/test/blacklist_test.rb | 68 ++ .../Homebrew/test/test/bottle_collector_test.rb | 38 + Library/Homebrew/test/test/bottle_filename_test.rb | 31 + Library/Homebrew/test/test/bottle_hooks_test.rb | 47 + Library/Homebrew/test/test/bottle_test.rb | 21 + .../Homebrew/test/test/build_environment_test.rb | 45 + Library/Homebrew/test/test/build_options_test.rb | 49 + Library/Homebrew/test/test/bundle_test.rb | 22 + Library/Homebrew/test/test/cache_formula_test.rb | 8 + Library/Homebrew/test/test/cache_test.rb | 8 + Library/Homebrew/test/test/cask_test.rb | 10 + Library/Homebrew/test/test/cat_test.rb | 8 + Library/Homebrew/test/test/caveats_test.rb | 29 + Library/Homebrew/test/test/cellar_formula_test.rb | 8 + Library/Homebrew/test/test/cellar_test.rb | 8 + Library/Homebrew/test/test/checksum_test.rb | 22 + .../test/test/checksum_verification_test.rb | 39 + Library/Homebrew/test/test/cleaner_test.rb | 223 ++++ Library/Homebrew/test/test/cleanup_test.rb | 91 ++ Library/Homebrew/test/test/command_test.rb | 11 + Library/Homebrew/test/test/commands_test.rb | 86 ++ .../Homebrew/test/test/compiler_failure_test.rb | 52 + .../Homebrew/test/test/compiler_selector_test.rb | 116 ++ Library/Homebrew/test/test/config_test.rb | 8 + Library/Homebrew/test/test/create_test.rb | 12 + Library/Homebrew/test/test/custom_command_test.rb | 18 + Library/Homebrew/test/test/dependencies_test.rb | 115 ++ .../test/test/dependency_collector_test.rb | 146 +++ .../test/test/dependency_expansion_test.rb | 137 +++ Library/Homebrew/test/test/dependency_test.rb | 125 +++ Library/Homebrew/test/test/deps_test.rb | 16 + Library/Homebrew/test/test/desc_test.rb | 17 + Library/Homebrew/test/test/descriptions_test.rb | 45 + Library/Homebrew/test/test/diagnostic_test.rb | 197 ++++ Library/Homebrew/test/test/doctor_test.rb | 8 + .../Homebrew/test/test/download_strategies_test.rb | 188 ++++ Library/Homebrew/test/test/edit_test.rb | 11 + Library/Homebrew/test/test/exceptions_test.rb | 142 +++ Library/Homebrew/test/test/fetch_test.rb | 11 + .../test/test/formula_installer_bottle_test.rb | 78 ++ .../Homebrew/test/test/formula_installer_test.rb | 138 +++ Library/Homebrew/test/test/formula_lock_test.rb | 22 + Library/Homebrew/test/test/formula_pin_test.rb | 54 + .../test/test/formula_spec_selection_test.rb | 99 ++ Library/Homebrew/test/test/formula_support_test.rb | 28 + Library/Homebrew/test/test/formula_test.rb | 1180 ++++++++++++++++++++ .../Homebrew/test/test/formula_validation_test.rb | 75 ++ Library/Homebrew/test/test/formulary_test.rb | 208 ++++ .../Homebrew/test/test/gpg2_requirement_test.rb | 24 + Library/Homebrew/test/test/gpg_test.rb | 20 + Library/Homebrew/test/test/hardware_test.rb | 15 + Library/Homebrew/test/test/help_test.rb | 21 + Library/Homebrew/test/test/home_test.rb | 12 + Library/Homebrew/test/test/info_test.rb | 29 + Library/Homebrew/test/test/inreplace_test.rb | 119 ++ Library/Homebrew/test/test/install_test.rb | 30 + Library/Homebrew/test/test/irb_test.rb | 19 + Library/Homebrew/test/test/json_test.rb | 20 + Library/Homebrew/test/test/keg_test.rb | 400 +++++++ Library/Homebrew/test/test/language_go_test.rb | 17 + .../test/test/language_module_requirement_test.rb | 55 + Library/Homebrew/test/test/language_python_test.rb | 99 ++ Library/Homebrew/test/test/leaves_test.rb | 15 + Library/Homebrew/test/test/link_test.rb | 23 + Library/Homebrew/test/test/linkapps_test.rb | 15 + Library/Homebrew/test/test/list_test.rb | 13 + Library/Homebrew/test/test/log_formula_test.rb | 27 + Library/Homebrew/test/test/log_test.rb | 13 + Library/Homebrew/test/test/migrate_test.rb | 18 + Library/Homebrew/test/test/migrator_test.rb | 264 +++++ Library/Homebrew/test/test/missing_test.rb | 34 + Library/Homebrew/test/test/mpi_requirement_test.rb | 12 + Library/Homebrew/test/test/options_test.rb | 157 +++ .../Homebrew/test/test/os/mac/blacklist_test.rb | 12 + .../test/test/os/mac/bottle_collector_test.rb | 26 + .../Homebrew/test/test/os/mac/bottle_tag_test.rb | 79 ++ .../test/test/os/mac/dependency_collector_test.rb | 57 + .../Homebrew/test/test/os/mac/diagnostic_test.rb | 49 + Library/Homebrew/test/test/os/mac/keg_test.rb | 69 ++ Library/Homebrew/test/test/os/mac/language_test.rb | 19 + Library/Homebrew/test/test/os/mac/mach_test.rb | 208 ++++ Library/Homebrew/test/test/os/mac/version_test.rb | 53 + .../test/test/os/mac/x11_requirement_test.rb | 13 + Library/Homebrew/test/test/outdated_test.rb | 10 + Library/Homebrew/test/test/patch_test.rb | 154 +++ Library/Homebrew/test/test/patching_test.rb | 253 +++++ Library/Homebrew/test/test/pathname_test.rb | 267 +++++ Library/Homebrew/test/test/pin_unpin_test.rb | 18 + Library/Homebrew/test/test/pkg_version_test.rb | 51 + Library/Homebrew/test/test/prefix_formula_test.rb | 8 + Library/Homebrew/test/test/prefix_test.rb | 8 + Library/Homebrew/test/test/prune_test.rb | 21 + Library/Homebrew/test/test/pull_offline_test.rb | 10 + Library/Homebrew/test/test/pull_test.rb | 27 + Library/Homebrew/test/test/readall_test.rb | 12 + .../Homebrew/test/test/reinstall_pinned_test.rb | 15 + Library/Homebrew/test/test/reinstall_test.rb | 15 + Library/Homebrew/test/test/repository_test.rb | 10 + Library/Homebrew/test/test/requirement_test.rb | 152 +++ Library/Homebrew/test/test/resource_test.rb | 132 +++ Library/Homebrew/test/test/sandbox_test.rb | 76 ++ .../Homebrew/test/test/search_remote_tap_test.rb | 19 + Library/Homebrew/test/test/search_test.rb | 30 + Library/Homebrew/test/test/services_test.rb | 11 + Library/Homebrew/test/test/sh_test.rb | 8 + Library/Homebrew/test/test/shell_test.rb | 59 + Library/Homebrew/test/test/software_spec_test.rb | 181 +++ Library/Homebrew/test/test/stdlib_test.rb | 61 + Library/Homebrew/test/test/string_test.rb | 40 + Library/Homebrew/test/test/switch_test.rb | 20 + Library/Homebrew/test/test/tab_test.rb | 270 +++++ Library/Homebrew/test/test/tap_new_test.rb | 9 + Library/Homebrew/test/test/tap_test.rb | 329 ++++++ Library/Homebrew/test/test/test_formula_test.rb | 30 + Library/Homebrew/test/test/uninstall_test.rb | 67 ++ Library/Homebrew/test/test/unlink_test.rb | 10 + Library/Homebrew/test/test/unlinkapps_test.rb | 19 + Library/Homebrew/test/test/unpack_test.rb | 13 + Library/Homebrew/test/test/update_report_test.rb | 134 +++ Library/Homebrew/test/test/upgrade_test.rb | 12 + Library/Homebrew/test/test/uses_test.rb | 16 + Library/Homebrew/test/test/utils/tty_test.rb | 46 + Library/Homebrew/test/test/utils_test.rb | 235 ++++ Library/Homebrew/test/test/version_test.rb | 8 + Library/Homebrew/test/test/versions_test.rb | 530 +++++++++ Library/Homebrew/test/test/x11_requirement_test.rb | 31 + Library/Homebrew/test/test_ARGV.rb | 80 -- Library/Homebrew/test/test_ENV.rb | 201 ---- Library/Homebrew/test/test_analytics.rb | 26 - Library/Homebrew/test/test_audit.rb | 472 -------- Library/Homebrew/test/test_bash.rb | 34 - Library/Homebrew/test/test_blacklist.rb | 68 -- Library/Homebrew/test/test_bottle.rb | 21 - Library/Homebrew/test/test_bottle_collector.rb | 38 - Library/Homebrew/test/test_bottle_filename.rb | 31 - Library/Homebrew/test/test_bottle_hooks.rb | 47 - Library/Homebrew/test/test_build_environment.rb | 45 - Library/Homebrew/test/test_build_options.rb | 49 - Library/Homebrew/test/test_bundle.rb | 22 - Library/Homebrew/test/test_cache.rb | 8 - Library/Homebrew/test/test_cache_formula.rb | 8 - Library/Homebrew/test/test_cask.rb | 10 - Library/Homebrew/test/test_cat.rb | 8 - Library/Homebrew/test/test_caveats.rb | 29 - Library/Homebrew/test/test_cellar.rb | 8 - Library/Homebrew/test/test_cellar_formula.rb | 8 - Library/Homebrew/test/test_checksum.rb | 22 - .../Homebrew/test/test_checksum_verification.rb | 39 - Library/Homebrew/test/test_cleaner.rb | 223 ---- Library/Homebrew/test/test_cleanup.rb | 91 -- Library/Homebrew/test/test_command.rb | 11 - Library/Homebrew/test/test_commands.rb | 86 -- Library/Homebrew/test/test_compiler_failure.rb | 52 - Library/Homebrew/test/test_compiler_selector.rb | 116 -- Library/Homebrew/test/test_config.rb | 8 - Library/Homebrew/test/test_create.rb | 12 - Library/Homebrew/test/test_custom_command.rb | 18 - Library/Homebrew/test/test_dependencies.rb | 115 -- Library/Homebrew/test/test_dependency.rb | 125 --- Library/Homebrew/test/test_dependency_collector.rb | 146 --- Library/Homebrew/test/test_dependency_expansion.rb | 137 --- Library/Homebrew/test/test_deps.rb | 16 - Library/Homebrew/test/test_desc.rb | 17 - Library/Homebrew/test/test_descriptions.rb | 45 - Library/Homebrew/test/test_diagnostic.rb | 197 ---- Library/Homebrew/test/test_doctor.rb | 8 - Library/Homebrew/test/test_download_strategies.rb | 188 ---- Library/Homebrew/test/test_edit.rb | 11 - Library/Homebrew/test/test_exceptions.rb | 142 --- Library/Homebrew/test/test_fetch.rb | 11 - Library/Homebrew/test/test_formula.rb | 1180 -------------------- Library/Homebrew/test/test_formula_installer.rb | 138 --- .../Homebrew/test/test_formula_installer_bottle.rb | 78 -- Library/Homebrew/test/test_formula_lock.rb | 22 - Library/Homebrew/test/test_formula_pin.rb | 54 - .../Homebrew/test/test_formula_spec_selection.rb | 99 -- Library/Homebrew/test/test_formula_support.rb | 28 - Library/Homebrew/test/test_formula_validation.rb | 75 -- Library/Homebrew/test/test_formulary.rb | 208 ---- Library/Homebrew/test/test_gpg.rb | 20 - Library/Homebrew/test/test_gpg2_requirement.rb | 24 - Library/Homebrew/test/test_hardware.rb | 15 - Library/Homebrew/test/test_help.rb | 21 - Library/Homebrew/test/test_home.rb | 12 - Library/Homebrew/test/test_info.rb | 29 - Library/Homebrew/test/test_inreplace.rb | 119 -- Library/Homebrew/test/test_install.rb | 30 - Library/Homebrew/test/test_irb.rb | 19 - Library/Homebrew/test/test_json.rb | 20 - Library/Homebrew/test/test_keg.rb | 400 ------- Library/Homebrew/test/test_language_go.rb | 17 - .../test/test_language_module_requirement.rb | 55 - Library/Homebrew/test/test_language_python.rb | 99 -- Library/Homebrew/test/test_leaves.rb | 15 - Library/Homebrew/test/test_link.rb | 23 - Library/Homebrew/test/test_linkapps.rb | 15 - Library/Homebrew/test/test_list.rb | 13 - Library/Homebrew/test/test_log.rb | 13 - Library/Homebrew/test/test_log_formula.rb | 27 - Library/Homebrew/test/test_migrate.rb | 18 - Library/Homebrew/test/test_migrator.rb | 264 ----- Library/Homebrew/test/test_missing.rb | 34 - Library/Homebrew/test/test_mpi_requirement.rb | 12 - Library/Homebrew/test/test_options.rb | 157 --- Library/Homebrew/test/test_os_mac_blacklist.rb | 12 - .../Homebrew/test/test_os_mac_bottle_collector.rb | 26 - Library/Homebrew/test/test_os_mac_bottle_tag.rb | 79 -- .../test/test_os_mac_dependency_collector.rb | 57 - Library/Homebrew/test/test_os_mac_diagnostic.rb | 49 - Library/Homebrew/test/test_os_mac_keg.rb | 69 -- Library/Homebrew/test/test_os_mac_language.rb | 19 - Library/Homebrew/test/test_os_mac_mach.rb | 208 ---- Library/Homebrew/test/test_os_mac_version.rb | 53 - .../Homebrew/test/test_os_mac_x11_requirement.rb | 13 - Library/Homebrew/test/test_outdated.rb | 10 - Library/Homebrew/test/test_patch.rb | 154 --- Library/Homebrew/test/test_patching.rb | 253 ----- Library/Homebrew/test/test_pathname.rb | 267 ----- Library/Homebrew/test/test_pin_unpin.rb | 18 - Library/Homebrew/test/test_pkg_version.rb | 51 - Library/Homebrew/test/test_prefix.rb | 8 - Library/Homebrew/test/test_prefix_formula.rb | 8 - Library/Homebrew/test/test_prune.rb | 21 - Library/Homebrew/test/test_pull.rb | 27 - Library/Homebrew/test/test_pull_offline.rb | 10 - Library/Homebrew/test/test_readall.rb | 12 - Library/Homebrew/test/test_reinstall.rb | 15 - Library/Homebrew/test/test_reinstall_pinned.rb | 15 - Library/Homebrew/test/test_repository.rb | 10 - Library/Homebrew/test/test_requirement.rb | 152 --- Library/Homebrew/test/test_resource.rb | 132 --- Library/Homebrew/test/test_sandbox.rb | 76 -- Library/Homebrew/test/test_search.rb | 30 - Library/Homebrew/test/test_search_remote_tap.rb | 19 - Library/Homebrew/test/test_services.rb | 11 - Library/Homebrew/test/test_sh.rb | 8 - Library/Homebrew/test/test_shell.rb | 59 - Library/Homebrew/test/test_software_spec.rb | 181 --- Library/Homebrew/test/test_stdlib.rb | 61 - Library/Homebrew/test/test_string.rb | 40 - Library/Homebrew/test/test_switch.rb | 20 - Library/Homebrew/test/test_tab.rb | 270 ----- Library/Homebrew/test/test_tap.rb | 329 ------ Library/Homebrew/test/test_tap_new.rb | 9 - Library/Homebrew/test/test_test_formula.rb | 30 - Library/Homebrew/test/test_uninstall.rb | 67 -- Library/Homebrew/test/test_unlink.rb | 10 - Library/Homebrew/test/test_unlinkapps.rb | 19 - Library/Homebrew/test/test_unpack.rb | 13 - Library/Homebrew/test/test_update_report.rb | 134 --- Library/Homebrew/test/test_upgrade.rb | 12 - Library/Homebrew/test/test_uses.rb | 16 - Library/Homebrew/test/test_utils.rb | 279 ----- Library/Homebrew/test/test_version.rb | 8 - Library/Homebrew/test/test_versions.rb | 530 --------- Library/Homebrew/test/test_x11_requirement.rb | 31 - 262 files changed, 10420 insertions(+), 10420 deletions(-) create mode 100644 Library/Homebrew/test/test/ARGV_test.rb create mode 100644 Library/Homebrew/test/test/ENV_test.rb create mode 100644 Library/Homebrew/test/test/analytics_test.rb create mode 100644 Library/Homebrew/test/test/audit_test.rb create mode 100644 Library/Homebrew/test/test/bash_test.rb create mode 100644 Library/Homebrew/test/test/blacklist_test.rb create mode 100644 Library/Homebrew/test/test/bottle_collector_test.rb create mode 100644 Library/Homebrew/test/test/bottle_filename_test.rb create mode 100644 Library/Homebrew/test/test/bottle_hooks_test.rb create mode 100644 Library/Homebrew/test/test/bottle_test.rb create mode 100644 Library/Homebrew/test/test/build_environment_test.rb create mode 100644 Library/Homebrew/test/test/build_options_test.rb create mode 100644 Library/Homebrew/test/test/bundle_test.rb create mode 100644 Library/Homebrew/test/test/cache_formula_test.rb create mode 100644 Library/Homebrew/test/test/cache_test.rb create mode 100644 Library/Homebrew/test/test/cask_test.rb create mode 100644 Library/Homebrew/test/test/cat_test.rb create mode 100644 Library/Homebrew/test/test/caveats_test.rb create mode 100644 Library/Homebrew/test/test/cellar_formula_test.rb create mode 100644 Library/Homebrew/test/test/cellar_test.rb create mode 100644 Library/Homebrew/test/test/checksum_test.rb create mode 100644 Library/Homebrew/test/test/checksum_verification_test.rb create mode 100644 Library/Homebrew/test/test/cleaner_test.rb create mode 100644 Library/Homebrew/test/test/cleanup_test.rb create mode 100644 Library/Homebrew/test/test/command_test.rb create mode 100644 Library/Homebrew/test/test/commands_test.rb create mode 100644 Library/Homebrew/test/test/compiler_failure_test.rb create mode 100644 Library/Homebrew/test/test/compiler_selector_test.rb create mode 100644 Library/Homebrew/test/test/config_test.rb create mode 100644 Library/Homebrew/test/test/create_test.rb create mode 100644 Library/Homebrew/test/test/custom_command_test.rb create mode 100644 Library/Homebrew/test/test/dependencies_test.rb create mode 100644 Library/Homebrew/test/test/dependency_collector_test.rb create mode 100644 Library/Homebrew/test/test/dependency_expansion_test.rb create mode 100644 Library/Homebrew/test/test/dependency_test.rb create mode 100644 Library/Homebrew/test/test/deps_test.rb create mode 100644 Library/Homebrew/test/test/desc_test.rb create mode 100644 Library/Homebrew/test/test/descriptions_test.rb create mode 100644 Library/Homebrew/test/test/diagnostic_test.rb create mode 100644 Library/Homebrew/test/test/doctor_test.rb create mode 100644 Library/Homebrew/test/test/download_strategies_test.rb create mode 100644 Library/Homebrew/test/test/edit_test.rb create mode 100644 Library/Homebrew/test/test/exceptions_test.rb create mode 100644 Library/Homebrew/test/test/fetch_test.rb create mode 100644 Library/Homebrew/test/test/formula_installer_bottle_test.rb create mode 100644 Library/Homebrew/test/test/formula_installer_test.rb create mode 100644 Library/Homebrew/test/test/formula_lock_test.rb create mode 100644 Library/Homebrew/test/test/formula_pin_test.rb create mode 100644 Library/Homebrew/test/test/formula_spec_selection_test.rb create mode 100644 Library/Homebrew/test/test/formula_support_test.rb create mode 100644 Library/Homebrew/test/test/formula_test.rb create mode 100644 Library/Homebrew/test/test/formula_validation_test.rb create mode 100644 Library/Homebrew/test/test/formulary_test.rb create mode 100644 Library/Homebrew/test/test/gpg2_requirement_test.rb create mode 100644 Library/Homebrew/test/test/gpg_test.rb create mode 100644 Library/Homebrew/test/test/hardware_test.rb create mode 100644 Library/Homebrew/test/test/help_test.rb create mode 100644 Library/Homebrew/test/test/home_test.rb create mode 100644 Library/Homebrew/test/test/info_test.rb create mode 100644 Library/Homebrew/test/test/inreplace_test.rb create mode 100644 Library/Homebrew/test/test/install_test.rb create mode 100644 Library/Homebrew/test/test/irb_test.rb create mode 100644 Library/Homebrew/test/test/json_test.rb create mode 100644 Library/Homebrew/test/test/keg_test.rb create mode 100644 Library/Homebrew/test/test/language_go_test.rb create mode 100644 Library/Homebrew/test/test/language_module_requirement_test.rb create mode 100644 Library/Homebrew/test/test/language_python_test.rb create mode 100644 Library/Homebrew/test/test/leaves_test.rb create mode 100644 Library/Homebrew/test/test/link_test.rb create mode 100644 Library/Homebrew/test/test/linkapps_test.rb create mode 100644 Library/Homebrew/test/test/list_test.rb create mode 100644 Library/Homebrew/test/test/log_formula_test.rb create mode 100644 Library/Homebrew/test/test/log_test.rb create mode 100644 Library/Homebrew/test/test/migrate_test.rb create mode 100644 Library/Homebrew/test/test/migrator_test.rb create mode 100644 Library/Homebrew/test/test/missing_test.rb create mode 100644 Library/Homebrew/test/test/mpi_requirement_test.rb create mode 100644 Library/Homebrew/test/test/options_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/blacklist_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/bottle_collector_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/bottle_tag_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/dependency_collector_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/diagnostic_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/keg_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/language_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/mach_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/version_test.rb create mode 100644 Library/Homebrew/test/test/os/mac/x11_requirement_test.rb create mode 100644 Library/Homebrew/test/test/outdated_test.rb create mode 100644 Library/Homebrew/test/test/patch_test.rb create mode 100644 Library/Homebrew/test/test/patching_test.rb create mode 100644 Library/Homebrew/test/test/pathname_test.rb create mode 100644 Library/Homebrew/test/test/pin_unpin_test.rb create mode 100644 Library/Homebrew/test/test/pkg_version_test.rb create mode 100644 Library/Homebrew/test/test/prefix_formula_test.rb create mode 100644 Library/Homebrew/test/test/prefix_test.rb create mode 100644 Library/Homebrew/test/test/prune_test.rb create mode 100644 Library/Homebrew/test/test/pull_offline_test.rb create mode 100644 Library/Homebrew/test/test/pull_test.rb create mode 100644 Library/Homebrew/test/test/readall_test.rb create mode 100644 Library/Homebrew/test/test/reinstall_pinned_test.rb create mode 100644 Library/Homebrew/test/test/reinstall_test.rb create mode 100644 Library/Homebrew/test/test/repository_test.rb create mode 100644 Library/Homebrew/test/test/requirement_test.rb create mode 100644 Library/Homebrew/test/test/resource_test.rb create mode 100644 Library/Homebrew/test/test/sandbox_test.rb create mode 100644 Library/Homebrew/test/test/search_remote_tap_test.rb create mode 100644 Library/Homebrew/test/test/search_test.rb create mode 100644 Library/Homebrew/test/test/services_test.rb create mode 100644 Library/Homebrew/test/test/sh_test.rb create mode 100644 Library/Homebrew/test/test/shell_test.rb create mode 100644 Library/Homebrew/test/test/software_spec_test.rb create mode 100644 Library/Homebrew/test/test/stdlib_test.rb create mode 100644 Library/Homebrew/test/test/string_test.rb create mode 100644 Library/Homebrew/test/test/switch_test.rb create mode 100644 Library/Homebrew/test/test/tab_test.rb create mode 100644 Library/Homebrew/test/test/tap_new_test.rb create mode 100644 Library/Homebrew/test/test/tap_test.rb create mode 100644 Library/Homebrew/test/test/test_formula_test.rb create mode 100644 Library/Homebrew/test/test/uninstall_test.rb create mode 100644 Library/Homebrew/test/test/unlink_test.rb create mode 100644 Library/Homebrew/test/test/unlinkapps_test.rb create mode 100644 Library/Homebrew/test/test/unpack_test.rb create mode 100644 Library/Homebrew/test/test/update_report_test.rb create mode 100644 Library/Homebrew/test/test/upgrade_test.rb create mode 100644 Library/Homebrew/test/test/uses_test.rb create mode 100644 Library/Homebrew/test/test/utils/tty_test.rb create mode 100644 Library/Homebrew/test/test/utils_test.rb create mode 100644 Library/Homebrew/test/test/version_test.rb create mode 100644 Library/Homebrew/test/test/versions_test.rb create mode 100644 Library/Homebrew/test/test/x11_requirement_test.rb delete mode 100644 Library/Homebrew/test/test_ARGV.rb delete mode 100644 Library/Homebrew/test/test_ENV.rb delete mode 100644 Library/Homebrew/test/test_analytics.rb delete mode 100644 Library/Homebrew/test/test_audit.rb delete mode 100644 Library/Homebrew/test/test_bash.rb delete mode 100644 Library/Homebrew/test/test_blacklist.rb delete mode 100644 Library/Homebrew/test/test_bottle.rb delete mode 100644 Library/Homebrew/test/test_bottle_collector.rb delete mode 100644 Library/Homebrew/test/test_bottle_filename.rb delete mode 100644 Library/Homebrew/test/test_bottle_hooks.rb delete mode 100644 Library/Homebrew/test/test_build_environment.rb delete mode 100644 Library/Homebrew/test/test_build_options.rb delete mode 100644 Library/Homebrew/test/test_bundle.rb delete mode 100644 Library/Homebrew/test/test_cache.rb delete mode 100644 Library/Homebrew/test/test_cache_formula.rb delete mode 100644 Library/Homebrew/test/test_cask.rb delete mode 100644 Library/Homebrew/test/test_cat.rb delete mode 100644 Library/Homebrew/test/test_caveats.rb delete mode 100644 Library/Homebrew/test/test_cellar.rb delete mode 100644 Library/Homebrew/test/test_cellar_formula.rb delete mode 100644 Library/Homebrew/test/test_checksum.rb delete mode 100644 Library/Homebrew/test/test_checksum_verification.rb delete mode 100644 Library/Homebrew/test/test_cleaner.rb delete mode 100644 Library/Homebrew/test/test_cleanup.rb delete mode 100644 Library/Homebrew/test/test_command.rb delete mode 100644 Library/Homebrew/test/test_commands.rb delete mode 100644 Library/Homebrew/test/test_compiler_failure.rb delete mode 100644 Library/Homebrew/test/test_compiler_selector.rb delete mode 100644 Library/Homebrew/test/test_config.rb delete mode 100644 Library/Homebrew/test/test_create.rb delete mode 100644 Library/Homebrew/test/test_custom_command.rb delete mode 100644 Library/Homebrew/test/test_dependencies.rb delete mode 100644 Library/Homebrew/test/test_dependency.rb delete mode 100644 Library/Homebrew/test/test_dependency_collector.rb delete mode 100644 Library/Homebrew/test/test_dependency_expansion.rb delete mode 100644 Library/Homebrew/test/test_deps.rb delete mode 100644 Library/Homebrew/test/test_desc.rb delete mode 100644 Library/Homebrew/test/test_descriptions.rb delete mode 100644 Library/Homebrew/test/test_diagnostic.rb delete mode 100644 Library/Homebrew/test/test_doctor.rb delete mode 100644 Library/Homebrew/test/test_download_strategies.rb delete mode 100644 Library/Homebrew/test/test_edit.rb delete mode 100644 Library/Homebrew/test/test_exceptions.rb delete mode 100644 Library/Homebrew/test/test_fetch.rb delete mode 100644 Library/Homebrew/test/test_formula.rb delete mode 100644 Library/Homebrew/test/test_formula_installer.rb delete mode 100644 Library/Homebrew/test/test_formula_installer_bottle.rb delete mode 100644 Library/Homebrew/test/test_formula_lock.rb delete mode 100644 Library/Homebrew/test/test_formula_pin.rb delete mode 100644 Library/Homebrew/test/test_formula_spec_selection.rb delete mode 100644 Library/Homebrew/test/test_formula_support.rb delete mode 100644 Library/Homebrew/test/test_formula_validation.rb delete mode 100644 Library/Homebrew/test/test_formulary.rb delete mode 100644 Library/Homebrew/test/test_gpg.rb delete mode 100644 Library/Homebrew/test/test_gpg2_requirement.rb delete mode 100644 Library/Homebrew/test/test_hardware.rb delete mode 100644 Library/Homebrew/test/test_help.rb delete mode 100644 Library/Homebrew/test/test_home.rb delete mode 100644 Library/Homebrew/test/test_info.rb delete mode 100644 Library/Homebrew/test/test_inreplace.rb delete mode 100644 Library/Homebrew/test/test_install.rb delete mode 100644 Library/Homebrew/test/test_irb.rb delete mode 100644 Library/Homebrew/test/test_json.rb delete mode 100644 Library/Homebrew/test/test_keg.rb delete mode 100644 Library/Homebrew/test/test_language_go.rb delete mode 100644 Library/Homebrew/test/test_language_module_requirement.rb delete mode 100644 Library/Homebrew/test/test_language_python.rb delete mode 100644 Library/Homebrew/test/test_leaves.rb delete mode 100644 Library/Homebrew/test/test_link.rb delete mode 100644 Library/Homebrew/test/test_linkapps.rb delete mode 100644 Library/Homebrew/test/test_list.rb delete mode 100644 Library/Homebrew/test/test_log.rb delete mode 100644 Library/Homebrew/test/test_log_formula.rb delete mode 100644 Library/Homebrew/test/test_migrate.rb delete mode 100644 Library/Homebrew/test/test_migrator.rb delete mode 100644 Library/Homebrew/test/test_missing.rb delete mode 100644 Library/Homebrew/test/test_mpi_requirement.rb delete mode 100644 Library/Homebrew/test/test_options.rb delete mode 100644 Library/Homebrew/test/test_os_mac_blacklist.rb delete mode 100644 Library/Homebrew/test/test_os_mac_bottle_collector.rb delete mode 100644 Library/Homebrew/test/test_os_mac_bottle_tag.rb delete mode 100644 Library/Homebrew/test/test_os_mac_dependency_collector.rb delete mode 100644 Library/Homebrew/test/test_os_mac_diagnostic.rb delete mode 100644 Library/Homebrew/test/test_os_mac_keg.rb delete mode 100644 Library/Homebrew/test/test_os_mac_language.rb delete mode 100644 Library/Homebrew/test/test_os_mac_mach.rb delete mode 100644 Library/Homebrew/test/test_os_mac_version.rb delete mode 100644 Library/Homebrew/test/test_os_mac_x11_requirement.rb delete mode 100644 Library/Homebrew/test/test_outdated.rb delete mode 100644 Library/Homebrew/test/test_patch.rb delete mode 100644 Library/Homebrew/test/test_patching.rb delete mode 100644 Library/Homebrew/test/test_pathname.rb delete mode 100644 Library/Homebrew/test/test_pin_unpin.rb delete mode 100644 Library/Homebrew/test/test_pkg_version.rb delete mode 100644 Library/Homebrew/test/test_prefix.rb delete mode 100644 Library/Homebrew/test/test_prefix_formula.rb delete mode 100644 Library/Homebrew/test/test_prune.rb delete mode 100644 Library/Homebrew/test/test_pull.rb delete mode 100644 Library/Homebrew/test/test_pull_offline.rb delete mode 100644 Library/Homebrew/test/test_readall.rb delete mode 100644 Library/Homebrew/test/test_reinstall.rb delete mode 100644 Library/Homebrew/test/test_reinstall_pinned.rb delete mode 100644 Library/Homebrew/test/test_repository.rb delete mode 100644 Library/Homebrew/test/test_requirement.rb delete mode 100644 Library/Homebrew/test/test_resource.rb delete mode 100644 Library/Homebrew/test/test_sandbox.rb delete mode 100644 Library/Homebrew/test/test_search.rb delete mode 100644 Library/Homebrew/test/test_search_remote_tap.rb delete mode 100644 Library/Homebrew/test/test_services.rb delete mode 100644 Library/Homebrew/test/test_sh.rb delete mode 100644 Library/Homebrew/test/test_shell.rb delete mode 100644 Library/Homebrew/test/test_software_spec.rb delete mode 100644 Library/Homebrew/test/test_stdlib.rb delete mode 100644 Library/Homebrew/test/test_string.rb delete mode 100644 Library/Homebrew/test/test_switch.rb delete mode 100644 Library/Homebrew/test/test_tab.rb delete mode 100644 Library/Homebrew/test/test_tap.rb delete mode 100644 Library/Homebrew/test/test_tap_new.rb delete mode 100644 Library/Homebrew/test/test_test_formula.rb delete mode 100644 Library/Homebrew/test/test_uninstall.rb delete mode 100644 Library/Homebrew/test/test_unlink.rb delete mode 100644 Library/Homebrew/test/test_unlinkapps.rb delete mode 100644 Library/Homebrew/test/test_unpack.rb delete mode 100644 Library/Homebrew/test/test_update_report.rb delete mode 100644 Library/Homebrew/test/test_upgrade.rb delete mode 100644 Library/Homebrew/test/test_uses.rb delete mode 100644 Library/Homebrew/test/test_utils.rb delete mode 100644 Library/Homebrew/test/test_version.rb delete mode 100644 Library/Homebrew/test/test_versions.rb delete mode 100644 Library/Homebrew/test/test_x11_requirement.rb (limited to 'Library') diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index ee7fa9275..df9a00a16 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -8,7 +8,7 @@ module Homebrew module_function def tests - (HOMEBREW_LIBRARY/"Homebrew").cd do + HOMEBREW_LIBRARY_PATH.cd do ENV.delete "HOMEBREW_VERBOSE" ENV.delete "VERBOSE" ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" @@ -44,8 +44,8 @@ module Homebrew # Make it easier to reproduce test runs. ENV["SEED"] = ARGV.next if ARGV.include? "--seed" - files = Dir["test/test_*.rb"] - files -= Dir["test/test_os_mac_*.rb"] unless OS.mac? + files = Dir.glob("test/test/**/*_test.rb") + .reject { |p| !OS.mac? && p.start_with?("test/test/os/mac/") } opts = [] opts << "--serialize-stdout" if ENV["CI"] @@ -54,16 +54,14 @@ module Homebrew args << "--trace" if ARGV.include? "--trace" if ARGV.value("only") - ENV["HOMEBREW_TESTS_ONLY"] = "1" - test_name, test_method = ARGV.value("only").split("/", 2) - files = ["test/test_#{test_name}.rb"] + test_name, test_method = ARGV.value("only").split(":", 2) + files = Dir.glob("test/test/{#{test_name},#{test_name}/**/*}_test.rb") args << "--name=test_#{test_method}" if test_method end args += ARGV.named.select { |v| v[/^TEST(OPTS)?=/] } - system "bundle", "exec", "parallel_test", *opts, - "--", *args, "--", *files + system "bundle", "exec", "parallel_test", *opts, "--", *args, "--", *files Homebrew.failed = !$?.success? diff --git a/Library/Homebrew/test/test/ARGV_test.rb b/Library/Homebrew/test/test/ARGV_test.rb new file mode 100644 index 000000000..6805e0c62 --- /dev/null +++ b/Library/Homebrew/test/test/ARGV_test.rb @@ -0,0 +1,80 @@ +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/test/ENV_test.rb b/Library/Homebrew/test/test/ENV_test.rb new file mode 100644 index 000000000..e38c75c6e --- /dev/null +++ b/Library/Homebrew/test/test/ENV_test.rb @@ -0,0 +1,201 @@ +require "testing_env" +require "extend/ENV" +require "helper/integration_command_test_case" + +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, :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/test/analytics_test.rb b/Library/Homebrew/test/test/analytics_test.rb new file mode 100644 index 000000000..00e0593db --- /dev/null +++ b/Library/Homebrew/test/test/analytics_test.rb @@ -0,0 +1,26 @@ +require "helper/integration_command_test_case" + +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/test/audit_test.rb b/Library/Homebrew/test/test/audit_test.rb new file mode 100644 index 000000000..2725f906e --- /dev/null +++ b/Library/Homebrew/test/test/audit_test.rb @@ -0,0 +1,472 @@ +require "testing_env" +require "fileutils" +require "pathname" +require "formulary" +require "dev-cmd/audit" + +class FormulaTextTests < Homebrew::TestCase + def setup + @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| + f.write <<-EOS.undent + class #{Formulary.class_s(name)} < Formula + #{body} + end + #{options[:patch]} + EOS + end + FormulaText.new path + end + + def test_simple_valid_formula + ft = formula_text "valid", 'url "http://www.example.com/valid-1.0.tar.gz"' + + refute ft.data?, "The formula should not have DATA" + refute ft.end?, "The formula should not have __END__" + assert ft.trailing_newline?, "The formula should have a trailing newline" + + assert ft =~ /\burl\b/, "The formula should match 'url'" + assert_nil ft.line_number(/desc/), "The formula should not match 'desc'" + assert_equal 2, ft.line_number(/\burl\b/) + assert ft.include?("Valid"), "The formula should include \"Valid\"" + end + + def test_trailing_newline + ft = formula_text "newline" + assert ft.trailing_newline?, "The formula must have a trailing newline" + end + + def test_has_data + ft = formula_text "data", "patch :DATA" + assert ft.data?, "The formula must have DATA" + end + + def test_has_end + ft = formula_text "end", "", patch: "__END__\na patch here" + assert ft.end?, "The formula must have __END__" + assert_equal "class End < Formula\n \nend", ft.without_patch + end +end + +class FormulaAuditorTests < Homebrew::TestCase + def setup + @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| + f.write text + end + FormulaAuditor.new Formulary.factory(path), options + end + + def test_init_no_problems + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + end + EOS + + assert_equal [], fa.problems + end + + def test_audit_file_permissions + File.stubs(:umask).returns 022 + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + end + EOS + + path = fa.formula.path + path.chmod 0400 + + fa.audit_file + assert_equal ["Incorrect file permissions (400): chmod 644 #{path}"], + fa.problems + end + + def test_audit_file_data_no_end + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + patch :DATA + end + EOS + fa.audit_file + assert_equal ["'DATA' was found, but no '__END__'"], fa.problems + end + + def test_audit_file_end_no_data + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + end + __END__ + a patch goes here + EOS + fa.audit_file + assert_equal ["'__END__' was found, but 'DATA' is not used"], fa.problems + end + + def test_audit_file_no_trailing_newline + fa = formula_auditor "foo", 'class Foo "http://www.freedesktop.org/wiki/bar", + "baz" => "http://www.freedesktop.org/wiki/Software/baz", + "qux" => "https://code.google.com/p/qux", + "quux" => "http://github.com/quux", + "corge" => "http://savannah.nongnu.org/corge", + "grault" => "http://grault.github.io/", + "garply" => "http://www.gnome.org/garply", + "waldo" => "http://www.gnu.org/waldo", + } + + formula_homepages.each do |name, homepage| + fa = formula_auditor name, <<-EOS.undent + class #{Formulary.class_s(name)} < Formula + homepage "#{homepage}" + url "http://example.com/#{name}-1.0.tgz" + end + EOS + + fa.audit_homepage + if homepage =~ %r{http:\/\/www\.freedesktop\.org} + if homepage =~ /Software/ + assert_match "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/www/Software/project_name`", + fa.problems.first + else + assert_match "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/project_name`", + fa.problems.first + end + elsif homepage =~ %r{https:\/\/code\.google\.com} + assert_match "#{homepage} should end with a slash", fa.problems.first + else + assert_match "Please use https:// for #{homepage}", fa.problems.first + end + end + end +end diff --git a/Library/Homebrew/test/test/bash_test.rb b/Library/Homebrew/test/test/bash_test.rb new file mode 100644 index 000000000..ff418c787 --- /dev/null +++ b/Library/Homebrew/test/test/bash_test.rb @@ -0,0 +1,34 @@ +require "testing_env" + +class BashTests < Homebrew::TestCase + def assert_valid_bash_syntax(file) + 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/test/blacklist_test.rb b/Library/Homebrew/test/test/blacklist_test.rb new file mode 100644 index 000000000..585a35484 --- /dev/null +++ b/Library/Homebrew/test/test/blacklist_test.rb @@ -0,0 +1,68 @@ +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/test/bottle_collector_test.rb b/Library/Homebrew/test/test/bottle_collector_test.rb new file mode 100644 index 000000000..d75e29ec8 --- /dev/null +++ b/Library/Homebrew/test/test/bottle_collector_test.rb @@ -0,0 +1,38 @@ +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/test/bottle_filename_test.rb b/Library/Homebrew/test/test/bottle_filename_test.rb new file mode 100644 index 000000000..6604e7d6a --- /dev/null +++ b/Library/Homebrew/test/test/bottle_filename_test.rb @@ -0,0 +1,31 @@ +require "testing_env" +require "formula" +require "software_spec" + +class BottleFilenameTests < Homebrew::TestCase + def fn(rebuild) + Bottle::Filename.new("foo", "1.0", :tag, rebuild) + end + + def test_prefix_suffix + assert_equal "foo-1.0.tag", fn(0).prefix + assert_equal ".bottle.tar.gz", fn(0).suffix + assert_equal ".bottle.1.tar.gz", fn(1).suffix + end + + def test_to_str + expected = "foo-1.0.tag.bottle.tar.gz" + assert_equal expected, fn(0).to_s + assert_equal expected, fn(0).to_str + end + + def test_create + f = formula do + url "https://example.com/foo.tar.gz" + version "1.0" + end + + expected = "formula_name-1.0.tag.bottle.tar.gz" + assert_equal expected, Bottle::Filename.create(f, :tag, 0).to_s + end +end diff --git a/Library/Homebrew/test/test/bottle_hooks_test.rb b/Library/Homebrew/test/test/bottle_hooks_test.rb new file mode 100644 index 000000000..3535d80ef --- /dev/null +++ b/Library/Homebrew/test/test/bottle_hooks_test.rb @@ -0,0 +1,47 @@ +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/test/bottle_test.rb b/Library/Homebrew/test/test/bottle_test.rb new file mode 100644 index 000000000..48727cfd9 --- /dev/null +++ b/Library/Homebrew/test/test/bottle_test.rb @@ -0,0 +1,21 @@ +require "helper/integration_command_test_case" + +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/test/build_environment_test.rb b/Library/Homebrew/test/test/build_environment_test.rb new file mode 100644 index 000000000..73a1c95f7 --- /dev/null +++ b/Library/Homebrew/test/test/build_environment_test.rb @@ -0,0 +1,45 @@ +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/test/build_options_test.rb b/Library/Homebrew/test/test/build_options_test.rb new file mode 100644 index 000000000..e460d25cc --- /dev/null +++ b/Library/Homebrew/test/test/build_options_test.rb @@ -0,0 +1,49 @@ +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/test/bundle_test.rb b/Library/Homebrew/test/test/bundle_test.rb new file mode 100644 index 000000000..6b040df1d --- /dev/null +++ b/Library/Homebrew/test/test/bundle_test.rb @@ -0,0 +1,22 @@ +require "helper/integration_command_test_case" + +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/test/cache_formula_test.rb b/Library/Homebrew/test/test/cache_formula_test.rb new file mode 100644 index 000000000..f4e37e2a2 --- /dev/null +++ b/Library/Homebrew/test/test/cache_formula_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestCacheFormula < IntegrationCommandTestCase + def test_cache_formula + assert_match %r{#{HOMEBREW_CACHE}/testball-}, + cmd("--cache", testball) + end +end diff --git a/Library/Homebrew/test/test/cache_test.rb b/Library/Homebrew/test/test/cache_test.rb new file mode 100644 index 000000000..cd7a5e2fa --- /dev/null +++ b/Library/Homebrew/test/test/cache_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestCache < IntegrationCommandTestCase + def test_cache + assert_equal HOMEBREW_CACHE.to_s, + cmd("--cache") + end +end diff --git a/Library/Homebrew/test/test/cask_test.rb b/Library/Homebrew/test/test/cask_test.rb new file mode 100644 index 000000000..6cae6d54b --- /dev/null +++ b/Library/Homebrew/test/test/cask_test.rb @@ -0,0 +1,10 @@ +require "helper/integration_command_test_case" + +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/test/cat_test.rb b/Library/Homebrew/test/test/cat_test.rb new file mode 100644 index 000000000..4cfd19c3d --- /dev/null +++ b/Library/Homebrew/test/test/cat_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +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/test/caveats_test.rb b/Library/Homebrew/test/test/caveats_test.rb new file mode 100644 index 000000000..9eaac5792 --- /dev/null +++ b/Library/Homebrew/test/test/caveats_test.rb @@ -0,0 +1,29 @@ +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/test/cellar_formula_test.rb b/Library/Homebrew/test/test/cellar_formula_test.rb new file mode 100644 index 000000000..7c458be9d --- /dev/null +++ b/Library/Homebrew/test/test/cellar_formula_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestCellarFormula < IntegrationCommandTestCase + def test_cellar_formula + assert_match "#{HOMEBREW_CELLAR}/testball", + cmd("--cellar", testball) + end +end diff --git a/Library/Homebrew/test/test/cellar_test.rb b/Library/Homebrew/test/test/cellar_test.rb new file mode 100644 index 000000000..b793c5342 --- /dev/null +++ b/Library/Homebrew/test/test/cellar_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestCellar < IntegrationCommandTestCase + def test_cellar + assert_equal HOMEBREW_CELLAR.to_s, + cmd("--cellar") + end +end diff --git a/Library/Homebrew/test/test/checksum_test.rb b/Library/Homebrew/test/test/checksum_test.rb new file mode 100644 index 000000000..5505f6824 --- /dev/null +++ b/Library/Homebrew/test/test/checksum_test.rb @@ -0,0 +1,22 @@ +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/test/checksum_verification_test.rb b/Library/Homebrew/test/test/checksum_verification_test.rb new file mode 100644 index 000000000..e25d08b83 --- /dev/null +++ b/Library/Homebrew/test/test/checksum_verification_test.rb @@ -0,0 +1,39 @@ +require "testing_env" +require "formula" + +class ChecksumVerificationTests < Homebrew::TestCase + def assert_checksum_good + assert_nothing_raised { shutup { @_f.brew {} } } + end + + def assert_checksum_bad + assert_raises(ChecksumMismatchError) { shutup { @_f.brew {} } } + end + + def formula(&block) + super do + url "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz" + instance_eval(&block) + end + end + + def teardown + @_f.clear_cache + end + + def test_good_sha256 + formula do + sha256 TESTBALL_SHA256 + end + + assert_checksum_good + end + + def test_bad_sha256 + formula do + sha256 "dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8" + end + + assert_checksum_bad + end +end diff --git a/Library/Homebrew/test/test/cleaner_test.rb b/Library/Homebrew/test/test/cleaner_test.rb new file mode 100644 index 000000000..450a78d86 --- /dev/null +++ b/Library/Homebrew/test/test/cleaner_test.rb @@ -0,0 +1,223 @@ +require "testing_env" +require "cleaner" +require "formula" + +class CleanerTests < Homebrew::TestCase + include FileUtils + + def setup + @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 + cp "#{TEST_DIRECTORY}/mach/a.out", @f.bin + cp Dir["#{TEST_DIRECTORY}/mach/*.dylib"], @f.lib + + Cleaner.new(@f).clean + + assert_equal 0100555, (@f.bin/"a.out").stat.mode + assert_equal 0100444, (@f.lib/"fat.dylib").stat.mode + assert_equal 0100444, (@f.lib/"x86_64.dylib").stat.mode + assert_equal 0100444, (@f.lib/"i386.dylib").stat.mode + end + + def test_prunes_prefix_if_empty + Cleaner.new(@f).clean + refute_predicate @f.prefix, :directory? + end + + def test_prunes_empty_directories + subdir = @f.bin/"subdir" + subdir.mkpath + + Cleaner.new(@f).clean + + refute_predicate @f.bin, :directory? + refute_predicate subdir, :directory? + end + + def test_skip_clean_empty_directory + @f.class.skip_clean "bin" + @f.bin.mkpath + + Cleaner.new(@f).clean + + assert_predicate @f.bin, :directory? + end + + def test_skip_clean_directory_with_empty_subdir + @f.class.skip_clean "bin" + subdir = @f.bin/"subdir" + subdir.mkpath + + Cleaner.new(@f).clean + + assert_predicate @f.bin, :directory? + assert_predicate subdir, :directory? + end + + def test_removes_symlink_when_target_was_pruned_first + dir = @f.prefix/"b" + symlink = @f.prefix/"a" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + refute_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_removes_symlink_pointing_to_empty_directory + dir = @f.prefix/"b" + symlink = @f.prefix/"c" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + refute_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_removes_broken_symlinks + symlink = @f.prefix/"symlink" + ln_s "target", symlink + + Cleaner.new(@f).clean + + refute_predicate symlink, :symlink? + end + + def test_skip_clean_broken_symlink + @f.class.skip_clean "symlink" + symlink = @f.prefix/"symlink" + ln_s "target", symlink + + Cleaner.new(@f).clean + + assert_predicate symlink, :symlink? + end + + def test_skip_clean_symlink_pointing_to_empty_directory + @f.class.skip_clean "c" + dir = @f.prefix/"b" + symlink = @f.prefix/"c" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + assert_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_skip_clean_symlink_when_target_pruned + @f.class.skip_clean "a" + dir = @f.prefix/"b" + symlink = @f.prefix/"a" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + assert_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_removes_la_files + file = @f.lib/"foo.la" + + @f.lib.mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_removes_perllocal_files + file = @f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod" + + (@f.lib/"perl5/darwin-thread-multi-2level").mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_removes_packlist_files + file = @f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist" + + (@f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_skip_clean_la + file = @f.lib/"foo.la" + + @f.class.skip_clean :la + @f.lib.mkpath + touch file + + Cleaner.new(@f).clean + + assert_predicate file, :exist? + end + + def test_remove_charset_alias + file = @f.lib/"charset.alias" + + @f.lib.mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_skip_clean_subdir + dir = @f.lib/"subdir" + @f.class.skip_clean "lib/subdir" + + dir.mkpath + + Cleaner.new(@f).clean + + assert_predicate dir, :directory? + end + + def test_skip_clean_paths_are_anchored_to_prefix + dir1 = @f.bin/"a" + dir2 = @f.lib/"bin/a" + + @f.class.skip_clean "bin/a" + dir1.mkpath + dir2.mkpath + + Cleaner.new(@f).clean + + assert_predicate dir1, :exist? + refute_predicate dir2, :exist? + end +end diff --git a/Library/Homebrew/test/test/cleanup_test.rb b/Library/Homebrew/test/test/cleanup_test.rb new file mode 100644 index 000000000..dffcd12f2 --- /dev/null +++ b/Library/Homebrew/test/test/cleanup_test.rb @@ -0,0 +1,91 @@ +require "testing_env" +require "testball" +require "cleanup" +require "fileutils" +require "pathname" +require "helper/integration_command_test_case" + +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 + @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" + end + + def test_cleanup + shutup { Homebrew::Cleanup.cleanup } + refute_predicate @ds_store, :exist? + end + + def test_cleanup_dry_run + ARGV << "--dry-run" + shutup { Homebrew::Cleanup.cleanup } + assert_predicate @ds_store, :exist? + 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 + + 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? + + 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 + end + + def test_cleanup_logs + path = (HOMEBREW_LOGS/"delete_me") + path.mkpath + ARGV << "--prune=all" + shutup { Homebrew::Cleanup.cleanup_logs } + refute_predicate path, :exist? + end + + def test_cleanup_cache_incomplete_downloads + incomplete = (HOMEBREW_CACHE/"something.incomplete") + incomplete.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate incomplete, :exist? + end + + def test_cleanup_cache_java_cache + java_cache = (HOMEBREW_CACHE/"java_cache") + java_cache.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate java_cache, :exist? + end + + def test_cleanup_cache_npm_cache + npm_cache = (HOMEBREW_CACHE/"npm_cache") + npm_cache.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate npm_cache, :exist? + end +end diff --git a/Library/Homebrew/test/test/command_test.rb b/Library/Homebrew/test/test/command_test.rb new file mode 100644 index 000000000..d05184631 --- /dev/null +++ b/Library/Homebrew/test/test/command_test.rb @@ -0,0 +1,11 @@ +require "helper/integration_command_test_case" + +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/test/commands_test.rb b/Library/Homebrew/test/test/commands_test.rb new file mode 100644 index 000000000..ef138049c --- /dev/null +++ b/Library/Homebrew/test/test/commands_test.rb @@ -0,0 +1,86 @@ +require "testing_env" +require "cmd/command" +require "cmd/commands" +require "fileutils" +require "helper/integration_command_test_case" + +class IntegrationCommandTestCommands < IntegrationCommandTestCase + def test_commands + assert_match "Built-in commands", + cmd("commands") + end +end + +class CommandsTests < Homebrew::TestCase + def setup + @cmds = [ + # internal commands + HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", + HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", + + # internal development commands + HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", + HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", + ] + + @cmds.each { |f| FileUtils.touch f } + end + + def teardown + @cmds.each(&:unlink) + end + + def test_internal_commands + cmds = Homebrew.internal_commands + assert cmds.include?("rbcmd"), "Ruby commands files should be recognized" + assert cmds.include?("shcmd"), "Shell commands files should be recognized" + refute cmds.include?("rbdevcmd"), "Dev commands shouldn't be included" + end + + def test_internal_developer_commands + cmds = Homebrew.internal_developer_commands + assert cmds.include?("rbdevcmd"), "Ruby commands files should be recognized" + assert cmds.include?("shdevcmd"), "Shell commands files should be recognized" + refute cmds.include?("rbcmd"), "Non-dev commands shouldn't be included" + 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}" + FileUtils.touch path + FileUtils.chmod 0755, path + end + + FileUtils.touch "#{dir}/brew-t4" + + ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" + cmds = Homebrew.external_commands + + assert cmds.include?("t1"), "Executable files should be included" + assert cmds.include?("t2"), "Executable Ruby files should be included" + refute cmds.include?("t3"), + "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 + assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", + Commands.path("rbcmd") + assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", + Commands.path("shcmd") + assert_nil Commands.path("idontexist1234") + end + + def test_internal_dev_command_path + assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", + Commands.path("rbdevcmd") + assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", + Commands.path("shdevcmd") + end +end diff --git a/Library/Homebrew/test/test/compiler_failure_test.rb b/Library/Homebrew/test/test/compiler_failure_test.rb new file mode 100644 index 000000000..c0b74d128 --- /dev/null +++ b/Library/Homebrew/test/test/compiler_failure_test.rb @@ -0,0 +1,52 @@ +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/test/compiler_selector_test.rb b/Library/Homebrew/test/test/compiler_selector_test.rb new file mode 100644 index 000000000..b1591bdbe --- /dev/null +++ b/Library/Homebrew/test/test/compiler_selector_test.rb @@ -0,0 +1,116 @@ +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/test/config_test.rb b/Library/Homebrew/test/test/config_test.rb new file mode 100644 index 000000000..33a293735 --- /dev/null +++ b/Library/Homebrew/test/test/config_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestConfig < IntegrationCommandTestCase + def test_config + assert_match "HOMEBREW_VERSION: #{HOMEBREW_VERSION}", + cmd("config") + end +end diff --git a/Library/Homebrew/test/test/create_test.rb b/Library/Homebrew/test/test/create_test.rb new file mode 100644 index 000000000..5f194ea02 --- /dev/null +++ b/Library/Homebrew/test/test/create_test.rb @@ -0,0 +1,12 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestCreate < IntegrationCommandTestCase + def test_create + url = "file://#{TEST_DIRECTORY}/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/test/custom_command_test.rb b/Library/Homebrew/test/test/custom_command_test.rb new file mode 100644 index 000000000..bc27e2121 --- /dev/null +++ b/Library/Homebrew/test/test/custom_command_test.rb @@ -0,0 +1,18 @@ +require "helper/integration_command_test_case" + +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/test/dependencies_test.rb b/Library/Homebrew/test/test/dependencies_test.rb new file mode 100644 index 000000000..db3b78226 --- /dev/null +++ b/Library/Homebrew/test/test/dependencies_test.rb @@ -0,0 +1,115 @@ +require "testing_env" +require "dependencies" +require "dependency" +require "requirements" + +class DependenciesTests < Homebrew::TestCase + def setup + @deps = Dependencies.new + end + + def test_shovel_returns_self + assert_same @deps, @deps << Dependency.new("foo") + end + + def test_preserves_order + hash = { 0 => "foo", 1 => "bar", 2 => "baz" } + @deps << Dependency.new(hash[0]) + @deps << Dependency.new(hash[1]) + @deps << Dependency.new(hash[2]) + @deps.each_with_index do |dep, idx| + assert_equal hash[idx], dep.name + end + end + + def test_repetition + @deps << Dependency.new("foo") + @deps << Dependency.new("bar") + assert_equal "foo, bar", @deps*", " + end + + def test_to_a + dep = Dependency.new("foo") + @deps << dep + assert_equal [dep], @deps.to_a + end + + def test_to_ary + dep = Dependency.new("foo") + @deps << dep + assert_equal [dep], @deps.to_ary + end + + def test_type_helpers + foo = Dependency.new("foo") + bar = Dependency.new("bar", [:optional]) + baz = Dependency.new("baz", [:build]) + qux = Dependency.new("qux", [:recommended]) + quux = Dependency.new("quux") + @deps << foo << bar << baz << qux << quux + assert_equal [foo, quux], @deps.required + assert_equal [bar], @deps.optional + assert_equal [baz], @deps.build + assert_equal [qux], @deps.recommended + assert_equal [foo, baz, quux, qux].sort_by(&:name), @deps.default.sort_by(&:name) + end + + def test_equality + a = Dependencies.new + b = Dependencies.new + + dep = Dependency.new("foo") + + a << dep + b << dep + + assert_equal a, b + assert_eql a, b + + b << Dependency.new("bar", [:optional]) + + refute_equal a, b + refute_eql a, b + end + + def test_empty + a = Dependencies.new + assert a.empty? + a << Dependency.new("foo") + refute a.empty? + end + + def test_inspect + a = Dependencies.new + assert_equal "#", a.inspect + a << Dependency.new("foo") + assert_equal "#]>", a.inspect + end +end + +class RequirementsTests < Homebrew::TestCase + def setup + @reqs = Requirements.new + end + + def test_shovel_returns_self + assert_same @reqs, @reqs << Object.new + end + + def test_merging_multiple_dependencies + @reqs << X11Requirement.new << X11Requirement.new + assert_equal 1, @reqs.count + @reqs << Requirement.new + assert_equal 2, @reqs.count + end + + def test_comparison_prefers_larger + @reqs << X11Requirement.new << X11Requirement.new("x11", %w[2.6]) + assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a + end + + def test_comparison_does_not_merge_smaller + @reqs << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new + assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a + end +end diff --git a/Library/Homebrew/test/test/dependency_collector_test.rb b/Library/Homebrew/test/test/dependency_collector_test.rb new file mode 100644 index 000000000..1c7f70118 --- /dev/null +++ b/Library/Homebrew/test/test/dependency_collector_test.rb @@ -0,0 +1,146 @@ +require "testing_env" +require "dependency_collector" + +class DependencyCollectorTests < Homebrew::TestCase + def find_dependency(name) + @d.deps.find { |dep| dep.name == name } + end + + def find_requirement(klass) + @d.requirements.find { |req| req.is_a? klass } + end + + def setup + @d = DependencyCollector.new + end + + def teardown + DependencyCollector.clear_cache + end + + def test_dependency_creation + @d.add "foo" => :build + @d.add "bar" => ["--universal", :optional] + assert_instance_of Dependency, find_dependency("foo") + assert_equal 2, find_dependency("bar").tags.length + end + + def test_add_returns_created_dep + ret = @d.add "foo" + assert_equal Dependency.new("foo"), ret + end + + def test_dependency_tags + assert_predicate Dependency.new("foo", [:build]), :build? + assert_predicate Dependency.new("foo", [:build, :optional]), :optional? + assert_includes Dependency.new("foo", ["universal"]).options, "--universal" + assert_empty Dependency.new("foo").tags + end + + def test_requirement_creation + @d.add :x11 + assert_instance_of X11Requirement, find_requirement(X11Requirement) + end + + def test_no_duplicate_requirements + 2.times { @d.add :x11 } + assert_equal 1, @d.requirements.count + end + + def test_requirement_tags + @d.add x11: "2.5.1" + @d.add xcode: :build + assert_empty find_requirement(X11Requirement).tags + assert_predicate find_requirement(XcodeRequirement), :build? + end + + def test_x11_no_tag + @d.add :x11 + assert_empty find_requirement(X11Requirement).tags + end + + def test_x11_min_version + @d.add x11: "2.5.1" + assert_equal "2.5.1", find_requirement(X11Requirement).min_version.to_s + end + + def test_x11_tag + @d.add x11: :optional + assert_predicate find_requirement(X11Requirement), :optional? + end + + def test_x11_min_version_and_tag + @d.add x11: ["2.5.1", :optional] + dep = find_requirement(X11Requirement) + assert_equal "2.5.1", dep.min_version.to_s + assert_predicate dep, :optional? + end + + def test_ant_dep + @d.add ant: :build + assert_equal find_dependency("ant"), Dependency.new("ant", [:build]) + end + + def test_raises_typeerror_for_unknown_classes + assert_raises(TypeError) { @d.add(Class.new) } + end + + def test_raises_typeerror_for_unknown_types + assert_raises(TypeError) { @d.add(Object.new) } + end + + def test_does_not_mutate_dependency_spec + spec = { "foo" => :optional } + copy = spec.dup + @d.add(spec) + assert_equal copy, spec + end + + def test_resource_dep_git_url + resource = Resource.new + resource.url("git://example.com/foo/bar.git") + assert_instance_of GitRequirement, @d.add(resource) + end + + def test_resource_dep_7z_url + resource = Resource.new + resource.url("http://example.com/foo.7z") + assert_equal Dependency.new("p7zip", [:build]), @d.add(resource) + end + + def test_resource_dep_gzip_url + resource = Resource.new + resource.url("http://example.com/foo.tar.gz") + assert_nil @d.add(resource) + end + + def test_resource_dep_lz_url + resource = Resource.new + resource.url("http://example.com/foo.lz") + assert_equal Dependency.new("lzip", [:build]), @d.add(resource) + end + + def test_resource_dep_lha_url + resource = Resource.new + resource.url("http://example.com/foo.lha") + assert_equal Dependency.new("lha", [:build]), @d.add(resource) + end + + def test_resource_dep_lzh_url + resource = Resource.new + resource.url("http://example.com/foo.lzh") + assert_equal Dependency.new("lha", [:build]), @d.add(resource) + end + + def test_resource_dep_rar_url + resource = Resource.new + resource.url("http://example.com/foo.rar") + assert_equal Dependency.new("unrar", [:build]), @d.add(resource) + end + + def test_resource_dep_raises_for_unknown_classes + resource = Resource.new + resource.download_strategy = Class.new + assert_raises(TypeError) { @d.add(resource) } + end +end diff --git a/Library/Homebrew/test/test/dependency_expansion_test.rb b/Library/Homebrew/test/test/dependency_expansion_test.rb new file mode 100644 index 000000000..9d6de35e2 --- /dev/null +++ b/Library/Homebrew/test/test/dependency_expansion_test.rb @@ -0,0 +1,137 @@ +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/test/dependency_test.rb b/Library/Homebrew/test/test/dependency_test.rb new file mode 100644 index 000000000..65255995e --- /dev/null +++ b/Library/Homebrew/test/test/dependency_test.rb @@ -0,0 +1,125 @@ +require "testing_env" +require "dependency" + +class DependableTests < Homebrew::TestCase + def setup + @tags = ["foo", "bar", :build] + @dep = Struct.new(:tags).new(@tags).extend(Dependable) + end + + def test_options + assert_equal %w[--foo --bar].sort, @dep.options.as_flags.sort + end + + def test_interrogation + assert_predicate @dep, :build? + refute_predicate @dep, :optional? + refute_predicate @dep, :recommended? + end +end + +class DependencyTests < Homebrew::TestCase + def test_accepts_single_tag + dep = Dependency.new("foo", %w[bar]) + assert_equal %w[bar], dep.tags + end + + def test_accepts_multiple_tags + dep = Dependency.new("foo", %w[bar baz]) + assert_equal %w[bar baz].sort, dep.tags.sort + end + + def test_preserves_symbol_tags + dep = Dependency.new("foo", [:build]) + assert_equal [:build], dep.tags + end + + def test_accepts_symbol_and_string_tags + dep = Dependency.new("foo", [:build, "bar"]) + assert_equal [:build, "bar"], dep.tags + end + + def test_merge_repeats + dep = Dependency.new("foo", [:build], nil, "foo") + dep2 = Dependency.new("foo", ["bar"], nil, "foo2") + dep3 = Dependency.new("xyz", ["abc"], nil, "foo") + merged = Dependency.merge_repeats([dep, dep2, dep3]) + assert_equal 2, merged.length + assert_equal Dependency, merged.first.class + + foo_named_dep = merged.find { |d| d.name == "foo" } + assert_equal ["bar"], foo_named_dep.tags + assert_includes foo_named_dep.option_names, "foo" + assert_includes foo_named_dep.option_names, "foo2" + + xyz_named_dep = merged.find { |d| d.name == "xyz" } + assert_equal ["abc"], xyz_named_dep.tags + assert_includes xyz_named_dep.option_names, "foo" + refute_includes xyz_named_dep.option_names, "foo2" + end + + def test_merges_necessity_tags + required_dep = Dependency.new("foo") + recommended_dep = Dependency.new("foo", [:recommended]) + optional_dep = Dependency.new("foo", [:optional]) + + deps = Dependency.merge_repeats([required_dep, recommended_dep]) + assert_equal deps.count, 1 + assert_predicate deps.first, :required? + refute_predicate deps.first, :recommended? + refute_predicate deps.first, :optional? + + deps = Dependency.merge_repeats([required_dep, optional_dep]) + assert_equal deps.count, 1 + assert_predicate deps.first, :required? + refute_predicate deps.first, :recommended? + refute_predicate deps.first, :optional? + + deps = Dependency.merge_repeats([recommended_dep, optional_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :required? + assert_predicate deps.first, :recommended? + refute_predicate deps.first, :optional? + end + + def test_merges_temporality_tags + normal_dep = Dependency.new("foo") + build_dep = Dependency.new("foo", [:build]) + run_dep = Dependency.new("foo", [:run]) + + deps = Dependency.merge_repeats([normal_dep, build_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :build? + refute_predicate deps.first, :run? + + deps = Dependency.merge_repeats([normal_dep, run_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :build? + refute_predicate deps.first, :run? + + deps = Dependency.merge_repeats([build_dep, run_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :build? + refute_predicate deps.first, :run? + end + + def test_equality + foo1 = Dependency.new("foo") + foo2 = Dependency.new("foo") + bar = Dependency.new("bar") + assert_equal foo1, foo2 + assert_eql foo1, foo2 + refute_equal foo1, bar + refute_eql foo1, bar + foo3 = Dependency.new("foo", [:build]) + refute_equal foo1, foo3 + refute_eql foo1, foo3 + end +end + +class TapDependencyTests < Homebrew::TestCase + def test_option_names + dep = TapDependency.new("foo/bar/dog") + assert_equal %w[dog], dep.option_names + end +end diff --git a/Library/Homebrew/test/test/deps_test.rb b/Library/Homebrew/test/test/deps_test.rb new file mode 100644 index 000000000..83cc9aa6a --- /dev/null +++ b/Library/Homebrew/test/test/deps_test.rb @@ -0,0 +1,16 @@ +require "helper/integration_command_test_case" + +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/test/desc_test.rb b/Library/Homebrew/test/test/desc_test.rb new file mode 100644 index 000000000..075ea991a --- /dev/null +++ b/Library/Homebrew/test/test/desc_test.rb @@ -0,0 +1,17 @@ +require "helper/integration_command_test_case" + +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/test/descriptions_test.rb b/Library/Homebrew/test/test/descriptions_test.rb new file mode 100644 index 000000000..de38fdbd1 --- /dev/null +++ b/Library/Homebrew/test/test/descriptions_test.rb @@ -0,0 +1,45 @@ +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/test/diagnostic_test.rb b/Library/Homebrew/test/test/diagnostic_test.rb new file mode 100644 index 000000000..aa2e44cfc --- /dev/null +++ b/Library/Homebrew/test/test/diagnostic_test.rb @@ -0,0 +1,197 @@ +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 + # 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/test/doctor_test.rb b/Library/Homebrew/test/test/doctor_test.rb new file mode 100644 index 000000000..ccb909dce --- /dev/null +++ b/Library/Homebrew/test/test/doctor_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +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/test/download_strategies_test.rb b/Library/Homebrew/test/test/download_strategies_test.rb new file mode 100644 index 000000000..87218fb12 --- /dev/null +++ b/Library/Homebrew/test/test/download_strategies_test.rb @@ -0,0 +1,188 @@ +require "testing_env" +require "download_strategy" + +class ResourceDouble + attr_reader :url, :specs, :version + + def initialize(url = "http://example.com/foo.tar.gz", specs = {}) + @url = url + @specs = specs + 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 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/test/edit_test.rb b/Library/Homebrew/test/test/edit_test.rb new file mode 100644 index 000000000..8d1437173 --- /dev/null +++ b/Library/Homebrew/test/test/edit_test.rb @@ -0,0 +1,11 @@ +require "helper/integration_command_test_case" + +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/test/exceptions_test.rb b/Library/Homebrew/test/test/exceptions_test.rb new file mode 100644 index 000000000..689531c6e --- /dev/null +++ b/Library/Homebrew/test/test/exceptions_test.rb @@ -0,0 +1,142 @@ +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: "") + assert_match "bar does not define resource ", + ResourceMissingError.new(f, r).to_s + end + + def test_duplicate_resource_error + r = stub(inspect: "") + assert_equal "Resource 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/test/fetch_test.rb b/Library/Homebrew/test/test/fetch_test.rb new file mode 100644 index 000000000..7b57c6246 --- /dev/null +++ b/Library/Homebrew/test/test/fetch_test.rb @@ -0,0 +1,11 @@ +require "helper/integration_command_test_case" + +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/test/formula_installer_bottle_test.rb b/Library/Homebrew/test/test/formula_installer_bottle_test.rb new file mode 100644 index 000000000..d83c856b7 --- /dev/null +++ b/Library/Homebrew/test/test/formula_installer_bottle_test.rb @@ -0,0 +1,78 @@ +require "testing_env" +require "formula" +require "formula_installer" +require "keg" +require "tab" +require "testball" +require "testball_bottle" + +class InstallBottleTests < Homebrew::TestCase + def temporary_bottle_install(formula) + refute_predicate formula, :installed? + assert_predicate formula, :bottled? + assert_predicate formula, :pour_bottle? + + installer = FormulaInstaller.new(formula) + + shutup { installer.install } + + keg = Keg.new(formula.prefix) + + assert_predicate formula, :installed? + + begin + assert_predicate Tab.for_keg(keg), :poured_from_bottle + + yield formula + ensure + keg.unlink + keg.uninstall + formula.clear_cache + formula.bottle.clear_cache + end + + refute_predicate keg, :exist? + refute_predicate formula, :installed? + end + + def test_a_basic_bottle_install + DevelopmentTools.stubs(:installed?).returns(false) + + temporary_bottle_install(TestballBottle.new) do |f| + # Copied directly from test_formula_installer.rb as we expect + # the same behavior + + # Test that things made it into the Keg + assert_predicate f.bin, :directory? + + assert_predicate f.libexec, :directory? + + refute_predicate f.prefix+"main.c", :exist? + + # Test that things make it into the Cellar + keg = Keg.new f.prefix + keg.link + + bin = HOMEBREW_PREFIX+"bin" + assert_predicate bin, :directory? + end + end + + def test_build_tools_error + DevelopmentTools.stubs(:installed?).returns(false) + + # Testball doesn't have a bottle block, so use it to test this behavior + formula = Testball.new + + refute_predicate formula, :installed? + refute_predicate formula, :bottled? + + installer = FormulaInstaller.new(formula) + + assert_raises(BuildToolsError) do + installer.install + end + + refute_predicate formula, :installed? + end +end diff --git a/Library/Homebrew/test/test/formula_installer_test.rb b/Library/Homebrew/test/test/formula_installer_test.rb new file mode 100644 index 000000000..18bd910a6 --- /dev/null +++ b/Library/Homebrew/test/test/formula_installer_test.rb @@ -0,0 +1,138 @@ +require "testing_env" +require "formula" +require "formula_installer" +require "keg" +require "tab" +require "testball" +require "testball_bottle" + +class InstallTests < Homebrew::TestCase + def temporary_install(formula) + refute_predicate formula, :installed? + + installer = FormulaInstaller.new(formula) + + shutup { installer.install } + + keg = Keg.new(formula.prefix) + + assert_predicate formula, :installed? + + begin + Tab.clear_cache + refute_predicate Tab.for_keg(keg), :poured_from_bottle + + yield formula + ensure + Tab.clear_cache + keg.unlink + keg.uninstall + formula.clear_cache + # there will be log files when sandbox is enable. + formula.logs.rmtree if formula.logs.directory? + end + + refute_predicate keg, :exist? + refute_predicate formula, :installed? + end + + def test_a_basic_install + ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install + temporary_install(Testball.new) do |f| + # Test that things made it into the Keg + assert_predicate f.prefix+"readme", :exist? + + assert_predicate f.bin, :directory? + assert_equal 3, f.bin.children.length + + assert_predicate f.libexec, :directory? + assert_equal 1, f.libexec.children.length + + refute_predicate f.prefix+"main.c", :exist? + + refute_predicate f.prefix+"license", :exist? + + # Test that things make it into the Cellar + keg = Keg.new f.prefix + keg.link + + bin = HOMEBREW_PREFIX+"bin" + assert_predicate bin, :directory? + assert_equal 3, bin.children.length + assert_predicate f.prefix/".brew/testball.rb", :readable? + end + end + + def test_bottle_unneeded_formula_install + DevelopmentTools.stubs(:installed?).returns(false) + + formula = Testball.new + formula.stubs(:bottle_unneeded?).returns(true) + formula.stubs(:bottle_disabled?).returns(true) + + refute_predicate formula, :bottled? + assert_predicate formula, :bottle_unneeded? + assert_predicate formula, :bottle_disabled? + + temporary_install(formula) do |f| + assert_predicate f, :installed? + end + end + + def test_not_poured_from_bottle_when_compiler_specified + assert_nil ARGV.cc + + 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 } + end + end +end + +class FormulaInstallerTests < Homebrew::TestCase + def test_check_install_sanity_pinned_dep + dep_name = "dependency" + dep_path = CoreTap.new.formula_dir/"#{dep_name}.rb" + dep_path.write <<-EOS.undent + class #{Formulary.class_s(dep_name)} < Formula + url "foo" + version "0.2" + end + EOS + + Formulary::FORMULAE.delete(dep_path) + dependency = Formulary.factory(dep_name) + + dependent = formula do + url "foo" + version "0.5" + depends_on dependency.name.to_s + end + + dependency.prefix("0.1").join("bin/a").mkpath + HOMEBREW_PINNED_KEGS.mkpath + FileUtils.ln_s dependency.prefix("0.1"), HOMEBREW_PINNED_KEGS/dep_name + + dependency_keg = Keg.new(dependency.prefix("0.1")) + dependency_keg.link + + assert_predicate dependency_keg, :linked? + assert_predicate dependency, :pinned? + + 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/test/formula_lock_test.rb b/Library/Homebrew/test/test/formula_lock_test.rb new file mode 100644 index 000000000..80ee9dd25 --- /dev/null +++ b/Library/Homebrew/test/test/formula_lock_test.rb @@ -0,0 +1,22 @@ +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/test/formula_pin_test.rb b/Library/Homebrew/test/test/formula_pin_test.rb new file mode 100644 index 000000000..297d7703e --- /dev/null +++ b/Library/Homebrew/test/test/formula_pin_test.rb @@ -0,0 +1,54 @@ +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/test/formula_spec_selection_test.rb b/Library/Homebrew/test/test/formula_spec_selection_test.rb new file mode 100644 index 000000000..7148df173 --- /dev/null +++ b/Library/Homebrew/test/test/formula_spec_selection_test.rb @@ -0,0 +1,99 @@ +require "testing_env" +require "formula" + +class FormulaSpecSelectionTests < Homebrew::TestCase + def test_selects_stable_by_default + f = formula do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :stable? + end + + def test_selects_stable_when_exclusive + f = formula { url "foo-1.0" } + assert_predicate f, :stable? + end + + def test_selects_devel_before_head + f = formula do + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :devel? + end + + def test_selects_devel_when_exclusive + f = formula { devel { url "foo-1.1a" } } + assert_predicate f, :devel? + end + + def test_selects_head_when_exclusive + f = formula { head "foo" } + assert_predicate f, :head? + end + + def test_incomplete_spec_not_selected + f = formula do + sha256 TEST_SHA256 + version "1.0" + head "foo" + end + + assert_predicate f, :head? + end + + def test_incomplete_stable_not_set + f = formula do + sha256 TEST_SHA256 + devel { url "foo-1.1a" } + head "foo" + end + + assert_nil f.stable + assert_predicate f, :devel? + end + + def test_selects_head_when_requested + f = formula("test", Pathname.new(__FILE__).expand_path, :head) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :head? + end + + def test_selects_devel_when_requested + f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :devel? + end + + def test_incomplete_devel_not_set + f = formula do + url "foo-1.0" + devel { version "1.1a" } + head "foo" + end + + assert_nil f.devel + assert_predicate f, :stable? + end + + def test_does_not_raise_for_missing_spec + f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do + url "foo-1.0" + head "foo" + end + + assert_predicate f, :stable? + end +end diff --git a/Library/Homebrew/test/test/formula_support_test.rb b/Library/Homebrew/test/test/formula_support_test.rb new file mode 100644 index 000000000..c0a79f950 --- /dev/null +++ b/Library/Homebrew/test/test/formula_support_test.rb @@ -0,0 +1,28 @@ +require "testing_env" +require "formula_support" + +class KegOnlyReasonTests < Homebrew::TestCase + def test_to_s_explanation + r = KegOnlyReason.new :provided_by_osx, "test" + assert_equal "test", r.to_s + end + + def test_to_s_no_explanation + r = KegOnlyReason.new :provided_by_macos, "" + assert_match(/^macOS already provides/, r.to_s) + end +end + +class BottleDisableReasonTests < Homebrew::TestCase + def test_bottle_unneeded + bottle_disable_reason = BottleDisableReason.new :unneeded, nil + assert_predicate bottle_disable_reason, :unneeded? + assert_equal "This formula doesn't require compiling.", bottle_disable_reason.to_s + end + + def test_bottle_disabled + bottle_disable_reason = BottleDisableReason.new :disable, "reason" + refute_predicate bottle_disable_reason, :unneeded? + assert_equal "reason", bottle_disable_reason.to_s + end +end diff --git a/Library/Homebrew/test/test/formula_test.rb b/Library/Homebrew/test/test/formula_test.rb new file mode 100644 index 000000000..4aa835590 --- /dev/null +++ b/Library/Homebrew/test/test/formula_test.rb @@ -0,0 +1,1180 @@ +require "testing_env" +require "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/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 "f3" + end + + assert_equal %w[f3], f4.deps.map(&:name) + assert_equal %w[f1 f2 f3], f4.recursive_dependencies.map(&:name) + assert_equal %w[f2 f3], f4.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/test/formula_validation_test.rb b/Library/Homebrew/test/test/formula_validation_test.rb new file mode 100644 index 000000000..c40eb6733 --- /dev/null +++ b/Library/Homebrew/test/test/formula_validation_test.rb @@ -0,0 +1,75 @@ +require "testing_env" +require "formula" + +class FormulaValidationTests < Homebrew::TestCase + def assert_invalid(attr, &block) + e = assert_raises(FormulaValidationError, &block) + assert_equal attr, e.attr + end + + def test_cant_override_brew + e = assert_raises(RuntimeError) { formula { def brew; end } } + assert_match(/You cannot override Formula#brew/, e.message) + end + + def test_validates_name + assert_invalid :name do + formula "name with spaces" do + url "foo" + version "1.0" + end + end + end + + def test_validates_url + assert_invalid :url do + formula do + url "" + version "1" + end + end + end + + def test_validates_version + assert_invalid :version do + formula do + url "foo" + version "version with spaces" + end + end + + assert_invalid :version do + formula do + url "foo" + version "" + end + end + + assert_invalid :version do + formula do + url "foo" + version nil + end + end + end + + def test_devel_only_valid + f = formula do + devel do + url "foo" + version "1.0" + end + end + + assert_predicate f, :devel? + end + + def test_head_only_valid + f = formula { head "foo" } + assert_predicate f, :head? + end + + def test_empty_formula_invalid + assert_raises(FormulaSpecificationError) { formula {} } + end +end diff --git a/Library/Homebrew/test/test/formulary_test.rb b/Library/Homebrew/test/test/formulary_test.rb new file mode 100644 index 000000000..690ff089a --- /dev/null +++ b/Library/Homebrew/test/test/formulary_test.rb @@ -0,0 +1,208 @@ +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_DIRECTORY}/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://#{File.expand_path("..", __FILE__)}/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/test/gpg2_requirement_test.rb b/Library/Homebrew/test/test/gpg2_requirement_test.rb new file mode 100644 index 000000000..fa7fc9ea4 --- /dev/null +++ b/Library/Homebrew/test/test/gpg2_requirement_test.rb @@ -0,0 +1,24 @@ +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/test/gpg_test.rb b/Library/Homebrew/test/test/gpg_test.rb new file mode 100644 index 000000000..0374bdab4 --- /dev/null +++ b/Library/Homebrew/test/test/gpg_test.rb @@ -0,0 +1,20 @@ +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/test/hardware_test.rb b/Library/Homebrew/test/test/hardware_test.rb new file mode 100644 index 000000000..2bea5387d --- /dev/null +++ b/Library/Homebrew/test/test/hardware_test.rb @@ -0,0 +1,15 @@ +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, :dunno] + assert_includes families, Hardware::CPU.family + end + end +end diff --git a/Library/Homebrew/test/test/help_test.rb b/Library/Homebrew/test/test/help_test.rb new file mode 100644 index 000000000..9c14f9b78 --- /dev/null +++ b/Library/Homebrew/test/test/help_test.rb @@ -0,0 +1,21 @@ +require "helper/integration_command_test_case" + +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/test/home_test.rb b/Library/Homebrew/test/test/home_test.rb new file mode 100644 index 000000000..9c26353be --- /dev/null +++ b/Library/Homebrew/test/test/home_test.rb @@ -0,0 +1,12 @@ +require "helper/integration_command_test_case" + +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/test/info_test.rb b/Library/Homebrew/test/test/info_test.rb new file mode 100644 index 000000000..35f9183e1 --- /dev/null +++ b/Library/Homebrew/test/test/info_test.rb @@ -0,0 +1,29 @@ +require "testing_env" +require "cmd/info" +require "formula" +require "helper/integration_command_test_case" + +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/test/inreplace_test.rb b/Library/Homebrew/test/test/inreplace_test.rb new file mode 100644 index 000000000..0e62f9d3f --- /dev/null +++ b/Library/Homebrew/test/test/inreplace_test.rb @@ -0,0 +1,119 @@ +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/test/install_test.rb b/Library/Homebrew/test/test/install_test.rb new file mode 100644 index 000000000..7135dddb2 --- /dev/null +++ b/Library/Homebrew/test/test/install_test.rb @@ -0,0 +1,30 @@ +require "helper/integration_command_test_case" + +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_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 +end diff --git a/Library/Homebrew/test/test/irb_test.rb b/Library/Homebrew/test/test/irb_test.rb new file mode 100644 index 000000000..bf35b6524 --- /dev/null +++ b/Library/Homebrew/test/test/irb_test.rb @@ -0,0 +1,19 @@ +require "helper/integration_command_test_case" + +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/test/json_test.rb b/Library/Homebrew/test/test/json_test.rb new file mode 100644 index 000000000..14d2f2b4c --- /dev/null +++ b/Library/Homebrew/test/test/json_test.rb @@ -0,0 +1,20 @@ +require "testing_env" +require "utils/json" + +class JsonSmokeTest < Homebrew::TestCase + def test_encode + hash = { "foo" => ["bar", "baz"] } + json = '{"foo":["bar","baz"]}' + assert_equal json, Utils::JSON.dump(hash) + end + + def test_decode + hash = { "foo" => ["bar", "baz"], "qux" => 1 } + json = '{"foo":["bar","baz"],"qux":1}' + assert_equal hash, Utils::JSON.load(json) + end + + def test_decode_failure + assert_raises(Utils::JSON::Error) { Utils::JSON.load("nope") } + end +end diff --git a/Library/Homebrew/test/test/keg_test.rb b/Library/Homebrew/test/test/keg_test.rb new file mode 100644 index 000000000..fdc739c9d --- /dev/null +++ b/Library/Homebrew/test/test/keg_test.rb @@ -0,0 +1,400 @@ +require "testing_env" +require "keg" +require "stringio" + +class LinkTests < 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 + + 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 < LinkTests + 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 + Formula.clear_cache + keg + end + + def setup + super + @dependent = setup_test_keg("bar", "1.0") + end + + def alter_tab(keg = @dependent) + tab = Tab.for_keg(keg) + yield tab + tab.write + end + + def dependencies(deps) + alter_tab do |tab| + tab.tabfile = @dependent.join("INSTALL_RECEIPT.json") + tab.runtime_dependencies = deps + end + 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) + dependencies [] + alter_tab { |t| t.source["path"] = nil } + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg]) + 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_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_empty @keg.installed_dependents + assert_nil 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 +end diff --git a/Library/Homebrew/test/test/language_go_test.rb b/Library/Homebrew/test/test/language_go_test.rb new file mode 100644 index 000000000..692a5d2cc --- /dev/null +++ b/Library/Homebrew/test/test/language_go_test.rb @@ -0,0 +1,17 @@ +# -*- 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/test/language_module_requirement_test.rb b/Library/Homebrew/test/test/language_module_requirement_test.rb new file mode 100644 index 000000000..dfa992287 --- /dev/null +++ b/Library/Homebrew/test/test/language_module_requirement_test.rb @@ -0,0 +1,55 @@ +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/test/language_python_test.rb b/Library/Homebrew/test/test/language_python_test.rb new file mode 100644 index 000000000..d1e3867f7 --- /dev/null +++ b/Library/Homebrew/test/test/language_python_test.rb @@ -0,0 +1,99 @@ +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/test/leaves_test.rb b/Library/Homebrew/test/test/leaves_test.rb new file mode 100644 index 000000000..2a9bbadd9 --- /dev/null +++ b/Library/Homebrew/test/test/leaves_test.rb @@ -0,0 +1,15 @@ +require "helper/integration_command_test_case" + +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/test/link_test.rb b/Library/Homebrew/test/test/link_test.rb new file mode 100644 index 000000000..3f0507072 --- /dev/null +++ b/Library/Homebrew/test/test/link_test.rb @@ -0,0 +1,23 @@ +require "helper/integration_command_test_case" + +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/test/linkapps_test.rb b/Library/Homebrew/test/test/linkapps_test.rb new file mode 100644 index 000000000..b7c4cb811 --- /dev/null +++ b/Library/Homebrew/test/test/linkapps_test.rb @@ -0,0 +1,15 @@ +require "helper/integration_command_test_case" + +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/test/list_test.rb b/Library/Homebrew/test/test/list_test.rb new file mode 100644 index 000000000..1ffdb4528 --- /dev/null +++ b/Library/Homebrew/test/test/list_test.rb @@ -0,0 +1,13 @@ +require "helper/integration_command_test_case" + +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/test/log_formula_test.rb b/Library/Homebrew/test/test/log_formula_test.rb new file mode 100644 index 000000000..34509bf72 --- /dev/null +++ b/Library/Homebrew/test/test/log_formula_test.rb @@ -0,0 +1,27 @@ +require "helper/integration_command_test_case" + +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/test/log_test.rb b/Library/Homebrew/test/test/log_test.rb new file mode 100644 index 000000000..b20a098fd --- /dev/null +++ b/Library/Homebrew/test/test/log_test.rb @@ -0,0 +1,13 @@ +require "helper/integration_command_test_case" + +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/test/migrate_test.rb b/Library/Homebrew/test/test/migrate_test.rb new file mode 100644 index 000000000..53b32777a --- /dev/null +++ b/Library/Homebrew/test/test/migrate_test.rb @@ -0,0 +1,18 @@ +require "helper/integration_command_test_case" + +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/test/migrator_test.rb b/Library/Homebrew/test/test/migrator_test.rb new file mode 100644 index 000000000..cefb8b7a3 --- /dev/null +++ b/Library/Homebrew/test/test/migrator_test.rb @@ -0,0 +1,264 @@ +require "testing_env" +require "migrator" +require "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/test/missing_test.rb b/Library/Homebrew/test/test/missing_test.rb new file mode 100644 index 000000000..565f413da --- /dev/null +++ b/Library/Homebrew/test/test/missing_test.rb @@ -0,0 +1,34 @@ +require "helper/integration_command_test_case" + +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/test/mpi_requirement_test.rb b/Library/Homebrew/test/test/mpi_requirement_test.rb new file mode 100644 index 000000000..e0f97e8ee --- /dev/null +++ b/Library/Homebrew/test/test/mpi_requirement_test.rb @@ -0,0 +1,12 @@ +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/test/options_test.rb b/Library/Homebrew/test/test/options_test.rb new file mode 100644 index 000000000..bfde7a9b6 --- /dev/null +++ b/Library/Homebrew/test/test/options_test.rb @@ -0,0 +1,157 @@ +require "testing_env" +require "options" +require "helper/integration_command_test_case" + +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.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.inspect + @options << Option.new("foo") + assert_equal "#]>", @options.inspect + end +end diff --git a/Library/Homebrew/test/test/os/mac/blacklist_test.rb b/Library/Homebrew/test/test/os/mac/blacklist_test.rb new file mode 100644 index 000000000..26dd84ed9 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/blacklist_test.rb @@ -0,0 +1,12 @@ +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/test/os/mac/bottle_collector_test.rb b/Library/Homebrew/test/test/os/mac/bottle_collector_test.rb new file mode 100644 index 000000000..2f88050ae --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/bottle_collector_test.rb @@ -0,0 +1,26 @@ +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/test/os/mac/bottle_tag_test.rb b/Library/Homebrew/test/test/os/mac/bottle_tag_test.rb new file mode 100644 index 000000000..996bd4d53 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/bottle_tag_test.rb @@ -0,0 +1,79 @@ +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/test/os/mac/dependency_collector_test.rb b/Library/Homebrew/test/test/os/mac/dependency_collector_test.rb new file mode 100644 index 000000000..4fdf3ebe4 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/dependency_collector_test.rb @@ -0,0 +1,57 @@ +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/test/os/mac/diagnostic_test.rb b/Library/Homebrew/test/test/os/mac/diagnostic_test.rb new file mode 100644 index 000000000..655aa1d46 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/diagnostic_test.rb @@ -0,0 +1,49 @@ +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/test/os/mac/keg_test.rb b/Library/Homebrew/test/test/os/mac/keg_test.rb new file mode 100644 index 000000000..e79cbc921 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/keg_test.rb @@ -0,0 +1,69 @@ +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/test/os/mac/language_test.rb b/Library/Homebrew/test/test/os/mac/language_test.rb new file mode 100644 index 000000000..e328db5e0 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/language_test.rb @@ -0,0 +1,19 @@ +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/test/os/mac/mach_test.rb b/Library/Homebrew/test/test/os/mac/mach_test.rb new file mode 100644 index 000000000..404a21d60 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/mach_test.rb @@ -0,0 +1,208 @@ +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_DIRECTORY}/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_DIRECTORY}/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/test/os/mac/version_test.rb b/Library/Homebrew/test/test/os/mac/version_test.rb new file mode 100644 index 000000000..f702c7097 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/version_test.rb @@ -0,0 +1,53 @@ +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/test/os/mac/x11_requirement_test.rb b/Library/Homebrew/test/test/os/mac/x11_requirement_test.rb new file mode 100644 index 000000000..102937cb5 --- /dev/null +++ b/Library/Homebrew/test/test/os/mac/x11_requirement_test.rb @@ -0,0 +1,13 @@ +require "testing_env" +require "requirements/x11_requirement" + +class OSMacX11RequirementTests < Homebrew::TestCase + def test_satisfied + MacOS::XQuartz.stubs(:version).returns("2.7.5") + MacOS::XQuartz.stubs(:installed?).returns(true) + assert_predicate X11Requirement.new, :satisfied? + + MacOS::XQuartz.stubs(:installed?).returns(false) + refute_predicate X11Requirement.new, :satisfied? + end +end diff --git a/Library/Homebrew/test/test/outdated_test.rb b/Library/Homebrew/test/test/outdated_test.rb new file mode 100644 index 000000000..cc0f024c8 --- /dev/null +++ b/Library/Homebrew/test/test/outdated_test.rb @@ -0,0 +1,10 @@ +require "helper/integration_command_test_case" + +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/test/patch_test.rb b/Library/Homebrew/test/test/patch_test.rb new file mode 100644 index 000000000..62624720e --- /dev/null +++ b/Library/Homebrew/test/test/patch_test.rb @@ -0,0 +1,154 @@ +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 "#", 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 '#', @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/test/patching_test.rb b/Library/Homebrew/test/test/patching_test.rb new file mode 100644 index 000000000..18b848b10 --- /dev/null +++ b/Library/Homebrew/test/test/patching_test.rb @@ -0,0 +1,253 @@ +require "testing_env" +require "formula" + +class PatchingTests < Homebrew::TestCase + TESTBALL_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz".freeze + TESTBALL_PATCHES_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1-patches.tgz".freeze + PATCH_URL_A = "file://#{TEST_DIRECTORY}/patches/noop-a.diff".freeze + PATCH_URL_B = "file://#{TEST_DIRECTORY}/patches/noop-b.diff".freeze + PATCH_A_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-a.diff" + PATCH_B_CONTENTS = File.read "#{TEST_DIRECTORY}/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/test/pathname_test.rb b/Library/Homebrew/test/test/pathname_test.rb new file mode 100644 index 000000000..2f6360719 --- /dev/null +++ b/Library/Homebrew/test/test/pathname_test.rb @@ -0,0 +1,267 @@ +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/test/pin_unpin_test.rb b/Library/Homebrew/test/test/pin_unpin_test.rb new file mode 100644 index 000000000..37682d45e --- /dev/null +++ b/Library/Homebrew/test/test/pin_unpin_test.rb @@ -0,0 +1,18 @@ +require "helper/integration_command_test_case" + +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/test/pkg_version_test.rb b/Library/Homebrew/test/test/pkg_version_test.rb new file mode 100644 index 000000000..ff7896f8b --- /dev/null +++ b/Library/Homebrew/test/test/pkg_version_test.rb @@ -0,0 +1,51 @@ +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/test/prefix_formula_test.rb b/Library/Homebrew/test/test/prefix_formula_test.rb new file mode 100644 index 000000000..d76a966d7 --- /dev/null +++ b/Library/Homebrew/test/test/prefix_formula_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestPrefixFormula < IntegrationCommandTestCase + def test_prefix_formula + assert_match "#{HOMEBREW_CELLAR}/testball", + cmd("--prefix", testball) + end +end diff --git a/Library/Homebrew/test/test/prefix_test.rb b/Library/Homebrew/test/test/prefix_test.rb new file mode 100644 index 000000000..4aa63fa07 --- /dev/null +++ b/Library/Homebrew/test/test/prefix_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestPrefix < IntegrationCommandTestCase + def test_prefix + assert_equal HOMEBREW_PREFIX.to_s, + cmd("--prefix") + end +end diff --git a/Library/Homebrew/test/test/prune_test.rb b/Library/Homebrew/test/test/prune_test.rb new file mode 100644 index 000000000..293a3746d --- /dev/null +++ b/Library/Homebrew/test/test/prune_test.rb @@ -0,0 +1,21 @@ +require "helper/integration_command_test_case" + +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/test/pull_offline_test.rb b/Library/Homebrew/test/test/pull_offline_test.rb new file mode 100644 index 000000000..2716af346 --- /dev/null +++ b/Library/Homebrew/test/test/pull_offline_test.rb @@ -0,0 +1,10 @@ +require "helper/integration_command_test_case" + +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/test/pull_test.rb b/Library/Homebrew/test/test/pull_test.rb new file mode 100644 index 000000000..9707ff8a8 --- /dev/null +++ b/Library/Homebrew/test/test/pull_test.rb @@ -0,0 +1,27 @@ +require "helper/integration_command_test_case" + +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/test/readall_test.rb b/Library/Homebrew/test/test/readall_test.rb new file mode 100644 index 000000000..d0c078e49 --- /dev/null +++ b/Library/Homebrew/test/test/readall_test.rb @@ -0,0 +1,12 @@ +require "helper/integration_command_test_case" + +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/test/reinstall_pinned_test.rb b/Library/Homebrew/test/test/reinstall_pinned_test.rb new file mode 100644 index 000000000..c9cb8a849 --- /dev/null +++ b/Library/Homebrew/test/test/reinstall_pinned_test.rb @@ -0,0 +1,15 @@ +require "helper/integration_command_test_case" + +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/test/reinstall_test.rb b/Library/Homebrew/test/test/reinstall_test.rb new file mode 100644 index 000000000..d07a96051 --- /dev/null +++ b/Library/Homebrew/test/test/reinstall_test.rb @@ -0,0 +1,15 @@ +require "helper/integration_command_test_case" + +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 --with-foo", + cmd("reinstall", "testball") + assert foo_dir.exist? + end +end diff --git a/Library/Homebrew/test/test/repository_test.rb b/Library/Homebrew/test/test/repository_test.rb new file mode 100644 index 000000000..2029876ad --- /dev/null +++ b/Library/Homebrew/test/test/repository_test.rb @@ -0,0 +1,10 @@ +require "helper/integration_command_test_case" + +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/test/requirement_test.rb b/Library/Homebrew/test/test/requirement_test.rb new file mode 100644 index 000000000..580d42bfa --- /dev/null +++ b/Library/Homebrew/test/test/requirement_test.rb @@ -0,0 +1,152 @@ +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/test/resource_test.rb b/Library/Homebrew/test/test/resource_test.rb new file mode 100644 index 000000000..c1b526cb2 --- /dev/null +++ b/Library/Homebrew/test/test/resource_test.rb @@ -0,0 +1,132 @@ +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/test/sandbox_test.rb b/Library/Homebrew/test/test/sandbox_test.rb new file mode 100644 index 000000000..2a062cb10 --- /dev/null +++ b/Library/Homebrew/test/test/sandbox_test.rb @@ -0,0 +1,76 @@ +require "testing_env" +require "sandbox" + +class SandboxTest < Homebrew::TestCase + def setup + 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 + assert Sandbox.formula?(f), + "Formulae should be sandboxed if --sandbox was passed." + + ARGV.stubs(:sandbox?).returns false + assert Sandbox.formula?(f), + "Formulae should be sandboxed if in a sandboxed tap." + refute Sandbox.formula?(f2), + "Formulae should not be sandboxed if not in a sandboxed tap." + end + + def test_test? + ARGV.stubs(:no_sandbox?).returns false + assert Sandbox.test?, + "Tests should be sandboxed unless --no-sandbox was passed." + end + + def test_allow_write + @sandbox.allow_write @file + @sandbox.exec "touch", @file + assert_predicate @file, :exist? + end + + def test_deny_write + shutup do + assert_raises(ErrorDuringExecution) { @sandbox.exec "touch", @file } + end + refute_predicate @file, :exist? + end + + def test_complains_on_failure + Utils.expects(popen_read: "foo") + ARGV.stubs(verbose?: true) + out, _err = capture_io do + assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } + end + assert_match "foo", out + end + + def test_ignores_bogus_python_error + with_bogus_error = <<-EOS.undent + foo + Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc + bar + EOS + Utils.expects(popen_read: with_bogus_error) + ARGV.stubs(verbose?: true) + out, _err = capture_io do + assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } + end + refute_predicate out, :empty? + assert_match "foo", out + assert_match "bar", out + refute_match "Python", out + end +end diff --git a/Library/Homebrew/test/test/search_remote_tap_test.rb b/Library/Homebrew/test/test/search_remote_tap_test.rb new file mode 100644 index 000000000..9dd9ee654 --- /dev/null +++ b/Library/Homebrew/test/test/search_remote_tap_test.rb @@ -0,0 +1,19 @@ +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/test/search_test.rb b/Library/Homebrew/test/test/search_test.rb new file mode 100644 index 000000000..8310d1c2b --- /dev/null +++ b/Library/Homebrew/test/test/search_test.rb @@ -0,0 +1,30 @@ +require "helper/integration_command_test_case" + +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§ion=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§ion=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/test/services_test.rb b/Library/Homebrew/test/test/services_test.rb new file mode 100644 index 000000000..b5ccb7c77 --- /dev/null +++ b/Library/Homebrew/test/test/services_test.rb @@ -0,0 +1,11 @@ +require "helper/integration_command_test_case" + +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/test/sh_test.rb b/Library/Homebrew/test/test/sh_test.rb new file mode 100644 index 000000000..449b7b5b3 --- /dev/null +++ b/Library/Homebrew/test/test/sh_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +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/test/shell_test.rb b/Library/Homebrew/test/test/shell_test.rb new file mode 100644 index 000000000..877acb5c8 --- /dev/null +++ b/Library/Homebrew/test/test/shell_test.rb @@ -0,0 +1,59 @@ +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/test/software_spec_test.rb b/Library/Homebrew/test/test/software_spec_test.rb new file mode 100644 index 000000000..d9226f8c3 --- /dev/null +++ b/Library/Homebrew/test/test/software_spec_test.rb @@ -0,0 +1,181 @@ +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/test/stdlib_test.rb b/Library/Homebrew/test/test/stdlib_test.rb new file mode 100644 index 000000000..ee53e7c8c --- /dev/null +++ b/Library/Homebrew/test/test/stdlib_test.rb @@ -0,0 +1,61 @@ +require "testing_env" +require "formula" +require "cxxstdlib" + +class CxxStdlibTests < Homebrew::TestCase + def setup + @clang = CxxStdlib.create(:libstdcxx, :clang) + @gcc = CxxStdlib.create(:libstdcxx, :gcc) + @gcc4 = CxxStdlib.create(:libstdcxx, :gcc_4_0) + @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?(@gcc4) + 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 @gcc4, :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/test/string_test.rb b/Library/Homebrew/test/test/string_test.rb new file mode 100644 index 000000000..497c4badb --- /dev/null +++ b/Library/Homebrew/test/test/string_test.rb @@ -0,0 +1,40 @@ +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/test/switch_test.rb b/Library/Homebrew/test/test/switch_test.rb new file mode 100644 index 000000000..88fdf85b9 --- /dev/null +++ b/Library/Homebrew/test/test/switch_test.rb @@ -0,0 +1,20 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestSwitch < IntegrationCommandTestCase + def test_switch + assert_match "Usage: brew switch ", 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/test/tab_test.rb b/Library/Homebrew/test/test/tab_test.rb new file mode 100644 index 000000000..2c756cf68 --- /dev/null +++ b/Library/Homebrew/test/test/tab_test.rb @@ -0,0 +1,270 @@ +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_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_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/hombrew/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(Utils::JSON.load(@tab.to_json)) + assert_equal @tab.used_options.sort, tab.used_options.sort + assert_equal @tab.unused_options.sort, tab.unused_options.sort + assert_equal @tab.built_as_bottle, tab.built_as_bottle + assert_equal @tab.poured_from_bottle, tab.poured_from_bottle + 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 Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt.json").read + end + + def teardown + @f.rack.rmtree + end + + def test_for_keg + tab = Tab.for_keg(@f.prefix) + assert_equal @path, tab.tabfile + end + + def test_for_keg_nonexistent_path + @path.unlink + tab = Tab.for_keg(@f.prefix) + assert_nil tab.tabfile + end + + def test_for_formula + tab = Tab.for_formula(@f) + assert_equal @path, tab.tabfile + end + + def test_for_formula_nonexistent_path + @path.unlink + tab = Tab.for_formula(@f) + assert_nil tab.tabfile + end + + def test_for_formula_multiple_kegs + f2 = formula { url "foo-2.0" } + f2.prefix.mkpath + + assert_equal @f.rack, f2.rack + 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/test/tap_new_test.rb b/Library/Homebrew/test/test/tap_new_test.rb new file mode 100644 index 000000000..636024b0a --- /dev/null +++ b/Library/Homebrew/test/test/tap_new_test.rb @@ -0,0 +1,9 @@ +require "helper/integration_command_test_case" + +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/test/tap_test.rb b/Library/Homebrew/test/test/tap_test.rb new file mode 100644 index 000000000..71836aee9 --- /dev/null +++ b/Library/Homebrew/test/test/tap_test.rb @@ -0,0 +1,329 @@ +require "testing_env" +require "helper/integration_command_test_case" + +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/versions", 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 + @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + @path.mkpath + @tap = Tap.new("Homebrew", "foo") + end + + def setup_tap_files + @formula_file = @path/"Formula/foo.rb" + @formula_file.write <<-EOS.undent + class Foo < Formula + url "https://example.com/foo-1.0.tar.gz" + end + EOS + @alias_file = @path/"Aliases/bar" + @alias_file.parent.mkpath + ln_s @formula_file, @alias_file + (@path/"formula_renames.json").write <<-EOS.undent + { "oldname": "foo" } + EOS + (@path/"tap_migrations.json").write <<-EOS.undent + { "removed-formula": "homebrew/foo" } + EOS + @cmd_file = @path/"cmd/brew-tap-cmd.rb" + @cmd_file.parent.mkpath + touch @cmd_file + chmod 0755, @cmd_file + @manpage_file = @path/"man/man1/brew-tap-cmd.1" + @manpage_file.parent.mkpath + touch @manpage_file + 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" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" + system "git", "add", "--all" + system "git", "commit", "-m", "init" + end + end + ensure + ENV.replace(env) + end + + def teardown + @path.rmtree + end + + def test_fetch + assert_kind_of CoreTap, Tap.fetch("Homebrew", "homebrew") + tap = Tap.fetch("Homebrew", "foo") + assert_kind_of Tap, tap + assert_equal "homebrew/foo", tap.name + + assert_match "Invalid tap name", + assert_raises { Tap.fetch("foo") }.message + assert_match "Invalid tap name", + assert_raises { Tap.fetch("homebrew/homebrew/bar") }.message + assert_match "Invalid tap name", + assert_raises { Tap.fetch("homebrew", "homebrew/baz") }.message + ensure + Tap.clear_cache + end + + def test_names + assert_equal ["homebrew/core", "homebrew/foo"], Tap.names.sort + end + + def test_attributes + assert_equal "Homebrew", @tap.user + assert_equal "foo", @tap.repo + assert_equal "homebrew/foo", @tap.name + assert_equal @path, @tap.path + assert_predicate @tap, :installed? + assert_predicate @tap, :official? + refute_predicate @tap, :core_tap? + end + + def test_issues_url + t = Tap.new("someone", "foo") + path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" + path.mkpath + cd path do + shutup { system "git", "init" } + system "git", "remote", "add", "origin", + "https://github.com/someone/homebrew-foo" + end + assert_equal "https://github.com/someone/homebrew-foo/issues", t.issues_url + assert_equal "https://github.com/Homebrew/homebrew-foo/issues", @tap.issues_url + + (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath + assert_nil Tap.new("someone", "no-git").issues_url + ensure + path.parent.rmtree + end + + def test_files + setup_tap_files + + assert_equal [@formula_file], @tap.formula_files + assert_equal ["homebrew/foo/foo"], @tap.formula_names + assert_equal [@alias_file], @tap.alias_files + assert_equal ["homebrew/foo/bar"], @tap.aliases + assert_equal @tap.alias_table, "homebrew/foo/bar" => "homebrew/foo/foo" + assert_equal @tap.alias_reverse_table, "homebrew/foo/foo" => ["homebrew/foo/bar"] + assert_equal @tap.formula_renames, "oldname" => "foo" + assert_equal @tap.tap_migrations, "removed-formula" => "homebrew/foo" + assert_equal [@cmd_file], @tap.command_files + assert_kind_of Hash, @tap.to_hash + assert_equal true, @tap.formula_file?(@formula_file) + assert_equal true, @tap.formula_file?("Formula/foo.rb") + assert_equal false, @tap.formula_file?("bar.rb") + assert_equal false, @tap.formula_file?("Formula/baz.sh") + end + + def test_remote + setup_git_repo + + assert_equal "https://github.com/Homebrew/homebrew-foo", @tap.remote + assert_raises(TapUnavailableError) { Tap.new("Homebrew", "bar").remote } + refute_predicate @tap, :custom_remote? + + version_tap = Tap.new("Homebrew", "versions") + version_tap.path.mkpath + version_tap.path.cd do + shutup do + system "git", "init" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-versions" + end + end + refute_predicate version_tap, :private? + ensure + version_tap.path.rmtree if version_tap + end + + def test_remote_not_git_repo + assert_nil @tap.remote + end + + def test_remote_git_not_available + setup_git_repo + Utils.stubs(:git_available?).returns(false) + assert_nil @tap.remote + end + + def test_git_variant + 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 + end + + def test_private_remote + skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub.api_credentials + assert_predicate @tap, :private? + end + + def test_install_tap_already_tapped_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + assert_equal true, already_tapped_tap.installed? + assert_raises(TapAlreadyTappedError) { already_tapped_tap.install } + end + + def test_install_tap_remote_match_already_tapped_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + assert_equal true, already_tapped_tap.installed? + right_remote = @tap.remote + assert_raises(TapAlreadyTappedError) { already_tapped_tap.install clone_target: right_remote } + end + + def test_install_tap_remote_mismatch_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + touch @tap.path/".git/shallow" + assert_equal true, already_tapped_tap.installed? + wrong_remote = "#{@tap.remote}-oops" + assert_raises(TapRemoteMismatchError) { already_tapped_tap.install clone_target: wrong_remote, full_clone: true } + end + + def test_install_tap_already_unshallow_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + assert_raises(TapAlreadyUnshallowError) { already_tapped_tap.install full_clone: true } + end + + def test_uninstall_tap_unavailable_error + tap = Tap.new("Homebrew", "bar") + assert_raises(TapUnavailableError) { tap.uninstall } + end + + def test_install_git_error + tap = Tap.new("user", "repo") + assert_raises(ErrorDuringExecution) do + shutup { tap.install clone_target: "file:///not/existed/remote/url" } + end + refute_predicate tap, :installed? + refute_predicate Tap::TAP_DIRECTORY/"user", :exist? + end + + def test_install_and_uninstall + setup_tap_files + setup_git_repo + + tap = Tap.new("Homebrew", "bar") + shutup { tap.install clone_target: @tap.path/".git" } + assert_predicate tap, :installed? + assert_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :file? + shutup { tap.uninstall } + 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 + refute_predicate @tap, :pinned? + assert_raises(TapPinStatusError) { @tap.unpin } + @tap.pin + assert_predicate @tap, :pinned? + assert_raises(TapPinStatusError) { @tap.pin } + @tap.unpin + refute_predicate @tap, :pinned? + end + + def test_config + setup_git_repo + + assert_nil @tap.config["foo"] + @tap.config["foo"] = "bar" + assert_equal "bar", @tap.config["foo"] + @tap.config["foo"] = nil + assert_nil @tap.config["foo"] + end +end + +class CoreTapTest < Homebrew::TestCase + include FileUtils + + def setup + @repo = CoreTap.new + end + + def test_attributes + assert_equal "Homebrew", @repo.user + assert_equal "core", @repo.repo + assert_equal "homebrew/core", @repo.name + assert_equal [], @repo.command_files + assert_predicate @repo, :installed? + refute_predicate @repo, :pinned? + assert_predicate @repo, :official? + assert_predicate @repo, :core_tap? + end + + def test_forbidden_operations + assert_raises(RuntimeError) { @repo.uninstall } + assert_raises(RuntimeError) { @repo.pin } + assert_raises(RuntimeError) { @repo.unpin } + end + + def test_files + @formula_file = @repo.formula_dir/"foo.rb" + @formula_file.write <<-EOS.undent + class Foo < Formula + url "https://example.com/foo-1.0.tar.gz" + end + EOS + @alias_file = @repo.alias_dir/"bar" + @alias_file.parent.mkpath + ln_s @formula_file, @alias_file + + assert_equal [@formula_file], @repo.formula_files + assert_equal ["foo"], @repo.formula_names + assert_equal [@alias_file], @repo.alias_files + 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/test_formula_test.rb b/Library/Homebrew/test/test/test_formula_test.rb new file mode 100644 index 000000000..b3889d6a2 --- /dev/null +++ b/Library/Homebrew/test/test/test_formula_test.rb @@ -0,0 +1,30 @@ +require "helper/integration_command_test_case" + +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://#{File.expand_path("..", __FILE__)}/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/test/uninstall_test.rb b/Library/Homebrew/test/test/uninstall_test.rb new file mode 100644 index 000000000..d86db0e80 --- /dev/null +++ b/Library/Homebrew/test/test/uninstall_test.rb @@ -0,0 +1,67 @@ +require "helper/integration_command_test_case" +require "cmd/uninstall" + +class UninstallTests < Homebrew::TestCase + def setup + @dependency = formula("dependency") { url "f-1" } + @dependent = formula("dependent") do + url "f-1" + depends_on "dependency" + end + + [@dependency, @dependent].each { |f| f.installed_prefix.mkpath } + + tab = Tab.empty + tab.tabfile = @dependent.installed_prefix/Tab::FILENAME + tab.runtime_dependencies = [ + { "full_name" => "dependency", "version" => "1" }, + ] + tab.write + + stub_formula_loader @dependency + stub_formula_loader @dependent + end + + def teardown + Homebrew.failed = false + [@dependency, @dependent].each { |f| f.rack.rmtree } + end + + def handle_unsatisfied_dependents + capture_stderr do + opts = { @dependency.rack => [Keg.new(@dependency.installed_prefix)] } + Homebrew.handle_unsatisfied_dependents(opts) + end + end + + def test_check_for_testball_f2s_when_developer + skip "Flaky test" + assert_match "Warning", handle_unsatisfied_dependents + refute_predicate Homebrew, :failed? + end + + def test_check_for_dependents_when_not_developer + skip "Flaky test" + run_as_not_developer do + assert_match "Error", handle_unsatisfied_dependents + assert_predicate Homebrew, :failed? + end + end + + def test_check_for_dependents_when_ignore_dependencies + ARGV << "--ignore-dependencies" + run_as_not_developer do + 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/test/unlink_test.rb b/Library/Homebrew/test/test/unlink_test.rb new file mode 100644 index 000000000..091bd8c45 --- /dev/null +++ b/Library/Homebrew/test/test/unlink_test.rb @@ -0,0 +1,10 @@ +require "helper/integration_command_test_case" + +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/test/unlinkapps_test.rb b/Library/Homebrew/test/test/unlinkapps_test.rb new file mode 100644 index 000000000..2de4e3ff8 --- /dev/null +++ b/Library/Homebrew/test/test/unlinkapps_test.rb @@ -0,0 +1,19 @@ +require "helper/integration_command_test_case" + +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/test/unpack_test.rb b/Library/Homebrew/test/test/unpack_test.rb new file mode 100644 index 000000000..de1452a29 --- /dev/null +++ b/Library/Homebrew/test/test/unpack_test.rb @@ -0,0 +1,13 @@ +require "helper/integration_command_test_case" + +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/test/update_report_test.rb b/Library/Homebrew/test/test/update_report_test.rb new file mode 100644 index 000000000..6b6cec6ce --- /dev/null +++ b/Library/Homebrew/test/test/update_report_test.rb @@ -0,0 +1,134 @@ +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/test/upgrade_test.rb b/Library/Homebrew/test/test/upgrade_test.rb new file mode 100644 index 000000000..73618293b --- /dev/null +++ b/Library/Homebrew/test/test/upgrade_test.rb @@ -0,0 +1,12 @@ +require "helper/integration_command_test_case" + +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/test/uses_test.rb b/Library/Homebrew/test/test/uses_test.rb new file mode 100644 index 000000000..b0e79ef2d --- /dev/null +++ b/Library/Homebrew/test/test/uses_test.rb @@ -0,0 +1,16 @@ +require "helper/integration_command_test_case" + +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_equal "bar\nbaz", cmd("uses", "--recursive", "foo") + end +end diff --git a/Library/Homebrew/test/test/utils/tty_test.rb b/Library/Homebrew/test/test/utils/tty_test.rb new file mode 100644 index 000000000..09f092cbd --- /dev/null +++ b/Library/Homebrew/test/test/utils/tty_test.rb @@ -0,0 +1,46 @@ +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/test/utils_test.rb b/Library/Homebrew/test/test/utils_test.rb new file mode 100644 index 000000000..146f57b49 --- /dev/null +++ b/Library/Homebrew/test/test/utils_test.rb @@ -0,0 +1,235 @@ +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/"], + die: 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/test/version_test.rb b/Library/Homebrew/test/test/version_test.rb new file mode 100644 index 000000000..ca37e3567 --- /dev/null +++ b/Library/Homebrew/test/test/version_test.rb @@ -0,0 +1,8 @@ +require "helper/integration_command_test_case" + +class IntegrationCommandTestVersion < IntegrationCommandTestCase + def test_version + assert_match HOMEBREW_VERSION.to_s, + cmd("--version") + end +end diff --git a/Library/Homebrew/test/test/versions_test.rb b/Library/Homebrew/test/test/versions_test.rb new file mode 100644 index 000000000..a6e922178 --- /dev/null +++ b/Library/Homebrew/test/test/versions_test.rb @@ -0,0 +1,530 @@ +require "testing_env" +require "version" + +class VersionTests < Homebrew::TestCase + def test_accepts_objects_responding_to_to_str + value = stub(to_str: "0.1") + assert_equal "0.1", Version.create(value).to_s + end + + def test_raises_for_non_string_objects + assert_raises(TypeError) { Version.create(1.1) } + assert_raises(TypeError) { Version.create(1) } + assert_raises(TypeError) { Version.create(:symbol) } + end + + def test_detected_from_url? + refute Version.create("1.0").detected_from_url? + assert Version::FromURL.new("1.0").detected_from_url? + end +end + +class VersionTokenTests < Homebrew::TestCase + def test_inspect + assert_equal '#', + Version::Token.new("foo").inspect + end + + def test_to_s + assert_equal "foo", Version::Token.new("foo").to_s + end +end + +class NullVersionTests < Homebrew::TestCase + def test_null_version_is_always_smaller + assert_operator Version::NULL, :<, version("1") + end + + def test_null_version_is_never_greater + refute_operator Version::NULL, :>, version("0") + end + + def test_null_version_is_not_equal_to_itself + refute_eql Version::NULL, Version::NULL + end + + def test_null_version_creates_an_empty_string + assert_eql "", Version::NULL.to_s + end + + def test_null_version_produces_nan_as_a_float + # Float::NAN is not equal to itself so compare object IDs + assert_eql Float::NAN.object_id, Version::NULL.to_f.object_id + end +end + +class VersionNullTokenTests < Homebrew::TestCase + def test_inspect + assert_equal "#", Version::NullToken.new.inspect + end + + def test_comparing_null + assert_operator Version::NullToken.new, :==, Version::NullToken.new + end +end + +class VersionComparisonTests < Homebrew::TestCase + def test_comparing_regular_versions + assert_operator version("0.1"), :==, version("0.1.0") + assert_operator version("0.1"), :<, version("0.2") + assert_operator version("1.2.3"), :>, version("1.2.2") + assert_operator version("1.2.4"), :<, version("1.2.4.1") + + assert_operator version("1.2.3"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3"), :>, version("1.2.3beta2") + assert_operator version("1.2.3"), :>, version("1.2.3rc3") + assert_operator version("1.2.3"), :<, version("1.2.3-p34") + end + + def test_head + assert_operator version("HEAD"), :>, version("1.2.3") + assert_operator version("HEAD-abcdef"), :>, version("1.2.3") + assert_operator version("1.2.3"), :<, version("HEAD") + assert_operator version("1.2.3"), :<, version("HEAD-fedcba") + assert_operator version("HEAD-abcdef"), :==, version("HEAD-fedcba") + assert_operator version("HEAD"), :==, version("HEAD-fedcba") + end + + def test_comparing_alpha_versions + assert_operator version("1.2.3alpha"), :<, version("1.2.3") + assert_operator version("1.2.3"), :<, version("1.2.3a") + assert_operator version("1.2.3alpha4"), :==, version("1.2.3a4") + assert_operator version("1.2.3alpha4"), :==, version("1.2.3A4") + assert_operator version("1.2.3alpha4"), :>, version("1.2.3alpha3") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha5") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha10") + + assert_operator version("1.2.3alpha4"), :<, version("1.2.3beta2") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3rc3") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3-p34") + end + + def test_comparing_beta_versions + assert_operator version("1.2.3beta2"), :==, version("1.2.3b2") + assert_operator version("1.2.3beta2"), :==, version("1.2.3B2") + assert_operator version("1.2.3beta2"), :>, version("1.2.3beta1") + assert_operator version("1.2.3beta2"), :<, version("1.2.3beta3") + assert_operator version("1.2.3beta2"), :<, version("1.2.3beta10") + + assert_operator version("1.2.3beta2"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3beta2"), :<, version("1.2.3rc3") + assert_operator version("1.2.3beta2"), :<, version("1.2.3") + assert_operator version("1.2.3beta2"), :<, version("1.2.3-p34") + end + + def test_comparing_rc_versions + assert_operator version("1.2.3rc3"), :==, version("1.2.3RC3") + assert_operator version("1.2.3rc3"), :>, version("1.2.3rc2") + assert_operator version("1.2.3rc3"), :<, version("1.2.3rc4") + assert_operator version("1.2.3rc3"), :<, version("1.2.3rc10") + + assert_operator version("1.2.3rc3"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3rc3"), :>, version("1.2.3beta2") + assert_operator version("1.2.3rc3"), :<, version("1.2.3") + assert_operator version("1.2.3rc3"), :<, version("1.2.3-p34") + end + + def test_comparing_patchlevel_versions + assert_operator version("1.2.3-p34"), :==, version("1.2.3-P34") + assert_operator version("1.2.3-p34"), :>, version("1.2.3-p33") + assert_operator version("1.2.3-p34"), :<, version("1.2.3-p35") + assert_operator version("1.2.3-p34"), :>, version("1.2.3-p9") + + assert_operator version("1.2.3-p34"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3-p34"), :>, version("1.2.3beta2") + assert_operator version("1.2.3-p34"), :>, version("1.2.3rc3") + assert_operator version("1.2.3-p34"), :>, version("1.2.3") + end + + def test_comparing_unevenly_padded_versions + assert_operator version("2.1.0-p194"), :<, version("2.1-p195") + assert_operator version("2.1-p195"), :>, version("2.1.0-p194") + assert_operator version("2.1-p194"), :<, version("2.1.0-p195") + assert_operator version("2.1.0-p195"), :>, version("2.1-p194") + assert_operator version("2-p194"), :<, version("2.1-p195") + end + + def test_comparing_against_nil + assert_operator version("2.1.0-p194"), :>, nil + end + + def test_comparing_against_strings + assert_operator version("2.1.0-p194"), :==, "2.1.0-p194" + assert_operator version("1"), :==, 1 + end + + def test_comparison_returns_nil_for_non_version + v = version("1.0") + assert_nil v <=> Object.new + assert_raises(ArgumentError) { v > Object.new } + end + + def test_erlang_version + versions = %w[R16B R15B03-1 R15B03 R15B02 R15B01 R14B04 R14B03 + R14B02 R14B01 R14B R13B04 R13B03 R13B02-1].reverse + assert_equal versions, versions.sort_by { |v| version(v) } + end + + def test_hash_equality + v1 = version("0.1.0") + v2 = version("0.1.0") + v3 = version("0.1.1") + + assert_eql v1, v2 + refute_eql v1, v3 + assert_equal v1.hash, v2.hash + + h = { v1 => :foo } + assert_equal :foo, h[v2] + end +end + +class VersionParsingTests < Homebrew::TestCase + def test_pathname_version + 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 + assert_version_nil "http://example.com/blah.tar" + assert_version_nil "foo" + end + + def test_create + v = Version.create("1.20") + refute_predicate v, :head? + assert_equal "1.20", v.to_str + end + + def test_version_all_dots + assert_version_detected "1.14", "http://example.com/foo.bar.la.1.14.zip" + end + + def test_version_underscore_separator + assert_version_detected "1.1", "http://example.com/grc_1.1.tar.gz" + end + + def test_boost_version_style + assert_version_detected "1.39.0", "http://example.com/boost_1_39_0.tar.bz2" + end + + def test_erlang_version_style + assert_version_detected "R13B", "http://erlang.org/download/otp_src_R13B.tar.gz" + end + + def test_another_erlang_version_style + assert_version_detected "R15B01", "https://github.com/erlang/otp/tarball/OTP_R15B01" + end + + def test_yet_another_erlang_version_style + assert_version_detected "R15B03-1", "https://github.com/erlang/otp/tarball/OTP_R15B03-1" + end + + def test_p7zip_version_style + assert_version_detected "9.04", + "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2" + end + + def test_new_github_style + assert_version_detected "1.1.4", "https://github.com/sam-github/libnet/tarball/libnet-1.1.4" + end + + def test_codeload_style + assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" + end + + def test_elasticsearch_alpha_style + assert_version_detected "5.0.0-alpha5", "https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha5/elasticsearch-5.0.0-alpha5.tar.gz" + end + + def test_gloox_beta_style + assert_version_detected "1.0-beta7", "http://camaya.net/download/gloox-1.0-beta7.tar.bz2" + end + + def test_sphinx_beta_style + assert_version_detected "1.10-beta", "http://sphinxsearch.com/downloads/sphinx-1.10-beta.tar.gz" + end + + def test_astyle_verson_style + assert_version_detected "1.23", "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz" + end + + def test_version_dos2unix + assert_version_detected "3.1", "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz" + end + + def test_version_internal_dash + assert_version_detected "1.1-2", "http://example.com/foo-arse-1.1-2.tar.gz" + end + + def test_version_single_digit + assert_version_detected "45", "http://example.com/foo_bar.45.tar.gz" + end + + def test_noseparator_single_digit + assert_version_detected "45", "http://example.com/foo_bar45.tar.gz" + end + + def test_version_developer_that_hates_us_format + assert_version_detected "1.2.3", "http://example.com/foo-bar-la.1.2.3.tar.gz" + end + + def test_version_regular + assert_version_detected "1.21", "http://example.com/foo_bar-1.21.tar.gz" + end + + def test_version_sourceforge_download + assert_version_detected "1.21", "http://sourceforge.net/foo_bar-1.21.tar.gz/download" + assert_version_detected "1.21", "http://sf.net/foo_bar-1.21.tar.gz/download" + end + + def test_version_github + assert_version_detected "1.0.5", "http://github.com/lloyd/yajl/tarball/1.0.5" + end + + def test_version_github_with_high_patch_number + assert_version_detected "1.2.34", "http://github.com/lloyd/yajl/tarball/v1.2.34" + end + + def test_yet_another_version + assert_version_detected "0.15.1b", "http://example.com/mad-0.15.1b.tar.gz" + end + + def test_lame_version_style + assert_version_detected "398-2", "http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz" + end + + def test_ruby_version_style + assert_version_detected "1.9.1-p243", "ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz" + end + + def test_omega_version_style + assert_version_detected "0.80.2", "http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz" + end + + def test_rc_style + assert_version_detected "1.2.2rc1", "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2" + end + + def test_dash_rc_style + assert_version_detected "1.8.0-rc1", "http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz" + end + + def test_angband_version_style + assert_version_detected "3.0.9b", "http://rephial.org/downloads/3.0/angband-3.0.9b-src.tar.gz" + end + + def test_stable_suffix + assert_version_detected "1.4.14b", "http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz" + end + + def test_debian_style_1 + assert_version_detected "3.03", "http://ftp.de.debian.org/debian/pool/main/s/sl/sl_3.03.orig.tar.gz" + end + + def test_debian_style_2 + assert_version_detected "1.01b", "http://ftp.de.debian.org/debian/pool/main/m/mmv/mmv_1.01b.orig.tar.gz" + end + + def test_bottle_style + assert_version_detected "4.8.0", "https://homebrew.bintray.com/bottles/qt-4.8.0.lion.bottle.tar.gz" + end + + def test_versioned_bottle_style + assert_version_detected "4.8.1", "https://homebrew.bintray.com/bottles/qt-4.8.1.lion.bottle.1.tar.gz" + end + + def test_erlang_bottle_style + assert_version_detected "R15B", "https://homebrew.bintray.com/bottles/erlang-R15B.lion.bottle.tar.gz" + end + + def test_another_erlang_bottle_style + assert_version_detected "R15B01", "https://homebrew.bintray.com/bottles/erlang-R15B01.mountain_lion.bottle.tar.gz" + end + + def test_yet_another_erlang_bottle_style + assert_version_detected "R15B03-1", "https://homebrew.bintray.com/bottles/erlang-R15B03-1.mountainlion.bottle.tar.gz" + end + + def test_imagemagick_style + assert_version_detected "6.7.5-7", "http://downloads.sf.net/project/machomebrew/mirror/ImageMagick-6.7.5-7.tar.bz2" + end + + def test_imagemagick_bottle_style + assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.tar.gz" + end + + def test_imagemagick_versioned_bottle_style + assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.1.tar.gz" + end + + def test_dash_version_dash_style + assert_version_detected "3.4", "http://www.antlr.org/download/antlr-3.4-complete.jar" + end + + def test_jenkins_version_style + assert_version_detected "1.486", "http://mirrors.jenkins-ci.org/war/1.486/jenkins.war" + assert_version_detected "0.10.11", "https://github.com/hechoendrupal/DrupalConsole/releases/download/0.10.11/drupal.phar" + end + + def test_apache_version_style + assert_version_detected "1.2.0-rc2", "http://www.apache.org/dyn/closer.cgi?path=/cassandra/1.2.0/apache-cassandra-1.2.0-rc2-bin.tar.gz" + end + + def test_jpeg_style + assert_version_detected "8d", "http://www.ijg.org/files/jpegsrc.v8d.tar.gz" + end + + def test_version_ghc_style + assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-x86_64-apple-darwin.tar.bz2" + assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-i386-apple-darwin.tar.bz2" + end + + def test_pypy_version + assert_version_detected "1.4.1", "http://pypy.org/download/pypy-1.4.1-osx.tar.bz2" + end + + def test_openssl_version + assert_version_detected "0.9.8s", "http://www.openssl.org/source/openssl-0.9.8s.tar.gz" + end + + def test_xaw3d_version + assert_version_detected "1.5E", "ftp://ftp.visi.com/users/hawkeyd/X/Xaw3d-1.5E.tar.gz" + end + + def test_assimp_version + assert_version_detected "2.0.863", "http://downloads.sourceforge.net/project/assimp/assimp-2.0/assimp--2.0.863-sdk.zip" + end + + def test_cmucl_version + assert_version_detected "20c", "http://common-lisp.net/project/cmucl/downloads/release/20c/cmucl-20c-x86-darwin.tar.bz2" + end + + def test_fann_version + assert_version_detected "2.1.0beta", "http://downloads.sourceforge.net/project/fann/fann/2.1.0beta/fann-2.1.0beta.zip" + end + + def test_grads_version + assert_version_detected "2.0.1", "ftp://iges.org/grads/2.0/grads-2.0.1-bin-darwin9.8-intel.tar.gz" + end + + def test_haxe_version + assert_version_detected "2.08", "http://haxe.org/file/haxe-2.08-osx.tar.gz" + end + + def test_imap_version + assert_version_detected "2007f", "ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz" + end + + def test_suite3270_version + assert_version_detected "3.3.12ga7", "http://downloads.sourceforge.net/project/x3270/x3270/3.3.12ga7/suite3270-3.3.12ga7-src.tgz" + end + + def test_wwwoffle_version + assert_version_detected "2.9h", "http://www.gedanken.demon.co.uk/download-wwwoffle/wwwoffle-2.9h.tgz" + end + + def test_synergy_version + assert_version_detected "1.3.6p2", "http://synergy.googlecode.com/files/synergy-1.3.6p2-MacOSX-Universal.zip" + end + + def test_fontforge_version + assert_version_detected "20120731", "http://downloads.sourceforge.net/project/fontforge/fontforge-source/fontforge_full-20120731-b.tar.bz2" + end + + def test_ezlupdate_version + assert_version_detected "2011.10", "https://github.com/downloads/ezsystems/ezpublish-legacy/ezpublish_community_project-2011.10-with_ezc.tar.bz2" + end + + def test_aespipe_version_style + assert_version_detected "2.4c", + "http://loop-aes.sourceforge.net/aespipe/aespipe-v2.4c.tar.bz2" + end + + def test_win_style + assert_version_detected "0.9.17", + "http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.17-w32.zip" + assert_version_detected "1.29", + "http://ftpmirror.gnu.org/libidn/libidn-1.29-win64.zip" + end + + def test_with_arch + assert_version_detected "4.0.18-1", + "http://ftpmirror.gnu.org/mtools/mtools-4.0.18-1.i686.rpm" + assert_version_detected "5.5.7-5", + "http://ftpmirror.gnu.org/autogen/autogen-5.5.7-5.i386.rpm" + assert_version_detected "2.8", + "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x86.zip" + assert_version_detected "2.8", + "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x64.zip" + assert_version_detected "4.0.18", + "http://ftpmirror.gnu.org/mtools/mtools_4.0.18_i386.deb" + end + + def test_opam_version + assert_version_detected "2.18.3", + "https://opam.ocaml.org/archives/lablgtk.2.18.3+opam.tar.gz" + assert_version_detected "1.9", + "https://opam.ocaml.org/archives/sha.1.9+opam.tar.gz" + assert_version_detected "0.99.2", + "https://opam.ocaml.org/archives/ppx_tools.0.99.2+opam.tar.gz" + assert_version_detected "1.0.2", + "https://opam.ocaml.org/archives/easy-format.1.0.2+opam.tar.gz" + end + + def test_no_extension_version + assert_version_detected "1.8.12", "https://waf.io/waf-1.8.12" + assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" + assert_version_detected "0.9.1234", "https://my.datomic.com/downloads/free/0.9.1234" + assert_version_detected "0.9", "https://my.datomic.com/downloads/free/0.9.1t34" + assert_version_detected "1.2.3", "https://my.datomic.com/downloads/free/1.2.3" + end + + def test_dash_separated_version + assert_version_detected "6-20151227", "ftp://gcc.gnu.org/pub/gcc/snapshots/6-20151227/gcc-6-20151227.tar.bz2" + end + + def test_from_url + assert_version_detected "1.2.3", + "http://github.com/foo/bar.git", tag: "v1.2.3" + end +end + +class HeadVersionTests < Homebrew::TestCase + def test_create_head + v1 = Version.create("HEAD-abcdef") + v2 = Version.create("HEAD") + + assert_predicate v1, :head? + assert_predicate v2, :head? + end + + def test_commit_assigned + v = Version.create("HEAD-abcdef") + assert_equal "abcdef", v.commit + assert_equal "HEAD-abcdef", v.to_str + end + + def test_no_commit + v = Version.create("HEAD") + assert_nil v.commit + assert_equal "HEAD", v.to_str + end + + def test_update_commit + v1 = Version.create("HEAD-abcdef") + v2 = Version.create("HEAD") + + v1.update_commit("ffffff") + assert_equal "ffffff", v1.commit + assert_equal "HEAD-ffffff", v1.to_str + + v2.update_commit("ffffff") + assert_equal "ffffff", v2.commit + assert_equal "HEAD-ffffff", v2.to_str + end +end diff --git a/Library/Homebrew/test/test/x11_requirement_test.rb b/Library/Homebrew/test/test/x11_requirement_test.rb new file mode 100644 index 000000000..b82a59e53 --- /dev/null +++ b/Library/Homebrew/test/test/x11_requirement_test.rb @@ -0,0 +1,31 @@ +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 diff --git a/Library/Homebrew/test/test_ARGV.rb b/Library/Homebrew/test/test_ARGV.rb deleted file mode 100644 index 6805e0c62..000000000 --- a/Library/Homebrew/test/test_ARGV.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/test_ENV.rb b/Library/Homebrew/test/test_ENV.rb deleted file mode 100644 index e38c75c6e..000000000 --- a/Library/Homebrew/test/test_ENV.rb +++ /dev/null @@ -1,201 +0,0 @@ -require "testing_env" -require "extend/ENV" -require "helper/integration_command_test_case" - -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, :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/test_analytics.rb b/Library/Homebrew/test/test_analytics.rb deleted file mode 100644 index 00e0593db..000000000 --- a/Library/Homebrew/test/test_analytics.rb +++ /dev/null @@ -1,26 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_audit.rb b/Library/Homebrew/test/test_audit.rb deleted file mode 100644 index 2725f906e..000000000 --- a/Library/Homebrew/test/test_audit.rb +++ /dev/null @@ -1,472 +0,0 @@ -require "testing_env" -require "fileutils" -require "pathname" -require "formulary" -require "dev-cmd/audit" - -class FormulaTextTests < Homebrew::TestCase - def setup - @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| - f.write <<-EOS.undent - class #{Formulary.class_s(name)} < Formula - #{body} - end - #{options[:patch]} - EOS - end - FormulaText.new path - end - - def test_simple_valid_formula - ft = formula_text "valid", 'url "http://www.example.com/valid-1.0.tar.gz"' - - refute ft.data?, "The formula should not have DATA" - refute ft.end?, "The formula should not have __END__" - assert ft.trailing_newline?, "The formula should have a trailing newline" - - assert ft =~ /\burl\b/, "The formula should match 'url'" - assert_nil ft.line_number(/desc/), "The formula should not match 'desc'" - assert_equal 2, ft.line_number(/\burl\b/) - assert ft.include?("Valid"), "The formula should include \"Valid\"" - end - - def test_trailing_newline - ft = formula_text "newline" - assert ft.trailing_newline?, "The formula must have a trailing newline" - end - - def test_has_data - ft = formula_text "data", "patch :DATA" - assert ft.data?, "The formula must have DATA" - end - - def test_has_end - ft = formula_text "end", "", patch: "__END__\na patch here" - assert ft.end?, "The formula must have __END__" - assert_equal "class End < Formula\n \nend", ft.without_patch - end -end - -class FormulaAuditorTests < Homebrew::TestCase - def setup - @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| - f.write text - end - FormulaAuditor.new Formulary.factory(path), options - end - - def test_init_no_problems - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - assert_equal [], fa.problems - end - - def test_audit_file_permissions - File.stubs(:umask).returns 022 - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - path = fa.formula.path - path.chmod 0400 - - fa.audit_file - assert_equal ["Incorrect file permissions (400): chmod 644 #{path}"], - fa.problems - end - - def test_audit_file_data_no_end - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - patch :DATA - end - EOS - fa.audit_file - assert_equal ["'DATA' was found, but no '__END__'"], fa.problems - end - - def test_audit_file_end_no_data - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - __END__ - a patch goes here - EOS - fa.audit_file - assert_equal ["'__END__' was found, but 'DATA' is not used"], fa.problems - end - - def test_audit_file_no_trailing_newline - fa = formula_auditor "foo", 'class Foo "http://www.freedesktop.org/wiki/bar", - "baz" => "http://www.freedesktop.org/wiki/Software/baz", - "qux" => "https://code.google.com/p/qux", - "quux" => "http://github.com/quux", - "corge" => "http://savannah.nongnu.org/corge", - "grault" => "http://grault.github.io/", - "garply" => "http://www.gnome.org/garply", - "waldo" => "http://www.gnu.org/waldo", - } - - formula_homepages.each do |name, homepage| - fa = formula_auditor name, <<-EOS.undent - class #{Formulary.class_s(name)} < Formula - homepage "#{homepage}" - url "http://example.com/#{name}-1.0.tgz" - end - EOS - - fa.audit_homepage - if homepage =~ %r{http:\/\/www\.freedesktop\.org} - if homepage =~ /Software/ - assert_match "#{homepage} should be styled " \ - "`https://wiki.freedesktop.org/www/Software/project_name`", - fa.problems.first - else - assert_match "#{homepage} should be styled " \ - "`https://wiki.freedesktop.org/project_name`", - fa.problems.first - end - elsif homepage =~ %r{https:\/\/code\.google\.com} - assert_match "#{homepage} should end with a slash", fa.problems.first - else - assert_match "Please use https:// for #{homepage}", fa.problems.first - end - end - end -end diff --git a/Library/Homebrew/test/test_bash.rb b/Library/Homebrew/test/test_bash.rb deleted file mode 100644 index ff418c787..000000000 --- a/Library/Homebrew/test/test_bash.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "testing_env" - -class BashTests < Homebrew::TestCase - def assert_valid_bash_syntax(file) - 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/test_blacklist.rb b/Library/Homebrew/test/test_blacklist.rb deleted file mode 100644 index 585a35484..000000000 --- a/Library/Homebrew/test/test_blacklist.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/test_bottle.rb b/Library/Homebrew/test/test_bottle.rb deleted file mode 100644 index 48727cfd9..000000000 --- a/Library/Homebrew/test/test_bottle.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_bottle_collector.rb b/Library/Homebrew/test/test_bottle_collector.rb deleted file mode 100644 index d75e29ec8..000000000 --- a/Library/Homebrew/test/test_bottle_collector.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/test_bottle_filename.rb b/Library/Homebrew/test/test_bottle_filename.rb deleted file mode 100644 index 6604e7d6a..000000000 --- a/Library/Homebrew/test/test_bottle_filename.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "testing_env" -require "formula" -require "software_spec" - -class BottleFilenameTests < Homebrew::TestCase - def fn(rebuild) - Bottle::Filename.new("foo", "1.0", :tag, rebuild) - end - - def test_prefix_suffix - assert_equal "foo-1.0.tag", fn(0).prefix - assert_equal ".bottle.tar.gz", fn(0).suffix - assert_equal ".bottle.1.tar.gz", fn(1).suffix - end - - def test_to_str - expected = "foo-1.0.tag.bottle.tar.gz" - assert_equal expected, fn(0).to_s - assert_equal expected, fn(0).to_str - end - - def test_create - f = formula do - url "https://example.com/foo.tar.gz" - version "1.0" - end - - expected = "formula_name-1.0.tag.bottle.tar.gz" - assert_equal expected, Bottle::Filename.create(f, :tag, 0).to_s - end -end diff --git a/Library/Homebrew/test/test_bottle_hooks.rb b/Library/Homebrew/test/test_bottle_hooks.rb deleted file mode 100644 index 3535d80ef..000000000 --- a/Library/Homebrew/test/test_bottle_hooks.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/test_build_environment.rb b/Library/Homebrew/test/test_build_environment.rb deleted file mode 100644 index 73a1c95f7..000000000 --- a/Library/Homebrew/test/test_build_environment.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/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb deleted file mode 100644 index e460d25cc..000000000 --- a/Library/Homebrew/test/test_build_options.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/test_bundle.rb b/Library/Homebrew/test/test_bundle.rb deleted file mode 100644 index 6b040df1d..000000000 --- a/Library/Homebrew/test/test_bundle.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_cache.rb b/Library/Homebrew/test/test_cache.rb deleted file mode 100644 index cd7a5e2fa..000000000 --- a/Library/Homebrew/test/test_cache.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestCache < IntegrationCommandTestCase - def test_cache - assert_equal HOMEBREW_CACHE.to_s, - cmd("--cache") - end -end diff --git a/Library/Homebrew/test/test_cache_formula.rb b/Library/Homebrew/test/test_cache_formula.rb deleted file mode 100644 index f4e37e2a2..000000000 --- a/Library/Homebrew/test/test_cache_formula.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestCacheFormula < IntegrationCommandTestCase - def test_cache_formula - assert_match %r{#{HOMEBREW_CACHE}/testball-}, - cmd("--cache", testball) - end -end diff --git a/Library/Homebrew/test/test_cask.rb b/Library/Homebrew/test/test_cask.rb deleted file mode 100644 index 6cae6d54b..000000000 --- a/Library/Homebrew/test/test_cask.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_cat.rb b/Library/Homebrew/test/test_cat.rb deleted file mode 100644 index 4cfd19c3d..000000000 --- a/Library/Homebrew/test/test_cat.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_caveats.rb b/Library/Homebrew/test/test_caveats.rb deleted file mode 100644 index 9eaac5792..000000000 --- a/Library/Homebrew/test/test_caveats.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/test_cellar.rb b/Library/Homebrew/test/test_cellar.rb deleted file mode 100644 index b793c5342..000000000 --- a/Library/Homebrew/test/test_cellar.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestCellar < IntegrationCommandTestCase - def test_cellar - assert_equal HOMEBREW_CELLAR.to_s, - cmd("--cellar") - end -end diff --git a/Library/Homebrew/test/test_cellar_formula.rb b/Library/Homebrew/test/test_cellar_formula.rb deleted file mode 100644 index 7c458be9d..000000000 --- a/Library/Homebrew/test/test_cellar_formula.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestCellarFormula < IntegrationCommandTestCase - def test_cellar_formula - assert_match "#{HOMEBREW_CELLAR}/testball", - cmd("--cellar", testball) - end -end diff --git a/Library/Homebrew/test/test_checksum.rb b/Library/Homebrew/test/test_checksum.rb deleted file mode 100644 index 5505f6824..000000000 --- a/Library/Homebrew/test/test_checksum.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/test_checksum_verification.rb b/Library/Homebrew/test/test_checksum_verification.rb deleted file mode 100644 index e25d08b83..000000000 --- a/Library/Homebrew/test/test_checksum_verification.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "testing_env" -require "formula" - -class ChecksumVerificationTests < Homebrew::TestCase - def assert_checksum_good - assert_nothing_raised { shutup { @_f.brew {} } } - end - - def assert_checksum_bad - assert_raises(ChecksumMismatchError) { shutup { @_f.brew {} } } - end - - def formula(&block) - super do - url "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz" - instance_eval(&block) - end - end - - def teardown - @_f.clear_cache - end - - def test_good_sha256 - formula do - sha256 TESTBALL_SHA256 - end - - assert_checksum_good - end - - def test_bad_sha256 - formula do - sha256 "dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8" - end - - assert_checksum_bad - end -end diff --git a/Library/Homebrew/test/test_cleaner.rb b/Library/Homebrew/test/test_cleaner.rb deleted file mode 100644 index 450a78d86..000000000 --- a/Library/Homebrew/test/test_cleaner.rb +++ /dev/null @@ -1,223 +0,0 @@ -require "testing_env" -require "cleaner" -require "formula" - -class CleanerTests < Homebrew::TestCase - include FileUtils - - def setup - @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 - cp "#{TEST_DIRECTORY}/mach/a.out", @f.bin - cp Dir["#{TEST_DIRECTORY}/mach/*.dylib"], @f.lib - - Cleaner.new(@f).clean - - assert_equal 0100555, (@f.bin/"a.out").stat.mode - assert_equal 0100444, (@f.lib/"fat.dylib").stat.mode - assert_equal 0100444, (@f.lib/"x86_64.dylib").stat.mode - assert_equal 0100444, (@f.lib/"i386.dylib").stat.mode - end - - def test_prunes_prefix_if_empty - Cleaner.new(@f).clean - refute_predicate @f.prefix, :directory? - end - - def test_prunes_empty_directories - subdir = @f.bin/"subdir" - subdir.mkpath - - Cleaner.new(@f).clean - - refute_predicate @f.bin, :directory? - refute_predicate subdir, :directory? - end - - def test_skip_clean_empty_directory - @f.class.skip_clean "bin" - @f.bin.mkpath - - Cleaner.new(@f).clean - - assert_predicate @f.bin, :directory? - end - - def test_skip_clean_directory_with_empty_subdir - @f.class.skip_clean "bin" - subdir = @f.bin/"subdir" - subdir.mkpath - - Cleaner.new(@f).clean - - assert_predicate @f.bin, :directory? - assert_predicate subdir, :directory? - end - - def test_removes_symlink_when_target_was_pruned_first - dir = @f.prefix/"b" - symlink = @f.prefix/"a" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - refute_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_removes_symlink_pointing_to_empty_directory - dir = @f.prefix/"b" - symlink = @f.prefix/"c" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - refute_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_removes_broken_symlinks - symlink = @f.prefix/"symlink" - ln_s "target", symlink - - Cleaner.new(@f).clean - - refute_predicate symlink, :symlink? - end - - def test_skip_clean_broken_symlink - @f.class.skip_clean "symlink" - symlink = @f.prefix/"symlink" - ln_s "target", symlink - - Cleaner.new(@f).clean - - assert_predicate symlink, :symlink? - end - - def test_skip_clean_symlink_pointing_to_empty_directory - @f.class.skip_clean "c" - dir = @f.prefix/"b" - symlink = @f.prefix/"c" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - assert_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_skip_clean_symlink_when_target_pruned - @f.class.skip_clean "a" - dir = @f.prefix/"b" - symlink = @f.prefix/"a" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - assert_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_removes_la_files - file = @f.lib/"foo.la" - - @f.lib.mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_removes_perllocal_files - file = @f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod" - - (@f.lib/"perl5/darwin-thread-multi-2level").mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_removes_packlist_files - file = @f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist" - - (@f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_skip_clean_la - file = @f.lib/"foo.la" - - @f.class.skip_clean :la - @f.lib.mkpath - touch file - - Cleaner.new(@f).clean - - assert_predicate file, :exist? - end - - def test_remove_charset_alias - file = @f.lib/"charset.alias" - - @f.lib.mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_skip_clean_subdir - dir = @f.lib/"subdir" - @f.class.skip_clean "lib/subdir" - - dir.mkpath - - Cleaner.new(@f).clean - - assert_predicate dir, :directory? - end - - def test_skip_clean_paths_are_anchored_to_prefix - dir1 = @f.bin/"a" - dir2 = @f.lib/"bin/a" - - @f.class.skip_clean "bin/a" - dir1.mkpath - dir2.mkpath - - Cleaner.new(@f).clean - - assert_predicate dir1, :exist? - refute_predicate dir2, :exist? - end -end diff --git a/Library/Homebrew/test/test_cleanup.rb b/Library/Homebrew/test/test_cleanup.rb deleted file mode 100644 index dffcd12f2..000000000 --- a/Library/Homebrew/test/test_cleanup.rb +++ /dev/null @@ -1,91 +0,0 @@ -require "testing_env" -require "testball" -require "cleanup" -require "fileutils" -require "pathname" -require "helper/integration_command_test_case" - -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 - @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" - end - - def test_cleanup - shutup { Homebrew::Cleanup.cleanup } - refute_predicate @ds_store, :exist? - end - - def test_cleanup_dry_run - ARGV << "--dry-run" - shutup { Homebrew::Cleanup.cleanup } - assert_predicate @ds_store, :exist? - 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 - - 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? - - 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 - end - - def test_cleanup_logs - path = (HOMEBREW_LOGS/"delete_me") - path.mkpath - ARGV << "--prune=all" - shutup { Homebrew::Cleanup.cleanup_logs } - refute_predicate path, :exist? - end - - def test_cleanup_cache_incomplete_downloads - incomplete = (HOMEBREW_CACHE/"something.incomplete") - incomplete.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate incomplete, :exist? - end - - def test_cleanup_cache_java_cache - java_cache = (HOMEBREW_CACHE/"java_cache") - java_cache.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate java_cache, :exist? - end - - def test_cleanup_cache_npm_cache - npm_cache = (HOMEBREW_CACHE/"npm_cache") - npm_cache.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate npm_cache, :exist? - end -end diff --git a/Library/Homebrew/test/test_command.rb b/Library/Homebrew/test/test_command.rb deleted file mode 100644 index d05184631..000000000 --- a/Library/Homebrew/test/test_command.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_commands.rb b/Library/Homebrew/test/test_commands.rb deleted file mode 100644 index ef138049c..000000000 --- a/Library/Homebrew/test/test_commands.rb +++ /dev/null @@ -1,86 +0,0 @@ -require "testing_env" -require "cmd/command" -require "cmd/commands" -require "fileutils" -require "helper/integration_command_test_case" - -class IntegrationCommandTestCommands < IntegrationCommandTestCase - def test_commands - assert_match "Built-in commands", - cmd("commands") - end -end - -class CommandsTests < Homebrew::TestCase - def setup - @cmds = [ - # internal commands - HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - - # internal development commands - HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - ] - - @cmds.each { |f| FileUtils.touch f } - end - - def teardown - @cmds.each(&:unlink) - end - - def test_internal_commands - cmds = Homebrew.internal_commands - assert cmds.include?("rbcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbdevcmd"), "Dev commands shouldn't be included" - end - - def test_internal_developer_commands - cmds = Homebrew.internal_developer_commands - assert cmds.include?("rbdevcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shdevcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbcmd"), "Non-dev commands shouldn't be included" - 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}" - FileUtils.touch path - FileUtils.chmod 0755, path - end - - FileUtils.touch "#{dir}/brew-t4" - - ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" - cmds = Homebrew.external_commands - - assert cmds.include?("t1"), "Executable files should be included" - assert cmds.include?("t2"), "Executable Ruby files should be included" - refute cmds.include?("t3"), - "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 - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - Commands.path("rbcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - Commands.path("shcmd") - assert_nil Commands.path("idontexist1234") - end - - def test_internal_dev_command_path - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - Commands.path("rbdevcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - Commands.path("shdevcmd") - end -end diff --git a/Library/Homebrew/test/test_compiler_failure.rb b/Library/Homebrew/test/test_compiler_failure.rb deleted file mode 100644 index c0b74d128..000000000 --- a/Library/Homebrew/test/test_compiler_failure.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/test_compiler_selector.rb b/Library/Homebrew/test/test_compiler_selector.rb deleted file mode 100644 index b1591bdbe..000000000 --- a/Library/Homebrew/test/test_compiler_selector.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/test_config.rb b/Library/Homebrew/test/test_config.rb deleted file mode 100644 index 33a293735..000000000 --- a/Library/Homebrew/test/test_config.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestConfig < IntegrationCommandTestCase - def test_config - assert_match "HOMEBREW_VERSION: #{HOMEBREW_VERSION}", - cmd("config") - end -end diff --git a/Library/Homebrew/test/test_create.rb b/Library/Homebrew/test/test_create.rb deleted file mode 100644 index bb1a2cd2a..000000000 --- a/Library/Homebrew/test/test_create.rb +++ /dev/null @@ -1,12 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestCreate < IntegrationCommandTestCase - def test_create - url = "file://#{File.expand_path("..", __FILE__)}/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/test_custom_command.rb b/Library/Homebrew/test/test_custom_command.rb deleted file mode 100644 index bc27e2121..000000000 --- a/Library/Homebrew/test/test_custom_command.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_dependencies.rb b/Library/Homebrew/test/test_dependencies.rb deleted file mode 100644 index db3b78226..000000000 --- a/Library/Homebrew/test/test_dependencies.rb +++ /dev/null @@ -1,115 +0,0 @@ -require "testing_env" -require "dependencies" -require "dependency" -require "requirements" - -class DependenciesTests < Homebrew::TestCase - def setup - @deps = Dependencies.new - end - - def test_shovel_returns_self - assert_same @deps, @deps << Dependency.new("foo") - end - - def test_preserves_order - hash = { 0 => "foo", 1 => "bar", 2 => "baz" } - @deps << Dependency.new(hash[0]) - @deps << Dependency.new(hash[1]) - @deps << Dependency.new(hash[2]) - @deps.each_with_index do |dep, idx| - assert_equal hash[idx], dep.name - end - end - - def test_repetition - @deps << Dependency.new("foo") - @deps << Dependency.new("bar") - assert_equal "foo, bar", @deps*", " - end - - def test_to_a - dep = Dependency.new("foo") - @deps << dep - assert_equal [dep], @deps.to_a - end - - def test_to_ary - dep = Dependency.new("foo") - @deps << dep - assert_equal [dep], @deps.to_ary - end - - def test_type_helpers - foo = Dependency.new("foo") - bar = Dependency.new("bar", [:optional]) - baz = Dependency.new("baz", [:build]) - qux = Dependency.new("qux", [:recommended]) - quux = Dependency.new("quux") - @deps << foo << bar << baz << qux << quux - assert_equal [foo, quux], @deps.required - assert_equal [bar], @deps.optional - assert_equal [baz], @deps.build - assert_equal [qux], @deps.recommended - assert_equal [foo, baz, quux, qux].sort_by(&:name), @deps.default.sort_by(&:name) - end - - def test_equality - a = Dependencies.new - b = Dependencies.new - - dep = Dependency.new("foo") - - a << dep - b << dep - - assert_equal a, b - assert_eql a, b - - b << Dependency.new("bar", [:optional]) - - refute_equal a, b - refute_eql a, b - end - - def test_empty - a = Dependencies.new - assert a.empty? - a << Dependency.new("foo") - refute a.empty? - end - - def test_inspect - a = Dependencies.new - assert_equal "#", a.inspect - a << Dependency.new("foo") - assert_equal "#]>", a.inspect - end -end - -class RequirementsTests < Homebrew::TestCase - def setup - @reqs = Requirements.new - end - - def test_shovel_returns_self - assert_same @reqs, @reqs << Object.new - end - - def test_merging_multiple_dependencies - @reqs << X11Requirement.new << X11Requirement.new - assert_equal 1, @reqs.count - @reqs << Requirement.new - assert_equal 2, @reqs.count - end - - def test_comparison_prefers_larger - @reqs << X11Requirement.new << X11Requirement.new("x11", %w[2.6]) - assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a - end - - def test_comparison_does_not_merge_smaller - @reqs << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new - assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a - end -end diff --git a/Library/Homebrew/test/test_dependency.rb b/Library/Homebrew/test/test_dependency.rb deleted file mode 100644 index 65255995e..000000000 --- a/Library/Homebrew/test/test_dependency.rb +++ /dev/null @@ -1,125 +0,0 @@ -require "testing_env" -require "dependency" - -class DependableTests < Homebrew::TestCase - def setup - @tags = ["foo", "bar", :build] - @dep = Struct.new(:tags).new(@tags).extend(Dependable) - end - - def test_options - assert_equal %w[--foo --bar].sort, @dep.options.as_flags.sort - end - - def test_interrogation - assert_predicate @dep, :build? - refute_predicate @dep, :optional? - refute_predicate @dep, :recommended? - end -end - -class DependencyTests < Homebrew::TestCase - def test_accepts_single_tag - dep = Dependency.new("foo", %w[bar]) - assert_equal %w[bar], dep.tags - end - - def test_accepts_multiple_tags - dep = Dependency.new("foo", %w[bar baz]) - assert_equal %w[bar baz].sort, dep.tags.sort - end - - def test_preserves_symbol_tags - dep = Dependency.new("foo", [:build]) - assert_equal [:build], dep.tags - end - - def test_accepts_symbol_and_string_tags - dep = Dependency.new("foo", [:build, "bar"]) - assert_equal [:build, "bar"], dep.tags - end - - def test_merge_repeats - dep = Dependency.new("foo", [:build], nil, "foo") - dep2 = Dependency.new("foo", ["bar"], nil, "foo2") - dep3 = Dependency.new("xyz", ["abc"], nil, "foo") - merged = Dependency.merge_repeats([dep, dep2, dep3]) - assert_equal 2, merged.length - assert_equal Dependency, merged.first.class - - foo_named_dep = merged.find { |d| d.name == "foo" } - assert_equal ["bar"], foo_named_dep.tags - assert_includes foo_named_dep.option_names, "foo" - assert_includes foo_named_dep.option_names, "foo2" - - xyz_named_dep = merged.find { |d| d.name == "xyz" } - assert_equal ["abc"], xyz_named_dep.tags - assert_includes xyz_named_dep.option_names, "foo" - refute_includes xyz_named_dep.option_names, "foo2" - end - - def test_merges_necessity_tags - required_dep = Dependency.new("foo") - recommended_dep = Dependency.new("foo", [:recommended]) - optional_dep = Dependency.new("foo", [:optional]) - - deps = Dependency.merge_repeats([required_dep, recommended_dep]) - assert_equal deps.count, 1 - assert_predicate deps.first, :required? - refute_predicate deps.first, :recommended? - refute_predicate deps.first, :optional? - - deps = Dependency.merge_repeats([required_dep, optional_dep]) - assert_equal deps.count, 1 - assert_predicate deps.first, :required? - refute_predicate deps.first, :recommended? - refute_predicate deps.first, :optional? - - deps = Dependency.merge_repeats([recommended_dep, optional_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :required? - assert_predicate deps.first, :recommended? - refute_predicate deps.first, :optional? - end - - def test_merges_temporality_tags - normal_dep = Dependency.new("foo") - build_dep = Dependency.new("foo", [:build]) - run_dep = Dependency.new("foo", [:run]) - - deps = Dependency.merge_repeats([normal_dep, build_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :build? - refute_predicate deps.first, :run? - - deps = Dependency.merge_repeats([normal_dep, run_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :build? - refute_predicate deps.first, :run? - - deps = Dependency.merge_repeats([build_dep, run_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :build? - refute_predicate deps.first, :run? - end - - def test_equality - foo1 = Dependency.new("foo") - foo2 = Dependency.new("foo") - bar = Dependency.new("bar") - assert_equal foo1, foo2 - assert_eql foo1, foo2 - refute_equal foo1, bar - refute_eql foo1, bar - foo3 = Dependency.new("foo", [:build]) - refute_equal foo1, foo3 - refute_eql foo1, foo3 - end -end - -class TapDependencyTests < Homebrew::TestCase - def test_option_names - dep = TapDependency.new("foo/bar/dog") - assert_equal %w[dog], dep.option_names - end -end diff --git a/Library/Homebrew/test/test_dependency_collector.rb b/Library/Homebrew/test/test_dependency_collector.rb deleted file mode 100644 index 1c7f70118..000000000 --- a/Library/Homebrew/test/test_dependency_collector.rb +++ /dev/null @@ -1,146 +0,0 @@ -require "testing_env" -require "dependency_collector" - -class DependencyCollectorTests < Homebrew::TestCase - def find_dependency(name) - @d.deps.find { |dep| dep.name == name } - end - - def find_requirement(klass) - @d.requirements.find { |req| req.is_a? klass } - end - - def setup - @d = DependencyCollector.new - end - - def teardown - DependencyCollector.clear_cache - end - - def test_dependency_creation - @d.add "foo" => :build - @d.add "bar" => ["--universal", :optional] - assert_instance_of Dependency, find_dependency("foo") - assert_equal 2, find_dependency("bar").tags.length - end - - def test_add_returns_created_dep - ret = @d.add "foo" - assert_equal Dependency.new("foo"), ret - end - - def test_dependency_tags - assert_predicate Dependency.new("foo", [:build]), :build? - assert_predicate Dependency.new("foo", [:build, :optional]), :optional? - assert_includes Dependency.new("foo", ["universal"]).options, "--universal" - assert_empty Dependency.new("foo").tags - end - - def test_requirement_creation - @d.add :x11 - assert_instance_of X11Requirement, find_requirement(X11Requirement) - end - - def test_no_duplicate_requirements - 2.times { @d.add :x11 } - assert_equal 1, @d.requirements.count - end - - def test_requirement_tags - @d.add x11: "2.5.1" - @d.add xcode: :build - assert_empty find_requirement(X11Requirement).tags - assert_predicate find_requirement(XcodeRequirement), :build? - end - - def test_x11_no_tag - @d.add :x11 - assert_empty find_requirement(X11Requirement).tags - end - - def test_x11_min_version - @d.add x11: "2.5.1" - assert_equal "2.5.1", find_requirement(X11Requirement).min_version.to_s - end - - def test_x11_tag - @d.add x11: :optional - assert_predicate find_requirement(X11Requirement), :optional? - end - - def test_x11_min_version_and_tag - @d.add x11: ["2.5.1", :optional] - dep = find_requirement(X11Requirement) - assert_equal "2.5.1", dep.min_version.to_s - assert_predicate dep, :optional? - end - - def test_ant_dep - @d.add ant: :build - assert_equal find_dependency("ant"), Dependency.new("ant", [:build]) - end - - def test_raises_typeerror_for_unknown_classes - assert_raises(TypeError) { @d.add(Class.new) } - end - - def test_raises_typeerror_for_unknown_types - assert_raises(TypeError) { @d.add(Object.new) } - end - - def test_does_not_mutate_dependency_spec - spec = { "foo" => :optional } - copy = spec.dup - @d.add(spec) - assert_equal copy, spec - end - - def test_resource_dep_git_url - resource = Resource.new - resource.url("git://example.com/foo/bar.git") - assert_instance_of GitRequirement, @d.add(resource) - end - - def test_resource_dep_7z_url - resource = Resource.new - resource.url("http://example.com/foo.7z") - assert_equal Dependency.new("p7zip", [:build]), @d.add(resource) - end - - def test_resource_dep_gzip_url - resource = Resource.new - resource.url("http://example.com/foo.tar.gz") - assert_nil @d.add(resource) - end - - def test_resource_dep_lz_url - resource = Resource.new - resource.url("http://example.com/foo.lz") - assert_equal Dependency.new("lzip", [:build]), @d.add(resource) - end - - def test_resource_dep_lha_url - resource = Resource.new - resource.url("http://example.com/foo.lha") - assert_equal Dependency.new("lha", [:build]), @d.add(resource) - end - - def test_resource_dep_lzh_url - resource = Resource.new - resource.url("http://example.com/foo.lzh") - assert_equal Dependency.new("lha", [:build]), @d.add(resource) - end - - def test_resource_dep_rar_url - resource = Resource.new - resource.url("http://example.com/foo.rar") - assert_equal Dependency.new("unrar", [:build]), @d.add(resource) - end - - def test_resource_dep_raises_for_unknown_classes - resource = Resource.new - resource.download_strategy = Class.new - assert_raises(TypeError) { @d.add(resource) } - end -end diff --git a/Library/Homebrew/test/test_dependency_expansion.rb b/Library/Homebrew/test/test_dependency_expansion.rb deleted file mode 100644 index 9d6de35e2..000000000 --- a/Library/Homebrew/test/test_dependency_expansion.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/test_deps.rb b/Library/Homebrew/test/test_deps.rb deleted file mode 100644 index 83cc9aa6a..000000000 --- a/Library/Homebrew/test/test_deps.rb +++ /dev/null @@ -1,16 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_desc.rb b/Library/Homebrew/test/test_desc.rb deleted file mode 100644 index 075ea991a..000000000 --- a/Library/Homebrew/test/test_desc.rb +++ /dev/null @@ -1,17 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_descriptions.rb b/Library/Homebrew/test/test_descriptions.rb deleted file mode 100644 index de38fdbd1..000000000 --- a/Library/Homebrew/test/test_descriptions.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/test_diagnostic.rb b/Library/Homebrew/test/test_diagnostic.rb deleted file mode 100644 index aa2e44cfc..000000000 --- a/Library/Homebrew/test/test_diagnostic.rb +++ /dev/null @@ -1,197 +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 - # 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/test_doctor.rb b/Library/Homebrew/test/test_doctor.rb deleted file mode 100644 index ccb909dce..000000000 --- a/Library/Homebrew/test/test_doctor.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_download_strategies.rb b/Library/Homebrew/test/test_download_strategies.rb deleted file mode 100644 index 87218fb12..000000000 --- a/Library/Homebrew/test/test_download_strategies.rb +++ /dev/null @@ -1,188 +0,0 @@ -require "testing_env" -require "download_strategy" - -class ResourceDouble - attr_reader :url, :specs, :version - - def initialize(url = "http://example.com/foo.tar.gz", specs = {}) - @url = url - @specs = specs - 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 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/test_edit.rb b/Library/Homebrew/test/test_edit.rb deleted file mode 100644 index 8d1437173..000000000 --- a/Library/Homebrew/test/test_edit.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_exceptions.rb b/Library/Homebrew/test/test_exceptions.rb deleted file mode 100644 index 689531c6e..000000000 --- a/Library/Homebrew/test/test_exceptions.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: "") - assert_match "bar does not define resource ", - ResourceMissingError.new(f, r).to_s - end - - def test_duplicate_resource_error - r = stub(inspect: "") - assert_equal "Resource 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/test_fetch.rb b/Library/Homebrew/test/test_fetch.rb deleted file mode 100644 index 7b57c6246..000000000 --- a/Library/Homebrew/test/test_fetch.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_formula.rb b/Library/Homebrew/test/test_formula.rb deleted file mode 100644 index 4aa835590..000000000 --- a/Library/Homebrew/test/test_formula.rb +++ /dev/null @@ -1,1180 +0,0 @@ -require "testing_env" -require "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/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 "f3" - end - - assert_equal %w[f3], f4.deps.map(&:name) - assert_equal %w[f1 f2 f3], f4.recursive_dependencies.map(&:name) - assert_equal %w[f2 f3], f4.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/test_formula_installer.rb b/Library/Homebrew/test/test_formula_installer.rb deleted file mode 100644 index 18bd910a6..000000000 --- a/Library/Homebrew/test/test_formula_installer.rb +++ /dev/null @@ -1,138 +0,0 @@ -require "testing_env" -require "formula" -require "formula_installer" -require "keg" -require "tab" -require "testball" -require "testball_bottle" - -class InstallTests < Homebrew::TestCase - def temporary_install(formula) - refute_predicate formula, :installed? - - installer = FormulaInstaller.new(formula) - - shutup { installer.install } - - keg = Keg.new(formula.prefix) - - assert_predicate formula, :installed? - - begin - Tab.clear_cache - refute_predicate Tab.for_keg(keg), :poured_from_bottle - - yield formula - ensure - Tab.clear_cache - keg.unlink - keg.uninstall - formula.clear_cache - # there will be log files when sandbox is enable. - formula.logs.rmtree if formula.logs.directory? - end - - refute_predicate keg, :exist? - refute_predicate formula, :installed? - end - - def test_a_basic_install - ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install - temporary_install(Testball.new) do |f| - # Test that things made it into the Keg - assert_predicate f.prefix+"readme", :exist? - - assert_predicate f.bin, :directory? - assert_equal 3, f.bin.children.length - - assert_predicate f.libexec, :directory? - assert_equal 1, f.libexec.children.length - - refute_predicate f.prefix+"main.c", :exist? - - refute_predicate f.prefix+"license", :exist? - - # Test that things make it into the Cellar - keg = Keg.new f.prefix - keg.link - - bin = HOMEBREW_PREFIX+"bin" - assert_predicate bin, :directory? - assert_equal 3, bin.children.length - assert_predicate f.prefix/".brew/testball.rb", :readable? - end - end - - def test_bottle_unneeded_formula_install - DevelopmentTools.stubs(:installed?).returns(false) - - formula = Testball.new - formula.stubs(:bottle_unneeded?).returns(true) - formula.stubs(:bottle_disabled?).returns(true) - - refute_predicate formula, :bottled? - assert_predicate formula, :bottle_unneeded? - assert_predicate formula, :bottle_disabled? - - temporary_install(formula) do |f| - assert_predicate f, :installed? - end - end - - def test_not_poured_from_bottle_when_compiler_specified - assert_nil ARGV.cc - - 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 } - end - end -end - -class FormulaInstallerTests < Homebrew::TestCase - def test_check_install_sanity_pinned_dep - dep_name = "dependency" - dep_path = CoreTap.new.formula_dir/"#{dep_name}.rb" - dep_path.write <<-EOS.undent - class #{Formulary.class_s(dep_name)} < Formula - url "foo" - version "0.2" - end - EOS - - Formulary::FORMULAE.delete(dep_path) - dependency = Formulary.factory(dep_name) - - dependent = formula do - url "foo" - version "0.5" - depends_on dependency.name.to_s - end - - dependency.prefix("0.1").join("bin/a").mkpath - HOMEBREW_PINNED_KEGS.mkpath - FileUtils.ln_s dependency.prefix("0.1"), HOMEBREW_PINNED_KEGS/dep_name - - dependency_keg = Keg.new(dependency.prefix("0.1")) - dependency_keg.link - - assert_predicate dependency_keg, :linked? - assert_predicate dependency, :pinned? - - 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/test_formula_installer_bottle.rb b/Library/Homebrew/test/test_formula_installer_bottle.rb deleted file mode 100644 index d83c856b7..000000000 --- a/Library/Homebrew/test/test_formula_installer_bottle.rb +++ /dev/null @@ -1,78 +0,0 @@ -require "testing_env" -require "formula" -require "formula_installer" -require "keg" -require "tab" -require "testball" -require "testball_bottle" - -class InstallBottleTests < Homebrew::TestCase - def temporary_bottle_install(formula) - refute_predicate formula, :installed? - assert_predicate formula, :bottled? - assert_predicate formula, :pour_bottle? - - installer = FormulaInstaller.new(formula) - - shutup { installer.install } - - keg = Keg.new(formula.prefix) - - assert_predicate formula, :installed? - - begin - assert_predicate Tab.for_keg(keg), :poured_from_bottle - - yield formula - ensure - keg.unlink - keg.uninstall - formula.clear_cache - formula.bottle.clear_cache - end - - refute_predicate keg, :exist? - refute_predicate formula, :installed? - end - - def test_a_basic_bottle_install - DevelopmentTools.stubs(:installed?).returns(false) - - temporary_bottle_install(TestballBottle.new) do |f| - # Copied directly from test_formula_installer.rb as we expect - # the same behavior - - # Test that things made it into the Keg - assert_predicate f.bin, :directory? - - assert_predicate f.libexec, :directory? - - refute_predicate f.prefix+"main.c", :exist? - - # Test that things make it into the Cellar - keg = Keg.new f.prefix - keg.link - - bin = HOMEBREW_PREFIX+"bin" - assert_predicate bin, :directory? - end - end - - def test_build_tools_error - DevelopmentTools.stubs(:installed?).returns(false) - - # Testball doesn't have a bottle block, so use it to test this behavior - formula = Testball.new - - refute_predicate formula, :installed? - refute_predicate formula, :bottled? - - installer = FormulaInstaller.new(formula) - - assert_raises(BuildToolsError) do - installer.install - end - - refute_predicate formula, :installed? - end -end diff --git a/Library/Homebrew/test/test_formula_lock.rb b/Library/Homebrew/test/test_formula_lock.rb deleted file mode 100644 index 80ee9dd25..000000000 --- a/Library/Homebrew/test/test_formula_lock.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/test_formula_pin.rb b/Library/Homebrew/test/test_formula_pin.rb deleted file mode 100644 index 297d7703e..000000000 --- a/Library/Homebrew/test/test_formula_pin.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/test_formula_spec_selection.rb b/Library/Homebrew/test/test_formula_spec_selection.rb deleted file mode 100644 index 7148df173..000000000 --- a/Library/Homebrew/test/test_formula_spec_selection.rb +++ /dev/null @@ -1,99 +0,0 @@ -require "testing_env" -require "formula" - -class FormulaSpecSelectionTests < Homebrew::TestCase - def test_selects_stable_by_default - f = formula do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :stable? - end - - def test_selects_stable_when_exclusive - f = formula { url "foo-1.0" } - assert_predicate f, :stable? - end - - def test_selects_devel_before_head - f = formula do - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_selects_devel_when_exclusive - f = formula { devel { url "foo-1.1a" } } - assert_predicate f, :devel? - end - - def test_selects_head_when_exclusive - f = formula { head "foo" } - assert_predicate f, :head? - end - - def test_incomplete_spec_not_selected - f = formula do - sha256 TEST_SHA256 - version "1.0" - head "foo" - end - - assert_predicate f, :head? - end - - def test_incomplete_stable_not_set - f = formula do - sha256 TEST_SHA256 - devel { url "foo-1.1a" } - head "foo" - end - - assert_nil f.stable - assert_predicate f, :devel? - end - - def test_selects_head_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :head) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :head? - end - - def test_selects_devel_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_incomplete_devel_not_set - f = formula do - url "foo-1.0" - devel { version "1.1a" } - head "foo" - end - - assert_nil f.devel - assert_predicate f, :stable? - end - - def test_does_not_raise_for_missing_spec - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - head "foo" - end - - assert_predicate f, :stable? - end -end diff --git a/Library/Homebrew/test/test_formula_support.rb b/Library/Homebrew/test/test_formula_support.rb deleted file mode 100644 index c0a79f950..000000000 --- a/Library/Homebrew/test/test_formula_support.rb +++ /dev/null @@ -1,28 +0,0 @@ -require "testing_env" -require "formula_support" - -class KegOnlyReasonTests < Homebrew::TestCase - def test_to_s_explanation - r = KegOnlyReason.new :provided_by_osx, "test" - assert_equal "test", r.to_s - end - - def test_to_s_no_explanation - r = KegOnlyReason.new :provided_by_macos, "" - assert_match(/^macOS already provides/, r.to_s) - end -end - -class BottleDisableReasonTests < Homebrew::TestCase - def test_bottle_unneeded - bottle_disable_reason = BottleDisableReason.new :unneeded, nil - assert_predicate bottle_disable_reason, :unneeded? - assert_equal "This formula doesn't require compiling.", bottle_disable_reason.to_s - end - - def test_bottle_disabled - bottle_disable_reason = BottleDisableReason.new :disable, "reason" - refute_predicate bottle_disable_reason, :unneeded? - assert_equal "reason", bottle_disable_reason.to_s - end -end diff --git a/Library/Homebrew/test/test_formula_validation.rb b/Library/Homebrew/test/test_formula_validation.rb deleted file mode 100644 index c40eb6733..000000000 --- a/Library/Homebrew/test/test_formula_validation.rb +++ /dev/null @@ -1,75 +0,0 @@ -require "testing_env" -require "formula" - -class FormulaValidationTests < Homebrew::TestCase - def assert_invalid(attr, &block) - e = assert_raises(FormulaValidationError, &block) - assert_equal attr, e.attr - end - - def test_cant_override_brew - e = assert_raises(RuntimeError) { formula { def brew; end } } - assert_match(/You cannot override Formula#brew/, e.message) - end - - def test_validates_name - assert_invalid :name do - formula "name with spaces" do - url "foo" - version "1.0" - end - end - end - - def test_validates_url - assert_invalid :url do - formula do - url "" - version "1" - end - end - end - - def test_validates_version - assert_invalid :version do - formula do - url "foo" - version "version with spaces" - end - end - - assert_invalid :version do - formula do - url "foo" - version "" - end - end - - assert_invalid :version do - formula do - url "foo" - version nil - end - end - end - - def test_devel_only_valid - f = formula do - devel do - url "foo" - version "1.0" - end - end - - assert_predicate f, :devel? - end - - def test_head_only_valid - f = formula { head "foo" } - assert_predicate f, :head? - end - - def test_empty_formula_invalid - assert_raises(FormulaSpecificationError) { formula {} } - end -end diff --git a/Library/Homebrew/test/test_formulary.rb b/Library/Homebrew/test/test_formulary.rb deleted file mode 100644 index c545ff84d..000000000 --- a/Library/Homebrew/test/test_formulary.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("#{File.expand_path("..", __FILE__)}/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://#{File.expand_path("..", __FILE__)}/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/test_gpg.rb b/Library/Homebrew/test/test_gpg.rb deleted file mode 100644 index 0374bdab4..000000000 --- a/Library/Homebrew/test/test_gpg.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/test_gpg2_requirement.rb b/Library/Homebrew/test/test_gpg2_requirement.rb deleted file mode 100644 index fa7fc9ea4..000000000 --- a/Library/Homebrew/test/test_gpg2_requirement.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/test_hardware.rb b/Library/Homebrew/test/test_hardware.rb deleted file mode 100644 index 2bea5387d..000000000 --- a/Library/Homebrew/test/test_hardware.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, :dunno] - assert_includes families, Hardware::CPU.family - end - end -end diff --git a/Library/Homebrew/test/test_help.rb b/Library/Homebrew/test/test_help.rb deleted file mode 100644 index 9c14f9b78..000000000 --- a/Library/Homebrew/test/test_help.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_home.rb b/Library/Homebrew/test/test_home.rb deleted file mode 100644 index 9c26353be..000000000 --- a/Library/Homebrew/test/test_home.rb +++ /dev/null @@ -1,12 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_info.rb b/Library/Homebrew/test/test_info.rb deleted file mode 100644 index 35f9183e1..000000000 --- a/Library/Homebrew/test/test_info.rb +++ /dev/null @@ -1,29 +0,0 @@ -require "testing_env" -require "cmd/info" -require "formula" -require "helper/integration_command_test_case" - -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/test_inreplace.rb b/Library/Homebrew/test/test_inreplace.rb deleted file mode 100644 index 0e62f9d3f..000000000 --- a/Library/Homebrew/test/test_inreplace.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/test_install.rb b/Library/Homebrew/test/test_install.rb deleted file mode 100644 index 7135dddb2..000000000 --- a/Library/Homebrew/test/test_install.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "helper/integration_command_test_case" - -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_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 -end diff --git a/Library/Homebrew/test/test_irb.rb b/Library/Homebrew/test/test_irb.rb deleted file mode 100644 index bf35b6524..000000000 --- a/Library/Homebrew/test/test_irb.rb +++ /dev/null @@ -1,19 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_json.rb b/Library/Homebrew/test/test_json.rb deleted file mode 100644 index 14d2f2b4c..000000000 --- a/Library/Homebrew/test/test_json.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "testing_env" -require "utils/json" - -class JsonSmokeTest < Homebrew::TestCase - def test_encode - hash = { "foo" => ["bar", "baz"] } - json = '{"foo":["bar","baz"]}' - assert_equal json, Utils::JSON.dump(hash) - end - - def test_decode - hash = { "foo" => ["bar", "baz"], "qux" => 1 } - json = '{"foo":["bar","baz"],"qux":1}' - assert_equal hash, Utils::JSON.load(json) - end - - def test_decode_failure - assert_raises(Utils::JSON::Error) { Utils::JSON.load("nope") } - end -end diff --git a/Library/Homebrew/test/test_keg.rb b/Library/Homebrew/test/test_keg.rb deleted file mode 100644 index fdc739c9d..000000000 --- a/Library/Homebrew/test/test_keg.rb +++ /dev/null @@ -1,400 +0,0 @@ -require "testing_env" -require "keg" -require "stringio" - -class LinkTests < 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 - - 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 < LinkTests - 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 - Formula.clear_cache - keg - end - - def setup - super - @dependent = setup_test_keg("bar", "1.0") - end - - def alter_tab(keg = @dependent) - tab = Tab.for_keg(keg) - yield tab - tab.write - end - - def dependencies(deps) - alter_tab do |tab| - tab.tabfile = @dependent.join("INSTALL_RECEIPT.json") - tab.runtime_dependencies = deps - end - 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) - dependencies [] - alter_tab { |t| t.source["path"] = nil } - assert_empty @keg.installed_dependents - assert_nil Keg.find_some_installed_dependents([@keg]) - 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_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_empty @keg.installed_dependents - assert_nil 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 -end diff --git a/Library/Homebrew/test/test_language_go.rb b/Library/Homebrew/test/test_language_go.rb deleted file mode 100644 index 692a5d2cc..000000000 --- a/Library/Homebrew/test/test_language_go.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/test_language_module_requirement.rb b/Library/Homebrew/test/test_language_module_requirement.rb deleted file mode 100644 index dfa992287..000000000 --- a/Library/Homebrew/test/test_language_module_requirement.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/test_language_python.rb b/Library/Homebrew/test/test_language_python.rb deleted file mode 100644 index d1e3867f7..000000000 --- a/Library/Homebrew/test/test_language_python.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/test_leaves.rb b/Library/Homebrew/test/test_leaves.rb deleted file mode 100644 index 2a9bbadd9..000000000 --- a/Library/Homebrew/test/test_leaves.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_link.rb b/Library/Homebrew/test/test_link.rb deleted file mode 100644 index 3f0507072..000000000 --- a/Library/Homebrew/test/test_link.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_linkapps.rb b/Library/Homebrew/test/test_linkapps.rb deleted file mode 100644 index b7c4cb811..000000000 --- a/Library/Homebrew/test/test_linkapps.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_list.rb b/Library/Homebrew/test/test_list.rb deleted file mode 100644 index 1ffdb4528..000000000 --- a/Library/Homebrew/test/test_list.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_log.rb b/Library/Homebrew/test/test_log.rb deleted file mode 100644 index b20a098fd..000000000 --- a/Library/Homebrew/test/test_log.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_log_formula.rb b/Library/Homebrew/test/test_log_formula.rb deleted file mode 100644 index 34509bf72..000000000 --- a/Library/Homebrew/test/test_log_formula.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_migrate.rb b/Library/Homebrew/test/test_migrate.rb deleted file mode 100644 index 53b32777a..000000000 --- a/Library/Homebrew/test/test_migrate.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_migrator.rb b/Library/Homebrew/test/test_migrator.rb deleted file mode 100644 index cefb8b7a3..000000000 --- a/Library/Homebrew/test/test_migrator.rb +++ /dev/null @@ -1,264 +0,0 @@ -require "testing_env" -require "migrator" -require "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/test_missing.rb b/Library/Homebrew/test/test_missing.rb deleted file mode 100644 index 565f413da..000000000 --- a/Library/Homebrew/test/test_missing.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_mpi_requirement.rb b/Library/Homebrew/test/test_mpi_requirement.rb deleted file mode 100644 index e0f97e8ee..000000000 --- a/Library/Homebrew/test/test_mpi_requirement.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/test_options.rb b/Library/Homebrew/test/test_options.rb deleted file mode 100644 index bfde7a9b6..000000000 --- a/Library/Homebrew/test/test_options.rb +++ /dev/null @@ -1,157 +0,0 @@ -require "testing_env" -require "options" -require "helper/integration_command_test_case" - -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.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.inspect - @options << Option.new("foo") - assert_equal "#]>", @options.inspect - end -end diff --git a/Library/Homebrew/test/test_os_mac_blacklist.rb b/Library/Homebrew/test/test_os_mac_blacklist.rb deleted file mode 100644 index 26dd84ed9..000000000 --- a/Library/Homebrew/test/test_os_mac_blacklist.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/test_os_mac_bottle_collector.rb b/Library/Homebrew/test/test_os_mac_bottle_collector.rb deleted file mode 100644 index 2f88050ae..000000000 --- a/Library/Homebrew/test/test_os_mac_bottle_collector.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/test_os_mac_bottle_tag.rb b/Library/Homebrew/test/test_os_mac_bottle_tag.rb deleted file mode 100644 index 996bd4d53..000000000 --- a/Library/Homebrew/test/test_os_mac_bottle_tag.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/test_os_mac_dependency_collector.rb b/Library/Homebrew/test/test_os_mac_dependency_collector.rb deleted file mode 100644 index 4fdf3ebe4..000000000 --- a/Library/Homebrew/test/test_os_mac_dependency_collector.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/test_os_mac_diagnostic.rb b/Library/Homebrew/test/test_os_mac_diagnostic.rb deleted file mode 100644 index 655aa1d46..000000000 --- a/Library/Homebrew/test/test_os_mac_diagnostic.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/test_os_mac_keg.rb b/Library/Homebrew/test/test_os_mac_keg.rb deleted file mode 100644 index e79cbc921..000000000 --- a/Library/Homebrew/test/test_os_mac_keg.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/test_os_mac_language.rb b/Library/Homebrew/test/test_os_mac_language.rb deleted file mode 100644 index e328db5e0..000000000 --- a/Library/Homebrew/test/test_os_mac_language.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/test_os_mac_mach.rb b/Library/Homebrew/test/test_os_mac_mach.rb deleted file mode 100644 index 404a21d60..000000000 --- a/Library/Homebrew/test/test_os_mac_mach.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_DIRECTORY}/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_DIRECTORY}/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/test_os_mac_version.rb b/Library/Homebrew/test/test_os_mac_version.rb deleted file mode 100644 index f702c7097..000000000 --- a/Library/Homebrew/test/test_os_mac_version.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/test_os_mac_x11_requirement.rb b/Library/Homebrew/test/test_os_mac_x11_requirement.rb deleted file mode 100644 index 102937cb5..000000000 --- a/Library/Homebrew/test/test_os_mac_x11_requirement.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "testing_env" -require "requirements/x11_requirement" - -class OSMacX11RequirementTests < Homebrew::TestCase - def test_satisfied - MacOS::XQuartz.stubs(:version).returns("2.7.5") - MacOS::XQuartz.stubs(:installed?).returns(true) - assert_predicate X11Requirement.new, :satisfied? - - MacOS::XQuartz.stubs(:installed?).returns(false) - refute_predicate X11Requirement.new, :satisfied? - end -end diff --git a/Library/Homebrew/test/test_outdated.rb b/Library/Homebrew/test/test_outdated.rb deleted file mode 100644 index cc0f024c8..000000000 --- a/Library/Homebrew/test/test_outdated.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_patch.rb b/Library/Homebrew/test/test_patch.rb deleted file mode 100644 index 62624720e..000000000 --- a/Library/Homebrew/test/test_patch.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 "#", 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 '#', @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/test_patching.rb b/Library/Homebrew/test/test_patching.rb deleted file mode 100644 index 18b848b10..000000000 --- a/Library/Homebrew/test/test_patching.rb +++ /dev/null @@ -1,253 +0,0 @@ -require "testing_env" -require "formula" - -class PatchingTests < Homebrew::TestCase - TESTBALL_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz".freeze - TESTBALL_PATCHES_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1-patches.tgz".freeze - PATCH_URL_A = "file://#{TEST_DIRECTORY}/patches/noop-a.diff".freeze - PATCH_URL_B = "file://#{TEST_DIRECTORY}/patches/noop-b.diff".freeze - PATCH_A_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-a.diff" - PATCH_B_CONTENTS = File.read "#{TEST_DIRECTORY}/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/test_pathname.rb b/Library/Homebrew/test/test_pathname.rb deleted file mode 100644 index 2f6360719..000000000 --- a/Library/Homebrew/test/test_pathname.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/test_pin_unpin.rb b/Library/Homebrew/test/test_pin_unpin.rb deleted file mode 100644 index 37682d45e..000000000 --- a/Library/Homebrew/test/test_pin_unpin.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_pkg_version.rb b/Library/Homebrew/test/test_pkg_version.rb deleted file mode 100644 index ff7896f8b..000000000 --- a/Library/Homebrew/test/test_pkg_version.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/test_prefix.rb b/Library/Homebrew/test/test_prefix.rb deleted file mode 100644 index 4aa63fa07..000000000 --- a/Library/Homebrew/test/test_prefix.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestPrefix < IntegrationCommandTestCase - def test_prefix - assert_equal HOMEBREW_PREFIX.to_s, - cmd("--prefix") - end -end diff --git a/Library/Homebrew/test/test_prefix_formula.rb b/Library/Homebrew/test/test_prefix_formula.rb deleted file mode 100644 index d76a966d7..000000000 --- a/Library/Homebrew/test/test_prefix_formula.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestPrefixFormula < IntegrationCommandTestCase - def test_prefix_formula - assert_match "#{HOMEBREW_CELLAR}/testball", - cmd("--prefix", testball) - end -end diff --git a/Library/Homebrew/test/test_prune.rb b/Library/Homebrew/test/test_prune.rb deleted file mode 100644 index 293a3746d..000000000 --- a/Library/Homebrew/test/test_prune.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_pull.rb b/Library/Homebrew/test/test_pull.rb deleted file mode 100644 index 9707ff8a8..000000000 --- a/Library/Homebrew/test/test_pull.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_pull_offline.rb b/Library/Homebrew/test/test_pull_offline.rb deleted file mode 100644 index 2716af346..000000000 --- a/Library/Homebrew/test/test_pull_offline.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_readall.rb b/Library/Homebrew/test/test_readall.rb deleted file mode 100644 index d0c078e49..000000000 --- a/Library/Homebrew/test/test_readall.rb +++ /dev/null @@ -1,12 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_reinstall.rb b/Library/Homebrew/test/test_reinstall.rb deleted file mode 100644 index d07a96051..000000000 --- a/Library/Homebrew/test/test_reinstall.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "helper/integration_command_test_case" - -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 --with-foo", - cmd("reinstall", "testball") - assert foo_dir.exist? - end -end diff --git a/Library/Homebrew/test/test_reinstall_pinned.rb b/Library/Homebrew/test/test_reinstall_pinned.rb deleted file mode 100644 index c9cb8a849..000000000 --- a/Library/Homebrew/test/test_reinstall_pinned.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_repository.rb b/Library/Homebrew/test/test_repository.rb deleted file mode 100644 index 2029876ad..000000000 --- a/Library/Homebrew/test/test_repository.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_requirement.rb b/Library/Homebrew/test/test_requirement.rb deleted file mode 100644 index 580d42bfa..000000000 --- a/Library/Homebrew/test/test_requirement.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/test_resource.rb b/Library/Homebrew/test/test_resource.rb deleted file mode 100644 index c1b526cb2..000000000 --- a/Library/Homebrew/test/test_resource.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/test_sandbox.rb b/Library/Homebrew/test/test_sandbox.rb deleted file mode 100644 index 2a062cb10..000000000 --- a/Library/Homebrew/test/test_sandbox.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "testing_env" -require "sandbox" - -class SandboxTest < Homebrew::TestCase - def setup - 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 - assert Sandbox.formula?(f), - "Formulae should be sandboxed if --sandbox was passed." - - ARGV.stubs(:sandbox?).returns false - assert Sandbox.formula?(f), - "Formulae should be sandboxed if in a sandboxed tap." - refute Sandbox.formula?(f2), - "Formulae should not be sandboxed if not in a sandboxed tap." - end - - def test_test? - ARGV.stubs(:no_sandbox?).returns false - assert Sandbox.test?, - "Tests should be sandboxed unless --no-sandbox was passed." - end - - def test_allow_write - @sandbox.allow_write @file - @sandbox.exec "touch", @file - assert_predicate @file, :exist? - end - - def test_deny_write - shutup do - assert_raises(ErrorDuringExecution) { @sandbox.exec "touch", @file } - end - refute_predicate @file, :exist? - end - - def test_complains_on_failure - Utils.expects(popen_read: "foo") - ARGV.stubs(verbose?: true) - out, _err = capture_io do - assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } - end - assert_match "foo", out - end - - def test_ignores_bogus_python_error - with_bogus_error = <<-EOS.undent - foo - Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc - bar - EOS - Utils.expects(popen_read: with_bogus_error) - ARGV.stubs(verbose?: true) - out, _err = capture_io do - assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } - end - refute_predicate out, :empty? - assert_match "foo", out - assert_match "bar", out - refute_match "Python", out - end -end diff --git a/Library/Homebrew/test/test_search.rb b/Library/Homebrew/test/test_search.rb deleted file mode 100644 index 8310d1c2b..000000000 --- a/Library/Homebrew/test/test_search.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "helper/integration_command_test_case" - -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§ion=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§ion=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/test_search_remote_tap.rb b/Library/Homebrew/test/test_search_remote_tap.rb deleted file mode 100644 index 9dd9ee654..000000000 --- a/Library/Homebrew/test/test_search_remote_tap.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/test_services.rb b/Library/Homebrew/test/test_services.rb deleted file mode 100644 index b5ccb7c77..000000000 --- a/Library/Homebrew/test/test_services.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_sh.rb b/Library/Homebrew/test/test_sh.rb deleted file mode 100644 index 449b7b5b3..000000000 --- a/Library/Homebrew/test/test_sh.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_shell.rb b/Library/Homebrew/test/test_shell.rb deleted file mode 100644 index 877acb5c8..000000000 --- a/Library/Homebrew/test/test_shell.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/test_software_spec.rb b/Library/Homebrew/test/test_software_spec.rb deleted file mode 100644 index d9226f8c3..000000000 --- a/Library/Homebrew/test/test_software_spec.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/test_stdlib.rb b/Library/Homebrew/test/test_stdlib.rb deleted file mode 100644 index ee53e7c8c..000000000 --- a/Library/Homebrew/test/test_stdlib.rb +++ /dev/null @@ -1,61 +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) - @gcc4 = CxxStdlib.create(:libstdcxx, :gcc_4_0) - @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?(@gcc4) - 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 @gcc4, :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/test_string.rb b/Library/Homebrew/test/test_string.rb deleted file mode 100644 index 497c4badb..000000000 --- a/Library/Homebrew/test/test_string.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/test_switch.rb b/Library/Homebrew/test/test_switch.rb deleted file mode 100644 index 88fdf85b9..000000000 --- a/Library/Homebrew/test/test_switch.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestSwitch < IntegrationCommandTestCase - def test_switch - assert_match "Usage: brew switch ", 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/test_tab.rb b/Library/Homebrew/test/test_tab.rb deleted file mode 100644 index 2c756cf68..000000000 --- a/Library/Homebrew/test/test_tab.rb +++ /dev/null @@ -1,270 +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_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_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/hombrew/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(Utils::JSON.load(@tab.to_json)) - assert_equal @tab.used_options.sort, tab.used_options.sort - assert_equal @tab.unused_options.sort, tab.unused_options.sort - assert_equal @tab.built_as_bottle, tab.built_as_bottle - assert_equal @tab.poured_from_bottle, tab.poured_from_bottle - 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 Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt.json").read - end - - def teardown - @f.rack.rmtree - end - - def test_for_keg - tab = Tab.for_keg(@f.prefix) - assert_equal @path, tab.tabfile - end - - def test_for_keg_nonexistent_path - @path.unlink - tab = Tab.for_keg(@f.prefix) - assert_nil tab.tabfile - end - - def test_for_formula - tab = Tab.for_formula(@f) - assert_equal @path, tab.tabfile - end - - def test_for_formula_nonexistent_path - @path.unlink - tab = Tab.for_formula(@f) - assert_nil tab.tabfile - end - - def test_for_formula_multiple_kegs - f2 = formula { url "foo-2.0" } - f2.prefix.mkpath - - assert_equal @f.rack, f2.rack - 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/test_tap.rb b/Library/Homebrew/test/test_tap.rb deleted file mode 100644 index 71836aee9..000000000 --- a/Library/Homebrew/test/test_tap.rb +++ /dev/null @@ -1,329 +0,0 @@ -require "testing_env" -require "helper/integration_command_test_case" - -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/versions", 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 - @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" - @path.mkpath - @tap = Tap.new("Homebrew", "foo") - end - - def setup_tap_files - @formula_file = @path/"Formula/foo.rb" - @formula_file.write <<-EOS.undent - class Foo < Formula - url "https://example.com/foo-1.0.tar.gz" - end - EOS - @alias_file = @path/"Aliases/bar" - @alias_file.parent.mkpath - ln_s @formula_file, @alias_file - (@path/"formula_renames.json").write <<-EOS.undent - { "oldname": "foo" } - EOS - (@path/"tap_migrations.json").write <<-EOS.undent - { "removed-formula": "homebrew/foo" } - EOS - @cmd_file = @path/"cmd/brew-tap-cmd.rb" - @cmd_file.parent.mkpath - touch @cmd_file - chmod 0755, @cmd_file - @manpage_file = @path/"man/man1/brew-tap-cmd.1" - @manpage_file.parent.mkpath - touch @manpage_file - 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" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" - system "git", "add", "--all" - system "git", "commit", "-m", "init" - end - end - ensure - ENV.replace(env) - end - - def teardown - @path.rmtree - end - - def test_fetch - assert_kind_of CoreTap, Tap.fetch("Homebrew", "homebrew") - tap = Tap.fetch("Homebrew", "foo") - assert_kind_of Tap, tap - assert_equal "homebrew/foo", tap.name - - assert_match "Invalid tap name", - assert_raises { Tap.fetch("foo") }.message - assert_match "Invalid tap name", - assert_raises { Tap.fetch("homebrew/homebrew/bar") }.message - assert_match "Invalid tap name", - assert_raises { Tap.fetch("homebrew", "homebrew/baz") }.message - ensure - Tap.clear_cache - end - - def test_names - assert_equal ["homebrew/core", "homebrew/foo"], Tap.names.sort - end - - def test_attributes - assert_equal "Homebrew", @tap.user - assert_equal "foo", @tap.repo - assert_equal "homebrew/foo", @tap.name - assert_equal @path, @tap.path - assert_predicate @tap, :installed? - assert_predicate @tap, :official? - refute_predicate @tap, :core_tap? - end - - def test_issues_url - t = Tap.new("someone", "foo") - path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" - path.mkpath - cd path do - shutup { system "git", "init" } - system "git", "remote", "add", "origin", - "https://github.com/someone/homebrew-foo" - end - assert_equal "https://github.com/someone/homebrew-foo/issues", t.issues_url - assert_equal "https://github.com/Homebrew/homebrew-foo/issues", @tap.issues_url - - (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath - assert_nil Tap.new("someone", "no-git").issues_url - ensure - path.parent.rmtree - end - - def test_files - setup_tap_files - - assert_equal [@formula_file], @tap.formula_files - assert_equal ["homebrew/foo/foo"], @tap.formula_names - assert_equal [@alias_file], @tap.alias_files - assert_equal ["homebrew/foo/bar"], @tap.aliases - assert_equal @tap.alias_table, "homebrew/foo/bar" => "homebrew/foo/foo" - assert_equal @tap.alias_reverse_table, "homebrew/foo/foo" => ["homebrew/foo/bar"] - assert_equal @tap.formula_renames, "oldname" => "foo" - assert_equal @tap.tap_migrations, "removed-formula" => "homebrew/foo" - assert_equal [@cmd_file], @tap.command_files - assert_kind_of Hash, @tap.to_hash - assert_equal true, @tap.formula_file?(@formula_file) - assert_equal true, @tap.formula_file?("Formula/foo.rb") - assert_equal false, @tap.formula_file?("bar.rb") - assert_equal false, @tap.formula_file?("Formula/baz.sh") - end - - def test_remote - setup_git_repo - - assert_equal "https://github.com/Homebrew/homebrew-foo", @tap.remote - assert_raises(TapUnavailableError) { Tap.new("Homebrew", "bar").remote } - refute_predicate @tap, :custom_remote? - - version_tap = Tap.new("Homebrew", "versions") - version_tap.path.mkpath - version_tap.path.cd do - shutup do - system "git", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-versions" - end - end - refute_predicate version_tap, :private? - ensure - version_tap.path.rmtree if version_tap - end - - def test_remote_not_git_repo - assert_nil @tap.remote - end - - def test_remote_git_not_available - setup_git_repo - Utils.stubs(:git_available?).returns(false) - assert_nil @tap.remote - end - - def test_git_variant - 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 - end - - def test_private_remote - skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub.api_credentials - assert_predicate @tap, :private? - end - - def test_install_tap_already_tapped_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - assert_equal true, already_tapped_tap.installed? - assert_raises(TapAlreadyTappedError) { already_tapped_tap.install } - end - - def test_install_tap_remote_match_already_tapped_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - assert_equal true, already_tapped_tap.installed? - right_remote = @tap.remote - assert_raises(TapAlreadyTappedError) { already_tapped_tap.install clone_target: right_remote } - end - - def test_install_tap_remote_mismatch_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - touch @tap.path/".git/shallow" - assert_equal true, already_tapped_tap.installed? - wrong_remote = "#{@tap.remote}-oops" - assert_raises(TapRemoteMismatchError) { already_tapped_tap.install clone_target: wrong_remote, full_clone: true } - end - - def test_install_tap_already_unshallow_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - assert_raises(TapAlreadyUnshallowError) { already_tapped_tap.install full_clone: true } - end - - def test_uninstall_tap_unavailable_error - tap = Tap.new("Homebrew", "bar") - assert_raises(TapUnavailableError) { tap.uninstall } - end - - def test_install_git_error - tap = Tap.new("user", "repo") - assert_raises(ErrorDuringExecution) do - shutup { tap.install clone_target: "file:///not/existed/remote/url" } - end - refute_predicate tap, :installed? - refute_predicate Tap::TAP_DIRECTORY/"user", :exist? - end - - def test_install_and_uninstall - setup_tap_files - setup_git_repo - - tap = Tap.new("Homebrew", "bar") - shutup { tap.install clone_target: @tap.path/".git" } - assert_predicate tap, :installed? - assert_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :file? - shutup { tap.uninstall } - 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 - refute_predicate @tap, :pinned? - assert_raises(TapPinStatusError) { @tap.unpin } - @tap.pin - assert_predicate @tap, :pinned? - assert_raises(TapPinStatusError) { @tap.pin } - @tap.unpin - refute_predicate @tap, :pinned? - end - - def test_config - setup_git_repo - - assert_nil @tap.config["foo"] - @tap.config["foo"] = "bar" - assert_equal "bar", @tap.config["foo"] - @tap.config["foo"] = nil - assert_nil @tap.config["foo"] - end -end - -class CoreTapTest < Homebrew::TestCase - include FileUtils - - def setup - @repo = CoreTap.new - end - - def test_attributes - assert_equal "Homebrew", @repo.user - assert_equal "core", @repo.repo - assert_equal "homebrew/core", @repo.name - assert_equal [], @repo.command_files - assert_predicate @repo, :installed? - refute_predicate @repo, :pinned? - assert_predicate @repo, :official? - assert_predicate @repo, :core_tap? - end - - def test_forbidden_operations - assert_raises(RuntimeError) { @repo.uninstall } - assert_raises(RuntimeError) { @repo.pin } - assert_raises(RuntimeError) { @repo.unpin } - end - - def test_files - @formula_file = @repo.formula_dir/"foo.rb" - @formula_file.write <<-EOS.undent - class Foo < Formula - url "https://example.com/foo-1.0.tar.gz" - end - EOS - @alias_file = @repo.alias_dir/"bar" - @alias_file.parent.mkpath - ln_s @formula_file, @alias_file - - assert_equal [@formula_file], @repo.formula_files - assert_equal ["foo"], @repo.formula_names - assert_equal [@alias_file], @repo.alias_files - 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_tap_new.rb b/Library/Homebrew/test/test_tap_new.rb deleted file mode 100644 index 636024b0a..000000000 --- a/Library/Homebrew/test/test_tap_new.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_test_formula.rb b/Library/Homebrew/test/test_test_formula.rb deleted file mode 100644 index b3889d6a2..000000000 --- a/Library/Homebrew/test/test_test_formula.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "helper/integration_command_test_case" - -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://#{File.expand_path("..", __FILE__)}/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/test_uninstall.rb b/Library/Homebrew/test/test_uninstall.rb deleted file mode 100644 index d86db0e80..000000000 --- a/Library/Homebrew/test/test_uninstall.rb +++ /dev/null @@ -1,67 +0,0 @@ -require "helper/integration_command_test_case" -require "cmd/uninstall" - -class UninstallTests < Homebrew::TestCase - def setup - @dependency = formula("dependency") { url "f-1" } - @dependent = formula("dependent") do - url "f-1" - depends_on "dependency" - end - - [@dependency, @dependent].each { |f| f.installed_prefix.mkpath } - - tab = Tab.empty - tab.tabfile = @dependent.installed_prefix/Tab::FILENAME - tab.runtime_dependencies = [ - { "full_name" => "dependency", "version" => "1" }, - ] - tab.write - - stub_formula_loader @dependency - stub_formula_loader @dependent - end - - def teardown - Homebrew.failed = false - [@dependency, @dependent].each { |f| f.rack.rmtree } - end - - def handle_unsatisfied_dependents - capture_stderr do - opts = { @dependency.rack => [Keg.new(@dependency.installed_prefix)] } - Homebrew.handle_unsatisfied_dependents(opts) - end - end - - def test_check_for_testball_f2s_when_developer - skip "Flaky test" - assert_match "Warning", handle_unsatisfied_dependents - refute_predicate Homebrew, :failed? - end - - def test_check_for_dependents_when_not_developer - skip "Flaky test" - run_as_not_developer do - assert_match "Error", handle_unsatisfied_dependents - assert_predicate Homebrew, :failed? - end - end - - def test_check_for_dependents_when_ignore_dependencies - ARGV << "--ignore-dependencies" - run_as_not_developer do - 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/test_unlink.rb b/Library/Homebrew/test/test_unlink.rb deleted file mode 100644 index 091bd8c45..000000000 --- a/Library/Homebrew/test/test_unlink.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_unlinkapps.rb b/Library/Homebrew/test/test_unlinkapps.rb deleted file mode 100644 index 2de4e3ff8..000000000 --- a/Library/Homebrew/test/test_unlinkapps.rb +++ /dev/null @@ -1,19 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_unpack.rb b/Library/Homebrew/test/test_unpack.rb deleted file mode 100644 index de1452a29..000000000 --- a/Library/Homebrew/test/test_unpack.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_update_report.rb b/Library/Homebrew/test/test_update_report.rb deleted file mode 100644 index 6b6cec6ce..000000000 --- a/Library/Homebrew/test/test_update_report.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/test_upgrade.rb b/Library/Homebrew/test/test_upgrade.rb deleted file mode 100644 index 73618293b..000000000 --- a/Library/Homebrew/test/test_upgrade.rb +++ /dev/null @@ -1,12 +0,0 @@ -require "helper/integration_command_test_case" - -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/test_uses.rb b/Library/Homebrew/test/test_uses.rb deleted file mode 100644 index b0e79ef2d..000000000 --- a/Library/Homebrew/test/test_uses.rb +++ /dev/null @@ -1,16 +0,0 @@ -require "helper/integration_command_test_case" - -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_equal "bar\nbaz", cmd("uses", "--recursive", "foo") - end -end diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb deleted file mode 100644 index 7c0b6f78a..000000000 --- a/Library/Homebrew/test/test_utils.rb +++ /dev/null @@ -1,279 +0,0 @@ -require "testing_env" -require "utils" -require "tempfile" -require "utils/shell" - -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 - -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/"], - die: 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/test_version.rb b/Library/Homebrew/test/test_version.rb deleted file mode 100644 index ca37e3567..000000000 --- a/Library/Homebrew/test/test_version.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "helper/integration_command_test_case" - -class IntegrationCommandTestVersion < IntegrationCommandTestCase - def test_version - assert_match HOMEBREW_VERSION.to_s, - cmd("--version") - end -end diff --git a/Library/Homebrew/test/test_versions.rb b/Library/Homebrew/test/test_versions.rb deleted file mode 100644 index a6e922178..000000000 --- a/Library/Homebrew/test/test_versions.rb +++ /dev/null @@ -1,530 +0,0 @@ -require "testing_env" -require "version" - -class VersionTests < Homebrew::TestCase - def test_accepts_objects_responding_to_to_str - value = stub(to_str: "0.1") - assert_equal "0.1", Version.create(value).to_s - end - - def test_raises_for_non_string_objects - assert_raises(TypeError) { Version.create(1.1) } - assert_raises(TypeError) { Version.create(1) } - assert_raises(TypeError) { Version.create(:symbol) } - end - - def test_detected_from_url? - refute Version.create("1.0").detected_from_url? - assert Version::FromURL.new("1.0").detected_from_url? - end -end - -class VersionTokenTests < Homebrew::TestCase - def test_inspect - assert_equal '#', - Version::Token.new("foo").inspect - end - - def test_to_s - assert_equal "foo", Version::Token.new("foo").to_s - end -end - -class NullVersionTests < Homebrew::TestCase - def test_null_version_is_always_smaller - assert_operator Version::NULL, :<, version("1") - end - - def test_null_version_is_never_greater - refute_operator Version::NULL, :>, version("0") - end - - def test_null_version_is_not_equal_to_itself - refute_eql Version::NULL, Version::NULL - end - - def test_null_version_creates_an_empty_string - assert_eql "", Version::NULL.to_s - end - - def test_null_version_produces_nan_as_a_float - # Float::NAN is not equal to itself so compare object IDs - assert_eql Float::NAN.object_id, Version::NULL.to_f.object_id - end -end - -class VersionNullTokenTests < Homebrew::TestCase - def test_inspect - assert_equal "#", Version::NullToken.new.inspect - end - - def test_comparing_null - assert_operator Version::NullToken.new, :==, Version::NullToken.new - end -end - -class VersionComparisonTests < Homebrew::TestCase - def test_comparing_regular_versions - assert_operator version("0.1"), :==, version("0.1.0") - assert_operator version("0.1"), :<, version("0.2") - assert_operator version("1.2.3"), :>, version("1.2.2") - assert_operator version("1.2.4"), :<, version("1.2.4.1") - - assert_operator version("1.2.3"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3"), :>, version("1.2.3beta2") - assert_operator version("1.2.3"), :>, version("1.2.3rc3") - assert_operator version("1.2.3"), :<, version("1.2.3-p34") - end - - def test_head - assert_operator version("HEAD"), :>, version("1.2.3") - assert_operator version("HEAD-abcdef"), :>, version("1.2.3") - assert_operator version("1.2.3"), :<, version("HEAD") - assert_operator version("1.2.3"), :<, version("HEAD-fedcba") - assert_operator version("HEAD-abcdef"), :==, version("HEAD-fedcba") - assert_operator version("HEAD"), :==, version("HEAD-fedcba") - end - - def test_comparing_alpha_versions - assert_operator version("1.2.3alpha"), :<, version("1.2.3") - assert_operator version("1.2.3"), :<, version("1.2.3a") - assert_operator version("1.2.3alpha4"), :==, version("1.2.3a4") - assert_operator version("1.2.3alpha4"), :==, version("1.2.3A4") - assert_operator version("1.2.3alpha4"), :>, version("1.2.3alpha3") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha5") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha10") - - assert_operator version("1.2.3alpha4"), :<, version("1.2.3beta2") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3rc3") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3-p34") - end - - def test_comparing_beta_versions - assert_operator version("1.2.3beta2"), :==, version("1.2.3b2") - assert_operator version("1.2.3beta2"), :==, version("1.2.3B2") - assert_operator version("1.2.3beta2"), :>, version("1.2.3beta1") - assert_operator version("1.2.3beta2"), :<, version("1.2.3beta3") - assert_operator version("1.2.3beta2"), :<, version("1.2.3beta10") - - assert_operator version("1.2.3beta2"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3beta2"), :<, version("1.2.3rc3") - assert_operator version("1.2.3beta2"), :<, version("1.2.3") - assert_operator version("1.2.3beta2"), :<, version("1.2.3-p34") - end - - def test_comparing_rc_versions - assert_operator version("1.2.3rc3"), :==, version("1.2.3RC3") - assert_operator version("1.2.3rc3"), :>, version("1.2.3rc2") - assert_operator version("1.2.3rc3"), :<, version("1.2.3rc4") - assert_operator version("1.2.3rc3"), :<, version("1.2.3rc10") - - assert_operator version("1.2.3rc3"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3rc3"), :>, version("1.2.3beta2") - assert_operator version("1.2.3rc3"), :<, version("1.2.3") - assert_operator version("1.2.3rc3"), :<, version("1.2.3-p34") - end - - def test_comparing_patchlevel_versions - assert_operator version("1.2.3-p34"), :==, version("1.2.3-P34") - assert_operator version("1.2.3-p34"), :>, version("1.2.3-p33") - assert_operator version("1.2.3-p34"), :<, version("1.2.3-p35") - assert_operator version("1.2.3-p34"), :>, version("1.2.3-p9") - - assert_operator version("1.2.3-p34"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3-p34"), :>, version("1.2.3beta2") - assert_operator version("1.2.3-p34"), :>, version("1.2.3rc3") - assert_operator version("1.2.3-p34"), :>, version("1.2.3") - end - - def test_comparing_unevenly_padded_versions - assert_operator version("2.1.0-p194"), :<, version("2.1-p195") - assert_operator version("2.1-p195"), :>, version("2.1.0-p194") - assert_operator version("2.1-p194"), :<, version("2.1.0-p195") - assert_operator version("2.1.0-p195"), :>, version("2.1-p194") - assert_operator version("2-p194"), :<, version("2.1-p195") - end - - def test_comparing_against_nil - assert_operator version("2.1.0-p194"), :>, nil - end - - def test_comparing_against_strings - assert_operator version("2.1.0-p194"), :==, "2.1.0-p194" - assert_operator version("1"), :==, 1 - end - - def test_comparison_returns_nil_for_non_version - v = version("1.0") - assert_nil v <=> Object.new - assert_raises(ArgumentError) { v > Object.new } - end - - def test_erlang_version - versions = %w[R16B R15B03-1 R15B03 R15B02 R15B01 R14B04 R14B03 - R14B02 R14B01 R14B R13B04 R13B03 R13B02-1].reverse - assert_equal versions, versions.sort_by { |v| version(v) } - end - - def test_hash_equality - v1 = version("0.1.0") - v2 = version("0.1.0") - v3 = version("0.1.1") - - assert_eql v1, v2 - refute_eql v1, v3 - assert_equal v1.hash, v2.hash - - h = { v1 => :foo } - assert_equal :foo, h[v2] - end -end - -class VersionParsingTests < Homebrew::TestCase - def test_pathname_version - 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 - assert_version_nil "http://example.com/blah.tar" - assert_version_nil "foo" - end - - def test_create - v = Version.create("1.20") - refute_predicate v, :head? - assert_equal "1.20", v.to_str - end - - def test_version_all_dots - assert_version_detected "1.14", "http://example.com/foo.bar.la.1.14.zip" - end - - def test_version_underscore_separator - assert_version_detected "1.1", "http://example.com/grc_1.1.tar.gz" - end - - def test_boost_version_style - assert_version_detected "1.39.0", "http://example.com/boost_1_39_0.tar.bz2" - end - - def test_erlang_version_style - assert_version_detected "R13B", "http://erlang.org/download/otp_src_R13B.tar.gz" - end - - def test_another_erlang_version_style - assert_version_detected "R15B01", "https://github.com/erlang/otp/tarball/OTP_R15B01" - end - - def test_yet_another_erlang_version_style - assert_version_detected "R15B03-1", "https://github.com/erlang/otp/tarball/OTP_R15B03-1" - end - - def test_p7zip_version_style - assert_version_detected "9.04", - "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2" - end - - def test_new_github_style - assert_version_detected "1.1.4", "https://github.com/sam-github/libnet/tarball/libnet-1.1.4" - end - - def test_codeload_style - assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" - end - - def test_elasticsearch_alpha_style - assert_version_detected "5.0.0-alpha5", "https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha5/elasticsearch-5.0.0-alpha5.tar.gz" - end - - def test_gloox_beta_style - assert_version_detected "1.0-beta7", "http://camaya.net/download/gloox-1.0-beta7.tar.bz2" - end - - def test_sphinx_beta_style - assert_version_detected "1.10-beta", "http://sphinxsearch.com/downloads/sphinx-1.10-beta.tar.gz" - end - - def test_astyle_verson_style - assert_version_detected "1.23", "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz" - end - - def test_version_dos2unix - assert_version_detected "3.1", "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz" - end - - def test_version_internal_dash - assert_version_detected "1.1-2", "http://example.com/foo-arse-1.1-2.tar.gz" - end - - def test_version_single_digit - assert_version_detected "45", "http://example.com/foo_bar.45.tar.gz" - end - - def test_noseparator_single_digit - assert_version_detected "45", "http://example.com/foo_bar45.tar.gz" - end - - def test_version_developer_that_hates_us_format - assert_version_detected "1.2.3", "http://example.com/foo-bar-la.1.2.3.tar.gz" - end - - def test_version_regular - assert_version_detected "1.21", "http://example.com/foo_bar-1.21.tar.gz" - end - - def test_version_sourceforge_download - assert_version_detected "1.21", "http://sourceforge.net/foo_bar-1.21.tar.gz/download" - assert_version_detected "1.21", "http://sf.net/foo_bar-1.21.tar.gz/download" - end - - def test_version_github - assert_version_detected "1.0.5", "http://github.com/lloyd/yajl/tarball/1.0.5" - end - - def test_version_github_with_high_patch_number - assert_version_detected "1.2.34", "http://github.com/lloyd/yajl/tarball/v1.2.34" - end - - def test_yet_another_version - assert_version_detected "0.15.1b", "http://example.com/mad-0.15.1b.tar.gz" - end - - def test_lame_version_style - assert_version_detected "398-2", "http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz" - end - - def test_ruby_version_style - assert_version_detected "1.9.1-p243", "ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz" - end - - def test_omega_version_style - assert_version_detected "0.80.2", "http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz" - end - - def test_rc_style - assert_version_detected "1.2.2rc1", "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2" - end - - def test_dash_rc_style - assert_version_detected "1.8.0-rc1", "http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz" - end - - def test_angband_version_style - assert_version_detected "3.0.9b", "http://rephial.org/downloads/3.0/angband-3.0.9b-src.tar.gz" - end - - def test_stable_suffix - assert_version_detected "1.4.14b", "http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz" - end - - def test_debian_style_1 - assert_version_detected "3.03", "http://ftp.de.debian.org/debian/pool/main/s/sl/sl_3.03.orig.tar.gz" - end - - def test_debian_style_2 - assert_version_detected "1.01b", "http://ftp.de.debian.org/debian/pool/main/m/mmv/mmv_1.01b.orig.tar.gz" - end - - def test_bottle_style - assert_version_detected "4.8.0", "https://homebrew.bintray.com/bottles/qt-4.8.0.lion.bottle.tar.gz" - end - - def test_versioned_bottle_style - assert_version_detected "4.8.1", "https://homebrew.bintray.com/bottles/qt-4.8.1.lion.bottle.1.tar.gz" - end - - def test_erlang_bottle_style - assert_version_detected "R15B", "https://homebrew.bintray.com/bottles/erlang-R15B.lion.bottle.tar.gz" - end - - def test_another_erlang_bottle_style - assert_version_detected "R15B01", "https://homebrew.bintray.com/bottles/erlang-R15B01.mountain_lion.bottle.tar.gz" - end - - def test_yet_another_erlang_bottle_style - assert_version_detected "R15B03-1", "https://homebrew.bintray.com/bottles/erlang-R15B03-1.mountainlion.bottle.tar.gz" - end - - def test_imagemagick_style - assert_version_detected "6.7.5-7", "http://downloads.sf.net/project/machomebrew/mirror/ImageMagick-6.7.5-7.tar.bz2" - end - - def test_imagemagick_bottle_style - assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.tar.gz" - end - - def test_imagemagick_versioned_bottle_style - assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.1.tar.gz" - end - - def test_dash_version_dash_style - assert_version_detected "3.4", "http://www.antlr.org/download/antlr-3.4-complete.jar" - end - - def test_jenkins_version_style - assert_version_detected "1.486", "http://mirrors.jenkins-ci.org/war/1.486/jenkins.war" - assert_version_detected "0.10.11", "https://github.com/hechoendrupal/DrupalConsole/releases/download/0.10.11/drupal.phar" - end - - def test_apache_version_style - assert_version_detected "1.2.0-rc2", "http://www.apache.org/dyn/closer.cgi?path=/cassandra/1.2.0/apache-cassandra-1.2.0-rc2-bin.tar.gz" - end - - def test_jpeg_style - assert_version_detected "8d", "http://www.ijg.org/files/jpegsrc.v8d.tar.gz" - end - - def test_version_ghc_style - assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-x86_64-apple-darwin.tar.bz2" - assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-i386-apple-darwin.tar.bz2" - end - - def test_pypy_version - assert_version_detected "1.4.1", "http://pypy.org/download/pypy-1.4.1-osx.tar.bz2" - end - - def test_openssl_version - assert_version_detected "0.9.8s", "http://www.openssl.org/source/openssl-0.9.8s.tar.gz" - end - - def test_xaw3d_version - assert_version_detected "1.5E", "ftp://ftp.visi.com/users/hawkeyd/X/Xaw3d-1.5E.tar.gz" - end - - def test_assimp_version - assert_version_detected "2.0.863", "http://downloads.sourceforge.net/project/assimp/assimp-2.0/assimp--2.0.863-sdk.zip" - end - - def test_cmucl_version - assert_version_detected "20c", "http://common-lisp.net/project/cmucl/downloads/release/20c/cmucl-20c-x86-darwin.tar.bz2" - end - - def test_fann_version - assert_version_detected "2.1.0beta", "http://downloads.sourceforge.net/project/fann/fann/2.1.0beta/fann-2.1.0beta.zip" - end - - def test_grads_version - assert_version_detected "2.0.1", "ftp://iges.org/grads/2.0/grads-2.0.1-bin-darwin9.8-intel.tar.gz" - end - - def test_haxe_version - assert_version_detected "2.08", "http://haxe.org/file/haxe-2.08-osx.tar.gz" - end - - def test_imap_version - assert_version_detected "2007f", "ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz" - end - - def test_suite3270_version - assert_version_detected "3.3.12ga7", "http://downloads.sourceforge.net/project/x3270/x3270/3.3.12ga7/suite3270-3.3.12ga7-src.tgz" - end - - def test_wwwoffle_version - assert_version_detected "2.9h", "http://www.gedanken.demon.co.uk/download-wwwoffle/wwwoffle-2.9h.tgz" - end - - def test_synergy_version - assert_version_detected "1.3.6p2", "http://synergy.googlecode.com/files/synergy-1.3.6p2-MacOSX-Universal.zip" - end - - def test_fontforge_version - assert_version_detected "20120731", "http://downloads.sourceforge.net/project/fontforge/fontforge-source/fontforge_full-20120731-b.tar.bz2" - end - - def test_ezlupdate_version - assert_version_detected "2011.10", "https://github.com/downloads/ezsystems/ezpublish-legacy/ezpublish_community_project-2011.10-with_ezc.tar.bz2" - end - - def test_aespipe_version_style - assert_version_detected "2.4c", - "http://loop-aes.sourceforge.net/aespipe/aespipe-v2.4c.tar.bz2" - end - - def test_win_style - assert_version_detected "0.9.17", - "http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.17-w32.zip" - assert_version_detected "1.29", - "http://ftpmirror.gnu.org/libidn/libidn-1.29-win64.zip" - end - - def test_with_arch - assert_version_detected "4.0.18-1", - "http://ftpmirror.gnu.org/mtools/mtools-4.0.18-1.i686.rpm" - assert_version_detected "5.5.7-5", - "http://ftpmirror.gnu.org/autogen/autogen-5.5.7-5.i386.rpm" - assert_version_detected "2.8", - "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x86.zip" - assert_version_detected "2.8", - "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x64.zip" - assert_version_detected "4.0.18", - "http://ftpmirror.gnu.org/mtools/mtools_4.0.18_i386.deb" - end - - def test_opam_version - assert_version_detected "2.18.3", - "https://opam.ocaml.org/archives/lablgtk.2.18.3+opam.tar.gz" - assert_version_detected "1.9", - "https://opam.ocaml.org/archives/sha.1.9+opam.tar.gz" - assert_version_detected "0.99.2", - "https://opam.ocaml.org/archives/ppx_tools.0.99.2+opam.tar.gz" - assert_version_detected "1.0.2", - "https://opam.ocaml.org/archives/easy-format.1.0.2+opam.tar.gz" - end - - def test_no_extension_version - assert_version_detected "1.8.12", "https://waf.io/waf-1.8.12" - assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" - assert_version_detected "0.9.1234", "https://my.datomic.com/downloads/free/0.9.1234" - assert_version_detected "0.9", "https://my.datomic.com/downloads/free/0.9.1t34" - assert_version_detected "1.2.3", "https://my.datomic.com/downloads/free/1.2.3" - end - - def test_dash_separated_version - assert_version_detected "6-20151227", "ftp://gcc.gnu.org/pub/gcc/snapshots/6-20151227/gcc-6-20151227.tar.bz2" - end - - def test_from_url - assert_version_detected "1.2.3", - "http://github.com/foo/bar.git", tag: "v1.2.3" - end -end - -class HeadVersionTests < Homebrew::TestCase - def test_create_head - v1 = Version.create("HEAD-abcdef") - v2 = Version.create("HEAD") - - assert_predicate v1, :head? - assert_predicate v2, :head? - end - - def test_commit_assigned - v = Version.create("HEAD-abcdef") - assert_equal "abcdef", v.commit - assert_equal "HEAD-abcdef", v.to_str - end - - def test_no_commit - v = Version.create("HEAD") - assert_nil v.commit - assert_equal "HEAD", v.to_str - end - - def test_update_commit - v1 = Version.create("HEAD-abcdef") - v2 = Version.create("HEAD") - - v1.update_commit("ffffff") - assert_equal "ffffff", v1.commit - assert_equal "HEAD-ffffff", v1.to_str - - v2.update_commit("ffffff") - assert_equal "ffffff", v2.commit - assert_equal "HEAD-ffffff", v2.to_str - end -end diff --git a/Library/Homebrew/test/test_x11_requirement.rb b/Library/Homebrew/test/test_x11_requirement.rb deleted file mode 100644 index b82a59e53..000000000 --- a/Library/Homebrew/test/test_x11_requirement.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 -- cgit v1.2.3 From e3be9c068bd2168d3bbf077a55abb15a87eaf5bd Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 24 Oct 2016 18:57:57 +0200 Subject: Update `.rubocop_todo.yml`. --- Library/Homebrew/.rubocop_todo.yml | 6 +++--- Library/Homebrew/dev-cmd/audit.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml index 867a61966..9e48c6792 100644 --- a/Library/Homebrew/.rubocop_todo.yml +++ b/Library/Homebrew/.rubocop_todo.yml @@ -21,7 +21,7 @@ Lint/HandleExceptions: - 'extend/pathname.rb' - 'formula.rb' - 'formula_versions.rb' - - 'test/test_ENV.rb' + - 'test/ENV_test.rb' # Offense count: 3 Lint/IneffectiveAccessModifier: @@ -51,7 +51,7 @@ Lint/RescueException: - 'postinstall.rb' - 'readall.rb' - 'test.rb' - - 'test/test_ENV.rb' + - 'test/ENV_test.rb' - 'utils/fork.rb' # Offense count: 1 @@ -114,7 +114,7 @@ Style/MultilineBlockChain: - 'dev-cmd/audit.rb' - 'dev-cmd/man.rb' - 'diagnostic.rb' - - 'test/test_patching.rb' + - 'test/patching_test.rb' # Offense count: 4 # Cop supports --auto-correct. diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index c7461fc5a..df3b5fafe 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -761,7 +761,7 @@ class FormulaAuditor bin_names.each do |name| ["system", "shell_output", "pipe_output"].each do |cmd| if text =~ /(def test|test do).*#{cmd}[\(\s]+['"]#{Regexp.escape name}[\s'"]/m - problem %(fully scope test #{cmd} calls e.g. #{cmd} "\#{bin}/#{name}") + problem %Q(fully scope test #{cmd} calls e.g. #{cmd} "\#{bin}/#{name}") end end end -- cgit v1.2.3 From 4efdbbde06bc8785870315f7a334694e59b33528 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 24 Oct 2016 23:11:23 +0200 Subject: Rename `fs_leak_log` to `fs_leak.log` and move to `tmp`. --- Library/Homebrew/dev-cmd/tests.rb | 2 +- Library/Homebrew/test/testing_env.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index df9a00a16..656225516 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -65,7 +65,7 @@ module Homebrew Homebrew.failed = !$?.success? - if (fs_leak_log = HOMEBREW_LIBRARY/"Homebrew/test/fs_leak_log").file? + if (fs_leak_log = HOMEBREW_LIBRARY_PATH/"tmp/fs_leak.log").file? fs_leak_log_content = fs_leak_log.read unless fs_leak_log_content.empty? opoo "File leak is detected" diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb index 3fbf3e4b5..d441b4f1c 100644 --- a/Library/Homebrew/test/testing_env.rb +++ b/Library/Homebrew/test/testing_env.rb @@ -43,7 +43,7 @@ module Homebrew module FSLeakLogger def self.included(klass) require "find" - @@log = File.open("#{__dir__}/fs_leak_log", "w") + @@log = File.open(HOMEBREW_LIBRARY_PATH/"tmp/fs_leak.log", "w") klass.make_my_diffs_pretty! end -- cgit v1.2.3 From 4db1317f38f5a55574854e7bf1dfe4379e807b4f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 24 Oct 2016 22:53:25 +0200 Subject: Move all remaining fixtures to `test/support/fixtures`. --- Library/Homebrew/cask/spec/spec_helper.rb | 6 +- Library/Homebrew/cask/test/test_helper.rb | 6 +- .../testball_bottle-0.1.el_capitan.bottle.tar.gz | 1 - .../testball_bottle-0.1.linux_x86_64.bottle.tar.gz | 1 - ...stball_bottle-0.1.macintosh_intel.bottle.tar.gz | 1 - .../testball_bottle-0.1.mavericks.bottle.tar.gz | 1 - ...testball_bottle-0.1.mountain_lion.bottle.tar.gz | 1 - .../testball_bottle-0.1.sierra.bottle.tar.gz | 1 - .../testball_bottle-0.1.yosemite.bottle.tar.gz | Bin 1379 -> 0 bytes .../Homebrew/test/fixtures/cask/AppWithBinary.zip | Bin 306 -> 0 bytes .../test/fixtures/cask/AppWithEmbeddedBinary.zip | Bin 618 -> 0 bytes Library/Homebrew/test/fixtures/cask/MyFancyApp.zip | Bin 304 -> 0 bytes Library/Homebrew/test/fixtures/cask/MyFancyPkg.zip | Bin 532 -> 0 bytes .../Homebrew/test/fixtures/cask/NestedApp.dmg.zip | Bin 2494 -> 0 bytes .../Homebrew/test/fixtures/cask/caffeine-suite.zip | Bin 3170 -> 0 bytes Library/Homebrew/test/fixtures/cask/caffeine.zip | Bin 1328 -> 0 bytes .../test/fixtures/cask/caffeines-subdir.zip | Bin 3240 -> 0 bytes Library/Homebrew/test/fixtures/cask/caffeines.zip | Bin 2796 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.7z | Bin 143 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.air | Bin 5934 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.bz2 | Bin 59 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.cab | Bin 95 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.dmg | Bin 25337 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.gz | Bin 47 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.lzma | Bin 41 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.pkg | Bin 516 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.rar | Bin 87 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.sit | Bin 236 -> 0 bytes .../Homebrew/test/fixtures/cask/container.tar.gz | Bin 154 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.xar | Bin 4679 -> 0 bytes Library/Homebrew/test/fixtures/cask/container.xz | Bin 76 -> 0 bytes .../test/fixtures/cask/empty_directory/.gitignore | 0 .../Homebrew/test/fixtures/cask/naked_executable | 2 - .../test/fixtures/cask/transmission-2.61.dmg | Bin 28490 -> 0 bytes Library/Homebrew/test/fixtures/receipt.json | 37 ---- Library/Homebrew/test/fixtures/receipt_old.json | 17 -- Library/Homebrew/test/fixtures/test.diff | 10 -- Library/Homebrew/test/fixtures/test.eps | 25 --- Library/Homebrew/test/fixtures/test.gif | Bin 43 -> 0 bytes Library/Homebrew/test/fixtures/test.ico | Bin 1182 -> 0 bytes Library/Homebrew/test/fixtures/test.jpg | Bin 288 -> 0 bytes Library/Homebrew/test/fixtures/test.m4a | Bin 1689 -> 0 bytes Library/Homebrew/test/fixtures/test.mp3 | Bin 360 -> 0 bytes Library/Homebrew/test/fixtures/test.pcap | Bin 1415 -> 0 bytes Library/Homebrew/test/fixtures/test.pdf | 24 --- Library/Homebrew/test/fixtures/test.png | Bin 82 -> 0 bytes Library/Homebrew/test/fixtures/test.ps | 6 - Library/Homebrew/test/fixtures/test.svg | 4 - Library/Homebrew/test/fixtures/test.tiff | Bin 3916 -> 0 bytes Library/Homebrew/test/fixtures/test.wav | Bin 1070 -> 0 bytes .../Homebrew/test/fixtures/updater_fixture.yaml | 64 ------- Library/Homebrew/test/helper/env.rb | 15 -- .../test/helper/integration_command_test_case.rb | 200 --------------------- Library/Homebrew/test/helper/shutup.rb | 24 --- Library/Homebrew/test/lib/config.rb | 40 ----- Library/Homebrew/test/lib/integration_mocks.rb | 17 -- Library/Homebrew/test/mach/a.out | Bin 25072 -> 0 bytes Library/Homebrew/test/mach/fat.bundle | Bin 16472 -> 0 bytes Library/Homebrew/test/mach/fat.dylib | Bin 16452 -> 0 bytes Library/Homebrew/test/mach/i386.bundle | Bin 4168 -> 0 bytes Library/Homebrew/test/mach/i386.dylib | Bin 4164 -> 0 bytes Library/Homebrew/test/mach/x86_64.bundle | Bin 4184 -> 0 bytes Library/Homebrew/test/mach/x86_64.dylib | Bin 4176 -> 0 bytes Library/Homebrew/test/patches/noop-a.diff | 10 -- Library/Homebrew/test/patches/noop-b.diff | 10 -- Library/Homebrew/test/patches/noop-c.diff | 9 - .../testball_bottle-0.1.el_capitan.bottle.tar.gz | 1 + .../testball_bottle-0.1.linux_x86_64.bottle.tar.gz | 1 + ...stball_bottle-0.1.macintosh_intel.bottle.tar.gz | 1 + .../testball_bottle-0.1.mavericks.bottle.tar.gz | 1 + ...testball_bottle-0.1.mountain_lion.bottle.tar.gz | 1 + .../testball_bottle-0.1.sierra.bottle.tar.gz | 1 + .../testball_bottle-0.1.yosemite.bottle.tar.gz | Bin 0 -> 1379 bytes .../test/support/fixtures/cask/AppWithBinary.zip | Bin 0 -> 306 bytes .../fixtures/cask/AppWithEmbeddedBinary.zip | Bin 0 -> 618 bytes .../test/support/fixtures/cask/MyFancyApp.zip | Bin 0 -> 304 bytes .../test/support/fixtures/cask/MyFancyPkg.zip | Bin 0 -> 532 bytes .../test/support/fixtures/cask/NestedApp.dmg.zip | Bin 0 -> 2494 bytes .../test/support/fixtures/cask/caffeine-suite.zip | Bin 0 -> 3170 bytes .../test/support/fixtures/cask/caffeine.zip | Bin 0 -> 1328 bytes .../support/fixtures/cask/caffeines-subdir.zip | Bin 0 -> 3240 bytes .../test/support/fixtures/cask/caffeines.zip | Bin 0 -> 2796 bytes .../test/support/fixtures/cask/container.7z | Bin 0 -> 143 bytes .../test/support/fixtures/cask/container.air | Bin 0 -> 5934 bytes .../test/support/fixtures/cask/container.bz2 | Bin 0 -> 59 bytes .../test/support/fixtures/cask/container.cab | Bin 0 -> 95 bytes .../test/support/fixtures/cask/container.dmg | Bin 0 -> 25337 bytes .../test/support/fixtures/cask/container.gz | Bin 0 -> 47 bytes .../test/support/fixtures/cask/container.lzma | Bin 0 -> 41 bytes .../test/support/fixtures/cask/container.pkg | Bin 0 -> 516 bytes .../test/support/fixtures/cask/container.rar | Bin 0 -> 87 bytes .../test/support/fixtures/cask/container.sit | Bin 0 -> 236 bytes .../test/support/fixtures/cask/container.tar.gz | Bin 0 -> 154 bytes .../test/support/fixtures/cask/container.xar | Bin 0 -> 4679 bytes .../test/support/fixtures/cask/container.xz | Bin 0 -> 76 bytes .../fixtures/cask/empty_directory/.gitignore | 0 .../test/support/fixtures/cask/naked_executable | 2 + .../support/fixtures/cask/transmission-2.61.dmg | Bin 0 -> 28490 bytes Library/Homebrew/test/support/fixtures/mach/a.out | Bin 0 -> 25072 bytes .../Homebrew/test/support/fixtures/mach/fat.bundle | Bin 0 -> 16472 bytes .../Homebrew/test/support/fixtures/mach/fat.dylib | Bin 0 -> 16452 bytes .../test/support/fixtures/mach/i386.bundle | Bin 0 -> 4168 bytes .../Homebrew/test/support/fixtures/mach/i386.dylib | Bin 0 -> 4164 bytes .../test/support/fixtures/mach/x86_64.bundle | Bin 0 -> 4184 bytes .../test/support/fixtures/mach/x86_64.dylib | Bin 0 -> 4176 bytes .../test/support/fixtures/patches/noop-a.diff | 10 ++ .../test/support/fixtures/patches/noop-b.diff | 10 ++ .../test/support/fixtures/patches/noop-c.diff | 9 + .../Homebrew/test/support/fixtures/receipt.json | 37 ++++ .../test/support/fixtures/receipt_old.json | 17 ++ .../fixtures/tarballs/testball-0.1-patches.tgz | Bin 0 -> 368 bytes .../support/fixtures/tarballs/testball-0.1.tbz | Bin 0 -> 1318 bytes .../support/fixtures/tarballs/testbottest-0.1.tbz | Bin 0 -> 548 bytes Library/Homebrew/test/support/fixtures/test.diff | 10 ++ Library/Homebrew/test/support/fixtures/test.eps | 25 +++ Library/Homebrew/test/support/fixtures/test.gif | Bin 0 -> 43 bytes Library/Homebrew/test/support/fixtures/test.ico | Bin 0 -> 1182 bytes Library/Homebrew/test/support/fixtures/test.jpg | Bin 0 -> 288 bytes Library/Homebrew/test/support/fixtures/test.m4a | Bin 0 -> 1689 bytes Library/Homebrew/test/support/fixtures/test.mp3 | Bin 0 -> 360 bytes Library/Homebrew/test/support/fixtures/test.pcap | Bin 0 -> 1415 bytes Library/Homebrew/test/support/fixtures/test.pdf | 24 +++ Library/Homebrew/test/support/fixtures/test.png | Bin 0 -> 82 bytes Library/Homebrew/test/support/fixtures/test.ps | 6 + Library/Homebrew/test/support/fixtures/test.svg | 4 + Library/Homebrew/test/support/fixtures/test.tiff | Bin 0 -> 3916 bytes Library/Homebrew/test/support/fixtures/test.wav | Bin 0 -> 1070 bytes Library/Homebrew/test/support/fixtures/testball.rb | 15 ++ .../test/support/fixtures/testball_bottle.rb | 20 +++ .../Homebrew/test/support/fixtures/testbottest.rb | 14 ++ .../test/support/fixtures/updater_fixture.yaml | 64 +++++++ Library/Homebrew/test/support/helper/env.rb | 15 ++ .../helper/integration_command_test_case.rb | 200 +++++++++++++++++++++ Library/Homebrew/test/support/helper/shutup.rb | 24 +++ Library/Homebrew/test/support/lib/config.rb | 40 +++++ .../Homebrew/test/support/lib/integration_mocks.rb | 17 ++ .../test/tarballs/testball-0.1-patches.tgz | Bin 368 -> 0 bytes Library/Homebrew/test/tarballs/testball-0.1.tbz | Bin 1318 -> 0 bytes Library/Homebrew/test/tarballs/testbottest-0.1.tbz | Bin 548 -> 0 bytes Library/Homebrew/test/test/ENV_test.rb | 3 +- Library/Homebrew/test/test/analytics_test.rb | 3 +- Library/Homebrew/test/test/bottle_test.rb | 3 +- Library/Homebrew/test/test/bundle_test.rb | 3 +- Library/Homebrew/test/test/cache_formula_test.rb | 3 +- Library/Homebrew/test/test/cache_test.rb | 3 +- Library/Homebrew/test/test/cask_test.rb | 3 +- Library/Homebrew/test/test/cat_test.rb | 3 +- Library/Homebrew/test/test/cellar_formula_test.rb | 3 +- Library/Homebrew/test/test/cellar_test.rb | 3 +- .../test/test/checksum_verification_test.rb | 2 +- Library/Homebrew/test/test/cleaner_test.rb | 4 +- Library/Homebrew/test/test/cleanup_test.rb | 5 +- Library/Homebrew/test/test/command_test.rb | 3 +- Library/Homebrew/test/test/commands_test.rb | 3 +- Library/Homebrew/test/test/config_test.rb | 3 +- Library/Homebrew/test/test/create_test.rb | 5 +- Library/Homebrew/test/test/custom_command_test.rb | 3 +- Library/Homebrew/test/test/deps_test.rb | 3 +- Library/Homebrew/test/test/desc_test.rb | 3 +- Library/Homebrew/test/test/doctor_test.rb | 3 +- Library/Homebrew/test/test/edit_test.rb | 3 +- Library/Homebrew/test/test/fetch_test.rb | 3 +- .../test/test/formula_installer_bottle_test.rb | 4 +- .../Homebrew/test/test/formula_installer_test.rb | 4 +- Library/Homebrew/test/test/formula_test.rb | 2 +- Library/Homebrew/test/test/formulary_test.rb | 4 +- Library/Homebrew/test/test/help_test.rb | 3 +- Library/Homebrew/test/test/home_test.rb | 3 +- Library/Homebrew/test/test/info_test.rb | 3 +- Library/Homebrew/test/test/install_test.rb | 3 +- Library/Homebrew/test/test/irb_test.rb | 3 +- Library/Homebrew/test/test/leaves_test.rb | 3 +- Library/Homebrew/test/test/link_test.rb | 3 +- Library/Homebrew/test/test/linkapps_test.rb | 3 +- Library/Homebrew/test/test/list_test.rb | 3 +- Library/Homebrew/test/test/log_formula_test.rb | 3 +- Library/Homebrew/test/test/log_test.rb | 3 +- Library/Homebrew/test/test/migrate_test.rb | 3 +- Library/Homebrew/test/test/migrator_test.rb | 2 +- Library/Homebrew/test/test/missing_test.rb | 3 +- Library/Homebrew/test/test/options_test.rb | 3 +- Library/Homebrew/test/test/os/mac/mach_test.rb | 4 +- Library/Homebrew/test/test/outdated_test.rb | 3 +- Library/Homebrew/test/test/patching_test.rb | 12 +- Library/Homebrew/test/test/pin_unpin_test.rb | 3 +- Library/Homebrew/test/test/prefix_formula_test.rb | 3 +- Library/Homebrew/test/test/prefix_test.rb | 3 +- Library/Homebrew/test/test/prune_test.rb | 3 +- Library/Homebrew/test/test/pull_offline_test.rb | 3 +- Library/Homebrew/test/test/pull_test.rb | 3 +- Library/Homebrew/test/test/readall_test.rb | 3 +- .../Homebrew/test/test/reinstall_pinned_test.rb | 3 +- Library/Homebrew/test/test/reinstall_test.rb | 3 +- Library/Homebrew/test/test/repository_test.rb | 3 +- Library/Homebrew/test/test/search_test.rb | 3 +- Library/Homebrew/test/test/services_test.rb | 3 +- Library/Homebrew/test/test/sh_test.rb | 3 +- Library/Homebrew/test/test/switch_test.rb | 3 +- Library/Homebrew/test/test/tab_test.rb | 2 +- Library/Homebrew/test/test/tap_new_test.rb | 3 +- Library/Homebrew/test/test/tap_test.rb | 3 +- Library/Homebrew/test/test/test_formula_test.rb | 5 +- Library/Homebrew/test/test/uninstall_test.rb | 2 +- Library/Homebrew/test/test/unlink_test.rb | 3 +- Library/Homebrew/test/test/unlinkapps_test.rb | 3 +- Library/Homebrew/test/test/unpack_test.rb | 3 +- Library/Homebrew/test/test/upgrade_test.rb | 3 +- Library/Homebrew/test/test/uses_test.rb | 3 +- Library/Homebrew/test/test/version_test.rb | 3 +- Library/Homebrew/test/testball.rb | 15 -- Library/Homebrew/test/testball_bottle.rb | 20 --- Library/Homebrew/test/testbottest.rb | 14 -- Library/Homebrew/test/testing_env.rb | 17 +- 213 files changed, 725 insertions(+), 667 deletions(-) delete mode 120000 Library/Homebrew/test/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz delete mode 120000 Library/Homebrew/test/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz delete mode 120000 Library/Homebrew/test/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz delete mode 120000 Library/Homebrew/test/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz delete mode 120000 Library/Homebrew/test/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz delete mode 120000 Library/Homebrew/test/bottles/testball_bottle-0.1.sierra.bottle.tar.gz delete mode 100644 Library/Homebrew/test/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz delete mode 100644 Library/Homebrew/test/fixtures/cask/AppWithBinary.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/AppWithEmbeddedBinary.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/MyFancyApp.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/MyFancyPkg.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/NestedApp.dmg.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/caffeine-suite.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/caffeine.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/caffeines-subdir.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/caffeines.zip delete mode 100644 Library/Homebrew/test/fixtures/cask/container.7z delete mode 100644 Library/Homebrew/test/fixtures/cask/container.air delete mode 100755 Library/Homebrew/test/fixtures/cask/container.bz2 delete mode 100644 Library/Homebrew/test/fixtures/cask/container.cab delete mode 100644 Library/Homebrew/test/fixtures/cask/container.dmg delete mode 100755 Library/Homebrew/test/fixtures/cask/container.gz delete mode 100755 Library/Homebrew/test/fixtures/cask/container.lzma delete mode 100644 Library/Homebrew/test/fixtures/cask/container.pkg delete mode 100644 Library/Homebrew/test/fixtures/cask/container.rar delete mode 100755 Library/Homebrew/test/fixtures/cask/container.sit delete mode 100644 Library/Homebrew/test/fixtures/cask/container.tar.gz delete mode 100644 Library/Homebrew/test/fixtures/cask/container.xar delete mode 100755 Library/Homebrew/test/fixtures/cask/container.xz delete mode 100644 Library/Homebrew/test/fixtures/cask/empty_directory/.gitignore delete mode 100755 Library/Homebrew/test/fixtures/cask/naked_executable delete mode 100644 Library/Homebrew/test/fixtures/cask/transmission-2.61.dmg delete mode 100644 Library/Homebrew/test/fixtures/receipt.json delete mode 100644 Library/Homebrew/test/fixtures/receipt_old.json delete mode 100644 Library/Homebrew/test/fixtures/test.diff delete mode 100644 Library/Homebrew/test/fixtures/test.eps delete mode 100644 Library/Homebrew/test/fixtures/test.gif delete mode 100644 Library/Homebrew/test/fixtures/test.ico delete mode 100644 Library/Homebrew/test/fixtures/test.jpg delete mode 100644 Library/Homebrew/test/fixtures/test.m4a delete mode 100644 Library/Homebrew/test/fixtures/test.mp3 delete mode 100644 Library/Homebrew/test/fixtures/test.pcap delete mode 100644 Library/Homebrew/test/fixtures/test.pdf delete mode 100644 Library/Homebrew/test/fixtures/test.png delete mode 100644 Library/Homebrew/test/fixtures/test.ps delete mode 100644 Library/Homebrew/test/fixtures/test.svg delete mode 100644 Library/Homebrew/test/fixtures/test.tiff delete mode 100644 Library/Homebrew/test/fixtures/test.wav delete mode 100644 Library/Homebrew/test/fixtures/updater_fixture.yaml delete mode 100644 Library/Homebrew/test/helper/env.rb delete mode 100644 Library/Homebrew/test/helper/integration_command_test_case.rb delete mode 100644 Library/Homebrew/test/helper/shutup.rb delete mode 100644 Library/Homebrew/test/lib/config.rb delete mode 100644 Library/Homebrew/test/lib/integration_mocks.rb delete mode 100755 Library/Homebrew/test/mach/a.out delete mode 100644 Library/Homebrew/test/mach/fat.bundle delete mode 100644 Library/Homebrew/test/mach/fat.dylib delete mode 100644 Library/Homebrew/test/mach/i386.bundle delete mode 100644 Library/Homebrew/test/mach/i386.dylib delete mode 100644 Library/Homebrew/test/mach/x86_64.bundle delete mode 100644 Library/Homebrew/test/mach/x86_64.dylib delete mode 100644 Library/Homebrew/test/patches/noop-a.diff delete mode 100644 Library/Homebrew/test/patches/noop-b.diff delete mode 100644 Library/Homebrew/test/patches/noop-c.diff create mode 120000 Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz create mode 120000 Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz create mode 120000 Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz create mode 120000 Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz create mode 120000 Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz create mode 120000 Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.sierra.bottle.tar.gz create mode 100644 Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz create mode 100644 Library/Homebrew/test/support/fixtures/cask/AppWithBinary.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/AppWithEmbeddedBinary.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/MyFancyApp.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/MyFancyPkg.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/NestedApp.dmg.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/caffeine-suite.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/caffeine.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/caffeines-subdir.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/caffeines.zip create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.7z create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.air create mode 100755 Library/Homebrew/test/support/fixtures/cask/container.bz2 create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.cab create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.dmg create mode 100755 Library/Homebrew/test/support/fixtures/cask/container.gz create mode 100755 Library/Homebrew/test/support/fixtures/cask/container.lzma create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.pkg create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.rar create mode 100755 Library/Homebrew/test/support/fixtures/cask/container.sit create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.tar.gz create mode 100644 Library/Homebrew/test/support/fixtures/cask/container.xar create mode 100755 Library/Homebrew/test/support/fixtures/cask/container.xz create mode 100644 Library/Homebrew/test/support/fixtures/cask/empty_directory/.gitignore create mode 100755 Library/Homebrew/test/support/fixtures/cask/naked_executable create mode 100644 Library/Homebrew/test/support/fixtures/cask/transmission-2.61.dmg create mode 100755 Library/Homebrew/test/support/fixtures/mach/a.out create mode 100644 Library/Homebrew/test/support/fixtures/mach/fat.bundle create mode 100644 Library/Homebrew/test/support/fixtures/mach/fat.dylib create mode 100644 Library/Homebrew/test/support/fixtures/mach/i386.bundle create mode 100644 Library/Homebrew/test/support/fixtures/mach/i386.dylib create mode 100644 Library/Homebrew/test/support/fixtures/mach/x86_64.bundle create mode 100644 Library/Homebrew/test/support/fixtures/mach/x86_64.dylib create mode 100644 Library/Homebrew/test/support/fixtures/patches/noop-a.diff create mode 100644 Library/Homebrew/test/support/fixtures/patches/noop-b.diff create mode 100644 Library/Homebrew/test/support/fixtures/patches/noop-c.diff create mode 100644 Library/Homebrew/test/support/fixtures/receipt.json create mode 100644 Library/Homebrew/test/support/fixtures/receipt_old.json create mode 100644 Library/Homebrew/test/support/fixtures/tarballs/testball-0.1-patches.tgz create mode 100644 Library/Homebrew/test/support/fixtures/tarballs/testball-0.1.tbz create mode 100644 Library/Homebrew/test/support/fixtures/tarballs/testbottest-0.1.tbz create mode 100644 Library/Homebrew/test/support/fixtures/test.diff create mode 100644 Library/Homebrew/test/support/fixtures/test.eps create mode 100644 Library/Homebrew/test/support/fixtures/test.gif create mode 100644 Library/Homebrew/test/support/fixtures/test.ico create mode 100644 Library/Homebrew/test/support/fixtures/test.jpg create mode 100644 Library/Homebrew/test/support/fixtures/test.m4a create mode 100644 Library/Homebrew/test/support/fixtures/test.mp3 create mode 100644 Library/Homebrew/test/support/fixtures/test.pcap create mode 100644 Library/Homebrew/test/support/fixtures/test.pdf create mode 100644 Library/Homebrew/test/support/fixtures/test.png create mode 100644 Library/Homebrew/test/support/fixtures/test.ps create mode 100644 Library/Homebrew/test/support/fixtures/test.svg create mode 100644 Library/Homebrew/test/support/fixtures/test.tiff create mode 100644 Library/Homebrew/test/support/fixtures/test.wav create mode 100644 Library/Homebrew/test/support/fixtures/testball.rb create mode 100644 Library/Homebrew/test/support/fixtures/testball_bottle.rb create mode 100644 Library/Homebrew/test/support/fixtures/testbottest.rb create mode 100644 Library/Homebrew/test/support/fixtures/updater_fixture.yaml create mode 100644 Library/Homebrew/test/support/helper/env.rb create mode 100644 Library/Homebrew/test/support/helper/integration_command_test_case.rb create mode 100644 Library/Homebrew/test/support/helper/shutup.rb create mode 100644 Library/Homebrew/test/support/lib/config.rb create mode 100644 Library/Homebrew/test/support/lib/integration_mocks.rb delete mode 100644 Library/Homebrew/test/tarballs/testball-0.1-patches.tgz delete mode 100644 Library/Homebrew/test/tarballs/testball-0.1.tbz delete mode 100644 Library/Homebrew/test/tarballs/testbottest-0.1.tbz delete mode 100644 Library/Homebrew/test/testball.rb delete mode 100644 Library/Homebrew/test/testball_bottle.rb delete mode 100644 Library/Homebrew/test/testbottest.rb (limited to 'Library') diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb index 7e72a2cee..458fe00f4 100644 --- a/Library/Homebrew/cask/spec/spec_helper.rb +++ b/Library/Homebrew/cask/spec/spec_helper.rb @@ -8,15 +8,15 @@ end # add Homebrew to load path $LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew")) -$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew/test/lib")) +$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew/test/support/lib")) require "global" # add Homebrew-Cask to load path $LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s) -require "test/helper/env" -require "test/helper/shutup" +require "test/support/helper/env" +require "test/support/helper/shutup" Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "*.rb")).each(&method(:require)) diff --git a/Library/Homebrew/cask/test/test_helper.rb b/Library/Homebrew/cask/test/test_helper.rb index 73459cb25..275ede304 100644 --- a/Library/Homebrew/cask/test/test_helper.rb +++ b/Library/Homebrew/cask/test/test_helper.rb @@ -6,15 +6,15 @@ require "simplecov" if ENV["HOMEBREW_TESTS_COVERAGE"] # add Homebrew to load path $LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew")) -$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew/test/lib")) +$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew/test/support/lib")) require "global" # add Homebrew-Cask to load path $LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s) -require "test/helper/env" -require "test/helper/shutup" +require "test/support/helper/env" +require "test/support/helper/shutup" include Test::Helper::Env include Test::Helper::Shutup diff --git a/Library/Homebrew/test/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz b/Library/Homebrew/test/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz deleted file mode 120000 index 3e989830b..000000000 --- a/Library/Homebrew/test/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz +++ /dev/null @@ -1 +0,0 @@ -testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz b/Library/Homebrew/test/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz deleted file mode 120000 index 3e989830b..000000000 --- a/Library/Homebrew/test/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz +++ /dev/null @@ -1 +0,0 @@ -testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz b/Library/Homebrew/test/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz deleted file mode 120000 index 3e989830b..000000000 --- a/Library/Homebrew/test/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz +++ /dev/null @@ -1 +0,0 @@ -testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz b/Library/Homebrew/test/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz deleted file mode 120000 index 3e989830b..000000000 --- a/Library/Homebrew/test/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz +++ /dev/null @@ -1 +0,0 @@ -testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz b/Library/Homebrew/test/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz deleted file mode 120000 index 3e989830b..000000000 --- a/Library/Homebrew/test/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz +++ /dev/null @@ -1 +0,0 @@ -testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/bottles/testball_bottle-0.1.sierra.bottle.tar.gz b/Library/Homebrew/test/bottles/testball_bottle-0.1.sierra.bottle.tar.gz deleted file mode 120000 index 3e989830b..000000000 --- a/Library/Homebrew/test/bottles/testball_bottle-0.1.sierra.bottle.tar.gz +++ /dev/null @@ -1 +0,0 @@ -testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz b/Library/Homebrew/test/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz deleted file mode 100644 index d88838a94..000000000 Binary files a/Library/Homebrew/test/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/AppWithBinary.zip b/Library/Homebrew/test/fixtures/cask/AppWithBinary.zip deleted file mode 100644 index 4a5b318ba..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/AppWithBinary.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/AppWithEmbeddedBinary.zip b/Library/Homebrew/test/fixtures/cask/AppWithEmbeddedBinary.zip deleted file mode 100644 index 7c708038c..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/AppWithEmbeddedBinary.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/MyFancyApp.zip b/Library/Homebrew/test/fixtures/cask/MyFancyApp.zip deleted file mode 100644 index ba09ee681..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/MyFancyApp.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/MyFancyPkg.zip b/Library/Homebrew/test/fixtures/cask/MyFancyPkg.zip deleted file mode 100644 index ec4f97f07..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/MyFancyPkg.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/NestedApp.dmg.zip b/Library/Homebrew/test/fixtures/cask/NestedApp.dmg.zip deleted file mode 100644 index ae6686c7e..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/NestedApp.dmg.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/caffeine-suite.zip b/Library/Homebrew/test/fixtures/cask/caffeine-suite.zip deleted file mode 100644 index c38f771ae..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/caffeine-suite.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/caffeine.zip b/Library/Homebrew/test/fixtures/cask/caffeine.zip deleted file mode 100644 index 99d61bbfb..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/caffeine.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/caffeines-subdir.zip b/Library/Homebrew/test/fixtures/cask/caffeines-subdir.zip deleted file mode 100644 index ce5064d09..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/caffeines-subdir.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/caffeines.zip b/Library/Homebrew/test/fixtures/cask/caffeines.zip deleted file mode 100644 index 372fcc522..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/caffeines.zip and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.7z b/Library/Homebrew/test/fixtures/cask/container.7z deleted file mode 100644 index 30dbe24f7..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.7z and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.air b/Library/Homebrew/test/fixtures/cask/container.air deleted file mode 100644 index 64005aea3..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.air and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.bz2 b/Library/Homebrew/test/fixtures/cask/container.bz2 deleted file mode 100755 index 6ec60f31f..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.bz2 and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.cab b/Library/Homebrew/test/fixtures/cask/container.cab deleted file mode 100644 index edc741aa1..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.cab and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.dmg b/Library/Homebrew/test/fixtures/cask/container.dmg deleted file mode 100644 index 3b3cbf51c..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.dmg and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.gz b/Library/Homebrew/test/fixtures/cask/container.gz deleted file mode 100755 index 67ede6b96..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.gz and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.lzma b/Library/Homebrew/test/fixtures/cask/container.lzma deleted file mode 100755 index 2ff7ccee7..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.lzma and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.pkg b/Library/Homebrew/test/fixtures/cask/container.pkg deleted file mode 100644 index 274f27e7a..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.pkg and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.rar b/Library/Homebrew/test/fixtures/cask/container.rar deleted file mode 100644 index 7477c3bb4..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.rar and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.sit b/Library/Homebrew/test/fixtures/cask/container.sit deleted file mode 100755 index 3e29d21dc..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.sit and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.tar.gz b/Library/Homebrew/test/fixtures/cask/container.tar.gz deleted file mode 100644 index c464fb413..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.tar.gz and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.xar b/Library/Homebrew/test/fixtures/cask/container.xar deleted file mode 100644 index 563a5ba1e..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.xar and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/container.xz b/Library/Homebrew/test/fixtures/cask/container.xz deleted file mode 100755 index 74db22090..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/container.xz and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/cask/empty_directory/.gitignore b/Library/Homebrew/test/fixtures/cask/empty_directory/.gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/Library/Homebrew/test/fixtures/cask/naked_executable b/Library/Homebrew/test/fixtures/cask/naked_executable deleted file mode 100755 index 039e4d006..000000000 --- a/Library/Homebrew/test/fixtures/cask/naked_executable +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -exit 0 diff --git a/Library/Homebrew/test/fixtures/cask/transmission-2.61.dmg b/Library/Homebrew/test/fixtures/cask/transmission-2.61.dmg deleted file mode 100644 index e72afe027..000000000 Binary files a/Library/Homebrew/test/fixtures/cask/transmission-2.61.dmg and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/receipt.json b/Library/Homebrew/test/fixtures/receipt.json deleted file mode 100644 index 404251026..000000000 --- a/Library/Homebrew/test/fixtures/receipt.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "used_options": [ - "--with-foo", - "--without-bar" - ], - "unused_options": [ - "--with-baz", - "--without-qux" - ], - "built_as_bottle": false, - "poured_from_bottle": true, - "changed_files": [ - "INSTALL_RECEIPT.json", - "bin/foo" - ], - "time": 1403827774, - "HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", - "alias_path": "/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/test-formula", - "stdlib": "libcxx", - "compiler": "clang", - "runtime_dependencies": [ - { - "full_name": "foo", - "version": "1.0" - } - ], - "source": { - "path": "/usr/local/Library/Taps/hombrew/homebrew-core/Formula/foo.rb", - "tap": "homebrew/core", - "spec": "stable", - "versions": { - "stable": "2.14", - "devel": "2.15", - "head": "HEAD-0000000" - } - } -} diff --git a/Library/Homebrew/test/fixtures/receipt_old.json b/Library/Homebrew/test/fixtures/receipt_old.json deleted file mode 100644 index 955d56b47..000000000 --- a/Library/Homebrew/test/fixtures/receipt_old.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "used_options": [ - "--with-foo", - "--without-bar" - ], - "unused_options": [ - "--with-baz", - "--without-qux" - ], - "built_as_bottle": false, - "poured_from_bottle": true, - "tapped_from": "Homebrew/homebrew", - "time": 1403827774, - "HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", - "stdlib": "libcxx", - "compiler": "clang" -} diff --git a/Library/Homebrew/test/fixtures/test.diff b/Library/Homebrew/test/fixtures/test.diff deleted file mode 100644 index 7b57f8fc9..000000000 --- a/Library/Homebrew/test/fixtures/test.diff +++ /dev/null @@ -1,10 +0,0 @@ -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/fixtures/test.eps b/Library/Homebrew/test/fixtures/test.eps deleted file mode 100644 index 2832613e7..000000000 --- a/Library/Homebrew/test/fixtures/test.eps +++ /dev/null @@ -1,25 +0,0 @@ -%!PS-Adobe-2.0 EPSF-2.0 -%%BoundingBox: 73 499 211 513 -%%HiResBoundingBox: 73.000000 499.500000 211.000000 512.500000 -%%EndComments -% EPSF created by ps2eps 1.68 -%%BeginProlog -save -countdictstack -mark -newpath -/showpage {} def -/setpagedevice {pop} def -%%EndProlog -%%Page 1 1 -/Courier -20 selectfont -72 500 moveto -(Hello World!) show -showpage -%%Trailer -cleartomark -countdictstack -exch sub { end } repeat -restore -%%EOF diff --git a/Library/Homebrew/test/fixtures/test.gif b/Library/Homebrew/test/fixtures/test.gif deleted file mode 100644 index 0589d2082..000000000 Binary files a/Library/Homebrew/test/fixtures/test.gif and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.ico b/Library/Homebrew/test/fixtures/test.ico deleted file mode 100644 index 714f3478d..000000000 Binary files a/Library/Homebrew/test/fixtures/test.ico and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.jpg b/Library/Homebrew/test/fixtures/test.jpg deleted file mode 100644 index 1adaa50a6..000000000 Binary files a/Library/Homebrew/test/fixtures/test.jpg and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.m4a b/Library/Homebrew/test/fixtures/test.m4a deleted file mode 100644 index 7650fc482..000000000 Binary files a/Library/Homebrew/test/fixtures/test.m4a and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.mp3 b/Library/Homebrew/test/fixtures/test.mp3 deleted file mode 100644 index a01322383..000000000 Binary files a/Library/Homebrew/test/fixtures/test.mp3 and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.pcap b/Library/Homebrew/test/fixtures/test.pcap deleted file mode 100644 index 671197e8a..000000000 Binary files a/Library/Homebrew/test/fixtures/test.pcap and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.pdf b/Library/Homebrew/test/fixtures/test.pdf deleted file mode 100644 index 1f2ac6390..000000000 --- a/Library/Homebrew/test/fixtures/test.pdf +++ /dev/null @@ -1,24 +0,0 @@ -%PDF-1.6 -%μῦ -1 0 obj<>endobj -2 0 obj<>endobj -3 0 obj<>endobj -4 0 obj<>>>endobj -5 0 obj<>endobj -6 0 obj<>stream -BT /F1 24 Tf 175 720 Td (Homebrew test.)Tj ET -endstream -endobj -xref -0 7 -0000000000 65536 f -0000000016 00000 n -0000000059 00000 n -0000000108 00000 n -0000000202 00000 n -0000000238 00000 n -0000000299 00000 n -trailer<> -startxref -390 -%%EOF diff --git a/Library/Homebrew/test/fixtures/test.png b/Library/Homebrew/test/fixtures/test.png deleted file mode 100644 index 18d7a15a9..000000000 Binary files a/Library/Homebrew/test/fixtures/test.png and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.ps b/Library/Homebrew/test/fixtures/test.ps deleted file mode 100644 index 68aae0621..000000000 --- a/Library/Homebrew/test/fixtures/test.ps +++ /dev/null @@ -1,6 +0,0 @@ -%!PS -/Courier -20 selectfont -72 500 moveto -(Hello World!) show -showpage diff --git a/Library/Homebrew/test/fixtures/test.svg b/Library/Homebrew/test/fixtures/test.svg deleted file mode 100644 index 1869e624c..000000000 --- a/Library/Homebrew/test/fixtures/test.svg +++ /dev/null @@ -1,4 +0,0 @@ - -Homebrew - - diff --git a/Library/Homebrew/test/fixtures/test.tiff b/Library/Homebrew/test/fixtures/test.tiff deleted file mode 100644 index ae756b264..000000000 Binary files a/Library/Homebrew/test/fixtures/test.tiff and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/test.wav b/Library/Homebrew/test/fixtures/test.wav deleted file mode 100644 index c846b8a9b..000000000 Binary files a/Library/Homebrew/test/fixtures/test.wav and /dev/null differ diff --git a/Library/Homebrew/test/fixtures/updater_fixture.yaml b/Library/Homebrew/test/fixtures/updater_fixture.yaml deleted file mode 100644 index 06a6a0c7f..000000000 --- a/Library/Homebrew/test/fixtures/updater_fixture.yaml +++ /dev/null @@ -1,64 +0,0 @@ -update_git_diff_output_without_formulae_changes: | - M Library/Homebrew/ARGV+yeast.rb - A Library/Homebrew/beer_events.rb - A Library/Homebrew/hardware.rb - D Library/Homebrew/hw.model.c - M README - M bin/brew -update_git_diff_output_with_formulae_changes: | - M Library/Contributions/brew_bash_completion.sh - A Formula/antiword.rb - A Formula/bash-completion.rb - A Formula/ddrescue.rb - A Formula/dict.rb - A Formula/lua.rb - M Formula/xar.rb - M Formula/yajl.rb - M Library/Homebrew/ARGV+yeast.rb - M Library/Homebrew/beer_events.rb - M Library/Homebrew/hardware.rb - M Library/Homebrew/hw.model.c - M Library/Homebrew/hw.model.rb - M Library/Homebrew/pathname+yeast.rb - M Library/Homebrew/unittest.rb - M Library/Homebrew/utils.rb - M README - M bin/brew -update_git_diff_output_with_removed_formulae: | - A Formula/flac123.rb - M Formula/gdal.rb - M Formula/grass.rb - M Formula/json_spirit.rb - A Formula/libbson.rb - D Formula/libgsasl.rb -update_git_diff_output_with_changed_filetype: | - A Library/ENV/4.3/ant - T Library/ENV/4.3/bsdmake - M Library/ENV/4.3/make - M Formula/elixir.rb - A Formula/libbson.rb - D Formula/libgsasl.rb - M Library/Homebrew/cmd/update.rb - M SUPPORTERS.md -update_git_diff_output_with_formula_rename: | - R100 Formula/cv.rb Formula/progress.rb -update_git_diff_output_with_restructured_tap: | - R100 git.rb Formula/git.rb - R100 lua.rb Formula/lua.rb -update_git_diff_output_with_formula_rename_and_restructuring: | - R100 xchat.rb Formula/xchat2.rb -update_git_diff_simulate_homebrew_php_restructuring: | - R100 Formula/git.rb Abstract/git.rb - R100 Formula/lua.rb Abstract/lua.rb -update_git_diff_output_with_tap_formulae_changes: | - M Rakefile - M README.md - M Requirements/some_requirement.rb - D another_ruby_file.rb - A a_ruby_file.rb - A CONTRIBUTING.md - M Formula/git.rb - A Formula/lua.rb - M lib/not_a_formula.rb - A lib/not_a_formula2.rb - D lib/not_a_formula3.rb diff --git a/Library/Homebrew/test/helper/env.rb b/Library/Homebrew/test/helper/env.rb deleted file mode 100644 index 904a1d4c7..000000000 --- a/Library/Homebrew/test/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/helper/integration_command_test_case.rb b/Library/Homebrew/test/helper/integration_command_test_case.rb deleted file mode 100644 index 2f137e14a..000000000 --- a/Library/Homebrew/test/helper/integration_command_test_case.rb +++ /dev/null @@ -1,200 +0,0 @@ -require "bundler" -require "testing_env" -require "fileutils" -require "pathname" -require "formula" - -class IntegrationCommandTestCase < Homebrew::TestCase - def setup - @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/"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" - end - - def needs_macos - skip "Not on MacOS" unless OS.mac? - end - - def cmd_id_from_args(args) - args_pretty = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@") - test_pretty = "#{self.class.name}\##{name}.#{@cmd_id_index += 1}" - "[#{test_pretty}] brew #{args_pretty}" - 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/lib - -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 << "-rintegration_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 - - 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 - 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 - 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 - end - - def setup_test_formula(name, content = nil) - formula_path = CoreTap.new.formula_dir/"#{name}.rb" - - case name - when /^testball/ - content = <<-EOS.undent - desc "Some test" - homepage "https://example.com/#{name}" - url "file://#{File.expand_path("../..", __FILE__)}/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 \\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 - - formula_path.write <<-EOS.undent - class #{Formulary.class_s(name)} < Formula - #{content} - end - EOS - - formula_path - end - - def setup_remote_tap(name) - tap = Tap.fetch name - tap.install(full_clone: false, quiet: true) unless tap.installed? - tap - end - - def install_and_rename_coretap_formula(old_name, new_name) - core_tap = CoreTap.new - core_tap.path.cd do - shutup do - system "git", "init" - system "git", "add", "--all" - system "git", "commit", "-m", - "#{old_name.capitalize} has not yet been renamed" - end - end - - cmd("install", old_name) - (core_tap.path/"Formula/#{old_name}.rb").unlink - formula_renames = core_tap.path/"formula_renames.json" - formula_renames.write Utils::JSON.dump(old_name => new_name) - - core_tap.path.cd do - shutup do - system "git", "add", "--all" - system "git", "commit", "-m", - "#{old_name.capitalize} has been renamed to #{new_name.capitalize}" - end - end - end - - def testball - "#{File.expand_path("../..", __FILE__)}/testball.rb" - end -end diff --git a/Library/Homebrew/test/helper/shutup.rb b/Library/Homebrew/test/helper/shutup.rb deleted file mode 100644 index fa5f08d31..000000000 --- a/Library/Homebrew/test/helper/shutup.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Test - module Helper - module Shutup - def shutup - if ENV.key?("VERBOSE_TESTS") - yield - else - begin - tmperr = $stderr.clone - tmpout = $stdout.clone - $stderr.reopen("/dev/null") - $stdout.reopen("/dev/null") - yield - ensure - $stderr.reopen(tmperr) - $stdout.reopen(tmpout) - tmperr.close - tmpout.close - end - end - end - end - end -end diff --git a/Library/Homebrew/test/lib/config.rb b/Library/Homebrew/test/lib/config.rb deleted file mode 100644 index 4fe62d409..000000000 --- a/Library/Homebrew/test/lib/config.rb +++ /dev/null @@ -1,40 +0,0 @@ -unless ENV["HOMEBREW_BREW_FILE"] - raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" -end - -require "tmpdir" -require "pathname" - -HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"]) - -TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") do |k| - dir = Dir.mktmpdir("homebrew-tests-", ENV["HOMEBREW_TEMP"] || "/tmp") - at_exit { FileUtils.remove_entry(dir) } - ENV[k] = dir -end - -# Paths pointing into the Homebrew code base that persist across test runs -HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../..", __FILE__)) -HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent+"Homebrew/shims" -HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":") - -# Paths redirected to a temporary directory and wiped at the end of the test run -HOMEBREW_PREFIX = Pathname.new(TEST_TMPDIR).join("prefix") -HOMEBREW_REPOSITORY = HOMEBREW_PREFIX -HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY+"Library" -HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+"cache" -HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache" -HOMEBREW_LINKED_KEGS = HOMEBREW_PREFIX.parent+"linked" -HOMEBREW_PINNED_KEGS = HOMEBREW_PREFIX.parent+"pinned" -HOMEBREW_LOCK_DIR = HOMEBREW_PREFIX.parent+"locks" -HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar" -HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs" -HOMEBREW_TEMP = HOMEBREW_PREFIX.parent+"temp" - -TEST_FIXTURE_DIR = HOMEBREW_LIBRARY_PATH.join("test", "fixtures") - -TESTBALL_SHA1 = "be478fd8a80fe7f29196d6400326ac91dad68c37".freeze -TESTBALL_SHA256 = "91e3f7930c98d7ccfb288e115ed52d06b0e5bc16fec7dce8bdda86530027067b".freeze -TESTBALL_PATCHES_SHA256 = "799c2d551ac5c3a5759bea7796631a7906a6a24435b52261a317133a0bfb34d9".freeze -PATCH_A_SHA256 = "83404f4936d3257e65f176c4ffb5a5b8d6edd644a21c8d8dcc73e22a6d28fcfa".freeze -PATCH_B_SHA256 = "57958271bb802a59452d0816e0670d16c8b70bdf6530bcf6f78726489ad89b90".freeze diff --git a/Library/Homebrew/test/lib/integration_mocks.rb b/Library/Homebrew/test/lib/integration_mocks.rb deleted file mode 100644 index 6effb0cde..000000000 --- a/Library/Homebrew/test/lib/integration_mocks.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Homebrew - module Diagnostic - class Checks - def check_integration_test - "This is an integration test" if ENV["HOMEBREW_INTEGRATION_TEST"] - end - end - end - - def exec(*args) - if ENV["HOMEBREW_TESTS_COVERAGE"] && ENV["HOMEBREW_INTEGRATION_TEST"] - # Ensure we get coverage results before replacing the current process. - SimpleCov.result - end - Kernel.exec(*args) - end -end diff --git a/Library/Homebrew/test/mach/a.out b/Library/Homebrew/test/mach/a.out deleted file mode 100755 index 18e0e982f..000000000 Binary files a/Library/Homebrew/test/mach/a.out and /dev/null differ diff --git a/Library/Homebrew/test/mach/fat.bundle b/Library/Homebrew/test/mach/fat.bundle deleted file mode 100644 index f60f1e8bb..000000000 Binary files a/Library/Homebrew/test/mach/fat.bundle and /dev/null differ diff --git a/Library/Homebrew/test/mach/fat.dylib b/Library/Homebrew/test/mach/fat.dylib deleted file mode 100644 index 6886a6a8b..000000000 Binary files a/Library/Homebrew/test/mach/fat.dylib and /dev/null differ diff --git a/Library/Homebrew/test/mach/i386.bundle b/Library/Homebrew/test/mach/i386.bundle deleted file mode 100644 index b6f94710d..000000000 Binary files a/Library/Homebrew/test/mach/i386.bundle and /dev/null differ diff --git a/Library/Homebrew/test/mach/i386.dylib b/Library/Homebrew/test/mach/i386.dylib deleted file mode 100644 index 0304dca01..000000000 Binary files a/Library/Homebrew/test/mach/i386.dylib and /dev/null differ diff --git a/Library/Homebrew/test/mach/x86_64.bundle b/Library/Homebrew/test/mach/x86_64.bundle deleted file mode 100644 index d1bde419f..000000000 Binary files a/Library/Homebrew/test/mach/x86_64.bundle and /dev/null differ diff --git a/Library/Homebrew/test/mach/x86_64.dylib b/Library/Homebrew/test/mach/x86_64.dylib deleted file mode 100644 index 781b41cb4..000000000 Binary files a/Library/Homebrew/test/mach/x86_64.dylib and /dev/null differ diff --git a/Library/Homebrew/test/patches/noop-a.diff b/Library/Homebrew/test/patches/noop-a.diff deleted file mode 100644 index 7b57f8fc9..000000000 --- a/Library/Homebrew/test/patches/noop-a.diff +++ /dev/null @@ -1,10 +0,0 @@ -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/patches/noop-b.diff b/Library/Homebrew/test/patches/noop-b.diff deleted file mode 100644 index bc081ca82..000000000 --- a/Library/Homebrew/test/patches/noop-b.diff +++ /dev/null @@ -1,10 +0,0 @@ -diff --git libexec/NOOP libexec/NOOP -index bfdda4c..e08d8f4 100755 ---- libexec/NOOP -+++ 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/patches/noop-c.diff b/Library/Homebrew/test/patches/noop-c.diff deleted file mode 100644 index 6d0de5b7b..000000000 --- a/Library/Homebrew/test/patches/noop-c.diff +++ /dev/null @@ -1,9 +0,0 @@ -diff --git a/libexec/NOOP b/libexec/NOOP -index e08d8f4..3ebfb9d 100755 ---- a/libexec/NOOP -+++ b/libexec/NOOP -@@ -1,2 +1,2 @@ - #!/bin/bash --echo ABCD -\ No newline at end of file -+echo 1234 diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz new file mode 120000 index 000000000..3e989830b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz new file mode 120000 index 000000000..3e989830b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.linux_x86_64.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz new file mode 120000 index 000000000..3e989830b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.macintosh_intel.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz new file mode 120000 index 000000000..3e989830b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz new file mode 120000 index 000000000..3e989830b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.sierra.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.sierra.bottle.tar.gz new file mode 120000 index 000000000..3e989830b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.sierra.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz \ No newline at end of file diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz new file mode 100644 index 000000000..d88838a94 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz differ diff --git a/Library/Homebrew/test/support/fixtures/cask/AppWithBinary.zip b/Library/Homebrew/test/support/fixtures/cask/AppWithBinary.zip new file mode 100644 index 000000000..4a5b318ba Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/AppWithBinary.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/AppWithEmbeddedBinary.zip b/Library/Homebrew/test/support/fixtures/cask/AppWithEmbeddedBinary.zip new file mode 100644 index 000000000..7c708038c Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/AppWithEmbeddedBinary.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/MyFancyApp.zip b/Library/Homebrew/test/support/fixtures/cask/MyFancyApp.zip new file mode 100644 index 000000000..ba09ee681 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/MyFancyApp.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/MyFancyPkg.zip b/Library/Homebrew/test/support/fixtures/cask/MyFancyPkg.zip new file mode 100644 index 000000000..ec4f97f07 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/MyFancyPkg.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/NestedApp.dmg.zip b/Library/Homebrew/test/support/fixtures/cask/NestedApp.dmg.zip new file mode 100644 index 000000000..ae6686c7e Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/NestedApp.dmg.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/caffeine-suite.zip b/Library/Homebrew/test/support/fixtures/cask/caffeine-suite.zip new file mode 100644 index 000000000..c38f771ae Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/caffeine-suite.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/caffeine.zip b/Library/Homebrew/test/support/fixtures/cask/caffeine.zip new file mode 100644 index 000000000..99d61bbfb Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/caffeine.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/caffeines-subdir.zip b/Library/Homebrew/test/support/fixtures/cask/caffeines-subdir.zip new file mode 100644 index 000000000..ce5064d09 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/caffeines-subdir.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/caffeines.zip b/Library/Homebrew/test/support/fixtures/cask/caffeines.zip new file mode 100644 index 000000000..372fcc522 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/caffeines.zip differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.7z b/Library/Homebrew/test/support/fixtures/cask/container.7z new file mode 100644 index 000000000..30dbe24f7 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.7z differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.air b/Library/Homebrew/test/support/fixtures/cask/container.air new file mode 100644 index 000000000..64005aea3 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.air differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.bz2 b/Library/Homebrew/test/support/fixtures/cask/container.bz2 new file mode 100755 index 000000000..6ec60f31f Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.bz2 differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.cab b/Library/Homebrew/test/support/fixtures/cask/container.cab new file mode 100644 index 000000000..edc741aa1 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.cab differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.dmg b/Library/Homebrew/test/support/fixtures/cask/container.dmg new file mode 100644 index 000000000..3b3cbf51c Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.dmg differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.gz b/Library/Homebrew/test/support/fixtures/cask/container.gz new file mode 100755 index 000000000..67ede6b96 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.gz differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.lzma b/Library/Homebrew/test/support/fixtures/cask/container.lzma new file mode 100755 index 000000000..2ff7ccee7 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.lzma differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.pkg b/Library/Homebrew/test/support/fixtures/cask/container.pkg new file mode 100644 index 000000000..274f27e7a Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.pkg differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.rar b/Library/Homebrew/test/support/fixtures/cask/container.rar new file mode 100644 index 000000000..7477c3bb4 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.rar differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.sit b/Library/Homebrew/test/support/fixtures/cask/container.sit new file mode 100755 index 000000000..3e29d21dc Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.sit differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.tar.gz b/Library/Homebrew/test/support/fixtures/cask/container.tar.gz new file mode 100644 index 000000000..c464fb413 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.tar.gz differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.xar b/Library/Homebrew/test/support/fixtures/cask/container.xar new file mode 100644 index 000000000..563a5ba1e Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.xar differ diff --git a/Library/Homebrew/test/support/fixtures/cask/container.xz b/Library/Homebrew/test/support/fixtures/cask/container.xz new file mode 100755 index 000000000..74db22090 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/container.xz differ diff --git a/Library/Homebrew/test/support/fixtures/cask/empty_directory/.gitignore b/Library/Homebrew/test/support/fixtures/cask/empty_directory/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/Library/Homebrew/test/support/fixtures/cask/naked_executable b/Library/Homebrew/test/support/fixtures/cask/naked_executable new file mode 100755 index 000000000..039e4d006 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/naked_executable @@ -0,0 +1,2 @@ +#!/bin/sh +exit 0 diff --git a/Library/Homebrew/test/support/fixtures/cask/transmission-2.61.dmg b/Library/Homebrew/test/support/fixtures/cask/transmission-2.61.dmg new file mode 100644 index 000000000..e72afe027 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/cask/transmission-2.61.dmg differ diff --git a/Library/Homebrew/test/support/fixtures/mach/a.out b/Library/Homebrew/test/support/fixtures/mach/a.out new file mode 100755 index 000000000..18e0e982f Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/mach/a.out differ diff --git a/Library/Homebrew/test/support/fixtures/mach/fat.bundle b/Library/Homebrew/test/support/fixtures/mach/fat.bundle new file mode 100644 index 000000000..f60f1e8bb Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/mach/fat.bundle differ diff --git a/Library/Homebrew/test/support/fixtures/mach/fat.dylib b/Library/Homebrew/test/support/fixtures/mach/fat.dylib new file mode 100644 index 000000000..6886a6a8b Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/mach/fat.dylib differ diff --git a/Library/Homebrew/test/support/fixtures/mach/i386.bundle b/Library/Homebrew/test/support/fixtures/mach/i386.bundle new file mode 100644 index 000000000..b6f94710d Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/mach/i386.bundle differ diff --git a/Library/Homebrew/test/support/fixtures/mach/i386.dylib b/Library/Homebrew/test/support/fixtures/mach/i386.dylib new file mode 100644 index 000000000..0304dca01 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/mach/i386.dylib differ diff --git a/Library/Homebrew/test/support/fixtures/mach/x86_64.bundle b/Library/Homebrew/test/support/fixtures/mach/x86_64.bundle new file mode 100644 index 000000000..d1bde419f Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/mach/x86_64.bundle differ diff --git a/Library/Homebrew/test/support/fixtures/mach/x86_64.dylib b/Library/Homebrew/test/support/fixtures/mach/x86_64.dylib new file mode 100644 index 000000000..781b41cb4 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/mach/x86_64.dylib differ diff --git a/Library/Homebrew/test/support/fixtures/patches/noop-a.diff b/Library/Homebrew/test/support/fixtures/patches/noop-a.diff new file mode 100644 index 000000000..7b57f8fc9 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/patches/noop-a.diff @@ -0,0 +1,10 @@ +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/support/fixtures/patches/noop-b.diff b/Library/Homebrew/test/support/fixtures/patches/noop-b.diff new file mode 100644 index 000000000..bc081ca82 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/patches/noop-b.diff @@ -0,0 +1,10 @@ +diff --git libexec/NOOP libexec/NOOP +index bfdda4c..e08d8f4 100755 +--- libexec/NOOP ++++ 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/support/fixtures/patches/noop-c.diff b/Library/Homebrew/test/support/fixtures/patches/noop-c.diff new file mode 100644 index 000000000..6d0de5b7b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/patches/noop-c.diff @@ -0,0 +1,9 @@ +diff --git a/libexec/NOOP b/libexec/NOOP +index e08d8f4..3ebfb9d 100755 +--- a/libexec/NOOP ++++ b/libexec/NOOP +@@ -1,2 +1,2 @@ + #!/bin/bash +-echo ABCD +\ No newline at end of file ++echo 1234 diff --git a/Library/Homebrew/test/support/fixtures/receipt.json b/Library/Homebrew/test/support/fixtures/receipt.json new file mode 100644 index 000000000..404251026 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/receipt.json @@ -0,0 +1,37 @@ +{ + "used_options": [ + "--with-foo", + "--without-bar" + ], + "unused_options": [ + "--with-baz", + "--without-qux" + ], + "built_as_bottle": false, + "poured_from_bottle": true, + "changed_files": [ + "INSTALL_RECEIPT.json", + "bin/foo" + ], + "time": 1403827774, + "HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", + "alias_path": "/usr/local/Library/Taps/homebrew/homebrew-core/Aliases/test-formula", + "stdlib": "libcxx", + "compiler": "clang", + "runtime_dependencies": [ + { + "full_name": "foo", + "version": "1.0" + } + ], + "source": { + "path": "/usr/local/Library/Taps/hombrew/homebrew-core/Formula/foo.rb", + "tap": "homebrew/core", + "spec": "stable", + "versions": { + "stable": "2.14", + "devel": "2.15", + "head": "HEAD-0000000" + } + } +} diff --git a/Library/Homebrew/test/support/fixtures/receipt_old.json b/Library/Homebrew/test/support/fixtures/receipt_old.json new file mode 100644 index 000000000..955d56b47 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/receipt_old.json @@ -0,0 +1,17 @@ +{ + "used_options": [ + "--with-foo", + "--without-bar" + ], + "unused_options": [ + "--with-baz", + "--without-qux" + ], + "built_as_bottle": false, + "poured_from_bottle": true, + "tapped_from": "Homebrew/homebrew", + "time": 1403827774, + "HEAD": "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", + "stdlib": "libcxx", + "compiler": "clang" +} diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball-0.1-patches.tgz b/Library/Homebrew/test/support/fixtures/tarballs/testball-0.1-patches.tgz new file mode 100644 index 000000000..4b43f535e Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/tarballs/testball-0.1-patches.tgz differ diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testball-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testball-0.1.tbz new file mode 100644 index 000000000..c7e1af1f4 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/tarballs/testball-0.1.tbz differ diff --git a/Library/Homebrew/test/support/fixtures/tarballs/testbottest-0.1.tbz b/Library/Homebrew/test/support/fixtures/tarballs/testbottest-0.1.tbz new file mode 100644 index 000000000..83f7ab1dd Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/tarballs/testbottest-0.1.tbz differ diff --git a/Library/Homebrew/test/support/fixtures/test.diff b/Library/Homebrew/test/support/fixtures/test.diff new file mode 100644 index 000000000..7b57f8fc9 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/test.diff @@ -0,0 +1,10 @@ +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/support/fixtures/test.eps b/Library/Homebrew/test/support/fixtures/test.eps new file mode 100644 index 000000000..2832613e7 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/test.eps @@ -0,0 +1,25 @@ +%!PS-Adobe-2.0 EPSF-2.0 +%%BoundingBox: 73 499 211 513 +%%HiResBoundingBox: 73.000000 499.500000 211.000000 512.500000 +%%EndComments +% EPSF created by ps2eps 1.68 +%%BeginProlog +save +countdictstack +mark +newpath +/showpage {} def +/setpagedevice {pop} def +%%EndProlog +%%Page 1 1 +/Courier +20 selectfont +72 500 moveto +(Hello World!) show +showpage +%%Trailer +cleartomark +countdictstack +exch sub { end } repeat +restore +%%EOF diff --git a/Library/Homebrew/test/support/fixtures/test.gif b/Library/Homebrew/test/support/fixtures/test.gif new file mode 100644 index 000000000..0589d2082 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.gif differ diff --git a/Library/Homebrew/test/support/fixtures/test.ico b/Library/Homebrew/test/support/fixtures/test.ico new file mode 100644 index 000000000..714f3478d Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.ico differ diff --git a/Library/Homebrew/test/support/fixtures/test.jpg b/Library/Homebrew/test/support/fixtures/test.jpg new file mode 100644 index 000000000..1adaa50a6 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.jpg differ diff --git a/Library/Homebrew/test/support/fixtures/test.m4a b/Library/Homebrew/test/support/fixtures/test.m4a new file mode 100644 index 000000000..7650fc482 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.m4a differ diff --git a/Library/Homebrew/test/support/fixtures/test.mp3 b/Library/Homebrew/test/support/fixtures/test.mp3 new file mode 100644 index 000000000..a01322383 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.mp3 differ diff --git a/Library/Homebrew/test/support/fixtures/test.pcap b/Library/Homebrew/test/support/fixtures/test.pcap new file mode 100644 index 000000000..671197e8a Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.pcap differ diff --git a/Library/Homebrew/test/support/fixtures/test.pdf b/Library/Homebrew/test/support/fixtures/test.pdf new file mode 100644 index 000000000..1f2ac6390 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/test.pdf @@ -0,0 +1,24 @@ +%PDF-1.6 +%μῦ +1 0 obj<>endobj +2 0 obj<>endobj +3 0 obj<>endobj +4 0 obj<>>>endobj +5 0 obj<>endobj +6 0 obj<>stream +BT /F1 24 Tf 175 720 Td (Homebrew test.)Tj ET +endstream +endobj +xref +0 7 +0000000000 65536 f +0000000016 00000 n +0000000059 00000 n +0000000108 00000 n +0000000202 00000 n +0000000238 00000 n +0000000299 00000 n +trailer<> +startxref +390 +%%EOF diff --git a/Library/Homebrew/test/support/fixtures/test.png b/Library/Homebrew/test/support/fixtures/test.png new file mode 100644 index 000000000..18d7a15a9 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.png differ diff --git a/Library/Homebrew/test/support/fixtures/test.ps b/Library/Homebrew/test/support/fixtures/test.ps new file mode 100644 index 000000000..68aae0621 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/test.ps @@ -0,0 +1,6 @@ +%!PS +/Courier +20 selectfont +72 500 moveto +(Hello World!) show +showpage diff --git a/Library/Homebrew/test/support/fixtures/test.svg b/Library/Homebrew/test/support/fixtures/test.svg new file mode 100644 index 000000000..1869e624c --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/test.svg @@ -0,0 +1,4 @@ + +Homebrew + + diff --git a/Library/Homebrew/test/support/fixtures/test.tiff b/Library/Homebrew/test/support/fixtures/test.tiff new file mode 100644 index 000000000..ae756b264 Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.tiff differ diff --git a/Library/Homebrew/test/support/fixtures/test.wav b/Library/Homebrew/test/support/fixtures/test.wav new file mode 100644 index 000000000..c846b8a9b Binary files /dev/null and b/Library/Homebrew/test/support/fixtures/test.wav differ diff --git a/Library/Homebrew/test/support/fixtures/testball.rb b/Library/Homebrew/test/support/fixtures/testball.rb new file mode 100644 index 000000000..ba725f51e --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/testball.rb @@ -0,0 +1,15 @@ +class Testball < Formula + def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) + self.class.instance_eval do + stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + stable.sha256 TESTBALL_SHA256 + end + super + end + + def install + prefix.install "bin" + prefix.install "libexec" + Dir.chdir "doc" + end +end diff --git a/Library/Homebrew/test/support/fixtures/testball_bottle.rb b/Library/Homebrew/test/support/fixtures/testball_bottle.rb new file mode 100644 index 000000000..9453255e6 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/testball_bottle.rb @@ -0,0 +1,20 @@ +class TestballBottle < Formula + def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) + self.class.instance_eval do + stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + stable.sha256 TESTBALL_SHA256 + stable.bottle do + cellar :any_skip_relocation + root_url "file://#{TEST_FIXTURE_DIR}/bottles" + sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => Utils::Bottles.tag + end + cxxstdlib_check :skip + end + super + end + + def install + prefix.install "bin" + prefix.install "libexec" + end +end diff --git a/Library/Homebrew/test/support/fixtures/testbottest.rb b/Library/Homebrew/test/support/fixtures/testbottest.rb new file mode 100644 index 000000000..28b88567e --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/testbottest.rb @@ -0,0 +1,14 @@ +class Testbottest < Formula + desc "Minimal C program and Makefile used for testing Homebrew." + homepage "https://github.com/Homebrew/brew" + url "file://#{TEST_FIXTURE_DIR}/tarballs/testbottest-0.1.tbz" + sha256 "78b54d8f31585c9773bed12b4aa4ab2ce458ebd044b9406cb24d40aa5107f082" + + def install + system "make", "install", "PREFIX=#{prefix}" + end + + test do + assert_equal "testbottest\n", shell_output("#{bin}/testbottest") + end +end diff --git a/Library/Homebrew/test/support/fixtures/updater_fixture.yaml b/Library/Homebrew/test/support/fixtures/updater_fixture.yaml new file mode 100644 index 000000000..06a6a0c7f --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/updater_fixture.yaml @@ -0,0 +1,64 @@ +update_git_diff_output_without_formulae_changes: | + M Library/Homebrew/ARGV+yeast.rb + A Library/Homebrew/beer_events.rb + A Library/Homebrew/hardware.rb + D Library/Homebrew/hw.model.c + M README + M bin/brew +update_git_diff_output_with_formulae_changes: | + M Library/Contributions/brew_bash_completion.sh + A Formula/antiword.rb + A Formula/bash-completion.rb + A Formula/ddrescue.rb + A Formula/dict.rb + A Formula/lua.rb + M Formula/xar.rb + M Formula/yajl.rb + M Library/Homebrew/ARGV+yeast.rb + M Library/Homebrew/beer_events.rb + M Library/Homebrew/hardware.rb + M Library/Homebrew/hw.model.c + M Library/Homebrew/hw.model.rb + M Library/Homebrew/pathname+yeast.rb + M Library/Homebrew/unittest.rb + M Library/Homebrew/utils.rb + M README + M bin/brew +update_git_diff_output_with_removed_formulae: | + A Formula/flac123.rb + M Formula/gdal.rb + M Formula/grass.rb + M Formula/json_spirit.rb + A Formula/libbson.rb + D Formula/libgsasl.rb +update_git_diff_output_with_changed_filetype: | + A Library/ENV/4.3/ant + T Library/ENV/4.3/bsdmake + M Library/ENV/4.3/make + M Formula/elixir.rb + A Formula/libbson.rb + D Formula/libgsasl.rb + M Library/Homebrew/cmd/update.rb + M SUPPORTERS.md +update_git_diff_output_with_formula_rename: | + R100 Formula/cv.rb Formula/progress.rb +update_git_diff_output_with_restructured_tap: | + R100 git.rb Formula/git.rb + R100 lua.rb Formula/lua.rb +update_git_diff_output_with_formula_rename_and_restructuring: | + R100 xchat.rb Formula/xchat2.rb +update_git_diff_simulate_homebrew_php_restructuring: | + R100 Formula/git.rb Abstract/git.rb + R100 Formula/lua.rb Abstract/lua.rb +update_git_diff_output_with_tap_formulae_changes: | + M Rakefile + M README.md + M Requirements/some_requirement.rb + D another_ruby_file.rb + A a_ruby_file.rb + A CONTRIBUTING.md + M Formula/git.rb + A Formula/lua.rb + M lib/not_a_formula.rb + A lib/not_a_formula2.rb + D lib/not_a_formula3.rb diff --git a/Library/Homebrew/test/support/helper/env.rb b/Library/Homebrew/test/support/helper/env.rb new file mode 100644 index 000000000..904a1d4c7 --- /dev/null +++ b/Library/Homebrew/test/support/helper/env.rb @@ -0,0 +1,15 @@ +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/integration_command_test_case.rb b/Library/Homebrew/test/support/helper/integration_command_test_case.rb new file mode 100644 index 000000000..d7ae67423 --- /dev/null +++ b/Library/Homebrew/test/support/helper/integration_command_test_case.rb @@ -0,0 +1,200 @@ +require "bundler" +require "fileutils" +require "pathname" +require "formula" + +class IntegrationCommandTestCase < Homebrew::TestCase + def setup + @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" + end + + def needs_macos + skip "Not on MacOS" unless OS.mac? + end + + def cmd_id_from_args(args) + args_pretty = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@") + test_pretty = "#{self.class.name}\##{name}.#{@cmd_id_index += 1}" + "[#{test_pretty}] brew #{args_pretty}" + 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 + -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 << "-rintegration_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 + + 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 + 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 + 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 + end + + def setup_test_formula(name, content = nil) + formula_path = CoreTap.new.formula_dir/"#{name}.rb" + + 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 \\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 + + formula_path.write <<-EOS.undent + class #{Formulary.class_s(name)} < Formula + #{content} + end + EOS + + formula_path + end + + def setup_remote_tap(name) + tap = Tap.fetch name + tap.install(full_clone: false, quiet: true) unless tap.installed? + tap + end + + def install_and_rename_coretap_formula(old_name, new_name) + core_tap = CoreTap.new + core_tap.path.cd do + shutup do + system "git", "init" + system "git", "add", "--all" + system "git", "commit", "-m", + "#{old_name.capitalize} has not yet been renamed" + end + end + + cmd("install", old_name) + (core_tap.path/"Formula/#{old_name}.rb").unlink + formula_renames = core_tap.path/"formula_renames.json" + formula_renames.write Utils::JSON.dump(old_name => new_name) + + core_tap.path.cd do + shutup do + 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 diff --git a/Library/Homebrew/test/support/helper/shutup.rb b/Library/Homebrew/test/support/helper/shutup.rb new file mode 100644 index 000000000..fa5f08d31 --- /dev/null +++ b/Library/Homebrew/test/support/helper/shutup.rb @@ -0,0 +1,24 @@ +module Test + module Helper + module Shutup + def shutup + if ENV.key?("VERBOSE_TESTS") + yield + else + begin + tmperr = $stderr.clone + tmpout = $stdout.clone + $stderr.reopen("/dev/null") + $stdout.reopen("/dev/null") + yield + ensure + $stderr.reopen(tmperr) + $stdout.reopen(tmpout) + tmperr.close + tmpout.close + end + end + end + end + end +end diff --git a/Library/Homebrew/test/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb new file mode 100644 index 000000000..f6fdb4ecb --- /dev/null +++ b/Library/Homebrew/test/support/lib/config.rb @@ -0,0 +1,40 @@ +unless ENV["HOMEBREW_BREW_FILE"] + raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" +end + +require "tmpdir" +require "pathname" + +HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"]) + +TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") do |k| + dir = Dir.mktmpdir("homebrew-tests-", ENV["HOMEBREW_TEMP"] || "/tmp") + at_exit { FileUtils.remove_entry(dir) } + ENV[k] = dir +end + +# Paths pointing into the Homebrew code base that persist across test runs +HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../../..", __FILE__)) +HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent+"Homebrew/shims" +HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":") + +# Paths redirected to a temporary directory and wiped at the end of the test run +HOMEBREW_PREFIX = Pathname.new(TEST_TMPDIR).join("prefix") +HOMEBREW_REPOSITORY = HOMEBREW_PREFIX +HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY+"Library" +HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+"cache" +HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache" +HOMEBREW_LINKED_KEGS = HOMEBREW_PREFIX.parent+"linked" +HOMEBREW_PINNED_KEGS = HOMEBREW_PREFIX.parent+"pinned" +HOMEBREW_LOCK_DIR = HOMEBREW_PREFIX.parent+"locks" +HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar" +HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs" +HOMEBREW_TEMP = HOMEBREW_PREFIX.parent+"temp" + +TEST_FIXTURE_DIR = HOMEBREW_LIBRARY_PATH.join("test", "support", "fixtures") + +TESTBALL_SHA1 = "be478fd8a80fe7f29196d6400326ac91dad68c37".freeze +TESTBALL_SHA256 = "91e3f7930c98d7ccfb288e115ed52d06b0e5bc16fec7dce8bdda86530027067b".freeze +TESTBALL_PATCHES_SHA256 = "799c2d551ac5c3a5759bea7796631a7906a6a24435b52261a317133a0bfb34d9".freeze +PATCH_A_SHA256 = "83404f4936d3257e65f176c4ffb5a5b8d6edd644a21c8d8dcc73e22a6d28fcfa".freeze +PATCH_B_SHA256 = "57958271bb802a59452d0816e0670d16c8b70bdf6530bcf6f78726489ad89b90".freeze diff --git a/Library/Homebrew/test/support/lib/integration_mocks.rb b/Library/Homebrew/test/support/lib/integration_mocks.rb new file mode 100644 index 000000000..6effb0cde --- /dev/null +++ b/Library/Homebrew/test/support/lib/integration_mocks.rb @@ -0,0 +1,17 @@ +module Homebrew + module Diagnostic + class Checks + def check_integration_test + "This is an integration test" if ENV["HOMEBREW_INTEGRATION_TEST"] + end + end + end + + def exec(*args) + if ENV["HOMEBREW_TESTS_COVERAGE"] && ENV["HOMEBREW_INTEGRATION_TEST"] + # Ensure we get coverage results before replacing the current process. + SimpleCov.result + end + Kernel.exec(*args) + end +end diff --git a/Library/Homebrew/test/tarballs/testball-0.1-patches.tgz b/Library/Homebrew/test/tarballs/testball-0.1-patches.tgz deleted file mode 100644 index 4b43f535e..000000000 Binary files a/Library/Homebrew/test/tarballs/testball-0.1-patches.tgz and /dev/null differ diff --git a/Library/Homebrew/test/tarballs/testball-0.1.tbz b/Library/Homebrew/test/tarballs/testball-0.1.tbz deleted file mode 100644 index c7e1af1f4..000000000 Binary files a/Library/Homebrew/test/tarballs/testball-0.1.tbz and /dev/null differ diff --git a/Library/Homebrew/test/tarballs/testbottest-0.1.tbz b/Library/Homebrew/test/tarballs/testbottest-0.1.tbz deleted file mode 100644 index 83f7ab1dd..000000000 Binary files a/Library/Homebrew/test/tarballs/testbottest-0.1.tbz and /dev/null differ diff --git a/Library/Homebrew/test/test/ENV_test.rb b/Library/Homebrew/test/test/ENV_test.rb index e38c75c6e..1736d34af 100644 --- a/Library/Homebrew/test/test/ENV_test.rb +++ b/Library/Homebrew/test/test/ENV_test.rb @@ -1,6 +1,7 @@ require "testing_env" require "extend/ENV" -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestEnv < IntegrationCommandTestCase def test_env diff --git a/Library/Homebrew/test/test/analytics_test.rb b/Library/Homebrew/test/test/analytics_test.rb index 00e0593db..266c5bd09 100644 --- a/Library/Homebrew/test/test/analytics_test.rb +++ b/Library/Homebrew/test/test/analytics_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestAnalytics < IntegrationCommandTestCase def test_analytics diff --git a/Library/Homebrew/test/test/bottle_test.rb b/Library/Homebrew/test/test/bottle_test.rb index 48727cfd9..5fdba0af8 100644 --- a/Library/Homebrew/test/test/bottle_test.rb +++ b/Library/Homebrew/test/test/bottle_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestBottle < IntegrationCommandTestCase def test_bottle diff --git a/Library/Homebrew/test/test/bundle_test.rb b/Library/Homebrew/test/test/bundle_test.rb index 6b040df1d..ea18d5f84 100644 --- a/Library/Homebrew/test/test/bundle_test.rb +++ b/Library/Homebrew/test/test/bundle_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestBundle < IntegrationCommandTestCase def test_bundle diff --git a/Library/Homebrew/test/test/cache_formula_test.rb b/Library/Homebrew/test/test/cache_formula_test.rb index f4e37e2a2..c64ce9809 100644 --- a/Library/Homebrew/test/test/cache_formula_test.rb +++ b/Library/Homebrew/test/test/cache_formula_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCacheFormula < IntegrationCommandTestCase def test_cache_formula diff --git a/Library/Homebrew/test/test/cache_test.rb b/Library/Homebrew/test/test/cache_test.rb index cd7a5e2fa..f8c035676 100644 --- a/Library/Homebrew/test/test/cache_test.rb +++ b/Library/Homebrew/test/test/cache_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCache < IntegrationCommandTestCase def test_cache diff --git a/Library/Homebrew/test/test/cask_test.rb b/Library/Homebrew/test/test/cask_test.rb index 6cae6d54b..ad7a2a0a0 100644 --- a/Library/Homebrew/test/test/cask_test.rb +++ b/Library/Homebrew/test/test/cask_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCask < IntegrationCommandTestCase def test_cask diff --git a/Library/Homebrew/test/test/cat_test.rb b/Library/Homebrew/test/test/cat_test.rb index 4cfd19c3d..df64188d6 100644 --- a/Library/Homebrew/test/test/cat_test.rb +++ b/Library/Homebrew/test/test/cat_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCat < IntegrationCommandTestCase def test_cat diff --git a/Library/Homebrew/test/test/cellar_formula_test.rb b/Library/Homebrew/test/test/cellar_formula_test.rb index 7c458be9d..6c3063ca3 100644 --- a/Library/Homebrew/test/test/cellar_formula_test.rb +++ b/Library/Homebrew/test/test/cellar_formula_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCellarFormula < IntegrationCommandTestCase def test_cellar_formula diff --git a/Library/Homebrew/test/test/cellar_test.rb b/Library/Homebrew/test/test/cellar_test.rb index b793c5342..32cdb1af5 100644 --- a/Library/Homebrew/test/test/cellar_test.rb +++ b/Library/Homebrew/test/test/cellar_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCellar < IntegrationCommandTestCase def test_cellar diff --git a/Library/Homebrew/test/test/checksum_verification_test.rb b/Library/Homebrew/test/test/checksum_verification_test.rb index e25d08b83..9017b528d 100644 --- a/Library/Homebrew/test/test/checksum_verification_test.rb +++ b/Library/Homebrew/test/test/checksum_verification_test.rb @@ -12,7 +12,7 @@ class ChecksumVerificationTests < Homebrew::TestCase def formula(&block) super do - url "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz" + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" instance_eval(&block) end end diff --git a/Library/Homebrew/test/test/cleaner_test.rb b/Library/Homebrew/test/test/cleaner_test.rb index 450a78d86..ac108421c 100644 --- a/Library/Homebrew/test/test/cleaner_test.rb +++ b/Library/Homebrew/test/test/cleaner_test.rb @@ -17,8 +17,8 @@ class CleanerTests < Homebrew::TestCase def test_clean_file @f.bin.mkpath @f.lib.mkpath - cp "#{TEST_DIRECTORY}/mach/a.out", @f.bin - cp Dir["#{TEST_DIRECTORY}/mach/*.dylib"], @f.lib + cp "#{TEST_FIXTURE_DIR}/mach/a.out", @f.bin + cp Dir["#{TEST_FIXTURE_DIR}/mach/*.dylib"], @f.lib Cleaner.new(@f).clean diff --git a/Library/Homebrew/test/test/cleanup_test.rb b/Library/Homebrew/test/test/cleanup_test.rb index dffcd12f2..fef249fcb 100644 --- a/Library/Homebrew/test/test/cleanup_test.rb +++ b/Library/Homebrew/test/test/cleanup_test.rb @@ -1,9 +1,10 @@ require "testing_env" -require "testball" +require "test/support/fixtures/testball" require "cleanup" require "fileutils" require "pathname" -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCleanup < IntegrationCommandTestCase def test_cleanup diff --git a/Library/Homebrew/test/test/command_test.rb b/Library/Homebrew/test/test/command_test.rb index d05184631..620a014b9 100644 --- a/Library/Homebrew/test/test/command_test.rb +++ b/Library/Homebrew/test/test/command_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCommand < IntegrationCommandTestCase def test_command diff --git a/Library/Homebrew/test/test/commands_test.rb b/Library/Homebrew/test/test/commands_test.rb index ef138049c..cbb446ae3 100644 --- a/Library/Homebrew/test/test/commands_test.rb +++ b/Library/Homebrew/test/test/commands_test.rb @@ -2,7 +2,8 @@ require "testing_env" require "cmd/command" require "cmd/commands" require "fileutils" -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCommands < IntegrationCommandTestCase def test_commands diff --git a/Library/Homebrew/test/test/config_test.rb b/Library/Homebrew/test/test/config_test.rb index 33a293735..1a793cc6b 100644 --- a/Library/Homebrew/test/test/config_test.rb +++ b/Library/Homebrew/test/test/config_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestConfig < IntegrationCommandTestCase def test_config diff --git a/Library/Homebrew/test/test/create_test.rb b/Library/Homebrew/test/test/create_test.rb index 5f194ea02..26a325a22 100644 --- a/Library/Homebrew/test/test/create_test.rb +++ b/Library/Homebrew/test/test/create_test.rb @@ -1,8 +1,9 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCreate < IntegrationCommandTestCase def test_create - url = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz" + 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" diff --git a/Library/Homebrew/test/test/custom_command_test.rb b/Library/Homebrew/test/test/custom_command_test.rb index bc27e2121..71bfafd9b 100644 --- a/Library/Homebrew/test/test/custom_command_test.rb +++ b/Library/Homebrew/test/test/custom_command_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCustomCommand < IntegrationCommandTestCase def test_custom_command diff --git a/Library/Homebrew/test/test/deps_test.rb b/Library/Homebrew/test/test/deps_test.rb index 83cc9aa6a..44803af5e 100644 --- a/Library/Homebrew/test/test/deps_test.rb +++ b/Library/Homebrew/test/test/deps_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestDeps < IntegrationCommandTestCase def test_deps diff --git a/Library/Homebrew/test/test/desc_test.rb b/Library/Homebrew/test/test/desc_test.rb index 075ea991a..7428c0792 100644 --- a/Library/Homebrew/test/test/desc_test.rb +++ b/Library/Homebrew/test/test/desc_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestDesc < IntegrationCommandTestCase def test_desc diff --git a/Library/Homebrew/test/test/doctor_test.rb b/Library/Homebrew/test/test/doctor_test.rb index ccb909dce..be1098d22 100644 --- a/Library/Homebrew/test/test/doctor_test.rb +++ b/Library/Homebrew/test/test/doctor_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestDoctor < IntegrationCommandTestCase def test_doctor diff --git a/Library/Homebrew/test/test/edit_test.rb b/Library/Homebrew/test/test/edit_test.rb index 8d1437173..c78db3bd8 100644 --- a/Library/Homebrew/test/test/edit_test.rb +++ b/Library/Homebrew/test/test/edit_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestEdit < IntegrationCommandTestCase def test_edit diff --git a/Library/Homebrew/test/test/fetch_test.rb b/Library/Homebrew/test/test/fetch_test.rb index 7b57c6246..e049db554 100644 --- a/Library/Homebrew/test/test/fetch_test.rb +++ b/Library/Homebrew/test/test/fetch_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestFetch < IntegrationCommandTestCase def test_fetch diff --git a/Library/Homebrew/test/test/formula_installer_bottle_test.rb b/Library/Homebrew/test/test/formula_installer_bottle_test.rb index d83c856b7..6a891f159 100644 --- a/Library/Homebrew/test/test/formula_installer_bottle_test.rb +++ b/Library/Homebrew/test/test/formula_installer_bottle_test.rb @@ -3,8 +3,8 @@ require "formula" require "formula_installer" require "keg" require "tab" -require "testball" -require "testball_bottle" +require "test/support/fixtures/testball" +require "test/support/fixtures/testball_bottle" class InstallBottleTests < Homebrew::TestCase def temporary_bottle_install(formula) diff --git a/Library/Homebrew/test/test/formula_installer_test.rb b/Library/Homebrew/test/test/formula_installer_test.rb index 18bd910a6..652548bd7 100644 --- a/Library/Homebrew/test/test/formula_installer_test.rb +++ b/Library/Homebrew/test/test/formula_installer_test.rb @@ -3,8 +3,8 @@ require "formula" require "formula_installer" require "keg" require "tab" -require "testball" -require "testball_bottle" +require "test/support/fixtures/testball" +require "test/support/fixtures/testball_bottle" class InstallTests < Homebrew::TestCase def temporary_install(formula) diff --git a/Library/Homebrew/test/test/formula_test.rb b/Library/Homebrew/test/test/formula_test.rb index 4aa835590..eef60a3e5 100644 --- a/Library/Homebrew/test/test/formula_test.rb +++ b/Library/Homebrew/test/test/formula_test.rb @@ -1,5 +1,5 @@ require "testing_env" -require "testball" +require "test/support/fixtures/testball" require "formula" class FormulaTests < Homebrew::TestCase diff --git a/Library/Homebrew/test/test/formulary_test.rb b/Library/Homebrew/test/test/formulary_test.rb index 690ff089a..3d88c8407 100644 --- a/Library/Homebrew/test/test/formulary_test.rb +++ b/Library/Homebrew/test/test/formulary_test.rb @@ -18,11 +18,11 @@ class FormularyFactoryTest < Homebrew::TestCase def setup @name = "testball_bottle" @path = CoreTap.new.formula_dir/"#{@name}.rb" - @bottle_dir = Pathname.new("#{TEST_DIRECTORY}/bottles") + @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://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" sha256 TESTBALL_SHA256 bottle do diff --git a/Library/Homebrew/test/test/help_test.rb b/Library/Homebrew/test/test/help_test.rb index 9c14f9b78..8c9a4bb08 100644 --- a/Library/Homebrew/test/test/help_test.rb +++ b/Library/Homebrew/test/test/help_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestHelp < IntegrationCommandTestCase def test_help diff --git a/Library/Homebrew/test/test/home_test.rb b/Library/Homebrew/test/test/home_test.rb index 9c26353be..9116442b7 100644 --- a/Library/Homebrew/test/test/home_test.rb +++ b/Library/Homebrew/test/test/home_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestHome < IntegrationCommandTestCase def test_home diff --git a/Library/Homebrew/test/test/info_test.rb b/Library/Homebrew/test/test/info_test.rb index 35f9183e1..a4186a5e9 100644 --- a/Library/Homebrew/test/test/info_test.rb +++ b/Library/Homebrew/test/test/info_test.rb @@ -1,7 +1,8 @@ require "testing_env" require "cmd/info" require "formula" -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestInfo < IntegrationCommandTestCase def test_info diff --git a/Library/Homebrew/test/test/install_test.rb b/Library/Homebrew/test/test/install_test.rb index 7135dddb2..313125931 100644 --- a/Library/Homebrew/test/test/install_test.rb +++ b/Library/Homebrew/test/test/install_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestInstall < IntegrationCommandTestCase def test_install diff --git a/Library/Homebrew/test/test/irb_test.rb b/Library/Homebrew/test/test/irb_test.rb index bf35b6524..77ca4a90d 100644 --- a/Library/Homebrew/test/test/irb_test.rb +++ b/Library/Homebrew/test/test/irb_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestIrb < IntegrationCommandTestCase def test_irb diff --git a/Library/Homebrew/test/test/leaves_test.rb b/Library/Homebrew/test/test/leaves_test.rb index 2a9bbadd9..ef25a4b6e 100644 --- a/Library/Homebrew/test/test/leaves_test.rb +++ b/Library/Homebrew/test/test/leaves_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLeaves < IntegrationCommandTestCase def test_leaves diff --git a/Library/Homebrew/test/test/link_test.rb b/Library/Homebrew/test/test/link_test.rb index 3f0507072..ecabe0c67 100644 --- a/Library/Homebrew/test/test/link_test.rb +++ b/Library/Homebrew/test/test/link_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLink < IntegrationCommandTestCase def test_link diff --git a/Library/Homebrew/test/test/linkapps_test.rb b/Library/Homebrew/test/test/linkapps_test.rb index b7c4cb811..a0b33a543 100644 --- a/Library/Homebrew/test/test/linkapps_test.rb +++ b/Library/Homebrew/test/test/linkapps_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLinkapps < IntegrationCommandTestCase def test_linkapps diff --git a/Library/Homebrew/test/test/list_test.rb b/Library/Homebrew/test/test/list_test.rb index 1ffdb4528..26aab741f 100644 --- a/Library/Homebrew/test/test/list_test.rb +++ b/Library/Homebrew/test/test/list_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestList < IntegrationCommandTestCase def test_list diff --git a/Library/Homebrew/test/test/log_formula_test.rb b/Library/Homebrew/test/test/log_formula_test.rb index 34509bf72..26c10d381 100644 --- a/Library/Homebrew/test/test/log_formula_test.rb +++ b/Library/Homebrew/test/test/log_formula_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLogFormula < IntegrationCommandTestCase def test_log_formula diff --git a/Library/Homebrew/test/test/log_test.rb b/Library/Homebrew/test/test/log_test.rb index b20a098fd..c9eb73d97 100644 --- a/Library/Homebrew/test/test/log_test.rb +++ b/Library/Homebrew/test/test/log_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLog < IntegrationCommandTestCase def test_log diff --git a/Library/Homebrew/test/test/migrate_test.rb b/Library/Homebrew/test/test/migrate_test.rb index 53b32777a..c267629a3 100644 --- a/Library/Homebrew/test/test/migrate_test.rb +++ b/Library/Homebrew/test/test/migrate_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestMigrate < IntegrationCommandTestCase def test_migrate diff --git a/Library/Homebrew/test/test/migrator_test.rb b/Library/Homebrew/test/test/migrator_test.rb index cefb8b7a3..8a2b6ad63 100644 --- a/Library/Homebrew/test/test/migrator_test.rb +++ b/Library/Homebrew/test/test/migrator_test.rb @@ -1,6 +1,6 @@ require "testing_env" require "migrator" -require "testball" +require "test/support/fixtures/testball" require "tab" require "keg" diff --git a/Library/Homebrew/test/test/missing_test.rb b/Library/Homebrew/test/test/missing_test.rb index 565f413da..9ad0ab0b8 100644 --- a/Library/Homebrew/test/test/missing_test.rb +++ b/Library/Homebrew/test/test/missing_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestMissing < IntegrationCommandTestCase def setup diff --git a/Library/Homebrew/test/test/options_test.rb b/Library/Homebrew/test/test/options_test.rb index bfde7a9b6..43ea26b97 100644 --- a/Library/Homebrew/test/test/options_test.rb +++ b/Library/Homebrew/test/test/options_test.rb @@ -1,6 +1,7 @@ require "testing_env" require "options" -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestOptions < IntegrationCommandTestCase def test_options diff --git a/Library/Homebrew/test/test/os/mac/mach_test.rb b/Library/Homebrew/test/test/os/mac/mach_test.rb index 404a21d60..a42f7316b 100644 --- a/Library/Homebrew/test/test/os/mac/mach_test.rb +++ b/Library/Homebrew/test/test/os/mac/mach_test.rb @@ -41,7 +41,7 @@ class MachOPathnameTests < Homebrew::TestCase end def test_mach_o_executable - pn = Pathname.new("#{TEST_DIRECTORY}/mach/a.out") + pn = Pathname.new("#{TEST_FIXTURE_DIR}/mach/a.out") assert_predicate pn, :universal? refute_predicate pn, :i386? refute_predicate pn, :x86_64? @@ -93,7 +93,7 @@ class MachOPathnameTests < Homebrew::TestCase end def test_non_mach_o - pn = Pathname.new("#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz") + pn = Pathname.new("#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz") refute_predicate pn, :universal? refute_predicate pn, :i386? refute_predicate pn, :x86_64? diff --git a/Library/Homebrew/test/test/outdated_test.rb b/Library/Homebrew/test/test/outdated_test.rb index cc0f024c8..03c2293d8 100644 --- a/Library/Homebrew/test/test/outdated_test.rb +++ b/Library/Homebrew/test/test/outdated_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestOutdated < IntegrationCommandTestCase def test_outdated diff --git a/Library/Homebrew/test/test/patching_test.rb b/Library/Homebrew/test/test/patching_test.rb index 18b848b10..ac14c8e1e 100644 --- a/Library/Homebrew/test/test/patching_test.rb +++ b/Library/Homebrew/test/test/patching_test.rb @@ -2,12 +2,12 @@ require "testing_env" require "formula" class PatchingTests < Homebrew::TestCase - TESTBALL_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz".freeze - TESTBALL_PATCHES_URL = "file://#{TEST_DIRECTORY}/tarballs/testball-0.1-patches.tgz".freeze - PATCH_URL_A = "file://#{TEST_DIRECTORY}/patches/noop-a.diff".freeze - PATCH_URL_B = "file://#{TEST_DIRECTORY}/patches/noop-b.diff".freeze - PATCH_A_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-a.diff" - PATCH_B_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-b.diff" + 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 diff --git a/Library/Homebrew/test/test/pin_unpin_test.rb b/Library/Homebrew/test/test/pin_unpin_test.rb index 37682d45e..9603620a3 100644 --- a/Library/Homebrew/test/test/pin_unpin_test.rb +++ b/Library/Homebrew/test/test/pin_unpin_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPinUnpin < IntegrationCommandTestCase def test_pin_unpin diff --git a/Library/Homebrew/test/test/prefix_formula_test.rb b/Library/Homebrew/test/test/prefix_formula_test.rb index d76a966d7..e51de2b6f 100644 --- a/Library/Homebrew/test/test/prefix_formula_test.rb +++ b/Library/Homebrew/test/test/prefix_formula_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPrefixFormula < IntegrationCommandTestCase def test_prefix_formula diff --git a/Library/Homebrew/test/test/prefix_test.rb b/Library/Homebrew/test/test/prefix_test.rb index 4aa63fa07..1b2114807 100644 --- a/Library/Homebrew/test/test/prefix_test.rb +++ b/Library/Homebrew/test/test/prefix_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPrefix < IntegrationCommandTestCase def test_prefix diff --git a/Library/Homebrew/test/test/prune_test.rb b/Library/Homebrew/test/test/prune_test.rb index 293a3746d..b81062112 100644 --- a/Library/Homebrew/test/test/prune_test.rb +++ b/Library/Homebrew/test/test/prune_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPrune < IntegrationCommandTestCase def test_prune diff --git a/Library/Homebrew/test/test/pull_offline_test.rb b/Library/Homebrew/test/test/pull_offline_test.rb index 2716af346..1429ca62e 100644 --- a/Library/Homebrew/test/test/pull_offline_test.rb +++ b/Library/Homebrew/test/test/pull_offline_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPullOffline < IntegrationCommandTestCase def test_pull_offline diff --git a/Library/Homebrew/test/test/pull_test.rb b/Library/Homebrew/test/test/pull_test.rb index 9707ff8a8..f772454ba 100644 --- a/Library/Homebrew/test/test/pull_test.rb +++ b/Library/Homebrew/test/test/pull_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPull < IntegrationCommandTestCase def test_pull diff --git a/Library/Homebrew/test/test/readall_test.rb b/Library/Homebrew/test/test/readall_test.rb index d0c078e49..cbb304ca1 100644 --- a/Library/Homebrew/test/test/readall_test.rb +++ b/Library/Homebrew/test/test/readall_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestReadall < IntegrationCommandTestCase def test_readall diff --git a/Library/Homebrew/test/test/reinstall_pinned_test.rb b/Library/Homebrew/test/test/reinstall_pinned_test.rb index c9cb8a849..36f5cfd74 100644 --- a/Library/Homebrew/test/test/reinstall_pinned_test.rb +++ b/Library/Homebrew/test/test/reinstall_pinned_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestReinstallPinned < IntegrationCommandTestCase def test_reinstall_pinned diff --git a/Library/Homebrew/test/test/reinstall_test.rb b/Library/Homebrew/test/test/reinstall_test.rb index d07a96051..501830102 100644 --- a/Library/Homebrew/test/test/reinstall_test.rb +++ b/Library/Homebrew/test/test/reinstall_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestReinstall < IntegrationCommandTestCase def test_reinstall diff --git a/Library/Homebrew/test/test/repository_test.rb b/Library/Homebrew/test/test/repository_test.rb index 2029876ad..352ab1d42 100644 --- a/Library/Homebrew/test/test/repository_test.rb +++ b/Library/Homebrew/test/test/repository_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestRepository < IntegrationCommandTestCase def test_repository diff --git a/Library/Homebrew/test/test/search_test.rb b/Library/Homebrew/test/test/search_test.rb index 8310d1c2b..95e555bf2 100644 --- a/Library/Homebrew/test/test/search_test.rb +++ b/Library/Homebrew/test/test/search_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestSearch < IntegrationCommandTestCase def test_search diff --git a/Library/Homebrew/test/test/services_test.rb b/Library/Homebrew/test/test/services_test.rb index b5ccb7c77..94fba4675 100644 --- a/Library/Homebrew/test/test/services_test.rb +++ b/Library/Homebrew/test/test/services_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestServices < IntegrationCommandTestCase def test_services diff --git a/Library/Homebrew/test/test/sh_test.rb b/Library/Homebrew/test/test/sh_test.rb index 449b7b5b3..67593b17e 100644 --- a/Library/Homebrew/test/test/sh_test.rb +++ b/Library/Homebrew/test/test/sh_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestSh < IntegrationCommandTestCase def test_sh diff --git a/Library/Homebrew/test/test/switch_test.rb b/Library/Homebrew/test/test/switch_test.rb index 88fdf85b9..766d24494 100644 --- a/Library/Homebrew/test/test/switch_test.rb +++ b/Library/Homebrew/test/test/switch_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestSwitch < IntegrationCommandTestCase def test_switch diff --git a/Library/Homebrew/test/test/tab_test.rb b/Library/Homebrew/test/test/tab_test.rb index 2c756cf68..76c9aacc9 100644 --- a/Library/Homebrew/test/test/tab_test.rb +++ b/Library/Homebrew/test/test/tab_test.rb @@ -218,7 +218,7 @@ class TabLoadingTests < Homebrew::TestCase @f = formula { url "foo-1.0" } @f.prefix.mkpath @path = @f.prefix.join(Tab::FILENAME) - @path.write Pathname.new(TEST_DIRECTORY).join("fixtures", "receipt.json").read + @path.write TEST_FIXTURE_DIR.join("receipt.json").read end def teardown diff --git a/Library/Homebrew/test/test/tap_new_test.rb b/Library/Homebrew/test/test/tap_new_test.rb index 636024b0a..57ad4a08e 100644 --- a/Library/Homebrew/test/test/tap_new_test.rb +++ b/Library/Homebrew/test/test/tap_new_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestTapNew < IntegrationCommandTestCase def test_tap_readme diff --git a/Library/Homebrew/test/test/tap_test.rb b/Library/Homebrew/test/test/tap_test.rb index 71836aee9..94597cdb3 100644 --- a/Library/Homebrew/test/test/tap_test.rb +++ b/Library/Homebrew/test/test/tap_test.rb @@ -1,5 +1,6 @@ require "testing_env" -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestTap < IntegrationCommandTestCase def test_tap diff --git a/Library/Homebrew/test/test/test_formula_test.rb b/Library/Homebrew/test/test/test_formula_test.rb index b3889d6a2..cab4db740 100644 --- a/Library/Homebrew/test/test/test_formula_test.rb +++ b/Library/Homebrew/test/test/test_formula_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestTestFormula < IntegrationCommandTestCase def test_test_formula @@ -13,7 +14,7 @@ class IntegrationCommandTestTestFormula < IntegrationCommandTestCase head "https://github.com/example/testball2.git" devel do - url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" sha256 "#{TESTBALL_SHA256}" end diff --git a/Library/Homebrew/test/test/uninstall_test.rb b/Library/Homebrew/test/test/uninstall_test.rb index d86db0e80..ffc6f0db7 100644 --- a/Library/Homebrew/test/test/uninstall_test.rb +++ b/Library/Homebrew/test/test/uninstall_test.rb @@ -1,4 +1,4 @@ -require "helper/integration_command_test_case" +require "test/support/helper/integration_command_test_case" require "cmd/uninstall" class UninstallTests < Homebrew::TestCase diff --git a/Library/Homebrew/test/test/unlink_test.rb b/Library/Homebrew/test/test/unlink_test.rb index 091bd8c45..a307dc638 100644 --- a/Library/Homebrew/test/test/unlink_test.rb +++ b/Library/Homebrew/test/test/unlink_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUnlink < IntegrationCommandTestCase def test_unlink diff --git a/Library/Homebrew/test/test/unlinkapps_test.rb b/Library/Homebrew/test/test/unlinkapps_test.rb index 2de4e3ff8..2dbbd84e9 100644 --- a/Library/Homebrew/test/test/unlinkapps_test.rb +++ b/Library/Homebrew/test/test/unlinkapps_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUnlinkapps < IntegrationCommandTestCase def test_unlinkapps diff --git a/Library/Homebrew/test/test/unpack_test.rb b/Library/Homebrew/test/test/unpack_test.rb index de1452a29..e044e713b 100644 --- a/Library/Homebrew/test/test/unpack_test.rb +++ b/Library/Homebrew/test/test/unpack_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUnpack < IntegrationCommandTestCase def test_unpack diff --git a/Library/Homebrew/test/test/upgrade_test.rb b/Library/Homebrew/test/test/upgrade_test.rb index 73618293b..7c74ca70e 100644 --- a/Library/Homebrew/test/test/upgrade_test.rb +++ b/Library/Homebrew/test/test/upgrade_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUpgrade < IntegrationCommandTestCase def test_upgrade diff --git a/Library/Homebrew/test/test/uses_test.rb b/Library/Homebrew/test/test/uses_test.rb index b0e79ef2d..494ce4d6e 100644 --- a/Library/Homebrew/test/test/uses_test.rb +++ b/Library/Homebrew/test/test/uses_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUses < IntegrationCommandTestCase def test_uses diff --git a/Library/Homebrew/test/test/version_test.rb b/Library/Homebrew/test/test/version_test.rb index ca37e3567..a783eda69 100644 --- a/Library/Homebrew/test/test/version_test.rb +++ b/Library/Homebrew/test/test/version_test.rb @@ -1,4 +1,5 @@ -require "helper/integration_command_test_case" +require "testing_env" +require "test/support/helper/integration_command_test_case" class IntegrationCommandTestVersion < IntegrationCommandTestCase def test_version diff --git a/Library/Homebrew/test/testball.rb b/Library/Homebrew/test/testball.rb deleted file mode 100644 index cce09738d..000000000 --- a/Library/Homebrew/test/testball.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Testball < Formula - def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) - self.class.instance_eval do - stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" - stable.sha256 TESTBALL_SHA256 - end - super - end - - def install - prefix.install "bin" - prefix.install "libexec" - Dir.chdir "doc" - end -end diff --git a/Library/Homebrew/test/testball_bottle.rb b/Library/Homebrew/test/testball_bottle.rb deleted file mode 100644 index 769f615aa..000000000 --- a/Library/Homebrew/test/testball_bottle.rb +++ /dev/null @@ -1,20 +0,0 @@ -class TestballBottle < Formula - def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) - self.class.instance_eval do - stable.url "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz" - stable.sha256 TESTBALL_SHA256 - stable.bottle do - cellar :any_skip_relocation - root_url "file://#{File.expand_path("..", __FILE__)}/bottles" - sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => Utils::Bottles.tag - end - cxxstdlib_check :skip - end - super - end - - def install - prefix.install "bin" - prefix.install "libexec" - end -end diff --git a/Library/Homebrew/test/testbottest.rb b/Library/Homebrew/test/testbottest.rb deleted file mode 100644 index f7695cab5..000000000 --- a/Library/Homebrew/test/testbottest.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Testbottest < Formula - desc "Minimal C program and Makefile used for testing Homebrew." - homepage "https://github.com/Homebrew/brew" - url "file://#{File.expand_path("..", __FILE__)}/tarballs/testbottest-0.1.tbz" - sha256 "78b54d8f31585c9773bed12b4aa4ab2ce458ebd044b9406cb24d40aa5107f082" - - def install - system "make", "install", "PREFIX=#{prefix}" - end - - test do - assert_equal "testbottest\n", shell_output("#{bin}/testbottest") - end -end diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb index d441b4f1c..76b943164 100644 --- a/Library/Homebrew/test/testing_env.rb +++ b/Library/Homebrew/test/testing_env.rb @@ -1,5 +1,5 @@ $:.unshift File.expand_path("../..", __FILE__) -$:.unshift File.expand_path("../lib", __FILE__) +$:.unshift File.expand_path("../support/lib", __FILE__) require "simplecov" if ENV["HOMEBREW_TESTS_COVERAGE"] require "global" @@ -9,9 +9,6 @@ require "formulary" (HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-core/Formula").mkpath %w[cache formula_cache locks cellar logs temp].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath } -# Test fixtures and files can be found relative to this path -TEST_DIRECTORY = File.dirname(File.expand_path(__FILE__)) - begin require "rubygems" require "minitest/autorun" @@ -43,7 +40,9 @@ module Homebrew module FSLeakLogger def self.included(klass) require "find" - @@log = File.open(HOMEBREW_LIBRARY_PATH/"tmp/fs_leak.log", "w") + logdir = HOMEBREW_LIBRARY_PATH.join("tmp") + logdir.mkdir unless logdir.directory? + @@log = File.open(logdir.join("fs_leak.log"), "w") klass.make_my_diffs_pretty! end @@ -63,8 +62,8 @@ module Homebrew end class TestCase < ::Minitest::Test - require "test/helper/env" - require "test/helper/shutup" + require "test/support/helper/env" + require "test/support/helper/shutup" include Test::Helper::Env include Test::Helper::Shutup @@ -107,11 +106,11 @@ module Homebrew end def dylib_path(name) - Pathname.new("#{TEST_DIRECTORY}/mach/#{name}.dylib") + Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.dylib") end def bundle_path(name) - Pathname.new("#{TEST_DIRECTORY}/mach/#{name}.bundle") + Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.bundle") end # Use a stubbed {Formulary::FormulaLoader} to make a given formula be found -- cgit v1.2.3 From 7b9fd538fabf450203c0120f996403e24bd02071 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 7 Nov 2016 00:01:57 +0100 Subject: Move `integration_mocks` to `test/support/helper`. --- .../support/helper/integration_command_test_case.rb | 3 ++- .../Homebrew/test/support/helper/integration_mocks.rb | 17 +++++++++++++++++ Library/Homebrew/test/support/lib/integration_mocks.rb | 17 ----------------- 3 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 Library/Homebrew/test/support/helper/integration_mocks.rb delete mode 100644 Library/Homebrew/test/support/lib/integration_mocks.rb (limited to 'Library') 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 d7ae67423..9306617eb 100644 --- a/Library/Homebrew/test/support/helper/integration_command_test_case.rb +++ b/Library/Homebrew/test/support/helper/integration_command_test_case.rb @@ -60,6 +60,7 @@ class IntegrationCommandTestCase < Homebrew::TestCase cmd_args = %W[ -W0 -I#{HOMEBREW_LIBRARY_PATH}/test/support/lib + -I#{HOMEBREW_LIBRARY_PATH} -rconfig ] if ENV["HOMEBREW_TESTS_COVERAGE"] @@ -70,7 +71,7 @@ class IntegrationCommandTestCase < Homebrew::TestCase cmd_args << "-rbundler/setup" cmd_args << "-rsimplecov" end - cmd_args << "-rintegration_mocks" + 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"] diff --git a/Library/Homebrew/test/support/helper/integration_mocks.rb b/Library/Homebrew/test/support/helper/integration_mocks.rb new file mode 100644 index 000000000..6effb0cde --- /dev/null +++ b/Library/Homebrew/test/support/helper/integration_mocks.rb @@ -0,0 +1,17 @@ +module Homebrew + module Diagnostic + class Checks + def check_integration_test + "This is an integration test" if ENV["HOMEBREW_INTEGRATION_TEST"] + end + end + end + + def exec(*args) + if ENV["HOMEBREW_TESTS_COVERAGE"] && ENV["HOMEBREW_INTEGRATION_TEST"] + # Ensure we get coverage results before replacing the current process. + SimpleCov.result + end + Kernel.exec(*args) + end +end diff --git a/Library/Homebrew/test/support/lib/integration_mocks.rb b/Library/Homebrew/test/support/lib/integration_mocks.rb deleted file mode 100644 index 6effb0cde..000000000 --- a/Library/Homebrew/test/support/lib/integration_mocks.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Homebrew - module Diagnostic - class Checks - def check_integration_test - "This is an integration test" if ENV["HOMEBREW_INTEGRATION_TEST"] - end - end - end - - def exec(*args) - if ENV["HOMEBREW_TESTS_COVERAGE"] && ENV["HOMEBREW_INTEGRATION_TEST"] - # Ensure we get coverage results before replacing the current process. - SimpleCov.result - end - Kernel.exec(*args) - end -end -- cgit v1.2.3 From 9d82acbf30e9a5d0eb06be9726803d362e2fa91e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 13 Nov 2016 21:31:53 +0100 Subject: Separate `Homebrew::TestCase` from `testing_env`. --- Library/Homebrew/.rubocop_todo.yml | 2 +- .../Homebrew/test/support/helper/fs_leak_logger.rb | 27 ++++++ Library/Homebrew/test/support/helper/test_case.rb | 64 ++++++++++++ .../test/support/helper/version_assertions.rb | 23 +++++ Library/Homebrew/test/testing_env.rb | 107 +-------------------- 5 files changed, 116 insertions(+), 107 deletions(-) create mode 100644 Library/Homebrew/test/support/helper/fs_leak_logger.rb create mode 100644 Library/Homebrew/test/support/helper/test_case.rb create mode 100644 Library/Homebrew/test/support/helper/version_assertions.rb (limited to 'Library') diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml index 9e48c6792..3705170fd 100644 --- a/Library/Homebrew/.rubocop_todo.yml +++ b/Library/Homebrew/.rubocop_todo.yml @@ -90,7 +90,7 @@ Style/ClassVars: Exclude: - 'dev-cmd/audit.rb' - 'formula_installer.rb' - - 'test/testing_env.rb' + - 'test/support/helper/fs_leak_logger.rb' # Offense count: 13 # Configuration parameters: AllowedVariables. diff --git a/Library/Homebrew/test/support/helper/fs_leak_logger.rb b/Library/Homebrew/test/support/helper/fs_leak_logger.rb new file mode 100644 index 000000000..f6a02dbc0 --- /dev/null +++ b/Library/Homebrew/test/support/helper/fs_leak_logger.rb @@ -0,0 +1,27 @@ +module Test + module Helper + module FSLeakLogger + def self.included(klass) + require "find" + logdir = HOMEBREW_LIBRARY_PATH.join("tmp") + logdir.mkdir unless logdir.directory? + @@log = File.open(logdir.join("fs_leak.log"), "w") + klass.make_my_diffs_pretty! + end + + def before_setup + @__files_before_test = [] + Find.find(TEST_TMPDIR) { |f| @__files_before_test << f.sub(TEST_TMPDIR, "") } + super + end + + def after_teardown + super + files_after_test = [] + Find.find(TEST_TMPDIR) { |f| files_after_test << f.sub(TEST_TMPDIR, "") } + return if @__files_before_test == files_after_test + @@log.puts location, diff(@__files_before_test, files_after_test) + end + end + end +end diff --git a/Library/Homebrew/test/support/helper/test_case.rb b/Library/Homebrew/test/support/helper/test_case.rb new file mode 100644 index 000000000..60c91e7bb --- /dev/null +++ b/Library/Homebrew/test/support/helper/test_case.rb @@ -0,0 +1,64 @@ +module Homebrew + class TestCase < ::Minitest::Test + require "test/support/helper/env" + require "test/support/helper/fs_leak_logger" + require "test/support/helper/shutup" + require "test/support/helper/version_assertions" + include Test::Helper::Env + include Test::Helper::FSLeakLogger + include Test::Helper::Shutup + include Test::Helper::VersionAssertions + + TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze + TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze + + 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) + end + + def mktmpdir(prefix_suffix = nil, &block) + Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block) + end + + def needs_compat + skip "Requires compat/ code" if ENV["HOMEBREW_NO_COMPAT"] + end + + def needs_python + skip "Requires Python" unless which("python") + end + + def assert_nothing_raised + yield + end + + def assert_eql(exp, act, msg = nil) + msg = message(msg, "") { diff exp, act } + assert exp.eql?(act), msg + end + + def refute_eql(exp, act, msg = nil) + msg = message(msg) do + "Expected #{mu_pp(act)} to not be eql to #{mu_pp(exp)}" + end + refute exp.eql?(act), msg + end + + 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 + + # 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 = mock + loader.stubs(:get_formula).returns(formula) + Formulary.stubs(:loader_for).with(ref, from: :keg).returns(loader) + Formulary.stubs(:loader_for).with(ref, from: nil).returns(loader) + end + end +end diff --git a/Library/Homebrew/test/support/helper/version_assertions.rb b/Library/Homebrew/test/support/helper/version_assertions.rb new file mode 100644 index 000000000..dc240d643 --- /dev/null +++ b/Library/Homebrew/test/support/helper/version_assertions.rb @@ -0,0 +1,23 @@ +require "rubygems" + +module Test + module Helper + module VersionAssertions + def version(v) + Version.create(v) + end + + def assert_version_equal(expected, actual) + assert_equal Version.create(expected), actual + end + + def assert_version_detected(expected, url, specs = {}) + assert_equal expected, Version.detect(url, specs).to_s + end + + def assert_version_nil(url) + assert Version.parse(url).null? + end + end + end +end diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb index 76b943164..be70b2fe7 100644 --- a/Library/Homebrew/test/testing_env.rb +++ b/Library/Homebrew/test/testing_env.rb @@ -10,7 +10,6 @@ require "formulary" %w[cache formula_cache locks cellar logs temp].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath } begin - require "rubygems" require "minitest/autorun" require "parallel_tests/test/runtime_logger" require "mocha/setup" @@ -18,108 +17,4 @@ rescue LoadError abort "Run `bundle install` or install the mocha and minitest gems before running the tests" end -module Homebrew - module VersionAssertions - def version(v) - Version.create(v) - end - - def assert_version_equal(expected, actual) - assert_equal Version.create(expected), actual - end - - def assert_version_detected(expected, url, specs = {}) - assert_equal expected, Version.detect(url, specs).to_s - end - - def assert_version_nil(url) - assert Version.parse(url).null? - end - end - - module FSLeakLogger - def self.included(klass) - require "find" - logdir = HOMEBREW_LIBRARY_PATH.join("tmp") - logdir.mkdir unless logdir.directory? - @@log = File.open(logdir.join("fs_leak.log"), "w") - klass.make_my_diffs_pretty! - end - - def before_setup - @__files_before_test = [] - Find.find(TEST_TMPDIR) { |f| @__files_before_test << f.sub(TEST_TMPDIR, "") } - super - end - - def after_teardown - super - files_after_test = [] - Find.find(TEST_TMPDIR) { |f| files_after_test << f.sub(TEST_TMPDIR, "") } - return if @__files_before_test == files_after_test - @@log.puts location, diff(@__files_before_test, files_after_test) - end - end - - class TestCase < ::Minitest::Test - require "test/support/helper/env" - require "test/support/helper/shutup" - include Test::Helper::Env - include Test::Helper::Shutup - - include VersionAssertions - include FSLeakLogger - - TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze - TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze - - 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) - end - - def mktmpdir(prefix_suffix = nil, &block) - Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block) - end - - def needs_compat - skip "Requires compat/ code" if ENV["HOMEBREW_NO_COMPAT"] - end - - def needs_python - skip "Requires Python" unless which("python") - end - - def assert_nothing_raised - yield - end - - def assert_eql(exp, act, msg = nil) - msg = message(msg, "") { diff exp, act } - assert exp.eql?(act), msg - end - - def refute_eql(exp, act, msg = nil) - msg = message(msg) do - "Expected #{mu_pp(act)} to not be eql to #{mu_pp(exp)}" - end - refute exp.eql?(act), msg - end - - 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 - - # 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 = mock - loader.stubs(:get_formula).returns(formula) - Formulary.stubs(:loader_for).with(ref, from: :keg).returns(loader) - Formulary.stubs(:loader_for).with(ref, from: nil).returns(loader) - end - end -end +require "test/support/helper/test_case" -- cgit v1.2.3 From 9dc1f8f3cd405bc299eb688075687f951afd3e13 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 13 Nov 2016 21:35:20 +0100 Subject: Require `integration_command_test_case` in `testing_env`. --- Library/Homebrew/test/support/helper/integration_command_test_case.rb | 1 + Library/Homebrew/test/test/ENV_test.rb | 1 - Library/Homebrew/test/test/analytics_test.rb | 1 - Library/Homebrew/test/test/bottle_test.rb | 1 - Library/Homebrew/test/test/bundle_test.rb | 1 - Library/Homebrew/test/test/cache_formula_test.rb | 1 - Library/Homebrew/test/test/cache_test.rb | 1 - Library/Homebrew/test/test/cask_test.rb | 1 - Library/Homebrew/test/test/cat_test.rb | 1 - Library/Homebrew/test/test/cellar_formula_test.rb | 1 - Library/Homebrew/test/test/cellar_test.rb | 1 - Library/Homebrew/test/test/cleanup_test.rb | 1 - Library/Homebrew/test/test/command_test.rb | 1 - Library/Homebrew/test/test/commands_test.rb | 1 - Library/Homebrew/test/test/config_test.rb | 1 - Library/Homebrew/test/test/create_test.rb | 1 - Library/Homebrew/test/test/custom_command_test.rb | 1 - Library/Homebrew/test/test/deps_test.rb | 1 - Library/Homebrew/test/test/desc_test.rb | 1 - Library/Homebrew/test/test/doctor_test.rb | 1 - Library/Homebrew/test/test/edit_test.rb | 1 - Library/Homebrew/test/test/fetch_test.rb | 1 - Library/Homebrew/test/test/help_test.rb | 1 - Library/Homebrew/test/test/home_test.rb | 1 - Library/Homebrew/test/test/info_test.rb | 1 - Library/Homebrew/test/test/install_test.rb | 1 - Library/Homebrew/test/test/irb_test.rb | 1 - Library/Homebrew/test/test/leaves_test.rb | 1 - Library/Homebrew/test/test/link_test.rb | 1 - Library/Homebrew/test/test/linkapps_test.rb | 1 - Library/Homebrew/test/test/list_test.rb | 1 - Library/Homebrew/test/test/log_formula_test.rb | 1 - Library/Homebrew/test/test/log_test.rb | 1 - Library/Homebrew/test/test/migrate_test.rb | 1 - Library/Homebrew/test/test/missing_test.rb | 1 - Library/Homebrew/test/test/options_test.rb | 1 - Library/Homebrew/test/test/outdated_test.rb | 1 - Library/Homebrew/test/test/pin_unpin_test.rb | 1 - Library/Homebrew/test/test/prefix_formula_test.rb | 1 - Library/Homebrew/test/test/prefix_test.rb | 1 - Library/Homebrew/test/test/prune_test.rb | 1 - Library/Homebrew/test/test/pull_offline_test.rb | 1 - Library/Homebrew/test/test/pull_test.rb | 1 - Library/Homebrew/test/test/readall_test.rb | 1 - Library/Homebrew/test/test/reinstall_pinned_test.rb | 1 - Library/Homebrew/test/test/reinstall_test.rb | 1 - Library/Homebrew/test/test/repository_test.rb | 1 - Library/Homebrew/test/test/search_test.rb | 1 - Library/Homebrew/test/test/services_test.rb | 1 - Library/Homebrew/test/test/sh_test.rb | 1 - Library/Homebrew/test/test/switch_test.rb | 1 - Library/Homebrew/test/test/tap_new_test.rb | 1 - Library/Homebrew/test/test/tap_test.rb | 1 - Library/Homebrew/test/test/test_formula_test.rb | 1 - Library/Homebrew/test/test/uninstall_test.rb | 1 - Library/Homebrew/test/test/unlink_test.rb | 1 - Library/Homebrew/test/test/unlinkapps_test.rb | 1 - Library/Homebrew/test/test/unpack_test.rb | 1 - Library/Homebrew/test/test/upgrade_test.rb | 1 - Library/Homebrew/test/test/uses_test.rb | 1 - Library/Homebrew/test/test/version_test.rb | 1 - Library/Homebrew/test/testing_env.rb | 1 + 62 files changed, 2 insertions(+), 60 deletions(-) (limited to 'Library') 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 9306617eb..5940fd84b 100644 --- a/Library/Homebrew/test/support/helper/integration_command_test_case.rb +++ b/Library/Homebrew/test/support/helper/integration_command_test_case.rb @@ -2,6 +2,7 @@ require "bundler" require "fileutils" require "pathname" require "formula" +require "test/support/helper/test_case" class IntegrationCommandTestCase < Homebrew::TestCase def setup diff --git a/Library/Homebrew/test/test/ENV_test.rb b/Library/Homebrew/test/test/ENV_test.rb index 1736d34af..6c0e68a9e 100644 --- a/Library/Homebrew/test/test/ENV_test.rb +++ b/Library/Homebrew/test/test/ENV_test.rb @@ -1,7 +1,6 @@ require "testing_env" require "extend/ENV" require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestEnv < IntegrationCommandTestCase def test_env diff --git a/Library/Homebrew/test/test/analytics_test.rb b/Library/Homebrew/test/test/analytics_test.rb index 266c5bd09..37040f3cd 100644 --- a/Library/Homebrew/test/test/analytics_test.rb +++ b/Library/Homebrew/test/test/analytics_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestAnalytics < IntegrationCommandTestCase def test_analytics diff --git a/Library/Homebrew/test/test/bottle_test.rb b/Library/Homebrew/test/test/bottle_test.rb index 5fdba0af8..c10746e09 100644 --- a/Library/Homebrew/test/test/bottle_test.rb +++ b/Library/Homebrew/test/test/bottle_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestBottle < IntegrationCommandTestCase def test_bottle diff --git a/Library/Homebrew/test/test/bundle_test.rb b/Library/Homebrew/test/test/bundle_test.rb index ea18d5f84..ae47977d8 100644 --- a/Library/Homebrew/test/test/bundle_test.rb +++ b/Library/Homebrew/test/test/bundle_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestBundle < IntegrationCommandTestCase def test_bundle diff --git a/Library/Homebrew/test/test/cache_formula_test.rb b/Library/Homebrew/test/test/cache_formula_test.rb index c64ce9809..6dcb6a745 100644 --- a/Library/Homebrew/test/test/cache_formula_test.rb +++ b/Library/Homebrew/test/test/cache_formula_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCacheFormula < IntegrationCommandTestCase def test_cache_formula diff --git a/Library/Homebrew/test/test/cache_test.rb b/Library/Homebrew/test/test/cache_test.rb index f8c035676..3a9e6b011 100644 --- a/Library/Homebrew/test/test/cache_test.rb +++ b/Library/Homebrew/test/test/cache_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCache < IntegrationCommandTestCase def test_cache diff --git a/Library/Homebrew/test/test/cask_test.rb b/Library/Homebrew/test/test/cask_test.rb index ad7a2a0a0..d5b81facb 100644 --- a/Library/Homebrew/test/test/cask_test.rb +++ b/Library/Homebrew/test/test/cask_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCask < IntegrationCommandTestCase def test_cask diff --git a/Library/Homebrew/test/test/cat_test.rb b/Library/Homebrew/test/test/cat_test.rb index df64188d6..bb37b5fde 100644 --- a/Library/Homebrew/test/test/cat_test.rb +++ b/Library/Homebrew/test/test/cat_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCat < IntegrationCommandTestCase def test_cat diff --git a/Library/Homebrew/test/test/cellar_formula_test.rb b/Library/Homebrew/test/test/cellar_formula_test.rb index 6c3063ca3..38a934a7b 100644 --- a/Library/Homebrew/test/test/cellar_formula_test.rb +++ b/Library/Homebrew/test/test/cellar_formula_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCellarFormula < IntegrationCommandTestCase def test_cellar_formula diff --git a/Library/Homebrew/test/test/cellar_test.rb b/Library/Homebrew/test/test/cellar_test.rb index 32cdb1af5..74d5389f8 100644 --- a/Library/Homebrew/test/test/cellar_test.rb +++ b/Library/Homebrew/test/test/cellar_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCellar < IntegrationCommandTestCase def test_cellar diff --git a/Library/Homebrew/test/test/cleanup_test.rb b/Library/Homebrew/test/test/cleanup_test.rb index fef249fcb..bb8e1cdc6 100644 --- a/Library/Homebrew/test/test/cleanup_test.rb +++ b/Library/Homebrew/test/test/cleanup_test.rb @@ -4,7 +4,6 @@ require "cleanup" require "fileutils" require "pathname" require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCleanup < IntegrationCommandTestCase def test_cleanup diff --git a/Library/Homebrew/test/test/command_test.rb b/Library/Homebrew/test/test/command_test.rb index 620a014b9..d5c7aaa88 100644 --- a/Library/Homebrew/test/test/command_test.rb +++ b/Library/Homebrew/test/test/command_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCommand < IntegrationCommandTestCase def test_command diff --git a/Library/Homebrew/test/test/commands_test.rb b/Library/Homebrew/test/test/commands_test.rb index cbb446ae3..d44d2da0e 100644 --- a/Library/Homebrew/test/test/commands_test.rb +++ b/Library/Homebrew/test/test/commands_test.rb @@ -3,7 +3,6 @@ require "cmd/command" require "cmd/commands" require "fileutils" require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCommands < IntegrationCommandTestCase def test_commands diff --git a/Library/Homebrew/test/test/config_test.rb b/Library/Homebrew/test/test/config_test.rb index 1a793cc6b..81da4660a 100644 --- a/Library/Homebrew/test/test/config_test.rb +++ b/Library/Homebrew/test/test/config_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestConfig < IntegrationCommandTestCase def test_config diff --git a/Library/Homebrew/test/test/create_test.rb b/Library/Homebrew/test/test/create_test.rb index 26a325a22..aeee428aa 100644 --- a/Library/Homebrew/test/test/create_test.rb +++ b/Library/Homebrew/test/test/create_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCreate < IntegrationCommandTestCase def test_create diff --git a/Library/Homebrew/test/test/custom_command_test.rb b/Library/Homebrew/test/test/custom_command_test.rb index 71bfafd9b..8d05bc6c7 100644 --- a/Library/Homebrew/test/test/custom_command_test.rb +++ b/Library/Homebrew/test/test/custom_command_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestCustomCommand < IntegrationCommandTestCase def test_custom_command diff --git a/Library/Homebrew/test/test/deps_test.rb b/Library/Homebrew/test/test/deps_test.rb index 44803af5e..01639857c 100644 --- a/Library/Homebrew/test/test/deps_test.rb +++ b/Library/Homebrew/test/test/deps_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestDeps < IntegrationCommandTestCase def test_deps diff --git a/Library/Homebrew/test/test/desc_test.rb b/Library/Homebrew/test/test/desc_test.rb index 7428c0792..2ba498135 100644 --- a/Library/Homebrew/test/test/desc_test.rb +++ b/Library/Homebrew/test/test/desc_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestDesc < IntegrationCommandTestCase def test_desc diff --git a/Library/Homebrew/test/test/doctor_test.rb b/Library/Homebrew/test/test/doctor_test.rb index be1098d22..d2dc871f4 100644 --- a/Library/Homebrew/test/test/doctor_test.rb +++ b/Library/Homebrew/test/test/doctor_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestDoctor < IntegrationCommandTestCase def test_doctor diff --git a/Library/Homebrew/test/test/edit_test.rb b/Library/Homebrew/test/test/edit_test.rb index c78db3bd8..9b6ded651 100644 --- a/Library/Homebrew/test/test/edit_test.rb +++ b/Library/Homebrew/test/test/edit_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestEdit < IntegrationCommandTestCase def test_edit diff --git a/Library/Homebrew/test/test/fetch_test.rb b/Library/Homebrew/test/test/fetch_test.rb index e049db554..e08e545e3 100644 --- a/Library/Homebrew/test/test/fetch_test.rb +++ b/Library/Homebrew/test/test/fetch_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestFetch < IntegrationCommandTestCase def test_fetch diff --git a/Library/Homebrew/test/test/help_test.rb b/Library/Homebrew/test/test/help_test.rb index 8c9a4bb08..92dd99721 100644 --- a/Library/Homebrew/test/test/help_test.rb +++ b/Library/Homebrew/test/test/help_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestHelp < IntegrationCommandTestCase def test_help diff --git a/Library/Homebrew/test/test/home_test.rb b/Library/Homebrew/test/test/home_test.rb index 9116442b7..ff06b72c1 100644 --- a/Library/Homebrew/test/test/home_test.rb +++ b/Library/Homebrew/test/test/home_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestHome < IntegrationCommandTestCase def test_home diff --git a/Library/Homebrew/test/test/info_test.rb b/Library/Homebrew/test/test/info_test.rb index a4186a5e9..f71044bf0 100644 --- a/Library/Homebrew/test/test/info_test.rb +++ b/Library/Homebrew/test/test/info_test.rb @@ -2,7 +2,6 @@ require "testing_env" require "cmd/info" require "formula" require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestInfo < IntegrationCommandTestCase def test_info diff --git a/Library/Homebrew/test/test/install_test.rb b/Library/Homebrew/test/test/install_test.rb index 313125931..fa1057a02 100644 --- a/Library/Homebrew/test/test/install_test.rb +++ b/Library/Homebrew/test/test/install_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestInstall < IntegrationCommandTestCase def test_install diff --git a/Library/Homebrew/test/test/irb_test.rb b/Library/Homebrew/test/test/irb_test.rb index 77ca4a90d..832ca39a5 100644 --- a/Library/Homebrew/test/test/irb_test.rb +++ b/Library/Homebrew/test/test/irb_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestIrb < IntegrationCommandTestCase def test_irb diff --git a/Library/Homebrew/test/test/leaves_test.rb b/Library/Homebrew/test/test/leaves_test.rb index ef25a4b6e..f73fba1ea 100644 --- a/Library/Homebrew/test/test/leaves_test.rb +++ b/Library/Homebrew/test/test/leaves_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLeaves < IntegrationCommandTestCase def test_leaves diff --git a/Library/Homebrew/test/test/link_test.rb b/Library/Homebrew/test/test/link_test.rb index ecabe0c67..062caa0c0 100644 --- a/Library/Homebrew/test/test/link_test.rb +++ b/Library/Homebrew/test/test/link_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLink < IntegrationCommandTestCase def test_link diff --git a/Library/Homebrew/test/test/linkapps_test.rb b/Library/Homebrew/test/test/linkapps_test.rb index a0b33a543..4c5b8ec13 100644 --- a/Library/Homebrew/test/test/linkapps_test.rb +++ b/Library/Homebrew/test/test/linkapps_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLinkapps < IntegrationCommandTestCase def test_linkapps diff --git a/Library/Homebrew/test/test/list_test.rb b/Library/Homebrew/test/test/list_test.rb index 26aab741f..3c691e3ad 100644 --- a/Library/Homebrew/test/test/list_test.rb +++ b/Library/Homebrew/test/test/list_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestList < IntegrationCommandTestCase def test_list diff --git a/Library/Homebrew/test/test/log_formula_test.rb b/Library/Homebrew/test/test/log_formula_test.rb index 26c10d381..bb6a1f661 100644 --- a/Library/Homebrew/test/test/log_formula_test.rb +++ b/Library/Homebrew/test/test/log_formula_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLogFormula < IntegrationCommandTestCase def test_log_formula diff --git a/Library/Homebrew/test/test/log_test.rb b/Library/Homebrew/test/test/log_test.rb index c9eb73d97..b2e150ccd 100644 --- a/Library/Homebrew/test/test/log_test.rb +++ b/Library/Homebrew/test/test/log_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestLog < IntegrationCommandTestCase def test_log diff --git a/Library/Homebrew/test/test/migrate_test.rb b/Library/Homebrew/test/test/migrate_test.rb index c267629a3..17929d038 100644 --- a/Library/Homebrew/test/test/migrate_test.rb +++ b/Library/Homebrew/test/test/migrate_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestMigrate < IntegrationCommandTestCase def test_migrate diff --git a/Library/Homebrew/test/test/missing_test.rb b/Library/Homebrew/test/test/missing_test.rb index 9ad0ab0b8..4f20d8a7a 100644 --- a/Library/Homebrew/test/test/missing_test.rb +++ b/Library/Homebrew/test/test/missing_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestMissing < IntegrationCommandTestCase def setup diff --git a/Library/Homebrew/test/test/options_test.rb b/Library/Homebrew/test/test/options_test.rb index 43ea26b97..e7189a604 100644 --- a/Library/Homebrew/test/test/options_test.rb +++ b/Library/Homebrew/test/test/options_test.rb @@ -1,7 +1,6 @@ require "testing_env" require "options" require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestOptions < IntegrationCommandTestCase def test_options diff --git a/Library/Homebrew/test/test/outdated_test.rb b/Library/Homebrew/test/test/outdated_test.rb index 03c2293d8..3e7148ded 100644 --- a/Library/Homebrew/test/test/outdated_test.rb +++ b/Library/Homebrew/test/test/outdated_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestOutdated < IntegrationCommandTestCase def test_outdated diff --git a/Library/Homebrew/test/test/pin_unpin_test.rb b/Library/Homebrew/test/test/pin_unpin_test.rb index 9603620a3..65fb9e4da 100644 --- a/Library/Homebrew/test/test/pin_unpin_test.rb +++ b/Library/Homebrew/test/test/pin_unpin_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPinUnpin < IntegrationCommandTestCase def test_pin_unpin diff --git a/Library/Homebrew/test/test/prefix_formula_test.rb b/Library/Homebrew/test/test/prefix_formula_test.rb index e51de2b6f..eb5970d3e 100644 --- a/Library/Homebrew/test/test/prefix_formula_test.rb +++ b/Library/Homebrew/test/test/prefix_formula_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPrefixFormula < IntegrationCommandTestCase def test_prefix_formula diff --git a/Library/Homebrew/test/test/prefix_test.rb b/Library/Homebrew/test/test/prefix_test.rb index 1b2114807..a3ae75542 100644 --- a/Library/Homebrew/test/test/prefix_test.rb +++ b/Library/Homebrew/test/test/prefix_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPrefix < IntegrationCommandTestCase def test_prefix diff --git a/Library/Homebrew/test/test/prune_test.rb b/Library/Homebrew/test/test/prune_test.rb index b81062112..8fa5df7b7 100644 --- a/Library/Homebrew/test/test/prune_test.rb +++ b/Library/Homebrew/test/test/prune_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPrune < IntegrationCommandTestCase def test_prune diff --git a/Library/Homebrew/test/test/pull_offline_test.rb b/Library/Homebrew/test/test/pull_offline_test.rb index 1429ca62e..c9d46cd74 100644 --- a/Library/Homebrew/test/test/pull_offline_test.rb +++ b/Library/Homebrew/test/test/pull_offline_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPullOffline < IntegrationCommandTestCase def test_pull_offline diff --git a/Library/Homebrew/test/test/pull_test.rb b/Library/Homebrew/test/test/pull_test.rb index f772454ba..445d73cb1 100644 --- a/Library/Homebrew/test/test/pull_test.rb +++ b/Library/Homebrew/test/test/pull_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestPull < IntegrationCommandTestCase def test_pull diff --git a/Library/Homebrew/test/test/readall_test.rb b/Library/Homebrew/test/test/readall_test.rb index cbb304ca1..3eec79dd8 100644 --- a/Library/Homebrew/test/test/readall_test.rb +++ b/Library/Homebrew/test/test/readall_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestReadall < IntegrationCommandTestCase def test_readall diff --git a/Library/Homebrew/test/test/reinstall_pinned_test.rb b/Library/Homebrew/test/test/reinstall_pinned_test.rb index 36f5cfd74..80f5518ea 100644 --- a/Library/Homebrew/test/test/reinstall_pinned_test.rb +++ b/Library/Homebrew/test/test/reinstall_pinned_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestReinstallPinned < IntegrationCommandTestCase def test_reinstall_pinned diff --git a/Library/Homebrew/test/test/reinstall_test.rb b/Library/Homebrew/test/test/reinstall_test.rb index 501830102..73877b35d 100644 --- a/Library/Homebrew/test/test/reinstall_test.rb +++ b/Library/Homebrew/test/test/reinstall_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestReinstall < IntegrationCommandTestCase def test_reinstall diff --git a/Library/Homebrew/test/test/repository_test.rb b/Library/Homebrew/test/test/repository_test.rb index 352ab1d42..77967a58d 100644 --- a/Library/Homebrew/test/test/repository_test.rb +++ b/Library/Homebrew/test/test/repository_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestRepository < IntegrationCommandTestCase def test_repository diff --git a/Library/Homebrew/test/test/search_test.rb b/Library/Homebrew/test/test/search_test.rb index 95e555bf2..70b6f01fb 100644 --- a/Library/Homebrew/test/test/search_test.rb +++ b/Library/Homebrew/test/test/search_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestSearch < IntegrationCommandTestCase def test_search diff --git a/Library/Homebrew/test/test/services_test.rb b/Library/Homebrew/test/test/services_test.rb index 94fba4675..280aeb9f4 100644 --- a/Library/Homebrew/test/test/services_test.rb +++ b/Library/Homebrew/test/test/services_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestServices < IntegrationCommandTestCase def test_services diff --git a/Library/Homebrew/test/test/sh_test.rb b/Library/Homebrew/test/test/sh_test.rb index 67593b17e..48fcdc54a 100644 --- a/Library/Homebrew/test/test/sh_test.rb +++ b/Library/Homebrew/test/test/sh_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestSh < IntegrationCommandTestCase def test_sh diff --git a/Library/Homebrew/test/test/switch_test.rb b/Library/Homebrew/test/test/switch_test.rb index 766d24494..af1926c39 100644 --- a/Library/Homebrew/test/test/switch_test.rb +++ b/Library/Homebrew/test/test/switch_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestSwitch < IntegrationCommandTestCase def test_switch diff --git a/Library/Homebrew/test/test/tap_new_test.rb b/Library/Homebrew/test/test/tap_new_test.rb index 57ad4a08e..261a334f0 100644 --- a/Library/Homebrew/test/test/tap_new_test.rb +++ b/Library/Homebrew/test/test/tap_new_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestTapNew < IntegrationCommandTestCase def test_tap_readme diff --git a/Library/Homebrew/test/test/tap_test.rb b/Library/Homebrew/test/test/tap_test.rb index 94597cdb3..b950cd166 100644 --- a/Library/Homebrew/test/test/tap_test.rb +++ b/Library/Homebrew/test/test/tap_test.rb @@ -1,6 +1,5 @@ require "testing_env" require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestTap < IntegrationCommandTestCase def test_tap diff --git a/Library/Homebrew/test/test/test_formula_test.rb b/Library/Homebrew/test/test/test_formula_test.rb index cab4db740..5ad2db9e9 100644 --- a/Library/Homebrew/test/test/test_formula_test.rb +++ b/Library/Homebrew/test/test/test_formula_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestTestFormula < IntegrationCommandTestCase def test_test_formula diff --git a/Library/Homebrew/test/test/uninstall_test.rb b/Library/Homebrew/test/test/uninstall_test.rb index ffc6f0db7..70a694353 100644 --- a/Library/Homebrew/test/test/uninstall_test.rb +++ b/Library/Homebrew/test/test/uninstall_test.rb @@ -1,4 +1,3 @@ -require "test/support/helper/integration_command_test_case" require "cmd/uninstall" class UninstallTests < Homebrew::TestCase diff --git a/Library/Homebrew/test/test/unlink_test.rb b/Library/Homebrew/test/test/unlink_test.rb index a307dc638..6d5cefc67 100644 --- a/Library/Homebrew/test/test/unlink_test.rb +++ b/Library/Homebrew/test/test/unlink_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUnlink < IntegrationCommandTestCase def test_unlink diff --git a/Library/Homebrew/test/test/unlinkapps_test.rb b/Library/Homebrew/test/test/unlinkapps_test.rb index 2dbbd84e9..9d9672199 100644 --- a/Library/Homebrew/test/test/unlinkapps_test.rb +++ b/Library/Homebrew/test/test/unlinkapps_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUnlinkapps < IntegrationCommandTestCase def test_unlinkapps diff --git a/Library/Homebrew/test/test/unpack_test.rb b/Library/Homebrew/test/test/unpack_test.rb index e044e713b..bbff6ad1c 100644 --- a/Library/Homebrew/test/test/unpack_test.rb +++ b/Library/Homebrew/test/test/unpack_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUnpack < IntegrationCommandTestCase def test_unpack diff --git a/Library/Homebrew/test/test/upgrade_test.rb b/Library/Homebrew/test/test/upgrade_test.rb index 7c74ca70e..f3f5dccc7 100644 --- a/Library/Homebrew/test/test/upgrade_test.rb +++ b/Library/Homebrew/test/test/upgrade_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUpgrade < IntegrationCommandTestCase def test_upgrade diff --git a/Library/Homebrew/test/test/uses_test.rb b/Library/Homebrew/test/test/uses_test.rb index 494ce4d6e..2b1555417 100644 --- a/Library/Homebrew/test/test/uses_test.rb +++ b/Library/Homebrew/test/test/uses_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestUses < IntegrationCommandTestCase def test_uses diff --git a/Library/Homebrew/test/test/version_test.rb b/Library/Homebrew/test/test/version_test.rb index a783eda69..e7ffbc4f6 100644 --- a/Library/Homebrew/test/test/version_test.rb +++ b/Library/Homebrew/test/test/version_test.rb @@ -1,5 +1,4 @@ require "testing_env" -require "test/support/helper/integration_command_test_case" class IntegrationCommandTestVersion < IntegrationCommandTestCase def test_version diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb index be70b2fe7..e2ba2e4e4 100644 --- a/Library/Homebrew/test/testing_env.rb +++ b/Library/Homebrew/test/testing_env.rb @@ -18,3 +18,4 @@ rescue LoadError end require "test/support/helper/test_case" +require "test/support/helper/integration_command_test_case" -- cgit v1.2.3 From 7457af2b231528e1287281f6cfe651600d5f3f5d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 13 Nov 2016 22:00:15 +0100 Subject: Move test files back directly to `test/`. --- Library/Homebrew/dev-cmd/tests.rb | 6 +- Library/Homebrew/test/ARGV_test.rb | 80 ++ Library/Homebrew/test/ENV_test.rb | 201 ++++ Library/Homebrew/test/analytics_test.rb | 26 + Library/Homebrew/test/audit_test.rb | 472 ++++++++ Library/Homebrew/test/bash_test.rb | 34 + Library/Homebrew/test/blacklist_test.rb | 68 ++ Library/Homebrew/test/bottle_collector_test.rb | 38 + Library/Homebrew/test/bottle_filename_test.rb | 31 + Library/Homebrew/test/bottle_hooks_test.rb | 47 + Library/Homebrew/test/bottle_test.rb | 21 + Library/Homebrew/test/build_environment_test.rb | 45 + Library/Homebrew/test/build_options_test.rb | 49 + Library/Homebrew/test/bundle_test.rb | 22 + Library/Homebrew/test/cache_formula_test.rb | 8 + Library/Homebrew/test/cache_test.rb | 8 + Library/Homebrew/test/cask_test.rb | 10 + Library/Homebrew/test/cat_test.rb | 8 + Library/Homebrew/test/caveats_test.rb | 29 + Library/Homebrew/test/cellar_formula_test.rb | 8 + Library/Homebrew/test/cellar_test.rb | 8 + Library/Homebrew/test/checksum_test.rb | 22 + .../Homebrew/test/checksum_verification_test.rb | 39 + Library/Homebrew/test/cleaner_test.rb | 223 ++++ Library/Homebrew/test/cleanup_test.rb | 91 ++ Library/Homebrew/test/command_test.rb | 11 + Library/Homebrew/test/commands_test.rb | 86 ++ Library/Homebrew/test/compiler_failure_test.rb | 52 + Library/Homebrew/test/compiler_selector_test.rb | 116 ++ Library/Homebrew/test/config_test.rb | 8 + Library/Homebrew/test/create_test.rb | 12 + Library/Homebrew/test/custom_command_test.rb | 18 + Library/Homebrew/test/dependencies_test.rb | 115 ++ Library/Homebrew/test/dependency_collector_test.rb | 146 +++ Library/Homebrew/test/dependency_expansion_test.rb | 137 +++ Library/Homebrew/test/dependency_test.rb | 125 +++ Library/Homebrew/test/deps_test.rb | 16 + Library/Homebrew/test/desc_test.rb | 17 + Library/Homebrew/test/descriptions_test.rb | 45 + Library/Homebrew/test/diagnostic_test.rb | 197 ++++ Library/Homebrew/test/doctor_test.rb | 8 + Library/Homebrew/test/download_strategies_test.rb | 188 ++++ Library/Homebrew/test/edit_test.rb | 11 + Library/Homebrew/test/exceptions_test.rb | 142 +++ Library/Homebrew/test/fetch_test.rb | 11 + .../Homebrew/test/formula_installer_bottle_test.rb | 78 ++ Library/Homebrew/test/formula_installer_test.rb | 138 +++ Library/Homebrew/test/formula_lock_test.rb | 22 + Library/Homebrew/test/formula_pin_test.rb | 54 + .../Homebrew/test/formula_spec_selection_test.rb | 99 ++ Library/Homebrew/test/formula_support_test.rb | 28 + Library/Homebrew/test/formula_test.rb | 1180 ++++++++++++++++++++ Library/Homebrew/test/formula_validation_test.rb | 75 ++ Library/Homebrew/test/formulary_test.rb | 208 ++++ Library/Homebrew/test/gpg2_requirement_test.rb | 24 + Library/Homebrew/test/gpg_test.rb | 20 + Library/Homebrew/test/hardware_test.rb | 15 + Library/Homebrew/test/help_test.rb | 21 + Library/Homebrew/test/home_test.rb | 12 + Library/Homebrew/test/info_test.rb | 29 + Library/Homebrew/test/inreplace_test.rb | 119 ++ Library/Homebrew/test/install_test.rb | 30 + Library/Homebrew/test/irb_test.rb | 19 + Library/Homebrew/test/json_test.rb | 20 + Library/Homebrew/test/keg_test.rb | 400 +++++++ Library/Homebrew/test/language_go_test.rb | 17 + .../test/language_module_requirement_test.rb | 55 + Library/Homebrew/test/language_python_test.rb | 99 ++ Library/Homebrew/test/leaves_test.rb | 15 + Library/Homebrew/test/link_test.rb | 23 + Library/Homebrew/test/linkapps_test.rb | 15 + Library/Homebrew/test/list_test.rb | 13 + Library/Homebrew/test/log_formula_test.rb | 27 + Library/Homebrew/test/log_test.rb | 13 + Library/Homebrew/test/migrate_test.rb | 18 + Library/Homebrew/test/migrator_test.rb | 264 +++++ Library/Homebrew/test/missing_test.rb | 34 + Library/Homebrew/test/mpi_requirement_test.rb | 12 + Library/Homebrew/test/options_test.rb | 157 +++ Library/Homebrew/test/os/mac/blacklist_test.rb | 12 + .../Homebrew/test/os/mac/bottle_collector_test.rb | 26 + Library/Homebrew/test/os/mac/bottle_tag_test.rb | 79 ++ .../test/os/mac/dependency_collector_test.rb | 57 + Library/Homebrew/test/os/mac/diagnostic_test.rb | 49 + Library/Homebrew/test/os/mac/keg_test.rb | 69 ++ Library/Homebrew/test/os/mac/language_test.rb | 19 + Library/Homebrew/test/os/mac/mach_test.rb | 208 ++++ Library/Homebrew/test/os/mac/version_test.rb | 53 + .../Homebrew/test/os/mac/x11_requirement_test.rb | 13 + Library/Homebrew/test/outdated_test.rb | 10 + Library/Homebrew/test/patch_test.rb | 154 +++ Library/Homebrew/test/patching_test.rb | 253 +++++ Library/Homebrew/test/pathname_test.rb | 267 +++++ Library/Homebrew/test/pin_unpin_test.rb | 18 + Library/Homebrew/test/pkg_version_test.rb | 51 + Library/Homebrew/test/prefix_formula_test.rb | 8 + Library/Homebrew/test/prefix_test.rb | 8 + Library/Homebrew/test/prune_test.rb | 21 + Library/Homebrew/test/pull_offline_test.rb | 10 + Library/Homebrew/test/pull_test.rb | 27 + Library/Homebrew/test/readall_test.rb | 12 + Library/Homebrew/test/reinstall_pinned_test.rb | 15 + Library/Homebrew/test/reinstall_test.rb | 15 + Library/Homebrew/test/repository_test.rb | 10 + Library/Homebrew/test/requirement_test.rb | 152 +++ Library/Homebrew/test/resource_test.rb | 132 +++ Library/Homebrew/test/sandbox_test.rb | 76 ++ Library/Homebrew/test/search_remote_tap_test.rb | 19 + Library/Homebrew/test/search_test.rb | 30 + Library/Homebrew/test/services_test.rb | 11 + Library/Homebrew/test/sh_test.rb | 8 + Library/Homebrew/test/shell_test.rb | 59 + Library/Homebrew/test/software_spec_test.rb | 181 +++ Library/Homebrew/test/stdlib_test.rb | 61 + Library/Homebrew/test/string_test.rb | 40 + Library/Homebrew/test/switch_test.rb | 20 + Library/Homebrew/test/tab_test.rb | 270 +++++ Library/Homebrew/test/tap_new_test.rb | 9 + Library/Homebrew/test/tap_test.rb | 329 ++++++ Library/Homebrew/test/test/ARGV_test.rb | 80 -- Library/Homebrew/test/test/ENV_test.rb | 201 ---- Library/Homebrew/test/test/analytics_test.rb | 26 - Library/Homebrew/test/test/audit_test.rb | 472 -------- Library/Homebrew/test/test/bash_test.rb | 34 - Library/Homebrew/test/test/blacklist_test.rb | 68 -- .../Homebrew/test/test/bottle_collector_test.rb | 38 - Library/Homebrew/test/test/bottle_filename_test.rb | 31 - Library/Homebrew/test/test/bottle_hooks_test.rb | 47 - Library/Homebrew/test/test/bottle_test.rb | 21 - .../Homebrew/test/test/build_environment_test.rb | 45 - Library/Homebrew/test/test/build_options_test.rb | 49 - Library/Homebrew/test/test/bundle_test.rb | 22 - Library/Homebrew/test/test/cache_formula_test.rb | 8 - Library/Homebrew/test/test/cache_test.rb | 8 - Library/Homebrew/test/test/cask_test.rb | 10 - Library/Homebrew/test/test/cat_test.rb | 8 - Library/Homebrew/test/test/caveats_test.rb | 29 - Library/Homebrew/test/test/cellar_formula_test.rb | 8 - Library/Homebrew/test/test/cellar_test.rb | 8 - Library/Homebrew/test/test/checksum_test.rb | 22 - .../test/test/checksum_verification_test.rb | 39 - Library/Homebrew/test/test/cleaner_test.rb | 223 ---- Library/Homebrew/test/test/cleanup_test.rb | 91 -- Library/Homebrew/test/test/command_test.rb | 11 - Library/Homebrew/test/test/commands_test.rb | 86 -- .../Homebrew/test/test/compiler_failure_test.rb | 52 - .../Homebrew/test/test/compiler_selector_test.rb | 116 -- Library/Homebrew/test/test/config_test.rb | 8 - Library/Homebrew/test/test/create_test.rb | 12 - Library/Homebrew/test/test/custom_command_test.rb | 18 - Library/Homebrew/test/test/dependencies_test.rb | 115 -- .../test/test/dependency_collector_test.rb | 146 --- .../test/test/dependency_expansion_test.rb | 137 --- Library/Homebrew/test/test/dependency_test.rb | 125 --- Library/Homebrew/test/test/deps_test.rb | 16 - Library/Homebrew/test/test/desc_test.rb | 17 - Library/Homebrew/test/test/descriptions_test.rb | 45 - Library/Homebrew/test/test/diagnostic_test.rb | 197 ---- Library/Homebrew/test/test/doctor_test.rb | 8 - .../Homebrew/test/test/download_strategies_test.rb | 188 ---- Library/Homebrew/test/test/edit_test.rb | 11 - Library/Homebrew/test/test/exceptions_test.rb | 142 --- Library/Homebrew/test/test/fetch_test.rb | 11 - .../test/test/formula_installer_bottle_test.rb | 78 -- .../Homebrew/test/test/formula_installer_test.rb | 138 --- Library/Homebrew/test/test/formula_lock_test.rb | 22 - Library/Homebrew/test/test/formula_pin_test.rb | 54 - .../test/test/formula_spec_selection_test.rb | 99 -- Library/Homebrew/test/test/formula_support_test.rb | 28 - Library/Homebrew/test/test/formula_test.rb | 1180 -------------------- .../Homebrew/test/test/formula_validation_test.rb | 75 -- Library/Homebrew/test/test/formulary_test.rb | 208 ---- .../Homebrew/test/test/gpg2_requirement_test.rb | 24 - Library/Homebrew/test/test/gpg_test.rb | 20 - Library/Homebrew/test/test/hardware_test.rb | 15 - Library/Homebrew/test/test/help_test.rb | 21 - Library/Homebrew/test/test/home_test.rb | 12 - Library/Homebrew/test/test/info_test.rb | 29 - Library/Homebrew/test/test/inreplace_test.rb | 119 -- Library/Homebrew/test/test/install_test.rb | 30 - Library/Homebrew/test/test/irb_test.rb | 19 - Library/Homebrew/test/test/json_test.rb | 20 - Library/Homebrew/test/test/keg_test.rb | 400 ------- Library/Homebrew/test/test/language_go_test.rb | 17 - .../test/test/language_module_requirement_test.rb | 55 - Library/Homebrew/test/test/language_python_test.rb | 99 -- Library/Homebrew/test/test/leaves_test.rb | 15 - Library/Homebrew/test/test/link_test.rb | 23 - Library/Homebrew/test/test/linkapps_test.rb | 15 - Library/Homebrew/test/test/list_test.rb | 13 - Library/Homebrew/test/test/log_formula_test.rb | 27 - Library/Homebrew/test/test/log_test.rb | 13 - Library/Homebrew/test/test/migrate_test.rb | 18 - Library/Homebrew/test/test/migrator_test.rb | 264 ----- Library/Homebrew/test/test/missing_test.rb | 34 - Library/Homebrew/test/test/mpi_requirement_test.rb | 12 - Library/Homebrew/test/test/options_test.rb | 157 --- .../Homebrew/test/test/os/mac/blacklist_test.rb | 12 - .../test/test/os/mac/bottle_collector_test.rb | 26 - .../Homebrew/test/test/os/mac/bottle_tag_test.rb | 79 -- .../test/test/os/mac/dependency_collector_test.rb | 57 - .../Homebrew/test/test/os/mac/diagnostic_test.rb | 49 - Library/Homebrew/test/test/os/mac/keg_test.rb | 69 -- Library/Homebrew/test/test/os/mac/language_test.rb | 19 - Library/Homebrew/test/test/os/mac/mach_test.rb | 208 ---- Library/Homebrew/test/test/os/mac/version_test.rb | 53 - .../test/test/os/mac/x11_requirement_test.rb | 13 - Library/Homebrew/test/test/outdated_test.rb | 10 - Library/Homebrew/test/test/patch_test.rb | 154 --- Library/Homebrew/test/test/patching_test.rb | 253 ----- Library/Homebrew/test/test/pathname_test.rb | 267 ----- Library/Homebrew/test/test/pin_unpin_test.rb | 18 - Library/Homebrew/test/test/pkg_version_test.rb | 51 - Library/Homebrew/test/test/prefix_formula_test.rb | 8 - Library/Homebrew/test/test/prefix_test.rb | 8 - Library/Homebrew/test/test/prune_test.rb | 21 - Library/Homebrew/test/test/pull_offline_test.rb | 10 - Library/Homebrew/test/test/pull_test.rb | 27 - Library/Homebrew/test/test/readall_test.rb | 12 - .../Homebrew/test/test/reinstall_pinned_test.rb | 15 - Library/Homebrew/test/test/reinstall_test.rb | 15 - Library/Homebrew/test/test/repository_test.rb | 10 - Library/Homebrew/test/test/requirement_test.rb | 152 --- Library/Homebrew/test/test/resource_test.rb | 132 --- Library/Homebrew/test/test/sandbox_test.rb | 76 -- .../Homebrew/test/test/search_remote_tap_test.rb | 19 - Library/Homebrew/test/test/search_test.rb | 30 - Library/Homebrew/test/test/services_test.rb | 11 - Library/Homebrew/test/test/sh_test.rb | 8 - Library/Homebrew/test/test/shell_test.rb | 59 - Library/Homebrew/test/test/software_spec_test.rb | 181 --- Library/Homebrew/test/test/stdlib_test.rb | 61 - Library/Homebrew/test/test/string_test.rb | 40 - Library/Homebrew/test/test/switch_test.rb | 20 - Library/Homebrew/test/test/tab_test.rb | 270 ----- Library/Homebrew/test/test/tap_new_test.rb | 9 - Library/Homebrew/test/test/tap_test.rb | 329 ------ Library/Homebrew/test/test/test_formula_test.rb | 30 - Library/Homebrew/test/test/uninstall_test.rb | 66 -- Library/Homebrew/test/test/unlink_test.rb | 10 - Library/Homebrew/test/test/unlinkapps_test.rb | 19 - Library/Homebrew/test/test/unpack_test.rb | 13 - Library/Homebrew/test/test/update_report_test.rb | 134 --- Library/Homebrew/test/test/upgrade_test.rb | 12 - Library/Homebrew/test/test/uses_test.rb | 16 - Library/Homebrew/test/test/utils/tty_test.rb | 46 - Library/Homebrew/test/test/utils_test.rb | 235 ---- Library/Homebrew/test/test/version_test.rb | 8 - Library/Homebrew/test/test/versions_test.rb | 530 --------- Library/Homebrew/test/test/x11_requirement_test.rb | 31 - Library/Homebrew/test/test_formula_test.rb | 30 + Library/Homebrew/test/uninstall_test.rb | 66 ++ Library/Homebrew/test/unlink_test.rb | 10 + Library/Homebrew/test/unlinkapps_test.rb | 19 + Library/Homebrew/test/unpack_test.rb | 13 + Library/Homebrew/test/update_report_test.rb | 134 +++ Library/Homebrew/test/upgrade_test.rb | 12 + Library/Homebrew/test/uses_test.rb | 16 + Library/Homebrew/test/utils/tty_test.rb | 46 + Library/Homebrew/test/utils_test.rb | 235 ++++ Library/Homebrew/test/version_test.rb | 8 + Library/Homebrew/test/versions_test.rb | 530 +++++++++ Library/Homebrew/test/x11_requirement_test.rb | 31 + 263 files changed, 10416 insertions(+), 10416 deletions(-) create mode 100644 Library/Homebrew/test/ARGV_test.rb create mode 100644 Library/Homebrew/test/ENV_test.rb create mode 100644 Library/Homebrew/test/analytics_test.rb create mode 100644 Library/Homebrew/test/audit_test.rb create mode 100644 Library/Homebrew/test/bash_test.rb create mode 100644 Library/Homebrew/test/blacklist_test.rb create mode 100644 Library/Homebrew/test/bottle_collector_test.rb create mode 100644 Library/Homebrew/test/bottle_filename_test.rb create mode 100644 Library/Homebrew/test/bottle_hooks_test.rb create mode 100644 Library/Homebrew/test/bottle_test.rb create mode 100644 Library/Homebrew/test/build_environment_test.rb create mode 100644 Library/Homebrew/test/build_options_test.rb create mode 100644 Library/Homebrew/test/bundle_test.rb create mode 100644 Library/Homebrew/test/cache_formula_test.rb create mode 100644 Library/Homebrew/test/cache_test.rb create mode 100644 Library/Homebrew/test/cask_test.rb create mode 100644 Library/Homebrew/test/cat_test.rb create mode 100644 Library/Homebrew/test/caveats_test.rb create mode 100644 Library/Homebrew/test/cellar_formula_test.rb create mode 100644 Library/Homebrew/test/cellar_test.rb create mode 100644 Library/Homebrew/test/checksum_test.rb create mode 100644 Library/Homebrew/test/checksum_verification_test.rb create mode 100644 Library/Homebrew/test/cleaner_test.rb create mode 100644 Library/Homebrew/test/cleanup_test.rb create mode 100644 Library/Homebrew/test/command_test.rb create mode 100644 Library/Homebrew/test/commands_test.rb create mode 100644 Library/Homebrew/test/compiler_failure_test.rb create mode 100644 Library/Homebrew/test/compiler_selector_test.rb create mode 100644 Library/Homebrew/test/config_test.rb create mode 100644 Library/Homebrew/test/create_test.rb create mode 100644 Library/Homebrew/test/custom_command_test.rb create mode 100644 Library/Homebrew/test/dependencies_test.rb create mode 100644 Library/Homebrew/test/dependency_collector_test.rb create mode 100644 Library/Homebrew/test/dependency_expansion_test.rb create mode 100644 Library/Homebrew/test/dependency_test.rb create mode 100644 Library/Homebrew/test/deps_test.rb create mode 100644 Library/Homebrew/test/desc_test.rb create mode 100644 Library/Homebrew/test/descriptions_test.rb create mode 100644 Library/Homebrew/test/diagnostic_test.rb create mode 100644 Library/Homebrew/test/doctor_test.rb create mode 100644 Library/Homebrew/test/download_strategies_test.rb create mode 100644 Library/Homebrew/test/edit_test.rb create mode 100644 Library/Homebrew/test/exceptions_test.rb create mode 100644 Library/Homebrew/test/fetch_test.rb create mode 100644 Library/Homebrew/test/formula_installer_bottle_test.rb create mode 100644 Library/Homebrew/test/formula_installer_test.rb create mode 100644 Library/Homebrew/test/formula_lock_test.rb create mode 100644 Library/Homebrew/test/formula_pin_test.rb create mode 100644 Library/Homebrew/test/formula_spec_selection_test.rb create mode 100644 Library/Homebrew/test/formula_support_test.rb create mode 100644 Library/Homebrew/test/formula_test.rb create mode 100644 Library/Homebrew/test/formula_validation_test.rb create mode 100644 Library/Homebrew/test/formulary_test.rb create mode 100644 Library/Homebrew/test/gpg2_requirement_test.rb create mode 100644 Library/Homebrew/test/gpg_test.rb create mode 100644 Library/Homebrew/test/hardware_test.rb create mode 100644 Library/Homebrew/test/help_test.rb create mode 100644 Library/Homebrew/test/home_test.rb create mode 100644 Library/Homebrew/test/info_test.rb create mode 100644 Library/Homebrew/test/inreplace_test.rb create mode 100644 Library/Homebrew/test/install_test.rb create mode 100644 Library/Homebrew/test/irb_test.rb create mode 100644 Library/Homebrew/test/json_test.rb create mode 100644 Library/Homebrew/test/keg_test.rb create mode 100644 Library/Homebrew/test/language_go_test.rb create mode 100644 Library/Homebrew/test/language_module_requirement_test.rb create mode 100644 Library/Homebrew/test/language_python_test.rb create mode 100644 Library/Homebrew/test/leaves_test.rb create mode 100644 Library/Homebrew/test/link_test.rb create mode 100644 Library/Homebrew/test/linkapps_test.rb create mode 100644 Library/Homebrew/test/list_test.rb create mode 100644 Library/Homebrew/test/log_formula_test.rb create mode 100644 Library/Homebrew/test/log_test.rb create mode 100644 Library/Homebrew/test/migrate_test.rb create mode 100644 Library/Homebrew/test/migrator_test.rb create mode 100644 Library/Homebrew/test/missing_test.rb create mode 100644 Library/Homebrew/test/mpi_requirement_test.rb create mode 100644 Library/Homebrew/test/options_test.rb create mode 100644 Library/Homebrew/test/os/mac/blacklist_test.rb create mode 100644 Library/Homebrew/test/os/mac/bottle_collector_test.rb create mode 100644 Library/Homebrew/test/os/mac/bottle_tag_test.rb create mode 100644 Library/Homebrew/test/os/mac/dependency_collector_test.rb create mode 100644 Library/Homebrew/test/os/mac/diagnostic_test.rb create mode 100644 Library/Homebrew/test/os/mac/keg_test.rb create mode 100644 Library/Homebrew/test/os/mac/language_test.rb create mode 100644 Library/Homebrew/test/os/mac/mach_test.rb create mode 100644 Library/Homebrew/test/os/mac/version_test.rb create mode 100644 Library/Homebrew/test/os/mac/x11_requirement_test.rb create mode 100644 Library/Homebrew/test/outdated_test.rb create mode 100644 Library/Homebrew/test/patch_test.rb create mode 100644 Library/Homebrew/test/patching_test.rb create mode 100644 Library/Homebrew/test/pathname_test.rb create mode 100644 Library/Homebrew/test/pin_unpin_test.rb create mode 100644 Library/Homebrew/test/pkg_version_test.rb create mode 100644 Library/Homebrew/test/prefix_formula_test.rb create mode 100644 Library/Homebrew/test/prefix_test.rb create mode 100644 Library/Homebrew/test/prune_test.rb create mode 100644 Library/Homebrew/test/pull_offline_test.rb create mode 100644 Library/Homebrew/test/pull_test.rb create mode 100644 Library/Homebrew/test/readall_test.rb create mode 100644 Library/Homebrew/test/reinstall_pinned_test.rb create mode 100644 Library/Homebrew/test/reinstall_test.rb create mode 100644 Library/Homebrew/test/repository_test.rb create mode 100644 Library/Homebrew/test/requirement_test.rb create mode 100644 Library/Homebrew/test/resource_test.rb create mode 100644 Library/Homebrew/test/sandbox_test.rb create mode 100644 Library/Homebrew/test/search_remote_tap_test.rb create mode 100644 Library/Homebrew/test/search_test.rb create mode 100644 Library/Homebrew/test/services_test.rb create mode 100644 Library/Homebrew/test/sh_test.rb create mode 100644 Library/Homebrew/test/shell_test.rb create mode 100644 Library/Homebrew/test/software_spec_test.rb create mode 100644 Library/Homebrew/test/stdlib_test.rb create mode 100644 Library/Homebrew/test/string_test.rb create mode 100644 Library/Homebrew/test/switch_test.rb create mode 100644 Library/Homebrew/test/tab_test.rb create mode 100644 Library/Homebrew/test/tap_new_test.rb create mode 100644 Library/Homebrew/test/tap_test.rb delete mode 100644 Library/Homebrew/test/test/ARGV_test.rb delete mode 100644 Library/Homebrew/test/test/ENV_test.rb delete mode 100644 Library/Homebrew/test/test/analytics_test.rb delete mode 100644 Library/Homebrew/test/test/audit_test.rb delete mode 100644 Library/Homebrew/test/test/bash_test.rb delete mode 100644 Library/Homebrew/test/test/blacklist_test.rb delete mode 100644 Library/Homebrew/test/test/bottle_collector_test.rb delete mode 100644 Library/Homebrew/test/test/bottle_filename_test.rb delete mode 100644 Library/Homebrew/test/test/bottle_hooks_test.rb delete mode 100644 Library/Homebrew/test/test/bottle_test.rb delete mode 100644 Library/Homebrew/test/test/build_environment_test.rb delete mode 100644 Library/Homebrew/test/test/build_options_test.rb delete mode 100644 Library/Homebrew/test/test/bundle_test.rb delete mode 100644 Library/Homebrew/test/test/cache_formula_test.rb delete mode 100644 Library/Homebrew/test/test/cache_test.rb delete mode 100644 Library/Homebrew/test/test/cask_test.rb delete mode 100644 Library/Homebrew/test/test/cat_test.rb delete mode 100644 Library/Homebrew/test/test/caveats_test.rb delete mode 100644 Library/Homebrew/test/test/cellar_formula_test.rb delete mode 100644 Library/Homebrew/test/test/cellar_test.rb delete mode 100644 Library/Homebrew/test/test/checksum_test.rb delete mode 100644 Library/Homebrew/test/test/checksum_verification_test.rb delete mode 100644 Library/Homebrew/test/test/cleaner_test.rb delete mode 100644 Library/Homebrew/test/test/cleanup_test.rb delete mode 100644 Library/Homebrew/test/test/command_test.rb delete mode 100644 Library/Homebrew/test/test/commands_test.rb delete mode 100644 Library/Homebrew/test/test/compiler_failure_test.rb delete mode 100644 Library/Homebrew/test/test/compiler_selector_test.rb delete mode 100644 Library/Homebrew/test/test/config_test.rb delete mode 100644 Library/Homebrew/test/test/create_test.rb delete mode 100644 Library/Homebrew/test/test/custom_command_test.rb delete mode 100644 Library/Homebrew/test/test/dependencies_test.rb delete mode 100644 Library/Homebrew/test/test/dependency_collector_test.rb delete mode 100644 Library/Homebrew/test/test/dependency_expansion_test.rb delete mode 100644 Library/Homebrew/test/test/dependency_test.rb delete mode 100644 Library/Homebrew/test/test/deps_test.rb delete mode 100644 Library/Homebrew/test/test/desc_test.rb delete mode 100644 Library/Homebrew/test/test/descriptions_test.rb delete mode 100644 Library/Homebrew/test/test/diagnostic_test.rb delete mode 100644 Library/Homebrew/test/test/doctor_test.rb delete mode 100644 Library/Homebrew/test/test/download_strategies_test.rb delete mode 100644 Library/Homebrew/test/test/edit_test.rb delete mode 100644 Library/Homebrew/test/test/exceptions_test.rb delete mode 100644 Library/Homebrew/test/test/fetch_test.rb delete mode 100644 Library/Homebrew/test/test/formula_installer_bottle_test.rb delete mode 100644 Library/Homebrew/test/test/formula_installer_test.rb delete mode 100644 Library/Homebrew/test/test/formula_lock_test.rb delete mode 100644 Library/Homebrew/test/test/formula_pin_test.rb delete mode 100644 Library/Homebrew/test/test/formula_spec_selection_test.rb delete mode 100644 Library/Homebrew/test/test/formula_support_test.rb delete mode 100644 Library/Homebrew/test/test/formula_test.rb delete mode 100644 Library/Homebrew/test/test/formula_validation_test.rb delete mode 100644 Library/Homebrew/test/test/formulary_test.rb delete mode 100644 Library/Homebrew/test/test/gpg2_requirement_test.rb delete mode 100644 Library/Homebrew/test/test/gpg_test.rb delete mode 100644 Library/Homebrew/test/test/hardware_test.rb delete mode 100644 Library/Homebrew/test/test/help_test.rb delete mode 100644 Library/Homebrew/test/test/home_test.rb delete mode 100644 Library/Homebrew/test/test/info_test.rb delete mode 100644 Library/Homebrew/test/test/inreplace_test.rb delete mode 100644 Library/Homebrew/test/test/install_test.rb delete mode 100644 Library/Homebrew/test/test/irb_test.rb delete mode 100644 Library/Homebrew/test/test/json_test.rb delete mode 100644 Library/Homebrew/test/test/keg_test.rb delete mode 100644 Library/Homebrew/test/test/language_go_test.rb delete mode 100644 Library/Homebrew/test/test/language_module_requirement_test.rb delete mode 100644 Library/Homebrew/test/test/language_python_test.rb delete mode 100644 Library/Homebrew/test/test/leaves_test.rb delete mode 100644 Library/Homebrew/test/test/link_test.rb delete mode 100644 Library/Homebrew/test/test/linkapps_test.rb delete mode 100644 Library/Homebrew/test/test/list_test.rb delete mode 100644 Library/Homebrew/test/test/log_formula_test.rb delete mode 100644 Library/Homebrew/test/test/log_test.rb delete mode 100644 Library/Homebrew/test/test/migrate_test.rb delete mode 100644 Library/Homebrew/test/test/migrator_test.rb delete mode 100644 Library/Homebrew/test/test/missing_test.rb delete mode 100644 Library/Homebrew/test/test/mpi_requirement_test.rb delete mode 100644 Library/Homebrew/test/test/options_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/blacklist_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/bottle_collector_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/bottle_tag_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/dependency_collector_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/diagnostic_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/keg_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/language_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/mach_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/version_test.rb delete mode 100644 Library/Homebrew/test/test/os/mac/x11_requirement_test.rb delete mode 100644 Library/Homebrew/test/test/outdated_test.rb delete mode 100644 Library/Homebrew/test/test/patch_test.rb delete mode 100644 Library/Homebrew/test/test/patching_test.rb delete mode 100644 Library/Homebrew/test/test/pathname_test.rb delete mode 100644 Library/Homebrew/test/test/pin_unpin_test.rb delete mode 100644 Library/Homebrew/test/test/pkg_version_test.rb delete mode 100644 Library/Homebrew/test/test/prefix_formula_test.rb delete mode 100644 Library/Homebrew/test/test/prefix_test.rb delete mode 100644 Library/Homebrew/test/test/prune_test.rb delete mode 100644 Library/Homebrew/test/test/pull_offline_test.rb delete mode 100644 Library/Homebrew/test/test/pull_test.rb delete mode 100644 Library/Homebrew/test/test/readall_test.rb delete mode 100644 Library/Homebrew/test/test/reinstall_pinned_test.rb delete mode 100644 Library/Homebrew/test/test/reinstall_test.rb delete mode 100644 Library/Homebrew/test/test/repository_test.rb delete mode 100644 Library/Homebrew/test/test/requirement_test.rb delete mode 100644 Library/Homebrew/test/test/resource_test.rb delete mode 100644 Library/Homebrew/test/test/sandbox_test.rb delete mode 100644 Library/Homebrew/test/test/search_remote_tap_test.rb delete mode 100644 Library/Homebrew/test/test/search_test.rb delete mode 100644 Library/Homebrew/test/test/services_test.rb delete mode 100644 Library/Homebrew/test/test/sh_test.rb delete mode 100644 Library/Homebrew/test/test/shell_test.rb delete mode 100644 Library/Homebrew/test/test/software_spec_test.rb delete mode 100644 Library/Homebrew/test/test/stdlib_test.rb delete mode 100644 Library/Homebrew/test/test/string_test.rb delete mode 100644 Library/Homebrew/test/test/switch_test.rb delete mode 100644 Library/Homebrew/test/test/tab_test.rb delete mode 100644 Library/Homebrew/test/test/tap_new_test.rb delete mode 100644 Library/Homebrew/test/test/tap_test.rb delete mode 100644 Library/Homebrew/test/test/test_formula_test.rb delete mode 100644 Library/Homebrew/test/test/uninstall_test.rb delete mode 100644 Library/Homebrew/test/test/unlink_test.rb delete mode 100644 Library/Homebrew/test/test/unlinkapps_test.rb delete mode 100644 Library/Homebrew/test/test/unpack_test.rb delete mode 100644 Library/Homebrew/test/test/update_report_test.rb delete mode 100644 Library/Homebrew/test/test/upgrade_test.rb delete mode 100644 Library/Homebrew/test/test/uses_test.rb delete mode 100644 Library/Homebrew/test/test/utils/tty_test.rb delete mode 100644 Library/Homebrew/test/test/utils_test.rb delete mode 100644 Library/Homebrew/test/test/version_test.rb delete mode 100644 Library/Homebrew/test/test/versions_test.rb delete mode 100644 Library/Homebrew/test/test/x11_requirement_test.rb create mode 100644 Library/Homebrew/test/test_formula_test.rb create mode 100644 Library/Homebrew/test/uninstall_test.rb create mode 100644 Library/Homebrew/test/unlink_test.rb create mode 100644 Library/Homebrew/test/unlinkapps_test.rb create mode 100644 Library/Homebrew/test/unpack_test.rb create mode 100644 Library/Homebrew/test/update_report_test.rb create mode 100644 Library/Homebrew/test/upgrade_test.rb create mode 100644 Library/Homebrew/test/uses_test.rb create mode 100644 Library/Homebrew/test/utils/tty_test.rb create mode 100644 Library/Homebrew/test/utils_test.rb create mode 100644 Library/Homebrew/test/version_test.rb create mode 100644 Library/Homebrew/test/versions_test.rb create mode 100644 Library/Homebrew/test/x11_requirement_test.rb (limited to 'Library') diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 656225516..c032b3437 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -44,8 +44,8 @@ module Homebrew # Make it easier to reproduce test runs. ENV["SEED"] = ARGV.next if ARGV.include? "--seed" - files = Dir.glob("test/test/**/*_test.rb") - .reject { |p| !OS.mac? && p.start_with?("test/test/os/mac/") } + files = Dir.glob("test/**/*_test.rb") + .reject { |p| !OS.mac? && p.start_with?("test/os/mac/") } opts = [] opts << "--serialize-stdout" if ENV["CI"] @@ -55,7 +55,7 @@ module Homebrew if ARGV.value("only") test_name, test_method = ARGV.value("only").split(":", 2) - files = Dir.glob("test/test/{#{test_name},#{test_name}/**/*}_test.rb") + files = Dir.glob("test/{#{test_name},#{test_name}/**/*}_test.rb") args << "--name=test_#{test_method}" if test_method end diff --git a/Library/Homebrew/test/ARGV_test.rb b/Library/Homebrew/test/ARGV_test.rb new file mode 100644 index 000000000..6805e0c62 --- /dev/null +++ b/Library/Homebrew/test/ARGV_test.rb @@ -0,0 +1,80 @@ +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_test.rb b/Library/Homebrew/test/ENV_test.rb new file mode 100644 index 000000000..6c0e68a9e --- /dev/null +++ b/Library/Homebrew/test/ENV_test.rb @@ -0,0 +1,201 @@ +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, :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/analytics_test.rb b/Library/Homebrew/test/analytics_test.rb new file mode 100644 index 000000000..37040f3cd --- /dev/null +++ b/Library/Homebrew/test/analytics_test.rb @@ -0,0 +1,26 @@ +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 new file mode 100644 index 000000000..2725f906e --- /dev/null +++ b/Library/Homebrew/test/audit_test.rb @@ -0,0 +1,472 @@ +require "testing_env" +require "fileutils" +require "pathname" +require "formulary" +require "dev-cmd/audit" + +class FormulaTextTests < Homebrew::TestCase + def setup + @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| + f.write <<-EOS.undent + class #{Formulary.class_s(name)} < Formula + #{body} + end + #{options[:patch]} + EOS + end + FormulaText.new path + end + + def test_simple_valid_formula + ft = formula_text "valid", 'url "http://www.example.com/valid-1.0.tar.gz"' + + refute ft.data?, "The formula should not have DATA" + refute ft.end?, "The formula should not have __END__" + assert ft.trailing_newline?, "The formula should have a trailing newline" + + assert ft =~ /\burl\b/, "The formula should match 'url'" + assert_nil ft.line_number(/desc/), "The formula should not match 'desc'" + assert_equal 2, ft.line_number(/\burl\b/) + assert ft.include?("Valid"), "The formula should include \"Valid\"" + end + + def test_trailing_newline + ft = formula_text "newline" + assert ft.trailing_newline?, "The formula must have a trailing newline" + end + + def test_has_data + ft = formula_text "data", "patch :DATA" + assert ft.data?, "The formula must have DATA" + end + + def test_has_end + ft = formula_text "end", "", patch: "__END__\na patch here" + assert ft.end?, "The formula must have __END__" + assert_equal "class End < Formula\n \nend", ft.without_patch + end +end + +class FormulaAuditorTests < Homebrew::TestCase + def setup + @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| + f.write text + end + FormulaAuditor.new Formulary.factory(path), options + end + + def test_init_no_problems + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + end + EOS + + assert_equal [], fa.problems + end + + def test_audit_file_permissions + File.stubs(:umask).returns 022 + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + end + EOS + + path = fa.formula.path + path.chmod 0400 + + fa.audit_file + assert_equal ["Incorrect file permissions (400): chmod 644 #{path}"], + fa.problems + end + + def test_audit_file_data_no_end + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + patch :DATA + end + EOS + fa.audit_file + assert_equal ["'DATA' was found, but no '__END__'"], fa.problems + end + + def test_audit_file_end_no_data + fa = formula_auditor "foo", <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + end + __END__ + a patch goes here + EOS + fa.audit_file + assert_equal ["'__END__' was found, but 'DATA' is not used"], fa.problems + end + + def test_audit_file_no_trailing_newline + fa = formula_auditor "foo", 'class Foo "http://www.freedesktop.org/wiki/bar", + "baz" => "http://www.freedesktop.org/wiki/Software/baz", + "qux" => "https://code.google.com/p/qux", + "quux" => "http://github.com/quux", + "corge" => "http://savannah.nongnu.org/corge", + "grault" => "http://grault.github.io/", + "garply" => "http://www.gnome.org/garply", + "waldo" => "http://www.gnu.org/waldo", + } + + formula_homepages.each do |name, homepage| + fa = formula_auditor name, <<-EOS.undent + class #{Formulary.class_s(name)} < Formula + homepage "#{homepage}" + url "http://example.com/#{name}-1.0.tgz" + end + EOS + + fa.audit_homepage + if homepage =~ %r{http:\/\/www\.freedesktop\.org} + if homepage =~ /Software/ + assert_match "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/www/Software/project_name`", + fa.problems.first + else + assert_match "#{homepage} should be styled " \ + "`https://wiki.freedesktop.org/project_name`", + fa.problems.first + end + elsif homepage =~ %r{https:\/\/code\.google\.com} + assert_match "#{homepage} should end with a slash", fa.problems.first + else + assert_match "Please use https:// for #{homepage}", fa.problems.first + end + end + end +end diff --git a/Library/Homebrew/test/bash_test.rb b/Library/Homebrew/test/bash_test.rb new file mode 100644 index 000000000..ff418c787 --- /dev/null +++ b/Library/Homebrew/test/bash_test.rb @@ -0,0 +1,34 @@ +require "testing_env" + +class BashTests < Homebrew::TestCase + def assert_valid_bash_syntax(file) + 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_test.rb b/Library/Homebrew/test/blacklist_test.rb new file mode 100644 index 000000000..585a35484 --- /dev/null +++ b/Library/Homebrew/test/blacklist_test.rb @@ -0,0 +1,68 @@ +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 new file mode 100644 index 000000000..d75e29ec8 --- /dev/null +++ b/Library/Homebrew/test/bottle_collector_test.rb @@ -0,0 +1,38 @@ +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_filename_test.rb b/Library/Homebrew/test/bottle_filename_test.rb new file mode 100644 index 000000000..6604e7d6a --- /dev/null +++ b/Library/Homebrew/test/bottle_filename_test.rb @@ -0,0 +1,31 @@ +require "testing_env" +require "formula" +require "software_spec" + +class BottleFilenameTests < Homebrew::TestCase + def fn(rebuild) + Bottle::Filename.new("foo", "1.0", :tag, rebuild) + end + + def test_prefix_suffix + assert_equal "foo-1.0.tag", fn(0).prefix + assert_equal ".bottle.tar.gz", fn(0).suffix + assert_equal ".bottle.1.tar.gz", fn(1).suffix + end + + def test_to_str + expected = "foo-1.0.tag.bottle.tar.gz" + assert_equal expected, fn(0).to_s + assert_equal expected, fn(0).to_str + end + + def test_create + f = formula do + url "https://example.com/foo.tar.gz" + version "1.0" + end + + expected = "formula_name-1.0.tag.bottle.tar.gz" + assert_equal expected, Bottle::Filename.create(f, :tag, 0).to_s + end +end diff --git a/Library/Homebrew/test/bottle_hooks_test.rb b/Library/Homebrew/test/bottle_hooks_test.rb new file mode 100644 index 000000000..3535d80ef --- /dev/null +++ b/Library/Homebrew/test/bottle_hooks_test.rb @@ -0,0 +1,47 @@ +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 new file mode 100644 index 000000000..c10746e09 --- /dev/null +++ b/Library/Homebrew/test/bottle_test.rb @@ -0,0 +1,21 @@ +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_test.rb b/Library/Homebrew/test/build_environment_test.rb new file mode 100644 index 000000000..73a1c95f7 --- /dev/null +++ b/Library/Homebrew/test/build_environment_test.rb @@ -0,0 +1,45 @@ +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_test.rb b/Library/Homebrew/test/build_options_test.rb new file mode 100644 index 000000000..e460d25cc --- /dev/null +++ b/Library/Homebrew/test/build_options_test.rb @@ -0,0 +1,49 @@ +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 new file mode 100644 index 000000000..ae47977d8 --- /dev/null +++ b/Library/Homebrew/test/bundle_test.rb @@ -0,0 +1,22 @@ +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 new file mode 100644 index 000000000..6dcb6a745 --- /dev/null +++ b/Library/Homebrew/test/cache_formula_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..3a9e6b011 --- /dev/null +++ b/Library/Homebrew/test/cache_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..d5b81facb --- /dev/null +++ b/Library/Homebrew/test/cask_test.rb @@ -0,0 +1,10 @@ +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 new file mode 100644 index 000000000..bb37b5fde --- /dev/null +++ b/Library/Homebrew/test/cat_test.rb @@ -0,0 +1,8 @@ +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_test.rb b/Library/Homebrew/test/caveats_test.rb new file mode 100644 index 000000000..9eaac5792 --- /dev/null +++ b/Library/Homebrew/test/caveats_test.rb @@ -0,0 +1,29 @@ +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 new file mode 100644 index 000000000..38a934a7b --- /dev/null +++ b/Library/Homebrew/test/cellar_formula_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..74d5389f8 --- /dev/null +++ b/Library/Homebrew/test/cellar_test.rb @@ -0,0 +1,8 @@ +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_test.rb b/Library/Homebrew/test/checksum_test.rb new file mode 100644 index 000000000..5505f6824 --- /dev/null +++ b/Library/Homebrew/test/checksum_test.rb @@ -0,0 +1,22 @@ +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 new file mode 100644 index 000000000..9017b528d --- /dev/null +++ b/Library/Homebrew/test/checksum_verification_test.rb @@ -0,0 +1,39 @@ +require "testing_env" +require "formula" + +class ChecksumVerificationTests < Homebrew::TestCase + def assert_checksum_good + assert_nothing_raised { shutup { @_f.brew {} } } + end + + def assert_checksum_bad + assert_raises(ChecksumMismatchError) { shutup { @_f.brew {} } } + end + + def formula(&block) + super do + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + instance_eval(&block) + end + end + + def teardown + @_f.clear_cache + end + + def test_good_sha256 + formula do + sha256 TESTBALL_SHA256 + end + + assert_checksum_good + end + + def test_bad_sha256 + formula do + sha256 "dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8" + end + + assert_checksum_bad + end +end diff --git a/Library/Homebrew/test/cleaner_test.rb b/Library/Homebrew/test/cleaner_test.rb new file mode 100644 index 000000000..ac108421c --- /dev/null +++ b/Library/Homebrew/test/cleaner_test.rb @@ -0,0 +1,223 @@ +require "testing_env" +require "cleaner" +require "formula" + +class CleanerTests < Homebrew::TestCase + include FileUtils + + def setup + @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 + cp "#{TEST_FIXTURE_DIR}/mach/a.out", @f.bin + cp Dir["#{TEST_FIXTURE_DIR}/mach/*.dylib"], @f.lib + + Cleaner.new(@f).clean + + assert_equal 0100555, (@f.bin/"a.out").stat.mode + assert_equal 0100444, (@f.lib/"fat.dylib").stat.mode + assert_equal 0100444, (@f.lib/"x86_64.dylib").stat.mode + assert_equal 0100444, (@f.lib/"i386.dylib").stat.mode + end + + def test_prunes_prefix_if_empty + Cleaner.new(@f).clean + refute_predicate @f.prefix, :directory? + end + + def test_prunes_empty_directories + subdir = @f.bin/"subdir" + subdir.mkpath + + Cleaner.new(@f).clean + + refute_predicate @f.bin, :directory? + refute_predicate subdir, :directory? + end + + def test_skip_clean_empty_directory + @f.class.skip_clean "bin" + @f.bin.mkpath + + Cleaner.new(@f).clean + + assert_predicate @f.bin, :directory? + end + + def test_skip_clean_directory_with_empty_subdir + @f.class.skip_clean "bin" + subdir = @f.bin/"subdir" + subdir.mkpath + + Cleaner.new(@f).clean + + assert_predicate @f.bin, :directory? + assert_predicate subdir, :directory? + end + + def test_removes_symlink_when_target_was_pruned_first + dir = @f.prefix/"b" + symlink = @f.prefix/"a" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + refute_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_removes_symlink_pointing_to_empty_directory + dir = @f.prefix/"b" + symlink = @f.prefix/"c" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + refute_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_removes_broken_symlinks + symlink = @f.prefix/"symlink" + ln_s "target", symlink + + Cleaner.new(@f).clean + + refute_predicate symlink, :symlink? + end + + def test_skip_clean_broken_symlink + @f.class.skip_clean "symlink" + symlink = @f.prefix/"symlink" + ln_s "target", symlink + + Cleaner.new(@f).clean + + assert_predicate symlink, :symlink? + end + + def test_skip_clean_symlink_pointing_to_empty_directory + @f.class.skip_clean "c" + dir = @f.prefix/"b" + symlink = @f.prefix/"c" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + assert_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_skip_clean_symlink_when_target_pruned + @f.class.skip_clean "a" + dir = @f.prefix/"b" + symlink = @f.prefix/"a" + + dir.mkpath + ln_s dir.basename, symlink + + Cleaner.new(@f).clean + + refute_predicate dir, :exist? + assert_predicate symlink, :symlink? + refute_predicate symlink, :exist? + end + + def test_removes_la_files + file = @f.lib/"foo.la" + + @f.lib.mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_removes_perllocal_files + file = @f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod" + + (@f.lib/"perl5/darwin-thread-multi-2level").mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_removes_packlist_files + file = @f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist" + + (@f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_skip_clean_la + file = @f.lib/"foo.la" + + @f.class.skip_clean :la + @f.lib.mkpath + touch file + + Cleaner.new(@f).clean + + assert_predicate file, :exist? + end + + def test_remove_charset_alias + file = @f.lib/"charset.alias" + + @f.lib.mkpath + touch file + + Cleaner.new(@f).clean + + refute_predicate file, :exist? + end + + def test_skip_clean_subdir + dir = @f.lib/"subdir" + @f.class.skip_clean "lib/subdir" + + dir.mkpath + + Cleaner.new(@f).clean + + assert_predicate dir, :directory? + end + + def test_skip_clean_paths_are_anchored_to_prefix + dir1 = @f.bin/"a" + dir2 = @f.lib/"bin/a" + + @f.class.skip_clean "bin/a" + dir1.mkpath + dir2.mkpath + + Cleaner.new(@f).clean + + assert_predicate dir1, :exist? + refute_predicate dir2, :exist? + end +end diff --git a/Library/Homebrew/test/cleanup_test.rb b/Library/Homebrew/test/cleanup_test.rb new file mode 100644 index 000000000..bb8e1cdc6 --- /dev/null +++ b/Library/Homebrew/test/cleanup_test.rb @@ -0,0 +1,91 @@ +require "testing_env" +require "test/support/fixtures/testball" +require "cleanup" +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 + @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" + end + + def test_cleanup + shutup { Homebrew::Cleanup.cleanup } + refute_predicate @ds_store, :exist? + end + + def test_cleanup_dry_run + ARGV << "--dry-run" + shutup { Homebrew::Cleanup.cleanup } + assert_predicate @ds_store, :exist? + 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 + + 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? + + 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 + end + + def test_cleanup_logs + path = (HOMEBREW_LOGS/"delete_me") + path.mkpath + ARGV << "--prune=all" + shutup { Homebrew::Cleanup.cleanup_logs } + refute_predicate path, :exist? + end + + def test_cleanup_cache_incomplete_downloads + incomplete = (HOMEBREW_CACHE/"something.incomplete") + incomplete.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate incomplete, :exist? + end + + def test_cleanup_cache_java_cache + java_cache = (HOMEBREW_CACHE/"java_cache") + java_cache.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate java_cache, :exist? + end + + def test_cleanup_cache_npm_cache + npm_cache = (HOMEBREW_CACHE/"npm_cache") + npm_cache.mkpath + shutup { Homebrew::Cleanup.cleanup_cache } + refute_predicate npm_cache, :exist? + end +end diff --git a/Library/Homebrew/test/command_test.rb b/Library/Homebrew/test/command_test.rb new file mode 100644 index 000000000..d5c7aaa88 --- /dev/null +++ b/Library/Homebrew/test/command_test.rb @@ -0,0 +1,11 @@ +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 new file mode 100644 index 000000000..d44d2da0e --- /dev/null +++ b/Library/Homebrew/test/commands_test.rb @@ -0,0 +1,86 @@ +require "testing_env" +require "cmd/command" +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 + @cmds = [ + # internal commands + HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", + HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", + + # internal development commands + HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", + HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", + ] + + @cmds.each { |f| FileUtils.touch f } + end + + def teardown + @cmds.each(&:unlink) + end + + def test_internal_commands + cmds = Homebrew.internal_commands + assert cmds.include?("rbcmd"), "Ruby commands files should be recognized" + assert cmds.include?("shcmd"), "Shell commands files should be recognized" + refute cmds.include?("rbdevcmd"), "Dev commands shouldn't be included" + end + + def test_internal_developer_commands + cmds = Homebrew.internal_developer_commands + assert cmds.include?("rbdevcmd"), "Ruby commands files should be recognized" + assert cmds.include?("shdevcmd"), "Shell commands files should be recognized" + refute cmds.include?("rbcmd"), "Non-dev commands shouldn't be included" + 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}" + FileUtils.touch path + FileUtils.chmod 0755, path + end + + FileUtils.touch "#{dir}/brew-t4" + + ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" + cmds = Homebrew.external_commands + + assert cmds.include?("t1"), "Executable files should be included" + assert cmds.include?("t2"), "Executable Ruby files should be included" + refute cmds.include?("t3"), + "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 + assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", + Commands.path("rbcmd") + assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", + Commands.path("shcmd") + assert_nil Commands.path("idontexist1234") + end + + def test_internal_dev_command_path + assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", + Commands.path("rbdevcmd") + assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", + Commands.path("shdevcmd") + end +end diff --git a/Library/Homebrew/test/compiler_failure_test.rb b/Library/Homebrew/test/compiler_failure_test.rb new file mode 100644 index 000000000..c0b74d128 --- /dev/null +++ b/Library/Homebrew/test/compiler_failure_test.rb @@ -0,0 +1,52 @@ +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_test.rb b/Library/Homebrew/test/compiler_selector_test.rb new file mode 100644 index 000000000..b1591bdbe --- /dev/null +++ b/Library/Homebrew/test/compiler_selector_test.rb @@ -0,0 +1,116 @@ +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 new file mode 100644 index 000000000..81da4660a --- /dev/null +++ b/Library/Homebrew/test/config_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..aeee428aa --- /dev/null +++ b/Library/Homebrew/test/create_test.rb @@ -0,0 +1,12 @@ +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 new file mode 100644 index 000000000..8d05bc6c7 --- /dev/null +++ b/Library/Homebrew/test/custom_command_test.rb @@ -0,0 +1,18 @@ +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/dependencies_test.rb b/Library/Homebrew/test/dependencies_test.rb new file mode 100644 index 000000000..db3b78226 --- /dev/null +++ b/Library/Homebrew/test/dependencies_test.rb @@ -0,0 +1,115 @@ +require "testing_env" +require "dependencies" +require "dependency" +require "requirements" + +class DependenciesTests < Homebrew::TestCase + def setup + @deps = Dependencies.new + end + + def test_shovel_returns_self + assert_same @deps, @deps << Dependency.new("foo") + end + + def test_preserves_order + hash = { 0 => "foo", 1 => "bar", 2 => "baz" } + @deps << Dependency.new(hash[0]) + @deps << Dependency.new(hash[1]) + @deps << Dependency.new(hash[2]) + @deps.each_with_index do |dep, idx| + assert_equal hash[idx], dep.name + end + end + + def test_repetition + @deps << Dependency.new("foo") + @deps << Dependency.new("bar") + assert_equal "foo, bar", @deps*", " + end + + def test_to_a + dep = Dependency.new("foo") + @deps << dep + assert_equal [dep], @deps.to_a + end + + def test_to_ary + dep = Dependency.new("foo") + @deps << dep + assert_equal [dep], @deps.to_ary + end + + def test_type_helpers + foo = Dependency.new("foo") + bar = Dependency.new("bar", [:optional]) + baz = Dependency.new("baz", [:build]) + qux = Dependency.new("qux", [:recommended]) + quux = Dependency.new("quux") + @deps << foo << bar << baz << qux << quux + assert_equal [foo, quux], @deps.required + assert_equal [bar], @deps.optional + assert_equal [baz], @deps.build + assert_equal [qux], @deps.recommended + assert_equal [foo, baz, quux, qux].sort_by(&:name), @deps.default.sort_by(&:name) + end + + def test_equality + a = Dependencies.new + b = Dependencies.new + + dep = Dependency.new("foo") + + a << dep + b << dep + + assert_equal a, b + assert_eql a, b + + b << Dependency.new("bar", [:optional]) + + refute_equal a, b + refute_eql a, b + end + + def test_empty + a = Dependencies.new + assert a.empty? + a << Dependency.new("foo") + refute a.empty? + end + + def test_inspect + a = Dependencies.new + assert_equal "#", a.inspect + a << Dependency.new("foo") + assert_equal "#]>", a.inspect + end +end + +class RequirementsTests < Homebrew::TestCase + def setup + @reqs = Requirements.new + end + + def test_shovel_returns_self + assert_same @reqs, @reqs << Object.new + end + + def test_merging_multiple_dependencies + @reqs << X11Requirement.new << X11Requirement.new + assert_equal 1, @reqs.count + @reqs << Requirement.new + assert_equal 2, @reqs.count + end + + def test_comparison_prefers_larger + @reqs << X11Requirement.new << X11Requirement.new("x11", %w[2.6]) + assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a + end + + def test_comparison_does_not_merge_smaller + @reqs << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new + assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a + end +end diff --git a/Library/Homebrew/test/dependency_collector_test.rb b/Library/Homebrew/test/dependency_collector_test.rb new file mode 100644 index 000000000..1c7f70118 --- /dev/null +++ b/Library/Homebrew/test/dependency_collector_test.rb @@ -0,0 +1,146 @@ +require "testing_env" +require "dependency_collector" + +class DependencyCollectorTests < Homebrew::TestCase + def find_dependency(name) + @d.deps.find { |dep| dep.name == name } + end + + def find_requirement(klass) + @d.requirements.find { |req| req.is_a? klass } + end + + def setup + @d = DependencyCollector.new + end + + def teardown + DependencyCollector.clear_cache + end + + def test_dependency_creation + @d.add "foo" => :build + @d.add "bar" => ["--universal", :optional] + assert_instance_of Dependency, find_dependency("foo") + assert_equal 2, find_dependency("bar").tags.length + end + + def test_add_returns_created_dep + ret = @d.add "foo" + assert_equal Dependency.new("foo"), ret + end + + def test_dependency_tags + assert_predicate Dependency.new("foo", [:build]), :build? + assert_predicate Dependency.new("foo", [:build, :optional]), :optional? + assert_includes Dependency.new("foo", ["universal"]).options, "--universal" + assert_empty Dependency.new("foo").tags + end + + def test_requirement_creation + @d.add :x11 + assert_instance_of X11Requirement, find_requirement(X11Requirement) + end + + def test_no_duplicate_requirements + 2.times { @d.add :x11 } + assert_equal 1, @d.requirements.count + end + + def test_requirement_tags + @d.add x11: "2.5.1" + @d.add xcode: :build + assert_empty find_requirement(X11Requirement).tags + assert_predicate find_requirement(XcodeRequirement), :build? + end + + def test_x11_no_tag + @d.add :x11 + assert_empty find_requirement(X11Requirement).tags + end + + def test_x11_min_version + @d.add x11: "2.5.1" + assert_equal "2.5.1", find_requirement(X11Requirement).min_version.to_s + end + + def test_x11_tag + @d.add x11: :optional + assert_predicate find_requirement(X11Requirement), :optional? + end + + def test_x11_min_version_and_tag + @d.add x11: ["2.5.1", :optional] + dep = find_requirement(X11Requirement) + assert_equal "2.5.1", dep.min_version.to_s + assert_predicate dep, :optional? + end + + def test_ant_dep + @d.add ant: :build + assert_equal find_dependency("ant"), Dependency.new("ant", [:build]) + end + + def test_raises_typeerror_for_unknown_classes + assert_raises(TypeError) { @d.add(Class.new) } + end + + def test_raises_typeerror_for_unknown_types + assert_raises(TypeError) { @d.add(Object.new) } + end + + def test_does_not_mutate_dependency_spec + spec = { "foo" => :optional } + copy = spec.dup + @d.add(spec) + assert_equal copy, spec + end + + def test_resource_dep_git_url + resource = Resource.new + resource.url("git://example.com/foo/bar.git") + assert_instance_of GitRequirement, @d.add(resource) + end + + def test_resource_dep_7z_url + resource = Resource.new + resource.url("http://example.com/foo.7z") + assert_equal Dependency.new("p7zip", [:build]), @d.add(resource) + end + + def test_resource_dep_gzip_url + resource = Resource.new + resource.url("http://example.com/foo.tar.gz") + assert_nil @d.add(resource) + end + + def test_resource_dep_lz_url + resource = Resource.new + resource.url("http://example.com/foo.lz") + assert_equal Dependency.new("lzip", [:build]), @d.add(resource) + end + + def test_resource_dep_lha_url + resource = Resource.new + resource.url("http://example.com/foo.lha") + assert_equal Dependency.new("lha", [:build]), @d.add(resource) + end + + def test_resource_dep_lzh_url + resource = Resource.new + resource.url("http://example.com/foo.lzh") + assert_equal Dependency.new("lha", [:build]), @d.add(resource) + end + + def test_resource_dep_rar_url + resource = Resource.new + resource.url("http://example.com/foo.rar") + assert_equal Dependency.new("unrar", [:build]), @d.add(resource) + end + + def test_resource_dep_raises_for_unknown_classes + resource = Resource.new + resource.download_strategy = Class.new + assert_raises(TypeError) { @d.add(resource) } + end +end diff --git a/Library/Homebrew/test/dependency_expansion_test.rb b/Library/Homebrew/test/dependency_expansion_test.rb new file mode 100644 index 000000000..9d6de35e2 --- /dev/null +++ b/Library/Homebrew/test/dependency_expansion_test.rb @@ -0,0 +1,137 @@ +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 new file mode 100644 index 000000000..65255995e --- /dev/null +++ b/Library/Homebrew/test/dependency_test.rb @@ -0,0 +1,125 @@ +require "testing_env" +require "dependency" + +class DependableTests < Homebrew::TestCase + def setup + @tags = ["foo", "bar", :build] + @dep = Struct.new(:tags).new(@tags).extend(Dependable) + end + + def test_options + assert_equal %w[--foo --bar].sort, @dep.options.as_flags.sort + end + + def test_interrogation + assert_predicate @dep, :build? + refute_predicate @dep, :optional? + refute_predicate @dep, :recommended? + end +end + +class DependencyTests < Homebrew::TestCase + def test_accepts_single_tag + dep = Dependency.new("foo", %w[bar]) + assert_equal %w[bar], dep.tags + end + + def test_accepts_multiple_tags + dep = Dependency.new("foo", %w[bar baz]) + assert_equal %w[bar baz].sort, dep.tags.sort + end + + def test_preserves_symbol_tags + dep = Dependency.new("foo", [:build]) + assert_equal [:build], dep.tags + end + + def test_accepts_symbol_and_string_tags + dep = Dependency.new("foo", [:build, "bar"]) + assert_equal [:build, "bar"], dep.tags + end + + def test_merge_repeats + dep = Dependency.new("foo", [:build], nil, "foo") + dep2 = Dependency.new("foo", ["bar"], nil, "foo2") + dep3 = Dependency.new("xyz", ["abc"], nil, "foo") + merged = Dependency.merge_repeats([dep, dep2, dep3]) + assert_equal 2, merged.length + assert_equal Dependency, merged.first.class + + foo_named_dep = merged.find { |d| d.name == "foo" } + assert_equal ["bar"], foo_named_dep.tags + assert_includes foo_named_dep.option_names, "foo" + assert_includes foo_named_dep.option_names, "foo2" + + xyz_named_dep = merged.find { |d| d.name == "xyz" } + assert_equal ["abc"], xyz_named_dep.tags + assert_includes xyz_named_dep.option_names, "foo" + refute_includes xyz_named_dep.option_names, "foo2" + end + + def test_merges_necessity_tags + required_dep = Dependency.new("foo") + recommended_dep = Dependency.new("foo", [:recommended]) + optional_dep = Dependency.new("foo", [:optional]) + + deps = Dependency.merge_repeats([required_dep, recommended_dep]) + assert_equal deps.count, 1 + assert_predicate deps.first, :required? + refute_predicate deps.first, :recommended? + refute_predicate deps.first, :optional? + + deps = Dependency.merge_repeats([required_dep, optional_dep]) + assert_equal deps.count, 1 + assert_predicate deps.first, :required? + refute_predicate deps.first, :recommended? + refute_predicate deps.first, :optional? + + deps = Dependency.merge_repeats([recommended_dep, optional_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :required? + assert_predicate deps.first, :recommended? + refute_predicate deps.first, :optional? + end + + def test_merges_temporality_tags + normal_dep = Dependency.new("foo") + build_dep = Dependency.new("foo", [:build]) + run_dep = Dependency.new("foo", [:run]) + + deps = Dependency.merge_repeats([normal_dep, build_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :build? + refute_predicate deps.first, :run? + + deps = Dependency.merge_repeats([normal_dep, run_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :build? + refute_predicate deps.first, :run? + + deps = Dependency.merge_repeats([build_dep, run_dep]) + assert_equal deps.count, 1 + refute_predicate deps.first, :build? + refute_predicate deps.first, :run? + end + + def test_equality + foo1 = Dependency.new("foo") + foo2 = Dependency.new("foo") + bar = Dependency.new("bar") + assert_equal foo1, foo2 + assert_eql foo1, foo2 + refute_equal foo1, bar + refute_eql foo1, bar + foo3 = Dependency.new("foo", [:build]) + refute_equal foo1, foo3 + refute_eql foo1, foo3 + end +end + +class TapDependencyTests < Homebrew::TestCase + def test_option_names + dep = TapDependency.new("foo/bar/dog") + assert_equal %w[dog], dep.option_names + end +end diff --git a/Library/Homebrew/test/deps_test.rb b/Library/Homebrew/test/deps_test.rb new file mode 100644 index 000000000..01639857c --- /dev/null +++ b/Library/Homebrew/test/deps_test.rb @@ -0,0 +1,16 @@ +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 new file mode 100644 index 000000000..2ba498135 --- /dev/null +++ b/Library/Homebrew/test/desc_test.rb @@ -0,0 +1,17 @@ +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_test.rb b/Library/Homebrew/test/descriptions_test.rb new file mode 100644 index 000000000..de38fdbd1 --- /dev/null +++ b/Library/Homebrew/test/descriptions_test.rb @@ -0,0 +1,45 @@ +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/diagnostic_test.rb b/Library/Homebrew/test/diagnostic_test.rb new file mode 100644 index 000000000..aa2e44cfc --- /dev/null +++ b/Library/Homebrew/test/diagnostic_test.rb @@ -0,0 +1,197 @@ +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 + # 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 new file mode 100644 index 000000000..d2dc871f4 --- /dev/null +++ b/Library/Homebrew/test/doctor_test.rb @@ -0,0 +1,8 @@ +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_test.rb b/Library/Homebrew/test/download_strategies_test.rb new file mode 100644 index 000000000..87218fb12 --- /dev/null +++ b/Library/Homebrew/test/download_strategies_test.rb @@ -0,0 +1,188 @@ +require "testing_env" +require "download_strategy" + +class ResourceDouble + attr_reader :url, :specs, :version + + def initialize(url = "http://example.com/foo.tar.gz", specs = {}) + @url = url + @specs = specs + 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 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 new file mode 100644 index 000000000..9b6ded651 --- /dev/null +++ b/Library/Homebrew/test/edit_test.rb @@ -0,0 +1,11 @@ +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/exceptions_test.rb b/Library/Homebrew/test/exceptions_test.rb new file mode 100644 index 000000000..689531c6e --- /dev/null +++ b/Library/Homebrew/test/exceptions_test.rb @@ -0,0 +1,142 @@ +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: "") + assert_match "bar does not define resource ", + ResourceMissingError.new(f, r).to_s + end + + def test_duplicate_resource_error + r = stub(inspect: "") + assert_equal "Resource 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 new file mode 100644 index 000000000..e08e545e3 --- /dev/null +++ b/Library/Homebrew/test/fetch_test.rb @@ -0,0 +1,11 @@ +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_bottle_test.rb b/Library/Homebrew/test/formula_installer_bottle_test.rb new file mode 100644 index 000000000..6a891f159 --- /dev/null +++ b/Library/Homebrew/test/formula_installer_bottle_test.rb @@ -0,0 +1,78 @@ +require "testing_env" +require "formula" +require "formula_installer" +require "keg" +require "tab" +require "test/support/fixtures/testball" +require "test/support/fixtures/testball_bottle" + +class InstallBottleTests < Homebrew::TestCase + def temporary_bottle_install(formula) + refute_predicate formula, :installed? + assert_predicate formula, :bottled? + assert_predicate formula, :pour_bottle? + + installer = FormulaInstaller.new(formula) + + shutup { installer.install } + + keg = Keg.new(formula.prefix) + + assert_predicate formula, :installed? + + begin + assert_predicate Tab.for_keg(keg), :poured_from_bottle + + yield formula + ensure + keg.unlink + keg.uninstall + formula.clear_cache + formula.bottle.clear_cache + end + + refute_predicate keg, :exist? + refute_predicate formula, :installed? + end + + def test_a_basic_bottle_install + DevelopmentTools.stubs(:installed?).returns(false) + + temporary_bottle_install(TestballBottle.new) do |f| + # Copied directly from test_formula_installer.rb as we expect + # the same behavior + + # Test that things made it into the Keg + assert_predicate f.bin, :directory? + + assert_predicate f.libexec, :directory? + + refute_predicate f.prefix+"main.c", :exist? + + # Test that things make it into the Cellar + keg = Keg.new f.prefix + keg.link + + bin = HOMEBREW_PREFIX+"bin" + assert_predicate bin, :directory? + end + end + + def test_build_tools_error + DevelopmentTools.stubs(:installed?).returns(false) + + # Testball doesn't have a bottle block, so use it to test this behavior + formula = Testball.new + + refute_predicate formula, :installed? + refute_predicate formula, :bottled? + + installer = FormulaInstaller.new(formula) + + assert_raises(BuildToolsError) do + installer.install + end + + refute_predicate formula, :installed? + end +end diff --git a/Library/Homebrew/test/formula_installer_test.rb b/Library/Homebrew/test/formula_installer_test.rb new file mode 100644 index 000000000..652548bd7 --- /dev/null +++ b/Library/Homebrew/test/formula_installer_test.rb @@ -0,0 +1,138 @@ +require "testing_env" +require "formula" +require "formula_installer" +require "keg" +require "tab" +require "test/support/fixtures/testball" +require "test/support/fixtures/testball_bottle" + +class InstallTests < Homebrew::TestCase + def temporary_install(formula) + refute_predicate formula, :installed? + + installer = FormulaInstaller.new(formula) + + shutup { installer.install } + + keg = Keg.new(formula.prefix) + + assert_predicate formula, :installed? + + begin + Tab.clear_cache + refute_predicate Tab.for_keg(keg), :poured_from_bottle + + yield formula + ensure + Tab.clear_cache + keg.unlink + keg.uninstall + formula.clear_cache + # there will be log files when sandbox is enable. + formula.logs.rmtree if formula.logs.directory? + end + + refute_predicate keg, :exist? + refute_predicate formula, :installed? + end + + def test_a_basic_install + ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install + temporary_install(Testball.new) do |f| + # Test that things made it into the Keg + assert_predicate f.prefix+"readme", :exist? + + assert_predicate f.bin, :directory? + assert_equal 3, f.bin.children.length + + assert_predicate f.libexec, :directory? + assert_equal 1, f.libexec.children.length + + refute_predicate f.prefix+"main.c", :exist? + + refute_predicate f.prefix+"license", :exist? + + # Test that things make it into the Cellar + keg = Keg.new f.prefix + keg.link + + bin = HOMEBREW_PREFIX+"bin" + assert_predicate bin, :directory? + assert_equal 3, bin.children.length + assert_predicate f.prefix/".brew/testball.rb", :readable? + end + end + + def test_bottle_unneeded_formula_install + DevelopmentTools.stubs(:installed?).returns(false) + + formula = Testball.new + formula.stubs(:bottle_unneeded?).returns(true) + formula.stubs(:bottle_disabled?).returns(true) + + refute_predicate formula, :bottled? + assert_predicate formula, :bottle_unneeded? + assert_predicate formula, :bottle_disabled? + + temporary_install(formula) do |f| + assert_predicate f, :installed? + end + end + + def test_not_poured_from_bottle_when_compiler_specified + assert_nil ARGV.cc + + 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 } + end + end +end + +class FormulaInstallerTests < Homebrew::TestCase + def test_check_install_sanity_pinned_dep + dep_name = "dependency" + dep_path = CoreTap.new.formula_dir/"#{dep_name}.rb" + dep_path.write <<-EOS.undent + class #{Formulary.class_s(dep_name)} < Formula + url "foo" + version "0.2" + end + EOS + + Formulary::FORMULAE.delete(dep_path) + dependency = Formulary.factory(dep_name) + + dependent = formula do + url "foo" + version "0.5" + depends_on dependency.name.to_s + end + + dependency.prefix("0.1").join("bin/a").mkpath + HOMEBREW_PINNED_KEGS.mkpath + FileUtils.ln_s dependency.prefix("0.1"), HOMEBREW_PINNED_KEGS/dep_name + + dependency_keg = Keg.new(dependency.prefix("0.1")) + dependency_keg.link + + assert_predicate dependency_keg, :linked? + assert_predicate dependency, :pinned? + + 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_test.rb b/Library/Homebrew/test/formula_lock_test.rb new file mode 100644 index 000000000..80ee9dd25 --- /dev/null +++ b/Library/Homebrew/test/formula_lock_test.rb @@ -0,0 +1,22 @@ +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_test.rb b/Library/Homebrew/test/formula_pin_test.rb new file mode 100644 index 000000000..297d7703e --- /dev/null +++ b/Library/Homebrew/test/formula_pin_test.rb @@ -0,0 +1,54 @@ +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_selection_test.rb b/Library/Homebrew/test/formula_spec_selection_test.rb new file mode 100644 index 000000000..7148df173 --- /dev/null +++ b/Library/Homebrew/test/formula_spec_selection_test.rb @@ -0,0 +1,99 @@ +require "testing_env" +require "formula" + +class FormulaSpecSelectionTests < Homebrew::TestCase + def test_selects_stable_by_default + f = formula do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :stable? + end + + def test_selects_stable_when_exclusive + f = formula { url "foo-1.0" } + assert_predicate f, :stable? + end + + def test_selects_devel_before_head + f = formula do + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :devel? + end + + def test_selects_devel_when_exclusive + f = formula { devel { url "foo-1.1a" } } + assert_predicate f, :devel? + end + + def test_selects_head_when_exclusive + f = formula { head "foo" } + assert_predicate f, :head? + end + + def test_incomplete_spec_not_selected + f = formula do + sha256 TEST_SHA256 + version "1.0" + head "foo" + end + + assert_predicate f, :head? + end + + def test_incomplete_stable_not_set + f = formula do + sha256 TEST_SHA256 + devel { url "foo-1.1a" } + head "foo" + end + + assert_nil f.stable + assert_predicate f, :devel? + end + + def test_selects_head_when_requested + f = formula("test", Pathname.new(__FILE__).expand_path, :head) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :head? + end + + def test_selects_devel_when_requested + f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do + url "foo-1.0" + devel { url "foo-1.1a" } + head "foo" + end + + assert_predicate f, :devel? + end + + def test_incomplete_devel_not_set + f = formula do + url "foo-1.0" + devel { version "1.1a" } + head "foo" + end + + assert_nil f.devel + assert_predicate f, :stable? + end + + def test_does_not_raise_for_missing_spec + f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do + url "foo-1.0" + head "foo" + end + + assert_predicate f, :stable? + end +end diff --git a/Library/Homebrew/test/formula_support_test.rb b/Library/Homebrew/test/formula_support_test.rb new file mode 100644 index 000000000..c0a79f950 --- /dev/null +++ b/Library/Homebrew/test/formula_support_test.rb @@ -0,0 +1,28 @@ +require "testing_env" +require "formula_support" + +class KegOnlyReasonTests < Homebrew::TestCase + def test_to_s_explanation + r = KegOnlyReason.new :provided_by_osx, "test" + assert_equal "test", r.to_s + end + + def test_to_s_no_explanation + r = KegOnlyReason.new :provided_by_macos, "" + assert_match(/^macOS already provides/, r.to_s) + end +end + +class BottleDisableReasonTests < Homebrew::TestCase + def test_bottle_unneeded + bottle_disable_reason = BottleDisableReason.new :unneeded, nil + assert_predicate bottle_disable_reason, :unneeded? + assert_equal "This formula doesn't require compiling.", bottle_disable_reason.to_s + end + + def test_bottle_disabled + bottle_disable_reason = BottleDisableReason.new :disable, "reason" + refute_predicate bottle_disable_reason, :unneeded? + assert_equal "reason", bottle_disable_reason.to_s + end +end diff --git a/Library/Homebrew/test/formula_test.rb b/Library/Homebrew/test/formula_test.rb new file mode 100644 index 000000000..eef60a3e5 --- /dev/null +++ b/Library/Homebrew/test/formula_test.rb @@ -0,0 +1,1180 @@ +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/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 "f3" + end + + assert_equal %w[f3], f4.deps.map(&:name) + assert_equal %w[f1 f2 f3], f4.recursive_dependencies.map(&:name) + assert_equal %w[f2 f3], f4.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/formula_validation_test.rb b/Library/Homebrew/test/formula_validation_test.rb new file mode 100644 index 000000000..c40eb6733 --- /dev/null +++ b/Library/Homebrew/test/formula_validation_test.rb @@ -0,0 +1,75 @@ +require "testing_env" +require "formula" + +class FormulaValidationTests < Homebrew::TestCase + def assert_invalid(attr, &block) + e = assert_raises(FormulaValidationError, &block) + assert_equal attr, e.attr + end + + def test_cant_override_brew + e = assert_raises(RuntimeError) { formula { def brew; end } } + assert_match(/You cannot override Formula#brew/, e.message) + end + + def test_validates_name + assert_invalid :name do + formula "name with spaces" do + url "foo" + version "1.0" + end + end + end + + def test_validates_url + assert_invalid :url do + formula do + url "" + version "1" + end + end + end + + def test_validates_version + assert_invalid :version do + formula do + url "foo" + version "version with spaces" + end + end + + assert_invalid :version do + formula do + url "foo" + version "" + end + end + + assert_invalid :version do + formula do + url "foo" + version nil + end + end + end + + def test_devel_only_valid + f = formula do + devel do + url "foo" + version "1.0" + end + end + + assert_predicate f, :devel? + end + + def test_head_only_valid + f = formula { head "foo" } + assert_predicate f, :head? + end + + def test_empty_formula_invalid + assert_raises(FormulaSpecificationError) { formula {} } + end +end diff --git a/Library/Homebrew/test/formulary_test.rb b/Library/Homebrew/test/formulary_test.rb new file mode 100644 index 000000000..3d88c8407 --- /dev/null +++ b/Library/Homebrew/test/formulary_test.rb @@ -0,0 +1,208 @@ +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_test.rb b/Library/Homebrew/test/gpg2_requirement_test.rb new file mode 100644 index 000000000..fa7fc9ea4 --- /dev/null +++ b/Library/Homebrew/test/gpg2_requirement_test.rb @@ -0,0 +1,24 @@ +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_test.rb b/Library/Homebrew/test/gpg_test.rb new file mode 100644 index 000000000..0374bdab4 --- /dev/null +++ b/Library/Homebrew/test/gpg_test.rb @@ -0,0 +1,20 @@ +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_test.rb b/Library/Homebrew/test/hardware_test.rb new file mode 100644 index 000000000..2bea5387d --- /dev/null +++ b/Library/Homebrew/test/hardware_test.rb @@ -0,0 +1,15 @@ +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, :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 new file mode 100644 index 000000000..92dd99721 --- /dev/null +++ b/Library/Homebrew/test/help_test.rb @@ -0,0 +1,21 @@ +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 new file mode 100644 index 000000000..ff06b72c1 --- /dev/null +++ b/Library/Homebrew/test/home_test.rb @@ -0,0 +1,12 @@ +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 new file mode 100644 index 000000000..f71044bf0 --- /dev/null +++ b/Library/Homebrew/test/info_test.rb @@ -0,0 +1,29 @@ +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_test.rb b/Library/Homebrew/test/inreplace_test.rb new file mode 100644 index 000000000..0e62f9d3f --- /dev/null +++ b/Library/Homebrew/test/inreplace_test.rb @@ -0,0 +1,119 @@ +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 new file mode 100644 index 000000000..fa1057a02 --- /dev/null +++ b/Library/Homebrew/test/install_test.rb @@ -0,0 +1,30 @@ +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_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 +end diff --git a/Library/Homebrew/test/irb_test.rb b/Library/Homebrew/test/irb_test.rb new file mode 100644 index 000000000..832ca39a5 --- /dev/null +++ b/Library/Homebrew/test/irb_test.rb @@ -0,0 +1,19 @@ +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/json_test.rb b/Library/Homebrew/test/json_test.rb new file mode 100644 index 000000000..14d2f2b4c --- /dev/null +++ b/Library/Homebrew/test/json_test.rb @@ -0,0 +1,20 @@ +require "testing_env" +require "utils/json" + +class JsonSmokeTest < Homebrew::TestCase + def test_encode + hash = { "foo" => ["bar", "baz"] } + json = '{"foo":["bar","baz"]}' + assert_equal json, Utils::JSON.dump(hash) + end + + def test_decode + hash = { "foo" => ["bar", "baz"], "qux" => 1 } + json = '{"foo":["bar","baz"],"qux":1}' + assert_equal hash, Utils::JSON.load(json) + end + + def test_decode_failure + assert_raises(Utils::JSON::Error) { Utils::JSON.load("nope") } + end +end diff --git a/Library/Homebrew/test/keg_test.rb b/Library/Homebrew/test/keg_test.rb new file mode 100644 index 000000000..fdc739c9d --- /dev/null +++ b/Library/Homebrew/test/keg_test.rb @@ -0,0 +1,400 @@ +require "testing_env" +require "keg" +require "stringio" + +class LinkTests < 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 + + 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 < LinkTests + 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 + Formula.clear_cache + keg + end + + def setup + super + @dependent = setup_test_keg("bar", "1.0") + end + + def alter_tab(keg = @dependent) + tab = Tab.for_keg(keg) + yield tab + tab.write + end + + def dependencies(deps) + alter_tab do |tab| + tab.tabfile = @dependent.join("INSTALL_RECEIPT.json") + tab.runtime_dependencies = deps + end + 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) + dependencies [] + alter_tab { |t| t.source["path"] = nil } + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg]) + 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_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_empty @keg.installed_dependents + assert_nil 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 +end diff --git a/Library/Homebrew/test/language_go_test.rb b/Library/Homebrew/test/language_go_test.rb new file mode 100644 index 000000000..692a5d2cc --- /dev/null +++ b/Library/Homebrew/test/language_go_test.rb @@ -0,0 +1,17 @@ +# -*- 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_test.rb b/Library/Homebrew/test/language_module_requirement_test.rb new file mode 100644 index 000000000..dfa992287 --- /dev/null +++ b/Library/Homebrew/test/language_module_requirement_test.rb @@ -0,0 +1,55 @@ +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 new file mode 100644 index 000000000..d1e3867f7 --- /dev/null +++ b/Library/Homebrew/test/language_python_test.rb @@ -0,0 +1,99 @@ +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 new file mode 100644 index 000000000..f73fba1ea --- /dev/null +++ b/Library/Homebrew/test/leaves_test.rb @@ -0,0 +1,15 @@ +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 new file mode 100644 index 000000000..062caa0c0 --- /dev/null +++ b/Library/Homebrew/test/link_test.rb @@ -0,0 +1,23 @@ +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 new file mode 100644 index 000000000..4c5b8ec13 --- /dev/null +++ b/Library/Homebrew/test/linkapps_test.rb @@ -0,0 +1,15 @@ +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 new file mode 100644 index 000000000..3c691e3ad --- /dev/null +++ b/Library/Homebrew/test/list_test.rb @@ -0,0 +1,13 @@ +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 new file mode 100644 index 000000000..bb6a1f661 --- /dev/null +++ b/Library/Homebrew/test/log_formula_test.rb @@ -0,0 +1,27 @@ +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 new file mode 100644 index 000000000..b2e150ccd --- /dev/null +++ b/Library/Homebrew/test/log_test.rb @@ -0,0 +1,13 @@ +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 new file mode 100644 index 000000000..17929d038 --- /dev/null +++ b/Library/Homebrew/test/migrate_test.rb @@ -0,0 +1,18 @@ +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_test.rb b/Library/Homebrew/test/migrator_test.rb new file mode 100644 index 000000000..8a2b6ad63 --- /dev/null +++ b/Library/Homebrew/test/migrator_test.rb @@ -0,0 +1,264 @@ +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 new file mode 100644 index 000000000..4f20d8a7a --- /dev/null +++ b/Library/Homebrew/test/missing_test.rb @@ -0,0 +1,34 @@ +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_test.rb b/Library/Homebrew/test/mpi_requirement_test.rb new file mode 100644 index 000000000..e0f97e8ee --- /dev/null +++ b/Library/Homebrew/test/mpi_requirement_test.rb @@ -0,0 +1,12 @@ +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_test.rb b/Library/Homebrew/test/options_test.rb new file mode 100644 index 000000000..e7189a604 --- /dev/null +++ b/Library/Homebrew/test/options_test.rb @@ -0,0 +1,157 @@ +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.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.inspect + @options << Option.new("foo") + assert_equal "#]>", @options.inspect + end +end diff --git a/Library/Homebrew/test/os/mac/blacklist_test.rb b/Library/Homebrew/test/os/mac/blacklist_test.rb new file mode 100644 index 000000000..26dd84ed9 --- /dev/null +++ b/Library/Homebrew/test/os/mac/blacklist_test.rb @@ -0,0 +1,12 @@ +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 new file mode 100644 index 000000000..2f88050ae --- /dev/null +++ b/Library/Homebrew/test/os/mac/bottle_collector_test.rb @@ -0,0 +1,26 @@ +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 new file mode 100644 index 000000000..996bd4d53 --- /dev/null +++ b/Library/Homebrew/test/os/mac/bottle_tag_test.rb @@ -0,0 +1,79 @@ +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_test.rb b/Library/Homebrew/test/os/mac/dependency_collector_test.rb new file mode 100644 index 000000000..4fdf3ebe4 --- /dev/null +++ b/Library/Homebrew/test/os/mac/dependency_collector_test.rb @@ -0,0 +1,57 @@ +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_test.rb b/Library/Homebrew/test/os/mac/diagnostic_test.rb new file mode 100644 index 000000000..655aa1d46 --- /dev/null +++ b/Library/Homebrew/test/os/mac/diagnostic_test.rb @@ -0,0 +1,49 @@ +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/keg_test.rb b/Library/Homebrew/test/os/mac/keg_test.rb new file mode 100644 index 000000000..e79cbc921 --- /dev/null +++ b/Library/Homebrew/test/os/mac/keg_test.rb @@ -0,0 +1,69 @@ +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 new file mode 100644 index 000000000..e328db5e0 --- /dev/null +++ b/Library/Homebrew/test/os/mac/language_test.rb @@ -0,0 +1,19 @@ +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_test.rb b/Library/Homebrew/test/os/mac/mach_test.rb new file mode 100644 index 000000000..a42f7316b --- /dev/null +++ b/Library/Homebrew/test/os/mac/mach_test.rb @@ -0,0 +1,208 @@ +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_test.rb b/Library/Homebrew/test/os/mac/version_test.rb new file mode 100644 index 000000000..f702c7097 --- /dev/null +++ b/Library/Homebrew/test/os/mac/version_test.rb @@ -0,0 +1,53 @@ +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/x11_requirement_test.rb b/Library/Homebrew/test/os/mac/x11_requirement_test.rb new file mode 100644 index 000000000..102937cb5 --- /dev/null +++ b/Library/Homebrew/test/os/mac/x11_requirement_test.rb @@ -0,0 +1,13 @@ +require "testing_env" +require "requirements/x11_requirement" + +class OSMacX11RequirementTests < Homebrew::TestCase + def test_satisfied + MacOS::XQuartz.stubs(:version).returns("2.7.5") + MacOS::XQuartz.stubs(:installed?).returns(true) + assert_predicate X11Requirement.new, :satisfied? + + MacOS::XQuartz.stubs(:installed?).returns(false) + refute_predicate X11Requirement.new, :satisfied? + end +end diff --git a/Library/Homebrew/test/outdated_test.rb b/Library/Homebrew/test/outdated_test.rb new file mode 100644 index 000000000..3e7148ded --- /dev/null +++ b/Library/Homebrew/test/outdated_test.rb @@ -0,0 +1,10 @@ +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_test.rb b/Library/Homebrew/test/patch_test.rb new file mode 100644 index 000000000..62624720e --- /dev/null +++ b/Library/Homebrew/test/patch_test.rb @@ -0,0 +1,154 @@ +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 "#", 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 '#', @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_test.rb b/Library/Homebrew/test/patching_test.rb new file mode 100644 index 000000000..ac14c8e1e --- /dev/null +++ b/Library/Homebrew/test/patching_test.rb @@ -0,0 +1,253 @@ +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_test.rb b/Library/Homebrew/test/pathname_test.rb new file mode 100644 index 000000000..2f6360719 --- /dev/null +++ b/Library/Homebrew/test/pathname_test.rb @@ -0,0 +1,267 @@ +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 new file mode 100644 index 000000000..65fb9e4da --- /dev/null +++ b/Library/Homebrew/test/pin_unpin_test.rb @@ -0,0 +1,18 @@ +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_test.rb b/Library/Homebrew/test/pkg_version_test.rb new file mode 100644 index 000000000..ff7896f8b --- /dev/null +++ b/Library/Homebrew/test/pkg_version_test.rb @@ -0,0 +1,51 @@ +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 new file mode 100644 index 000000000..eb5970d3e --- /dev/null +++ b/Library/Homebrew/test/prefix_formula_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..a3ae75542 --- /dev/null +++ b/Library/Homebrew/test/prefix_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..8fa5df7b7 --- /dev/null +++ b/Library/Homebrew/test/prune_test.rb @@ -0,0 +1,21 @@ +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 new file mode 100644 index 000000000..c9d46cd74 --- /dev/null +++ b/Library/Homebrew/test/pull_offline_test.rb @@ -0,0 +1,10 @@ +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 new file mode 100644 index 000000000..445d73cb1 --- /dev/null +++ b/Library/Homebrew/test/pull_test.rb @@ -0,0 +1,27 @@ +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 new file mode 100644 index 000000000..3eec79dd8 --- /dev/null +++ b/Library/Homebrew/test/readall_test.rb @@ -0,0 +1,12 @@ +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 new file mode 100644 index 000000000..80f5518ea --- /dev/null +++ b/Library/Homebrew/test/reinstall_pinned_test.rb @@ -0,0 +1,15 @@ +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 new file mode 100644 index 000000000..73877b35d --- /dev/null +++ b/Library/Homebrew/test/reinstall_test.rb @@ -0,0 +1,15 @@ +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 --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 new file mode 100644 index 000000000..77967a58d --- /dev/null +++ b/Library/Homebrew/test/repository_test.rb @@ -0,0 +1,10 @@ +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_test.rb b/Library/Homebrew/test/requirement_test.rb new file mode 100644 index 000000000..580d42bfa --- /dev/null +++ b/Library/Homebrew/test/requirement_test.rb @@ -0,0 +1,152 @@ +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_test.rb b/Library/Homebrew/test/resource_test.rb new file mode 100644 index 000000000..c1b526cb2 --- /dev/null +++ b/Library/Homebrew/test/resource_test.rb @@ -0,0 +1,132 @@ +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 new file mode 100644 index 000000000..2a062cb10 --- /dev/null +++ b/Library/Homebrew/test/sandbox_test.rb @@ -0,0 +1,76 @@ +require "testing_env" +require "sandbox" + +class SandboxTest < Homebrew::TestCase + def setup + 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 + assert Sandbox.formula?(f), + "Formulae should be sandboxed if --sandbox was passed." + + ARGV.stubs(:sandbox?).returns false + assert Sandbox.formula?(f), + "Formulae should be sandboxed if in a sandboxed tap." + refute Sandbox.formula?(f2), + "Formulae should not be sandboxed if not in a sandboxed tap." + end + + def test_test? + ARGV.stubs(:no_sandbox?).returns false + assert Sandbox.test?, + "Tests should be sandboxed unless --no-sandbox was passed." + end + + def test_allow_write + @sandbox.allow_write @file + @sandbox.exec "touch", @file + assert_predicate @file, :exist? + end + + def test_deny_write + shutup do + assert_raises(ErrorDuringExecution) { @sandbox.exec "touch", @file } + end + refute_predicate @file, :exist? + end + + def test_complains_on_failure + Utils.expects(popen_read: "foo") + ARGV.stubs(verbose?: true) + out, _err = capture_io do + assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } + end + assert_match "foo", out + end + + def test_ignores_bogus_python_error + with_bogus_error = <<-EOS.undent + foo + Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc + bar + EOS + Utils.expects(popen_read: with_bogus_error) + ARGV.stubs(verbose?: true) + out, _err = capture_io do + assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } + end + refute_predicate out, :empty? + assert_match "foo", out + assert_match "bar", out + refute_match "Python", out + end +end diff --git a/Library/Homebrew/test/search_remote_tap_test.rb b/Library/Homebrew/test/search_remote_tap_test.rb new file mode 100644 index 000000000..9dd9ee654 --- /dev/null +++ b/Library/Homebrew/test/search_remote_tap_test.rb @@ -0,0 +1,19 @@ +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 new file mode 100644 index 000000000..70b6f01fb --- /dev/null +++ b/Library/Homebrew/test/search_test.rb @@ -0,0 +1,30 @@ +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§ion=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§ion=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 new file mode 100644 index 000000000..280aeb9f4 --- /dev/null +++ b/Library/Homebrew/test/services_test.rb @@ -0,0 +1,11 @@ +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 new file mode 100644 index 000000000..48fcdc54a --- /dev/null +++ b/Library/Homebrew/test/sh_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..877acb5c8 --- /dev/null +++ b/Library/Homebrew/test/shell_test.rb @@ -0,0 +1,59 @@ +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_test.rb b/Library/Homebrew/test/software_spec_test.rb new file mode 100644 index 000000000..d9226f8c3 --- /dev/null +++ b/Library/Homebrew/test/software_spec_test.rb @@ -0,0 +1,181 @@ +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/stdlib_test.rb b/Library/Homebrew/test/stdlib_test.rb new file mode 100644 index 000000000..ee53e7c8c --- /dev/null +++ b/Library/Homebrew/test/stdlib_test.rb @@ -0,0 +1,61 @@ +require "testing_env" +require "formula" +require "cxxstdlib" + +class CxxStdlibTests < Homebrew::TestCase + def setup + @clang = CxxStdlib.create(:libstdcxx, :clang) + @gcc = CxxStdlib.create(:libstdcxx, :gcc) + @gcc4 = CxxStdlib.create(:libstdcxx, :gcc_4_0) + @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?(@gcc4) + 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 @gcc4, :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_test.rb b/Library/Homebrew/test/string_test.rb new file mode 100644 index 000000000..497c4badb --- /dev/null +++ b/Library/Homebrew/test/string_test.rb @@ -0,0 +1,40 @@ +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/switch_test.rb b/Library/Homebrew/test/switch_test.rb new file mode 100644 index 000000000..af1926c39 --- /dev/null +++ b/Library/Homebrew/test/switch_test.rb @@ -0,0 +1,20 @@ +require "testing_env" + +class IntegrationCommandTestSwitch < IntegrationCommandTestCase + def test_switch + assert_match "Usage: brew switch ", 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_test.rb b/Library/Homebrew/test/tab_test.rb new file mode 100644 index 000000000..76c9aacc9 --- /dev/null +++ b/Library/Homebrew/test/tab_test.rb @@ -0,0 +1,270 @@ +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_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_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/hombrew/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(Utils::JSON.load(@tab.to_json)) + assert_equal @tab.used_options.sort, tab.used_options.sort + assert_equal @tab.unused_options.sort, tab.unused_options.sort + assert_equal @tab.built_as_bottle, tab.built_as_bottle + assert_equal @tab.poured_from_bottle, tab.poured_from_bottle + 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 new file mode 100644 index 000000000..261a334f0 --- /dev/null +++ b/Library/Homebrew/test/tap_new_test.rb @@ -0,0 +1,9 @@ +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 new file mode 100644 index 000000000..b950cd166 --- /dev/null +++ b/Library/Homebrew/test/tap_test.rb @@ -0,0 +1,329 @@ +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/versions", 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 + @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" + @path.mkpath + @tap = Tap.new("Homebrew", "foo") + end + + def setup_tap_files + @formula_file = @path/"Formula/foo.rb" + @formula_file.write <<-EOS.undent + class Foo < Formula + url "https://example.com/foo-1.0.tar.gz" + end + EOS + @alias_file = @path/"Aliases/bar" + @alias_file.parent.mkpath + ln_s @formula_file, @alias_file + (@path/"formula_renames.json").write <<-EOS.undent + { "oldname": "foo" } + EOS + (@path/"tap_migrations.json").write <<-EOS.undent + { "removed-formula": "homebrew/foo" } + EOS + @cmd_file = @path/"cmd/brew-tap-cmd.rb" + @cmd_file.parent.mkpath + touch @cmd_file + chmod 0755, @cmd_file + @manpage_file = @path/"man/man1/brew-tap-cmd.1" + @manpage_file.parent.mkpath + touch @manpage_file + 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" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" + system "git", "add", "--all" + system "git", "commit", "-m", "init" + end + end + ensure + ENV.replace(env) + end + + def teardown + @path.rmtree + end + + def test_fetch + assert_kind_of CoreTap, Tap.fetch("Homebrew", "homebrew") + tap = Tap.fetch("Homebrew", "foo") + assert_kind_of Tap, tap + assert_equal "homebrew/foo", tap.name + + assert_match "Invalid tap name", + assert_raises { Tap.fetch("foo") }.message + assert_match "Invalid tap name", + assert_raises { Tap.fetch("homebrew/homebrew/bar") }.message + assert_match "Invalid tap name", + assert_raises { Tap.fetch("homebrew", "homebrew/baz") }.message + ensure + Tap.clear_cache + end + + def test_names + assert_equal ["homebrew/core", "homebrew/foo"], Tap.names.sort + end + + def test_attributes + assert_equal "Homebrew", @tap.user + assert_equal "foo", @tap.repo + assert_equal "homebrew/foo", @tap.name + assert_equal @path, @tap.path + assert_predicate @tap, :installed? + assert_predicate @tap, :official? + refute_predicate @tap, :core_tap? + end + + def test_issues_url + t = Tap.new("someone", "foo") + path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" + path.mkpath + cd path do + shutup { system "git", "init" } + system "git", "remote", "add", "origin", + "https://github.com/someone/homebrew-foo" + end + assert_equal "https://github.com/someone/homebrew-foo/issues", t.issues_url + assert_equal "https://github.com/Homebrew/homebrew-foo/issues", @tap.issues_url + + (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath + assert_nil Tap.new("someone", "no-git").issues_url + ensure + path.parent.rmtree + end + + def test_files + setup_tap_files + + assert_equal [@formula_file], @tap.formula_files + assert_equal ["homebrew/foo/foo"], @tap.formula_names + assert_equal [@alias_file], @tap.alias_files + assert_equal ["homebrew/foo/bar"], @tap.aliases + assert_equal @tap.alias_table, "homebrew/foo/bar" => "homebrew/foo/foo" + assert_equal @tap.alias_reverse_table, "homebrew/foo/foo" => ["homebrew/foo/bar"] + assert_equal @tap.formula_renames, "oldname" => "foo" + assert_equal @tap.tap_migrations, "removed-formula" => "homebrew/foo" + assert_equal [@cmd_file], @tap.command_files + assert_kind_of Hash, @tap.to_hash + assert_equal true, @tap.formula_file?(@formula_file) + assert_equal true, @tap.formula_file?("Formula/foo.rb") + assert_equal false, @tap.formula_file?("bar.rb") + assert_equal false, @tap.formula_file?("Formula/baz.sh") + end + + def test_remote + setup_git_repo + + assert_equal "https://github.com/Homebrew/homebrew-foo", @tap.remote + assert_raises(TapUnavailableError) { Tap.new("Homebrew", "bar").remote } + refute_predicate @tap, :custom_remote? + + version_tap = Tap.new("Homebrew", "versions") + version_tap.path.mkpath + version_tap.path.cd do + shutup do + system "git", "init" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-versions" + end + end + refute_predicate version_tap, :private? + ensure + version_tap.path.rmtree if version_tap + end + + def test_remote_not_git_repo + assert_nil @tap.remote + end + + def test_remote_git_not_available + setup_git_repo + Utils.stubs(:git_available?).returns(false) + assert_nil @tap.remote + end + + def test_git_variant + 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 + end + + def test_private_remote + skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub.api_credentials + assert_predicate @tap, :private? + end + + def test_install_tap_already_tapped_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + assert_equal true, already_tapped_tap.installed? + assert_raises(TapAlreadyTappedError) { already_tapped_tap.install } + end + + def test_install_tap_remote_match_already_tapped_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + assert_equal true, already_tapped_tap.installed? + right_remote = @tap.remote + assert_raises(TapAlreadyTappedError) { already_tapped_tap.install clone_target: right_remote } + end + + def test_install_tap_remote_mismatch_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + touch @tap.path/".git/shallow" + assert_equal true, already_tapped_tap.installed? + wrong_remote = "#{@tap.remote}-oops" + assert_raises(TapRemoteMismatchError) { already_tapped_tap.install clone_target: wrong_remote, full_clone: true } + end + + def test_install_tap_already_unshallow_error + setup_git_repo + already_tapped_tap = Tap.new("Homebrew", "foo") + assert_raises(TapAlreadyUnshallowError) { already_tapped_tap.install full_clone: true } + end + + def test_uninstall_tap_unavailable_error + tap = Tap.new("Homebrew", "bar") + assert_raises(TapUnavailableError) { tap.uninstall } + end + + def test_install_git_error + tap = Tap.new("user", "repo") + assert_raises(ErrorDuringExecution) do + shutup { tap.install clone_target: "file:///not/existed/remote/url" } + end + refute_predicate tap, :installed? + refute_predicate Tap::TAP_DIRECTORY/"user", :exist? + end + + def test_install_and_uninstall + setup_tap_files + setup_git_repo + + tap = Tap.new("Homebrew", "bar") + shutup { tap.install clone_target: @tap.path/".git" } + assert_predicate tap, :installed? + assert_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :file? + shutup { tap.uninstall } + 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 + refute_predicate @tap, :pinned? + assert_raises(TapPinStatusError) { @tap.unpin } + @tap.pin + assert_predicate @tap, :pinned? + assert_raises(TapPinStatusError) { @tap.pin } + @tap.unpin + refute_predicate @tap, :pinned? + end + + def test_config + setup_git_repo + + assert_nil @tap.config["foo"] + @tap.config["foo"] = "bar" + assert_equal "bar", @tap.config["foo"] + @tap.config["foo"] = nil + assert_nil @tap.config["foo"] + end +end + +class CoreTapTest < Homebrew::TestCase + include FileUtils + + def setup + @repo = CoreTap.new + end + + def test_attributes + assert_equal "Homebrew", @repo.user + assert_equal "core", @repo.repo + assert_equal "homebrew/core", @repo.name + assert_equal [], @repo.command_files + assert_predicate @repo, :installed? + refute_predicate @repo, :pinned? + assert_predicate @repo, :official? + assert_predicate @repo, :core_tap? + end + + def test_forbidden_operations + assert_raises(RuntimeError) { @repo.uninstall } + assert_raises(RuntimeError) { @repo.pin } + assert_raises(RuntimeError) { @repo.unpin } + end + + def test_files + @formula_file = @repo.formula_dir/"foo.rb" + @formula_file.write <<-EOS.undent + class Foo < Formula + url "https://example.com/foo-1.0.tar.gz" + end + EOS + @alias_file = @repo.alias_dir/"bar" + @alias_file.parent.mkpath + ln_s @formula_file, @alias_file + + assert_equal [@formula_file], @repo.formula_files + assert_equal ["foo"], @repo.formula_names + assert_equal [@alias_file], @repo.alias_files + 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/ARGV_test.rb b/Library/Homebrew/test/test/ARGV_test.rb deleted file mode 100644 index 6805e0c62..000000000 --- a/Library/Homebrew/test/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/test/ENV_test.rb b/Library/Homebrew/test/test/ENV_test.rb deleted file mode 100644 index 6c0e68a9e..000000000 --- a/Library/Homebrew/test/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, :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/test/analytics_test.rb b/Library/Homebrew/test/test/analytics_test.rb deleted file mode 100644 index 37040f3cd..000000000 --- a/Library/Homebrew/test/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/test/audit_test.rb b/Library/Homebrew/test/test/audit_test.rb deleted file mode 100644 index 2725f906e..000000000 --- a/Library/Homebrew/test/test/audit_test.rb +++ /dev/null @@ -1,472 +0,0 @@ -require "testing_env" -require "fileutils" -require "pathname" -require "formulary" -require "dev-cmd/audit" - -class FormulaTextTests < Homebrew::TestCase - def setup - @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| - f.write <<-EOS.undent - class #{Formulary.class_s(name)} < Formula - #{body} - end - #{options[:patch]} - EOS - end - FormulaText.new path - end - - def test_simple_valid_formula - ft = formula_text "valid", 'url "http://www.example.com/valid-1.0.tar.gz"' - - refute ft.data?, "The formula should not have DATA" - refute ft.end?, "The formula should not have __END__" - assert ft.trailing_newline?, "The formula should have a trailing newline" - - assert ft =~ /\burl\b/, "The formula should match 'url'" - assert_nil ft.line_number(/desc/), "The formula should not match 'desc'" - assert_equal 2, ft.line_number(/\burl\b/) - assert ft.include?("Valid"), "The formula should include \"Valid\"" - end - - def test_trailing_newline - ft = formula_text "newline" - assert ft.trailing_newline?, "The formula must have a trailing newline" - end - - def test_has_data - ft = formula_text "data", "patch :DATA" - assert ft.data?, "The formula must have DATA" - end - - def test_has_end - ft = formula_text "end", "", patch: "__END__\na patch here" - assert ft.end?, "The formula must have __END__" - assert_equal "class End < Formula\n \nend", ft.without_patch - end -end - -class FormulaAuditorTests < Homebrew::TestCase - def setup - @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| - f.write text - end - FormulaAuditor.new Formulary.factory(path), options - end - - def test_init_no_problems - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - assert_equal [], fa.problems - end - - def test_audit_file_permissions - File.stubs(:umask).returns 022 - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - path = fa.formula.path - path.chmod 0400 - - fa.audit_file - assert_equal ["Incorrect file permissions (400): chmod 644 #{path}"], - fa.problems - end - - def test_audit_file_data_no_end - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - patch :DATA - end - EOS - fa.audit_file - assert_equal ["'DATA' was found, but no '__END__'"], fa.problems - end - - def test_audit_file_end_no_data - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - __END__ - a patch goes here - EOS - fa.audit_file - assert_equal ["'__END__' was found, but 'DATA' is not used"], fa.problems - end - - def test_audit_file_no_trailing_newline - fa = formula_auditor "foo", 'class Foo "http://www.freedesktop.org/wiki/bar", - "baz" => "http://www.freedesktop.org/wiki/Software/baz", - "qux" => "https://code.google.com/p/qux", - "quux" => "http://github.com/quux", - "corge" => "http://savannah.nongnu.org/corge", - "grault" => "http://grault.github.io/", - "garply" => "http://www.gnome.org/garply", - "waldo" => "http://www.gnu.org/waldo", - } - - formula_homepages.each do |name, homepage| - fa = formula_auditor name, <<-EOS.undent - class #{Formulary.class_s(name)} < Formula - homepage "#{homepage}" - url "http://example.com/#{name}-1.0.tgz" - end - EOS - - fa.audit_homepage - if homepage =~ %r{http:\/\/www\.freedesktop\.org} - if homepage =~ /Software/ - assert_match "#{homepage} should be styled " \ - "`https://wiki.freedesktop.org/www/Software/project_name`", - fa.problems.first - else - assert_match "#{homepage} should be styled " \ - "`https://wiki.freedesktop.org/project_name`", - fa.problems.first - end - elsif homepage =~ %r{https:\/\/code\.google\.com} - assert_match "#{homepage} should end with a slash", fa.problems.first - else - assert_match "Please use https:// for #{homepage}", fa.problems.first - end - end - end -end diff --git a/Library/Homebrew/test/test/bash_test.rb b/Library/Homebrew/test/test/bash_test.rb deleted file mode 100644 index ff418c787..000000000 --- a/Library/Homebrew/test/test/bash_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "testing_env" - -class BashTests < Homebrew::TestCase - def assert_valid_bash_syntax(file) - 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/test/blacklist_test.rb b/Library/Homebrew/test/test/blacklist_test.rb deleted file mode 100644 index 585a35484..000000000 --- a/Library/Homebrew/test/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/test/bottle_collector_test.rb b/Library/Homebrew/test/test/bottle_collector_test.rb deleted file mode 100644 index d75e29ec8..000000000 --- a/Library/Homebrew/test/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/test/bottle_filename_test.rb b/Library/Homebrew/test/test/bottle_filename_test.rb deleted file mode 100644 index 6604e7d6a..000000000 --- a/Library/Homebrew/test/test/bottle_filename_test.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "testing_env" -require "formula" -require "software_spec" - -class BottleFilenameTests < Homebrew::TestCase - def fn(rebuild) - Bottle::Filename.new("foo", "1.0", :tag, rebuild) - end - - def test_prefix_suffix - assert_equal "foo-1.0.tag", fn(0).prefix - assert_equal ".bottle.tar.gz", fn(0).suffix - assert_equal ".bottle.1.tar.gz", fn(1).suffix - end - - def test_to_str - expected = "foo-1.0.tag.bottle.tar.gz" - assert_equal expected, fn(0).to_s - assert_equal expected, fn(0).to_str - end - - def test_create - f = formula do - url "https://example.com/foo.tar.gz" - version "1.0" - end - - expected = "formula_name-1.0.tag.bottle.tar.gz" - assert_equal expected, Bottle::Filename.create(f, :tag, 0).to_s - end -end diff --git a/Library/Homebrew/test/test/bottle_hooks_test.rb b/Library/Homebrew/test/test/bottle_hooks_test.rb deleted file mode 100644 index 3535d80ef..000000000 --- a/Library/Homebrew/test/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/test/bottle_test.rb b/Library/Homebrew/test/test/bottle_test.rb deleted file mode 100644 index c10746e09..000000000 --- a/Library/Homebrew/test/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/test/build_environment_test.rb b/Library/Homebrew/test/test/build_environment_test.rb deleted file mode 100644 index 73a1c95f7..000000000 --- a/Library/Homebrew/test/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/test/build_options_test.rb b/Library/Homebrew/test/test/build_options_test.rb deleted file mode 100644 index e460d25cc..000000000 --- a/Library/Homebrew/test/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/test/bundle_test.rb b/Library/Homebrew/test/test/bundle_test.rb deleted file mode 100644 index ae47977d8..000000000 --- a/Library/Homebrew/test/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/test/cache_formula_test.rb b/Library/Homebrew/test/test/cache_formula_test.rb deleted file mode 100644 index 6dcb6a745..000000000 --- a/Library/Homebrew/test/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/test/cache_test.rb b/Library/Homebrew/test/test/cache_test.rb deleted file mode 100644 index 3a9e6b011..000000000 --- a/Library/Homebrew/test/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/test/cask_test.rb b/Library/Homebrew/test/test/cask_test.rb deleted file mode 100644 index d5b81facb..000000000 --- a/Library/Homebrew/test/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/test/cat_test.rb b/Library/Homebrew/test/test/cat_test.rb deleted file mode 100644 index bb37b5fde..000000000 --- a/Library/Homebrew/test/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/test/caveats_test.rb b/Library/Homebrew/test/test/caveats_test.rb deleted file mode 100644 index 9eaac5792..000000000 --- a/Library/Homebrew/test/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/test/cellar_formula_test.rb b/Library/Homebrew/test/test/cellar_formula_test.rb deleted file mode 100644 index 38a934a7b..000000000 --- a/Library/Homebrew/test/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/test/cellar_test.rb b/Library/Homebrew/test/test/cellar_test.rb deleted file mode 100644 index 74d5389f8..000000000 --- a/Library/Homebrew/test/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/test/checksum_test.rb b/Library/Homebrew/test/test/checksum_test.rb deleted file mode 100644 index 5505f6824..000000000 --- a/Library/Homebrew/test/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/test/checksum_verification_test.rb b/Library/Homebrew/test/test/checksum_verification_test.rb deleted file mode 100644 index 9017b528d..000000000 --- a/Library/Homebrew/test/test/checksum_verification_test.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "testing_env" -require "formula" - -class ChecksumVerificationTests < Homebrew::TestCase - def assert_checksum_good - assert_nothing_raised { shutup { @_f.brew {} } } - end - - def assert_checksum_bad - assert_raises(ChecksumMismatchError) { shutup { @_f.brew {} } } - end - - def formula(&block) - super do - url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" - instance_eval(&block) - end - end - - def teardown - @_f.clear_cache - end - - def test_good_sha256 - formula do - sha256 TESTBALL_SHA256 - end - - assert_checksum_good - end - - def test_bad_sha256 - formula do - sha256 "dcbf5f44743b74add648c7e35e414076632fa3b24463d68d1f6afc5be77024f8" - end - - assert_checksum_bad - end -end diff --git a/Library/Homebrew/test/test/cleaner_test.rb b/Library/Homebrew/test/test/cleaner_test.rb deleted file mode 100644 index ac108421c..000000000 --- a/Library/Homebrew/test/test/cleaner_test.rb +++ /dev/null @@ -1,223 +0,0 @@ -require "testing_env" -require "cleaner" -require "formula" - -class CleanerTests < Homebrew::TestCase - include FileUtils - - def setup - @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 - cp "#{TEST_FIXTURE_DIR}/mach/a.out", @f.bin - cp Dir["#{TEST_FIXTURE_DIR}/mach/*.dylib"], @f.lib - - Cleaner.new(@f).clean - - assert_equal 0100555, (@f.bin/"a.out").stat.mode - assert_equal 0100444, (@f.lib/"fat.dylib").stat.mode - assert_equal 0100444, (@f.lib/"x86_64.dylib").stat.mode - assert_equal 0100444, (@f.lib/"i386.dylib").stat.mode - end - - def test_prunes_prefix_if_empty - Cleaner.new(@f).clean - refute_predicate @f.prefix, :directory? - end - - def test_prunes_empty_directories - subdir = @f.bin/"subdir" - subdir.mkpath - - Cleaner.new(@f).clean - - refute_predicate @f.bin, :directory? - refute_predicate subdir, :directory? - end - - def test_skip_clean_empty_directory - @f.class.skip_clean "bin" - @f.bin.mkpath - - Cleaner.new(@f).clean - - assert_predicate @f.bin, :directory? - end - - def test_skip_clean_directory_with_empty_subdir - @f.class.skip_clean "bin" - subdir = @f.bin/"subdir" - subdir.mkpath - - Cleaner.new(@f).clean - - assert_predicate @f.bin, :directory? - assert_predicate subdir, :directory? - end - - def test_removes_symlink_when_target_was_pruned_first - dir = @f.prefix/"b" - symlink = @f.prefix/"a" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - refute_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_removes_symlink_pointing_to_empty_directory - dir = @f.prefix/"b" - symlink = @f.prefix/"c" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - refute_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_removes_broken_symlinks - symlink = @f.prefix/"symlink" - ln_s "target", symlink - - Cleaner.new(@f).clean - - refute_predicate symlink, :symlink? - end - - def test_skip_clean_broken_symlink - @f.class.skip_clean "symlink" - symlink = @f.prefix/"symlink" - ln_s "target", symlink - - Cleaner.new(@f).clean - - assert_predicate symlink, :symlink? - end - - def test_skip_clean_symlink_pointing_to_empty_directory - @f.class.skip_clean "c" - dir = @f.prefix/"b" - symlink = @f.prefix/"c" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - assert_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_skip_clean_symlink_when_target_pruned - @f.class.skip_clean "a" - dir = @f.prefix/"b" - symlink = @f.prefix/"a" - - dir.mkpath - ln_s dir.basename, symlink - - Cleaner.new(@f).clean - - refute_predicate dir, :exist? - assert_predicate symlink, :symlink? - refute_predicate symlink, :exist? - end - - def test_removes_la_files - file = @f.lib/"foo.la" - - @f.lib.mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_removes_perllocal_files - file = @f.lib/"perl5/darwin-thread-multi-2level/perllocal.pod" - - (@f.lib/"perl5/darwin-thread-multi-2level").mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_removes_packlist_files - file = @f.lib/"perl5/darwin-thread-multi-2level/auto/test/.packlist" - - (@f.lib/"perl5/darwin-thread-multi-2level/auto/test").mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_skip_clean_la - file = @f.lib/"foo.la" - - @f.class.skip_clean :la - @f.lib.mkpath - touch file - - Cleaner.new(@f).clean - - assert_predicate file, :exist? - end - - def test_remove_charset_alias - file = @f.lib/"charset.alias" - - @f.lib.mkpath - touch file - - Cleaner.new(@f).clean - - refute_predicate file, :exist? - end - - def test_skip_clean_subdir - dir = @f.lib/"subdir" - @f.class.skip_clean "lib/subdir" - - dir.mkpath - - Cleaner.new(@f).clean - - assert_predicate dir, :directory? - end - - def test_skip_clean_paths_are_anchored_to_prefix - dir1 = @f.bin/"a" - dir2 = @f.lib/"bin/a" - - @f.class.skip_clean "bin/a" - dir1.mkpath - dir2.mkpath - - Cleaner.new(@f).clean - - assert_predicate dir1, :exist? - refute_predicate dir2, :exist? - end -end diff --git a/Library/Homebrew/test/test/cleanup_test.rb b/Library/Homebrew/test/test/cleanup_test.rb deleted file mode 100644 index bb8e1cdc6..000000000 --- a/Library/Homebrew/test/test/cleanup_test.rb +++ /dev/null @@ -1,91 +0,0 @@ -require "testing_env" -require "test/support/fixtures/testball" -require "cleanup" -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 - @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" - end - - def test_cleanup - shutup { Homebrew::Cleanup.cleanup } - refute_predicate @ds_store, :exist? - end - - def test_cleanup_dry_run - ARGV << "--dry-run" - shutup { Homebrew::Cleanup.cleanup } - assert_predicate @ds_store, :exist? - 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 - - 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? - - 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 - end - - def test_cleanup_logs - path = (HOMEBREW_LOGS/"delete_me") - path.mkpath - ARGV << "--prune=all" - shutup { Homebrew::Cleanup.cleanup_logs } - refute_predicate path, :exist? - end - - def test_cleanup_cache_incomplete_downloads - incomplete = (HOMEBREW_CACHE/"something.incomplete") - incomplete.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate incomplete, :exist? - end - - def test_cleanup_cache_java_cache - java_cache = (HOMEBREW_CACHE/"java_cache") - java_cache.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate java_cache, :exist? - end - - def test_cleanup_cache_npm_cache - npm_cache = (HOMEBREW_CACHE/"npm_cache") - npm_cache.mkpath - shutup { Homebrew::Cleanup.cleanup_cache } - refute_predicate npm_cache, :exist? - end -end diff --git a/Library/Homebrew/test/test/command_test.rb b/Library/Homebrew/test/test/command_test.rb deleted file mode 100644 index d5c7aaa88..000000000 --- a/Library/Homebrew/test/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/test/commands_test.rb b/Library/Homebrew/test/test/commands_test.rb deleted file mode 100644 index d44d2da0e..000000000 --- a/Library/Homebrew/test/test/commands_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -require "testing_env" -require "cmd/command" -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 - @cmds = [ - # internal commands - HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - - # internal development commands - HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - ] - - @cmds.each { |f| FileUtils.touch f } - end - - def teardown - @cmds.each(&:unlink) - end - - def test_internal_commands - cmds = Homebrew.internal_commands - assert cmds.include?("rbcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbdevcmd"), "Dev commands shouldn't be included" - end - - def test_internal_developer_commands - cmds = Homebrew.internal_developer_commands - assert cmds.include?("rbdevcmd"), "Ruby commands files should be recognized" - assert cmds.include?("shdevcmd"), "Shell commands files should be recognized" - refute cmds.include?("rbcmd"), "Non-dev commands shouldn't be included" - 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}" - FileUtils.touch path - FileUtils.chmod 0755, path - end - - FileUtils.touch "#{dir}/brew-t4" - - ENV["PATH"] += "#{File::PATH_SEPARATOR}#{dir}" - cmds = Homebrew.external_commands - - assert cmds.include?("t1"), "Executable files should be included" - assert cmds.include?("t2"), "Executable Ruby files should be included" - refute cmds.include?("t3"), - "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 - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", - Commands.path("rbcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"cmd/shcmd.sh", - Commands.path("shcmd") - assert_nil Commands.path("idontexist1234") - end - - def test_internal_dev_command_path - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/rbdevcmd.rb", - Commands.path("rbdevcmd") - assert_equal HOMEBREW_LIBRARY_PATH/"dev-cmd/shdevcmd.sh", - Commands.path("shdevcmd") - end -end diff --git a/Library/Homebrew/test/test/compiler_failure_test.rb b/Library/Homebrew/test/test/compiler_failure_test.rb deleted file mode 100644 index c0b74d128..000000000 --- a/Library/Homebrew/test/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/test/compiler_selector_test.rb b/Library/Homebrew/test/test/compiler_selector_test.rb deleted file mode 100644 index b1591bdbe..000000000 --- a/Library/Homebrew/test/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/test/config_test.rb b/Library/Homebrew/test/test/config_test.rb deleted file mode 100644 index 81da4660a..000000000 --- a/Library/Homebrew/test/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/test/create_test.rb b/Library/Homebrew/test/test/create_test.rb deleted file mode 100644 index aeee428aa..000000000 --- a/Library/Homebrew/test/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/test/custom_command_test.rb b/Library/Homebrew/test/test/custom_command_test.rb deleted file mode 100644 index 8d05bc6c7..000000000 --- a/Library/Homebrew/test/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/test/dependencies_test.rb b/Library/Homebrew/test/test/dependencies_test.rb deleted file mode 100644 index db3b78226..000000000 --- a/Library/Homebrew/test/test/dependencies_test.rb +++ /dev/null @@ -1,115 +0,0 @@ -require "testing_env" -require "dependencies" -require "dependency" -require "requirements" - -class DependenciesTests < Homebrew::TestCase - def setup - @deps = Dependencies.new - end - - def test_shovel_returns_self - assert_same @deps, @deps << Dependency.new("foo") - end - - def test_preserves_order - hash = { 0 => "foo", 1 => "bar", 2 => "baz" } - @deps << Dependency.new(hash[0]) - @deps << Dependency.new(hash[1]) - @deps << Dependency.new(hash[2]) - @deps.each_with_index do |dep, idx| - assert_equal hash[idx], dep.name - end - end - - def test_repetition - @deps << Dependency.new("foo") - @deps << Dependency.new("bar") - assert_equal "foo, bar", @deps*", " - end - - def test_to_a - dep = Dependency.new("foo") - @deps << dep - assert_equal [dep], @deps.to_a - end - - def test_to_ary - dep = Dependency.new("foo") - @deps << dep - assert_equal [dep], @deps.to_ary - end - - def test_type_helpers - foo = Dependency.new("foo") - bar = Dependency.new("bar", [:optional]) - baz = Dependency.new("baz", [:build]) - qux = Dependency.new("qux", [:recommended]) - quux = Dependency.new("quux") - @deps << foo << bar << baz << qux << quux - assert_equal [foo, quux], @deps.required - assert_equal [bar], @deps.optional - assert_equal [baz], @deps.build - assert_equal [qux], @deps.recommended - assert_equal [foo, baz, quux, qux].sort_by(&:name), @deps.default.sort_by(&:name) - end - - def test_equality - a = Dependencies.new - b = Dependencies.new - - dep = Dependency.new("foo") - - a << dep - b << dep - - assert_equal a, b - assert_eql a, b - - b << Dependency.new("bar", [:optional]) - - refute_equal a, b - refute_eql a, b - end - - def test_empty - a = Dependencies.new - assert a.empty? - a << Dependency.new("foo") - refute a.empty? - end - - def test_inspect - a = Dependencies.new - assert_equal "#", a.inspect - a << Dependency.new("foo") - assert_equal "#]>", a.inspect - end -end - -class RequirementsTests < Homebrew::TestCase - def setup - @reqs = Requirements.new - end - - def test_shovel_returns_self - assert_same @reqs, @reqs << Object.new - end - - def test_merging_multiple_dependencies - @reqs << X11Requirement.new << X11Requirement.new - assert_equal 1, @reqs.count - @reqs << Requirement.new - assert_equal 2, @reqs.count - end - - def test_comparison_prefers_larger - @reqs << X11Requirement.new << X11Requirement.new("x11", %w[2.6]) - assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a - end - - def test_comparison_does_not_merge_smaller - @reqs << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new - assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a - end -end diff --git a/Library/Homebrew/test/test/dependency_collector_test.rb b/Library/Homebrew/test/test/dependency_collector_test.rb deleted file mode 100644 index 1c7f70118..000000000 --- a/Library/Homebrew/test/test/dependency_collector_test.rb +++ /dev/null @@ -1,146 +0,0 @@ -require "testing_env" -require "dependency_collector" - -class DependencyCollectorTests < Homebrew::TestCase - def find_dependency(name) - @d.deps.find { |dep| dep.name == name } - end - - def find_requirement(klass) - @d.requirements.find { |req| req.is_a? klass } - end - - def setup - @d = DependencyCollector.new - end - - def teardown - DependencyCollector.clear_cache - end - - def test_dependency_creation - @d.add "foo" => :build - @d.add "bar" => ["--universal", :optional] - assert_instance_of Dependency, find_dependency("foo") - assert_equal 2, find_dependency("bar").tags.length - end - - def test_add_returns_created_dep - ret = @d.add "foo" - assert_equal Dependency.new("foo"), ret - end - - def test_dependency_tags - assert_predicate Dependency.new("foo", [:build]), :build? - assert_predicate Dependency.new("foo", [:build, :optional]), :optional? - assert_includes Dependency.new("foo", ["universal"]).options, "--universal" - assert_empty Dependency.new("foo").tags - end - - def test_requirement_creation - @d.add :x11 - assert_instance_of X11Requirement, find_requirement(X11Requirement) - end - - def test_no_duplicate_requirements - 2.times { @d.add :x11 } - assert_equal 1, @d.requirements.count - end - - def test_requirement_tags - @d.add x11: "2.5.1" - @d.add xcode: :build - assert_empty find_requirement(X11Requirement).tags - assert_predicate find_requirement(XcodeRequirement), :build? - end - - def test_x11_no_tag - @d.add :x11 - assert_empty find_requirement(X11Requirement).tags - end - - def test_x11_min_version - @d.add x11: "2.5.1" - assert_equal "2.5.1", find_requirement(X11Requirement).min_version.to_s - end - - def test_x11_tag - @d.add x11: :optional - assert_predicate find_requirement(X11Requirement), :optional? - end - - def test_x11_min_version_and_tag - @d.add x11: ["2.5.1", :optional] - dep = find_requirement(X11Requirement) - assert_equal "2.5.1", dep.min_version.to_s - assert_predicate dep, :optional? - end - - def test_ant_dep - @d.add ant: :build - assert_equal find_dependency("ant"), Dependency.new("ant", [:build]) - end - - def test_raises_typeerror_for_unknown_classes - assert_raises(TypeError) { @d.add(Class.new) } - end - - def test_raises_typeerror_for_unknown_types - assert_raises(TypeError) { @d.add(Object.new) } - end - - def test_does_not_mutate_dependency_spec - spec = { "foo" => :optional } - copy = spec.dup - @d.add(spec) - assert_equal copy, spec - end - - def test_resource_dep_git_url - resource = Resource.new - resource.url("git://example.com/foo/bar.git") - assert_instance_of GitRequirement, @d.add(resource) - end - - def test_resource_dep_7z_url - resource = Resource.new - resource.url("http://example.com/foo.7z") - assert_equal Dependency.new("p7zip", [:build]), @d.add(resource) - end - - def test_resource_dep_gzip_url - resource = Resource.new - resource.url("http://example.com/foo.tar.gz") - assert_nil @d.add(resource) - end - - def test_resource_dep_lz_url - resource = Resource.new - resource.url("http://example.com/foo.lz") - assert_equal Dependency.new("lzip", [:build]), @d.add(resource) - end - - def test_resource_dep_lha_url - resource = Resource.new - resource.url("http://example.com/foo.lha") - assert_equal Dependency.new("lha", [:build]), @d.add(resource) - end - - def test_resource_dep_lzh_url - resource = Resource.new - resource.url("http://example.com/foo.lzh") - assert_equal Dependency.new("lha", [:build]), @d.add(resource) - end - - def test_resource_dep_rar_url - resource = Resource.new - resource.url("http://example.com/foo.rar") - assert_equal Dependency.new("unrar", [:build]), @d.add(resource) - end - - def test_resource_dep_raises_for_unknown_classes - resource = Resource.new - resource.download_strategy = Class.new - assert_raises(TypeError) { @d.add(resource) } - end -end diff --git a/Library/Homebrew/test/test/dependency_expansion_test.rb b/Library/Homebrew/test/test/dependency_expansion_test.rb deleted file mode 100644 index 9d6de35e2..000000000 --- a/Library/Homebrew/test/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/test/dependency_test.rb b/Library/Homebrew/test/test/dependency_test.rb deleted file mode 100644 index 65255995e..000000000 --- a/Library/Homebrew/test/test/dependency_test.rb +++ /dev/null @@ -1,125 +0,0 @@ -require "testing_env" -require "dependency" - -class DependableTests < Homebrew::TestCase - def setup - @tags = ["foo", "bar", :build] - @dep = Struct.new(:tags).new(@tags).extend(Dependable) - end - - def test_options - assert_equal %w[--foo --bar].sort, @dep.options.as_flags.sort - end - - def test_interrogation - assert_predicate @dep, :build? - refute_predicate @dep, :optional? - refute_predicate @dep, :recommended? - end -end - -class DependencyTests < Homebrew::TestCase - def test_accepts_single_tag - dep = Dependency.new("foo", %w[bar]) - assert_equal %w[bar], dep.tags - end - - def test_accepts_multiple_tags - dep = Dependency.new("foo", %w[bar baz]) - assert_equal %w[bar baz].sort, dep.tags.sort - end - - def test_preserves_symbol_tags - dep = Dependency.new("foo", [:build]) - assert_equal [:build], dep.tags - end - - def test_accepts_symbol_and_string_tags - dep = Dependency.new("foo", [:build, "bar"]) - assert_equal [:build, "bar"], dep.tags - end - - def test_merge_repeats - dep = Dependency.new("foo", [:build], nil, "foo") - dep2 = Dependency.new("foo", ["bar"], nil, "foo2") - dep3 = Dependency.new("xyz", ["abc"], nil, "foo") - merged = Dependency.merge_repeats([dep, dep2, dep3]) - assert_equal 2, merged.length - assert_equal Dependency, merged.first.class - - foo_named_dep = merged.find { |d| d.name == "foo" } - assert_equal ["bar"], foo_named_dep.tags - assert_includes foo_named_dep.option_names, "foo" - assert_includes foo_named_dep.option_names, "foo2" - - xyz_named_dep = merged.find { |d| d.name == "xyz" } - assert_equal ["abc"], xyz_named_dep.tags - assert_includes xyz_named_dep.option_names, "foo" - refute_includes xyz_named_dep.option_names, "foo2" - end - - def test_merges_necessity_tags - required_dep = Dependency.new("foo") - recommended_dep = Dependency.new("foo", [:recommended]) - optional_dep = Dependency.new("foo", [:optional]) - - deps = Dependency.merge_repeats([required_dep, recommended_dep]) - assert_equal deps.count, 1 - assert_predicate deps.first, :required? - refute_predicate deps.first, :recommended? - refute_predicate deps.first, :optional? - - deps = Dependency.merge_repeats([required_dep, optional_dep]) - assert_equal deps.count, 1 - assert_predicate deps.first, :required? - refute_predicate deps.first, :recommended? - refute_predicate deps.first, :optional? - - deps = Dependency.merge_repeats([recommended_dep, optional_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :required? - assert_predicate deps.first, :recommended? - refute_predicate deps.first, :optional? - end - - def test_merges_temporality_tags - normal_dep = Dependency.new("foo") - build_dep = Dependency.new("foo", [:build]) - run_dep = Dependency.new("foo", [:run]) - - deps = Dependency.merge_repeats([normal_dep, build_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :build? - refute_predicate deps.first, :run? - - deps = Dependency.merge_repeats([normal_dep, run_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :build? - refute_predicate deps.first, :run? - - deps = Dependency.merge_repeats([build_dep, run_dep]) - assert_equal deps.count, 1 - refute_predicate deps.first, :build? - refute_predicate deps.first, :run? - end - - def test_equality - foo1 = Dependency.new("foo") - foo2 = Dependency.new("foo") - bar = Dependency.new("bar") - assert_equal foo1, foo2 - assert_eql foo1, foo2 - refute_equal foo1, bar - refute_eql foo1, bar - foo3 = Dependency.new("foo", [:build]) - refute_equal foo1, foo3 - refute_eql foo1, foo3 - end -end - -class TapDependencyTests < Homebrew::TestCase - def test_option_names - dep = TapDependency.new("foo/bar/dog") - assert_equal %w[dog], dep.option_names - end -end diff --git a/Library/Homebrew/test/test/deps_test.rb b/Library/Homebrew/test/test/deps_test.rb deleted file mode 100644 index 01639857c..000000000 --- a/Library/Homebrew/test/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/test/desc_test.rb b/Library/Homebrew/test/test/desc_test.rb deleted file mode 100644 index 2ba498135..000000000 --- a/Library/Homebrew/test/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/test/descriptions_test.rb b/Library/Homebrew/test/test/descriptions_test.rb deleted file mode 100644 index de38fdbd1..000000000 --- a/Library/Homebrew/test/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/test/diagnostic_test.rb b/Library/Homebrew/test/test/diagnostic_test.rb deleted file mode 100644 index aa2e44cfc..000000000 --- a/Library/Homebrew/test/test/diagnostic_test.rb +++ /dev/null @@ -1,197 +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 - # 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/test/doctor_test.rb b/Library/Homebrew/test/test/doctor_test.rb deleted file mode 100644 index d2dc871f4..000000000 --- a/Library/Homebrew/test/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/test/download_strategies_test.rb b/Library/Homebrew/test/test/download_strategies_test.rb deleted file mode 100644 index 87218fb12..000000000 --- a/Library/Homebrew/test/test/download_strategies_test.rb +++ /dev/null @@ -1,188 +0,0 @@ -require "testing_env" -require "download_strategy" - -class ResourceDouble - attr_reader :url, :specs, :version - - def initialize(url = "http://example.com/foo.tar.gz", specs = {}) - @url = url - @specs = specs - 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 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/test/edit_test.rb b/Library/Homebrew/test/test/edit_test.rb deleted file mode 100644 index 9b6ded651..000000000 --- a/Library/Homebrew/test/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/test/exceptions_test.rb b/Library/Homebrew/test/test/exceptions_test.rb deleted file mode 100644 index 689531c6e..000000000 --- a/Library/Homebrew/test/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: "") - assert_match "bar does not define resource ", - ResourceMissingError.new(f, r).to_s - end - - def test_duplicate_resource_error - r = stub(inspect: "") - assert_equal "Resource 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/test/fetch_test.rb b/Library/Homebrew/test/test/fetch_test.rb deleted file mode 100644 index e08e545e3..000000000 --- a/Library/Homebrew/test/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/test/formula_installer_bottle_test.rb b/Library/Homebrew/test/test/formula_installer_bottle_test.rb deleted file mode 100644 index 6a891f159..000000000 --- a/Library/Homebrew/test/test/formula_installer_bottle_test.rb +++ /dev/null @@ -1,78 +0,0 @@ -require "testing_env" -require "formula" -require "formula_installer" -require "keg" -require "tab" -require "test/support/fixtures/testball" -require "test/support/fixtures/testball_bottle" - -class InstallBottleTests < Homebrew::TestCase - def temporary_bottle_install(formula) - refute_predicate formula, :installed? - assert_predicate formula, :bottled? - assert_predicate formula, :pour_bottle? - - installer = FormulaInstaller.new(formula) - - shutup { installer.install } - - keg = Keg.new(formula.prefix) - - assert_predicate formula, :installed? - - begin - assert_predicate Tab.for_keg(keg), :poured_from_bottle - - yield formula - ensure - keg.unlink - keg.uninstall - formula.clear_cache - formula.bottle.clear_cache - end - - refute_predicate keg, :exist? - refute_predicate formula, :installed? - end - - def test_a_basic_bottle_install - DevelopmentTools.stubs(:installed?).returns(false) - - temporary_bottle_install(TestballBottle.new) do |f| - # Copied directly from test_formula_installer.rb as we expect - # the same behavior - - # Test that things made it into the Keg - assert_predicate f.bin, :directory? - - assert_predicate f.libexec, :directory? - - refute_predicate f.prefix+"main.c", :exist? - - # Test that things make it into the Cellar - keg = Keg.new f.prefix - keg.link - - bin = HOMEBREW_PREFIX+"bin" - assert_predicate bin, :directory? - end - end - - def test_build_tools_error - DevelopmentTools.stubs(:installed?).returns(false) - - # Testball doesn't have a bottle block, so use it to test this behavior - formula = Testball.new - - refute_predicate formula, :installed? - refute_predicate formula, :bottled? - - installer = FormulaInstaller.new(formula) - - assert_raises(BuildToolsError) do - installer.install - end - - refute_predicate formula, :installed? - end -end diff --git a/Library/Homebrew/test/test/formula_installer_test.rb b/Library/Homebrew/test/test/formula_installer_test.rb deleted file mode 100644 index 652548bd7..000000000 --- a/Library/Homebrew/test/test/formula_installer_test.rb +++ /dev/null @@ -1,138 +0,0 @@ -require "testing_env" -require "formula" -require "formula_installer" -require "keg" -require "tab" -require "test/support/fixtures/testball" -require "test/support/fixtures/testball_bottle" - -class InstallTests < Homebrew::TestCase - def temporary_install(formula) - refute_predicate formula, :installed? - - installer = FormulaInstaller.new(formula) - - shutup { installer.install } - - keg = Keg.new(formula.prefix) - - assert_predicate formula, :installed? - - begin - Tab.clear_cache - refute_predicate Tab.for_keg(keg), :poured_from_bottle - - yield formula - ensure - Tab.clear_cache - keg.unlink - keg.uninstall - formula.clear_cache - # there will be log files when sandbox is enable. - formula.logs.rmtree if formula.logs.directory? - end - - refute_predicate keg, :exist? - refute_predicate formula, :installed? - end - - def test_a_basic_install - ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install - temporary_install(Testball.new) do |f| - # Test that things made it into the Keg - assert_predicate f.prefix+"readme", :exist? - - assert_predicate f.bin, :directory? - assert_equal 3, f.bin.children.length - - assert_predicate f.libexec, :directory? - assert_equal 1, f.libexec.children.length - - refute_predicate f.prefix+"main.c", :exist? - - refute_predicate f.prefix+"license", :exist? - - # Test that things make it into the Cellar - keg = Keg.new f.prefix - keg.link - - bin = HOMEBREW_PREFIX+"bin" - assert_predicate bin, :directory? - assert_equal 3, bin.children.length - assert_predicate f.prefix/".brew/testball.rb", :readable? - end - end - - def test_bottle_unneeded_formula_install - DevelopmentTools.stubs(:installed?).returns(false) - - formula = Testball.new - formula.stubs(:bottle_unneeded?).returns(true) - formula.stubs(:bottle_disabled?).returns(true) - - refute_predicate formula, :bottled? - assert_predicate formula, :bottle_unneeded? - assert_predicate formula, :bottle_disabled? - - temporary_install(formula) do |f| - assert_predicate f, :installed? - end - end - - def test_not_poured_from_bottle_when_compiler_specified - assert_nil ARGV.cc - - 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 } - end - end -end - -class FormulaInstallerTests < Homebrew::TestCase - def test_check_install_sanity_pinned_dep - dep_name = "dependency" - dep_path = CoreTap.new.formula_dir/"#{dep_name}.rb" - dep_path.write <<-EOS.undent - class #{Formulary.class_s(dep_name)} < Formula - url "foo" - version "0.2" - end - EOS - - Formulary::FORMULAE.delete(dep_path) - dependency = Formulary.factory(dep_name) - - dependent = formula do - url "foo" - version "0.5" - depends_on dependency.name.to_s - end - - dependency.prefix("0.1").join("bin/a").mkpath - HOMEBREW_PINNED_KEGS.mkpath - FileUtils.ln_s dependency.prefix("0.1"), HOMEBREW_PINNED_KEGS/dep_name - - dependency_keg = Keg.new(dependency.prefix("0.1")) - dependency_keg.link - - assert_predicate dependency_keg, :linked? - assert_predicate dependency, :pinned? - - 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/test/formula_lock_test.rb b/Library/Homebrew/test/test/formula_lock_test.rb deleted file mode 100644 index 80ee9dd25..000000000 --- a/Library/Homebrew/test/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/test/formula_pin_test.rb b/Library/Homebrew/test/test/formula_pin_test.rb deleted file mode 100644 index 297d7703e..000000000 --- a/Library/Homebrew/test/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/test/formula_spec_selection_test.rb b/Library/Homebrew/test/test/formula_spec_selection_test.rb deleted file mode 100644 index 7148df173..000000000 --- a/Library/Homebrew/test/test/formula_spec_selection_test.rb +++ /dev/null @@ -1,99 +0,0 @@ -require "testing_env" -require "formula" - -class FormulaSpecSelectionTests < Homebrew::TestCase - def test_selects_stable_by_default - f = formula do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :stable? - end - - def test_selects_stable_when_exclusive - f = formula { url "foo-1.0" } - assert_predicate f, :stable? - end - - def test_selects_devel_before_head - f = formula do - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_selects_devel_when_exclusive - f = formula { devel { url "foo-1.1a" } } - assert_predicate f, :devel? - end - - def test_selects_head_when_exclusive - f = formula { head "foo" } - assert_predicate f, :head? - end - - def test_incomplete_spec_not_selected - f = formula do - sha256 TEST_SHA256 - version "1.0" - head "foo" - end - - assert_predicate f, :head? - end - - def test_incomplete_stable_not_set - f = formula do - sha256 TEST_SHA256 - devel { url "foo-1.1a" } - head "foo" - end - - assert_nil f.stable - assert_predicate f, :devel? - end - - def test_selects_head_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :head) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :head? - end - - def test_selects_devel_when_requested - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - devel { url "foo-1.1a" } - head "foo" - end - - assert_predicate f, :devel? - end - - def test_incomplete_devel_not_set - f = formula do - url "foo-1.0" - devel { version "1.1a" } - head "foo" - end - - assert_nil f.devel - assert_predicate f, :stable? - end - - def test_does_not_raise_for_missing_spec - f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do - url "foo-1.0" - head "foo" - end - - assert_predicate f, :stable? - end -end diff --git a/Library/Homebrew/test/test/formula_support_test.rb b/Library/Homebrew/test/test/formula_support_test.rb deleted file mode 100644 index c0a79f950..000000000 --- a/Library/Homebrew/test/test/formula_support_test.rb +++ /dev/null @@ -1,28 +0,0 @@ -require "testing_env" -require "formula_support" - -class KegOnlyReasonTests < Homebrew::TestCase - def test_to_s_explanation - r = KegOnlyReason.new :provided_by_osx, "test" - assert_equal "test", r.to_s - end - - def test_to_s_no_explanation - r = KegOnlyReason.new :provided_by_macos, "" - assert_match(/^macOS already provides/, r.to_s) - end -end - -class BottleDisableReasonTests < Homebrew::TestCase - def test_bottle_unneeded - bottle_disable_reason = BottleDisableReason.new :unneeded, nil - assert_predicate bottle_disable_reason, :unneeded? - assert_equal "This formula doesn't require compiling.", bottle_disable_reason.to_s - end - - def test_bottle_disabled - bottle_disable_reason = BottleDisableReason.new :disable, "reason" - refute_predicate bottle_disable_reason, :unneeded? - assert_equal "reason", bottle_disable_reason.to_s - 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 eef60a3e5..000000000 --- a/Library/Homebrew/test/test/formula_test.rb +++ /dev/null @@ -1,1180 +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/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 "f3" - end - - assert_equal %w[f3], f4.deps.map(&:name) - assert_equal %w[f1 f2 f3], f4.recursive_dependencies.map(&:name) - assert_equal %w[f2 f3], f4.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/test/formula_validation_test.rb b/Library/Homebrew/test/test/formula_validation_test.rb deleted file mode 100644 index c40eb6733..000000000 --- a/Library/Homebrew/test/test/formula_validation_test.rb +++ /dev/null @@ -1,75 +0,0 @@ -require "testing_env" -require "formula" - -class FormulaValidationTests < Homebrew::TestCase - def assert_invalid(attr, &block) - e = assert_raises(FormulaValidationError, &block) - assert_equal attr, e.attr - end - - def test_cant_override_brew - e = assert_raises(RuntimeError) { formula { def brew; end } } - assert_match(/You cannot override Formula#brew/, e.message) - end - - def test_validates_name - assert_invalid :name do - formula "name with spaces" do - url "foo" - version "1.0" - end - end - end - - def test_validates_url - assert_invalid :url do - formula do - url "" - version "1" - end - end - end - - def test_validates_version - assert_invalid :version do - formula do - url "foo" - version "version with spaces" - end - end - - assert_invalid :version do - formula do - url "foo" - version "" - end - end - - assert_invalid :version do - formula do - url "foo" - version nil - end - end - end - - def test_devel_only_valid - f = formula do - devel do - url "foo" - version "1.0" - end - end - - assert_predicate f, :devel? - end - - def test_head_only_valid - f = formula { head "foo" } - assert_predicate f, :head? - end - - def test_empty_formula_invalid - assert_raises(FormulaSpecificationError) { formula {} } - end -end diff --git a/Library/Homebrew/test/test/formulary_test.rb b/Library/Homebrew/test/test/formulary_test.rb deleted file mode 100644 index 3d88c8407..000000000 --- a/Library/Homebrew/test/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/test/gpg2_requirement_test.rb b/Library/Homebrew/test/test/gpg2_requirement_test.rb deleted file mode 100644 index fa7fc9ea4..000000000 --- a/Library/Homebrew/test/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/test/gpg_test.rb b/Library/Homebrew/test/test/gpg_test.rb deleted file mode 100644 index 0374bdab4..000000000 --- a/Library/Homebrew/test/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/test/hardware_test.rb b/Library/Homebrew/test/test/hardware_test.rb deleted file mode 100644 index 2bea5387d..000000000 --- a/Library/Homebrew/test/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, :dunno] - assert_includes families, Hardware::CPU.family - end - end -end diff --git a/Library/Homebrew/test/test/help_test.rb b/Library/Homebrew/test/test/help_test.rb deleted file mode 100644 index 92dd99721..000000000 --- a/Library/Homebrew/test/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/test/home_test.rb b/Library/Homebrew/test/test/home_test.rb deleted file mode 100644 index ff06b72c1..000000000 --- a/Library/Homebrew/test/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/test/info_test.rb b/Library/Homebrew/test/test/info_test.rb deleted file mode 100644 index f71044bf0..000000000 --- a/Library/Homebrew/test/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/test/inreplace_test.rb b/Library/Homebrew/test/test/inreplace_test.rb deleted file mode 100644 index 0e62f9d3f..000000000 --- a/Library/Homebrew/test/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/test/install_test.rb b/Library/Homebrew/test/test/install_test.rb deleted file mode 100644 index fa1057a02..000000000 --- a/Library/Homebrew/test/test/install_test.rb +++ /dev/null @@ -1,30 +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_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 -end diff --git a/Library/Homebrew/test/test/irb_test.rb b/Library/Homebrew/test/test/irb_test.rb deleted file mode 100644 index 832ca39a5..000000000 --- a/Library/Homebrew/test/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/test/json_test.rb b/Library/Homebrew/test/test/json_test.rb deleted file mode 100644 index 14d2f2b4c..000000000 --- a/Library/Homebrew/test/test/json_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "testing_env" -require "utils/json" - -class JsonSmokeTest < Homebrew::TestCase - def test_encode - hash = { "foo" => ["bar", "baz"] } - json = '{"foo":["bar","baz"]}' - assert_equal json, Utils::JSON.dump(hash) - end - - def test_decode - hash = { "foo" => ["bar", "baz"], "qux" => 1 } - json = '{"foo":["bar","baz"],"qux":1}' - assert_equal hash, Utils::JSON.load(json) - end - - def test_decode_failure - assert_raises(Utils::JSON::Error) { Utils::JSON.load("nope") } - end -end diff --git a/Library/Homebrew/test/test/keg_test.rb b/Library/Homebrew/test/test/keg_test.rb deleted file mode 100644 index fdc739c9d..000000000 --- a/Library/Homebrew/test/test/keg_test.rb +++ /dev/null @@ -1,400 +0,0 @@ -require "testing_env" -require "keg" -require "stringio" - -class LinkTests < 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 - - 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 < LinkTests - 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 - Formula.clear_cache - keg - end - - def setup - super - @dependent = setup_test_keg("bar", "1.0") - end - - def alter_tab(keg = @dependent) - tab = Tab.for_keg(keg) - yield tab - tab.write - end - - def dependencies(deps) - alter_tab do |tab| - tab.tabfile = @dependent.join("INSTALL_RECEIPT.json") - tab.runtime_dependencies = deps - end - 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) - dependencies [] - alter_tab { |t| t.source["path"] = nil } - assert_empty @keg.installed_dependents - assert_nil Keg.find_some_installed_dependents([@keg]) - 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_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_empty @keg.installed_dependents - assert_nil 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 -end diff --git a/Library/Homebrew/test/test/language_go_test.rb b/Library/Homebrew/test/test/language_go_test.rb deleted file mode 100644 index 692a5d2cc..000000000 --- a/Library/Homebrew/test/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/test/language_module_requirement_test.rb b/Library/Homebrew/test/test/language_module_requirement_test.rb deleted file mode 100644 index dfa992287..000000000 --- a/Library/Homebrew/test/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/test/language_python_test.rb b/Library/Homebrew/test/test/language_python_test.rb deleted file mode 100644 index d1e3867f7..000000000 --- a/Library/Homebrew/test/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/test/leaves_test.rb b/Library/Homebrew/test/test/leaves_test.rb deleted file mode 100644 index f73fba1ea..000000000 --- a/Library/Homebrew/test/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/test/link_test.rb b/Library/Homebrew/test/test/link_test.rb deleted file mode 100644 index 062caa0c0..000000000 --- a/Library/Homebrew/test/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/test/linkapps_test.rb b/Library/Homebrew/test/test/linkapps_test.rb deleted file mode 100644 index 4c5b8ec13..000000000 --- a/Library/Homebrew/test/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/test/list_test.rb b/Library/Homebrew/test/test/list_test.rb deleted file mode 100644 index 3c691e3ad..000000000 --- a/Library/Homebrew/test/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/test/log_formula_test.rb b/Library/Homebrew/test/test/log_formula_test.rb deleted file mode 100644 index bb6a1f661..000000000 --- a/Library/Homebrew/test/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/test/log_test.rb b/Library/Homebrew/test/test/log_test.rb deleted file mode 100644 index b2e150ccd..000000000 --- a/Library/Homebrew/test/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/test/migrate_test.rb b/Library/Homebrew/test/test/migrate_test.rb deleted file mode 100644 index 17929d038..000000000 --- a/Library/Homebrew/test/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/test/migrator_test.rb b/Library/Homebrew/test/test/migrator_test.rb deleted file mode 100644 index 8a2b6ad63..000000000 --- a/Library/Homebrew/test/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/test/missing_test.rb b/Library/Homebrew/test/test/missing_test.rb deleted file mode 100644 index 4f20d8a7a..000000000 --- a/Library/Homebrew/test/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/test/mpi_requirement_test.rb b/Library/Homebrew/test/test/mpi_requirement_test.rb deleted file mode 100644 index e0f97e8ee..000000000 --- a/Library/Homebrew/test/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/test/options_test.rb b/Library/Homebrew/test/test/options_test.rb deleted file mode 100644 index e7189a604..000000000 --- a/Library/Homebrew/test/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.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.inspect - @options << Option.new("foo") - assert_equal "#]>", @options.inspect - end -end diff --git a/Library/Homebrew/test/test/os/mac/blacklist_test.rb b/Library/Homebrew/test/test/os/mac/blacklist_test.rb deleted file mode 100644 index 26dd84ed9..000000000 --- a/Library/Homebrew/test/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/test/os/mac/bottle_collector_test.rb b/Library/Homebrew/test/test/os/mac/bottle_collector_test.rb deleted file mode 100644 index 2f88050ae..000000000 --- a/Library/Homebrew/test/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/test/os/mac/bottle_tag_test.rb b/Library/Homebrew/test/test/os/mac/bottle_tag_test.rb deleted file mode 100644 index 996bd4d53..000000000 --- a/Library/Homebrew/test/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/test/os/mac/dependency_collector_test.rb b/Library/Homebrew/test/test/os/mac/dependency_collector_test.rb deleted file mode 100644 index 4fdf3ebe4..000000000 --- a/Library/Homebrew/test/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/test/os/mac/diagnostic_test.rb b/Library/Homebrew/test/test/os/mac/diagnostic_test.rb deleted file mode 100644 index 655aa1d46..000000000 --- a/Library/Homebrew/test/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/test/os/mac/keg_test.rb b/Library/Homebrew/test/test/os/mac/keg_test.rb deleted file mode 100644 index e79cbc921..000000000 --- a/Library/Homebrew/test/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/test/os/mac/language_test.rb b/Library/Homebrew/test/test/os/mac/language_test.rb deleted file mode 100644 index e328db5e0..000000000 --- a/Library/Homebrew/test/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/test/os/mac/mach_test.rb b/Library/Homebrew/test/test/os/mac/mach_test.rb deleted file mode 100644 index a42f7316b..000000000 --- a/Library/Homebrew/test/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/test/os/mac/version_test.rb b/Library/Homebrew/test/test/os/mac/version_test.rb deleted file mode 100644 index f702c7097..000000000 --- a/Library/Homebrew/test/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/test/os/mac/x11_requirement_test.rb b/Library/Homebrew/test/test/os/mac/x11_requirement_test.rb deleted file mode 100644 index 102937cb5..000000000 --- a/Library/Homebrew/test/test/os/mac/x11_requirement_test.rb +++ /dev/null @@ -1,13 +0,0 @@ -require "testing_env" -require "requirements/x11_requirement" - -class OSMacX11RequirementTests < Homebrew::TestCase - def test_satisfied - MacOS::XQuartz.stubs(:version).returns("2.7.5") - MacOS::XQuartz.stubs(:installed?).returns(true) - assert_predicate X11Requirement.new, :satisfied? - - MacOS::XQuartz.stubs(:installed?).returns(false) - refute_predicate X11Requirement.new, :satisfied? - end -end diff --git a/Library/Homebrew/test/test/outdated_test.rb b/Library/Homebrew/test/test/outdated_test.rb deleted file mode 100644 index 3e7148ded..000000000 --- a/Library/Homebrew/test/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/test/patch_test.rb b/Library/Homebrew/test/test/patch_test.rb deleted file mode 100644 index 62624720e..000000000 --- a/Library/Homebrew/test/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 "#", 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 '#', @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/test/patching_test.rb b/Library/Homebrew/test/test/patching_test.rb deleted file mode 100644 index ac14c8e1e..000000000 --- a/Library/Homebrew/test/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/test/pathname_test.rb b/Library/Homebrew/test/test/pathname_test.rb deleted file mode 100644 index 2f6360719..000000000 --- a/Library/Homebrew/test/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/test/pin_unpin_test.rb b/Library/Homebrew/test/test/pin_unpin_test.rb deleted file mode 100644 index 65fb9e4da..000000000 --- a/Library/Homebrew/test/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/test/pkg_version_test.rb b/Library/Homebrew/test/test/pkg_version_test.rb deleted file mode 100644 index ff7896f8b..000000000 --- a/Library/Homebrew/test/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/test/prefix_formula_test.rb b/Library/Homebrew/test/test/prefix_formula_test.rb deleted file mode 100644 index eb5970d3e..000000000 --- a/Library/Homebrew/test/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/test/prefix_test.rb b/Library/Homebrew/test/test/prefix_test.rb deleted file mode 100644 index a3ae75542..000000000 --- a/Library/Homebrew/test/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/test/prune_test.rb b/Library/Homebrew/test/test/prune_test.rb deleted file mode 100644 index 8fa5df7b7..000000000 --- a/Library/Homebrew/test/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/test/pull_offline_test.rb b/Library/Homebrew/test/test/pull_offline_test.rb deleted file mode 100644 index c9d46cd74..000000000 --- a/Library/Homebrew/test/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/test/pull_test.rb b/Library/Homebrew/test/test/pull_test.rb deleted file mode 100644 index 445d73cb1..000000000 --- a/Library/Homebrew/test/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/test/readall_test.rb b/Library/Homebrew/test/test/readall_test.rb deleted file mode 100644 index 3eec79dd8..000000000 --- a/Library/Homebrew/test/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/test/reinstall_pinned_test.rb b/Library/Homebrew/test/test/reinstall_pinned_test.rb deleted file mode 100644 index 80f5518ea..000000000 --- a/Library/Homebrew/test/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/test/reinstall_test.rb b/Library/Homebrew/test/test/reinstall_test.rb deleted file mode 100644 index 73877b35d..000000000 --- a/Library/Homebrew/test/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 --with-foo", - cmd("reinstall", "testball") - assert foo_dir.exist? - end -end diff --git a/Library/Homebrew/test/test/repository_test.rb b/Library/Homebrew/test/test/repository_test.rb deleted file mode 100644 index 77967a58d..000000000 --- a/Library/Homebrew/test/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/test/requirement_test.rb b/Library/Homebrew/test/test/requirement_test.rb deleted file mode 100644 index 580d42bfa..000000000 --- a/Library/Homebrew/test/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/test/resource_test.rb b/Library/Homebrew/test/test/resource_test.rb deleted file mode 100644 index c1b526cb2..000000000 --- a/Library/Homebrew/test/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/test/sandbox_test.rb b/Library/Homebrew/test/test/sandbox_test.rb deleted file mode 100644 index 2a062cb10..000000000 --- a/Library/Homebrew/test/test/sandbox_test.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "testing_env" -require "sandbox" - -class SandboxTest < Homebrew::TestCase - def setup - 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 - assert Sandbox.formula?(f), - "Formulae should be sandboxed if --sandbox was passed." - - ARGV.stubs(:sandbox?).returns false - assert Sandbox.formula?(f), - "Formulae should be sandboxed if in a sandboxed tap." - refute Sandbox.formula?(f2), - "Formulae should not be sandboxed if not in a sandboxed tap." - end - - def test_test? - ARGV.stubs(:no_sandbox?).returns false - assert Sandbox.test?, - "Tests should be sandboxed unless --no-sandbox was passed." - end - - def test_allow_write - @sandbox.allow_write @file - @sandbox.exec "touch", @file - assert_predicate @file, :exist? - end - - def test_deny_write - shutup do - assert_raises(ErrorDuringExecution) { @sandbox.exec "touch", @file } - end - refute_predicate @file, :exist? - end - - def test_complains_on_failure - Utils.expects(popen_read: "foo") - ARGV.stubs(verbose?: true) - out, _err = capture_io do - assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } - end - assert_match "foo", out - end - - def test_ignores_bogus_python_error - with_bogus_error = <<-EOS.undent - foo - Mar 17 02:55:06 sandboxd[342]: Python(49765) deny file-write-unlink /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/errors.pyc - bar - EOS - Utils.expects(popen_read: with_bogus_error) - ARGV.stubs(verbose?: true) - out, _err = capture_io do - assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } - end - refute_predicate out, :empty? - assert_match "foo", out - assert_match "bar", out - refute_match "Python", out - end -end diff --git a/Library/Homebrew/test/test/search_remote_tap_test.rb b/Library/Homebrew/test/test/search_remote_tap_test.rb deleted file mode 100644 index 9dd9ee654..000000000 --- a/Library/Homebrew/test/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/test/search_test.rb b/Library/Homebrew/test/test/search_test.rb deleted file mode 100644 index 70b6f01fb..000000000 --- a/Library/Homebrew/test/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§ion=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§ion=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/test/services_test.rb b/Library/Homebrew/test/test/services_test.rb deleted file mode 100644 index 280aeb9f4..000000000 --- a/Library/Homebrew/test/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/test/sh_test.rb b/Library/Homebrew/test/test/sh_test.rb deleted file mode 100644 index 48fcdc54a..000000000 --- a/Library/Homebrew/test/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/test/shell_test.rb b/Library/Homebrew/test/test/shell_test.rb deleted file mode 100644 index 877acb5c8..000000000 --- a/Library/Homebrew/test/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/test/software_spec_test.rb b/Library/Homebrew/test/test/software_spec_test.rb deleted file mode 100644 index d9226f8c3..000000000 --- a/Library/Homebrew/test/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/test/stdlib_test.rb b/Library/Homebrew/test/test/stdlib_test.rb deleted file mode 100644 index ee53e7c8c..000000000 --- a/Library/Homebrew/test/test/stdlib_test.rb +++ /dev/null @@ -1,61 +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) - @gcc4 = CxxStdlib.create(:libstdcxx, :gcc_4_0) - @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?(@gcc4) - 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 @gcc4, :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/test/string_test.rb b/Library/Homebrew/test/test/string_test.rb deleted file mode 100644 index 497c4badb..000000000 --- a/Library/Homebrew/test/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/test/switch_test.rb b/Library/Homebrew/test/test/switch_test.rb deleted file mode 100644 index af1926c39..000000000 --- a/Library/Homebrew/test/test/switch_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require "testing_env" - -class IntegrationCommandTestSwitch < IntegrationCommandTestCase - def test_switch - assert_match "Usage: brew switch ", 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/test/tab_test.rb b/Library/Homebrew/test/test/tab_test.rb deleted file mode 100644 index 76c9aacc9..000000000 --- a/Library/Homebrew/test/test/tab_test.rb +++ /dev/null @@ -1,270 +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_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_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/hombrew/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(Utils::JSON.load(@tab.to_json)) - assert_equal @tab.used_options.sort, tab.used_options.sort - assert_equal @tab.unused_options.sort, tab.unused_options.sort - assert_equal @tab.built_as_bottle, tab.built_as_bottle - assert_equal @tab.poured_from_bottle, tab.poured_from_bottle - 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/test/tap_new_test.rb b/Library/Homebrew/test/test/tap_new_test.rb deleted file mode 100644 index 261a334f0..000000000 --- a/Library/Homebrew/test/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/test/tap_test.rb b/Library/Homebrew/test/test/tap_test.rb deleted file mode 100644 index b950cd166..000000000 --- a/Library/Homebrew/test/test/tap_test.rb +++ /dev/null @@ -1,329 +0,0 @@ -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/versions", 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 - @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" - @path.mkpath - @tap = Tap.new("Homebrew", "foo") - end - - def setup_tap_files - @formula_file = @path/"Formula/foo.rb" - @formula_file.write <<-EOS.undent - class Foo < Formula - url "https://example.com/foo-1.0.tar.gz" - end - EOS - @alias_file = @path/"Aliases/bar" - @alias_file.parent.mkpath - ln_s @formula_file, @alias_file - (@path/"formula_renames.json").write <<-EOS.undent - { "oldname": "foo" } - EOS - (@path/"tap_migrations.json").write <<-EOS.undent - { "removed-formula": "homebrew/foo" } - EOS - @cmd_file = @path/"cmd/brew-tap-cmd.rb" - @cmd_file.parent.mkpath - touch @cmd_file - chmod 0755, @cmd_file - @manpage_file = @path/"man/man1/brew-tap-cmd.1" - @manpage_file.parent.mkpath - touch @manpage_file - 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" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" - system "git", "add", "--all" - system "git", "commit", "-m", "init" - end - end - ensure - ENV.replace(env) - end - - def teardown - @path.rmtree - end - - def test_fetch - assert_kind_of CoreTap, Tap.fetch("Homebrew", "homebrew") - tap = Tap.fetch("Homebrew", "foo") - assert_kind_of Tap, tap - assert_equal "homebrew/foo", tap.name - - assert_match "Invalid tap name", - assert_raises { Tap.fetch("foo") }.message - assert_match "Invalid tap name", - assert_raises { Tap.fetch("homebrew/homebrew/bar") }.message - assert_match "Invalid tap name", - assert_raises { Tap.fetch("homebrew", "homebrew/baz") }.message - ensure - Tap.clear_cache - end - - def test_names - assert_equal ["homebrew/core", "homebrew/foo"], Tap.names.sort - end - - def test_attributes - assert_equal "Homebrew", @tap.user - assert_equal "foo", @tap.repo - assert_equal "homebrew/foo", @tap.name - assert_equal @path, @tap.path - assert_predicate @tap, :installed? - assert_predicate @tap, :official? - refute_predicate @tap, :core_tap? - end - - def test_issues_url - t = Tap.new("someone", "foo") - path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" - path.mkpath - cd path do - shutup { system "git", "init" } - system "git", "remote", "add", "origin", - "https://github.com/someone/homebrew-foo" - end - assert_equal "https://github.com/someone/homebrew-foo/issues", t.issues_url - assert_equal "https://github.com/Homebrew/homebrew-foo/issues", @tap.issues_url - - (Tap::TAP_DIRECTORY/"someone/homebrew-no-git").mkpath - assert_nil Tap.new("someone", "no-git").issues_url - ensure - path.parent.rmtree - end - - def test_files - setup_tap_files - - assert_equal [@formula_file], @tap.formula_files - assert_equal ["homebrew/foo/foo"], @tap.formula_names - assert_equal [@alias_file], @tap.alias_files - assert_equal ["homebrew/foo/bar"], @tap.aliases - assert_equal @tap.alias_table, "homebrew/foo/bar" => "homebrew/foo/foo" - assert_equal @tap.alias_reverse_table, "homebrew/foo/foo" => ["homebrew/foo/bar"] - assert_equal @tap.formula_renames, "oldname" => "foo" - assert_equal @tap.tap_migrations, "removed-formula" => "homebrew/foo" - assert_equal [@cmd_file], @tap.command_files - assert_kind_of Hash, @tap.to_hash - assert_equal true, @tap.formula_file?(@formula_file) - assert_equal true, @tap.formula_file?("Formula/foo.rb") - assert_equal false, @tap.formula_file?("bar.rb") - assert_equal false, @tap.formula_file?("Formula/baz.sh") - end - - def test_remote - setup_git_repo - - assert_equal "https://github.com/Homebrew/homebrew-foo", @tap.remote - assert_raises(TapUnavailableError) { Tap.new("Homebrew", "bar").remote } - refute_predicate @tap, :custom_remote? - - version_tap = Tap.new("Homebrew", "versions") - version_tap.path.mkpath - version_tap.path.cd do - shutup do - system "git", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-versions" - end - end - refute_predicate version_tap, :private? - ensure - version_tap.path.rmtree if version_tap - end - - def test_remote_not_git_repo - assert_nil @tap.remote - end - - def test_remote_git_not_available - setup_git_repo - Utils.stubs(:git_available?).returns(false) - assert_nil @tap.remote - end - - def test_git_variant - 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 - end - - def test_private_remote - skip "HOMEBREW_GITHUB_API_TOKEN is required" unless GitHub.api_credentials - assert_predicate @tap, :private? - end - - def test_install_tap_already_tapped_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - assert_equal true, already_tapped_tap.installed? - assert_raises(TapAlreadyTappedError) { already_tapped_tap.install } - end - - def test_install_tap_remote_match_already_tapped_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - assert_equal true, already_tapped_tap.installed? - right_remote = @tap.remote - assert_raises(TapAlreadyTappedError) { already_tapped_tap.install clone_target: right_remote } - end - - def test_install_tap_remote_mismatch_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - touch @tap.path/".git/shallow" - assert_equal true, already_tapped_tap.installed? - wrong_remote = "#{@tap.remote}-oops" - assert_raises(TapRemoteMismatchError) { already_tapped_tap.install clone_target: wrong_remote, full_clone: true } - end - - def test_install_tap_already_unshallow_error - setup_git_repo - already_tapped_tap = Tap.new("Homebrew", "foo") - assert_raises(TapAlreadyUnshallowError) { already_tapped_tap.install full_clone: true } - end - - def test_uninstall_tap_unavailable_error - tap = Tap.new("Homebrew", "bar") - assert_raises(TapUnavailableError) { tap.uninstall } - end - - def test_install_git_error - tap = Tap.new("user", "repo") - assert_raises(ErrorDuringExecution) do - shutup { tap.install clone_target: "file:///not/existed/remote/url" } - end - refute_predicate tap, :installed? - refute_predicate Tap::TAP_DIRECTORY/"user", :exist? - end - - def test_install_and_uninstall - setup_tap_files - setup_git_repo - - tap = Tap.new("Homebrew", "bar") - shutup { tap.install clone_target: @tap.path/".git" } - assert_predicate tap, :installed? - assert_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :file? - shutup { tap.uninstall } - 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 - refute_predicate @tap, :pinned? - assert_raises(TapPinStatusError) { @tap.unpin } - @tap.pin - assert_predicate @tap, :pinned? - assert_raises(TapPinStatusError) { @tap.pin } - @tap.unpin - refute_predicate @tap, :pinned? - end - - def test_config - setup_git_repo - - assert_nil @tap.config["foo"] - @tap.config["foo"] = "bar" - assert_equal "bar", @tap.config["foo"] - @tap.config["foo"] = nil - assert_nil @tap.config["foo"] - end -end - -class CoreTapTest < Homebrew::TestCase - include FileUtils - - def setup - @repo = CoreTap.new - end - - def test_attributes - assert_equal "Homebrew", @repo.user - assert_equal "core", @repo.repo - assert_equal "homebrew/core", @repo.name - assert_equal [], @repo.command_files - assert_predicate @repo, :installed? - refute_predicate @repo, :pinned? - assert_predicate @repo, :official? - assert_predicate @repo, :core_tap? - end - - def test_forbidden_operations - assert_raises(RuntimeError) { @repo.uninstall } - assert_raises(RuntimeError) { @repo.pin } - assert_raises(RuntimeError) { @repo.unpin } - end - - def test_files - @formula_file = @repo.formula_dir/"foo.rb" - @formula_file.write <<-EOS.undent - class Foo < Formula - url "https://example.com/foo-1.0.tar.gz" - end - EOS - @alias_file = @repo.alias_dir/"bar" - @alias_file.parent.mkpath - ln_s @formula_file, @alias_file - - assert_equal [@formula_file], @repo.formula_files - assert_equal ["foo"], @repo.formula_names - assert_equal [@alias_file], @repo.alias_files - 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/test_formula_test.rb b/Library/Homebrew/test/test/test_formula_test.rb deleted file mode 100644 index 5ad2db9e9..000000000 --- a/Library/Homebrew/test/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/test/uninstall_test.rb b/Library/Homebrew/test/test/uninstall_test.rb deleted file mode 100644 index 70a694353..000000000 --- a/Library/Homebrew/test/test/uninstall_test.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "cmd/uninstall" - -class UninstallTests < Homebrew::TestCase - def setup - @dependency = formula("dependency") { url "f-1" } - @dependent = formula("dependent") do - url "f-1" - depends_on "dependency" - end - - [@dependency, @dependent].each { |f| f.installed_prefix.mkpath } - - tab = Tab.empty - tab.tabfile = @dependent.installed_prefix/Tab::FILENAME - tab.runtime_dependencies = [ - { "full_name" => "dependency", "version" => "1" }, - ] - tab.write - - stub_formula_loader @dependency - stub_formula_loader @dependent - end - - def teardown - Homebrew.failed = false - [@dependency, @dependent].each { |f| f.rack.rmtree } - end - - def handle_unsatisfied_dependents - capture_stderr do - opts = { @dependency.rack => [Keg.new(@dependency.installed_prefix)] } - Homebrew.handle_unsatisfied_dependents(opts) - end - end - - def test_check_for_testball_f2s_when_developer - skip "Flaky test" - assert_match "Warning", handle_unsatisfied_dependents - refute_predicate Homebrew, :failed? - end - - def test_check_for_dependents_when_not_developer - skip "Flaky test" - run_as_not_developer do - assert_match "Error", handle_unsatisfied_dependents - assert_predicate Homebrew, :failed? - end - end - - def test_check_for_dependents_when_ignore_dependencies - ARGV << "--ignore-dependencies" - run_as_not_developer do - 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/test/unlink_test.rb b/Library/Homebrew/test/test/unlink_test.rb deleted file mode 100644 index 6d5cefc67..000000000 --- a/Library/Homebrew/test/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/test/unlinkapps_test.rb b/Library/Homebrew/test/test/unlinkapps_test.rb deleted file mode 100644 index 9d9672199..000000000 --- a/Library/Homebrew/test/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/test/unpack_test.rb b/Library/Homebrew/test/test/unpack_test.rb deleted file mode 100644 index bbff6ad1c..000000000 --- a/Library/Homebrew/test/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/test/update_report_test.rb b/Library/Homebrew/test/test/update_report_test.rb deleted file mode 100644 index 6b6cec6ce..000000000 --- a/Library/Homebrew/test/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/test/upgrade_test.rb b/Library/Homebrew/test/test/upgrade_test.rb deleted file mode 100644 index f3f5dccc7..000000000 --- a/Library/Homebrew/test/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/test/uses_test.rb b/Library/Homebrew/test/test/uses_test.rb deleted file mode 100644 index 2b1555417..000000000 --- a/Library/Homebrew/test/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_equal "bar\nbaz", cmd("uses", "--recursive", "foo") - end -end diff --git a/Library/Homebrew/test/test/utils/tty_test.rb b/Library/Homebrew/test/test/utils/tty_test.rb deleted file mode 100644 index 09f092cbd..000000000 --- a/Library/Homebrew/test/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/test/utils_test.rb b/Library/Homebrew/test/test/utils_test.rb deleted file mode 100644 index 146f57b49..000000000 --- a/Library/Homebrew/test/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/"], - die: 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/test/version_test.rb b/Library/Homebrew/test/test/version_test.rb deleted file mode 100644 index e7ffbc4f6..000000000 --- a/Library/Homebrew/test/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/test/versions_test.rb b/Library/Homebrew/test/test/versions_test.rb deleted file mode 100644 index a6e922178..000000000 --- a/Library/Homebrew/test/test/versions_test.rb +++ /dev/null @@ -1,530 +0,0 @@ -require "testing_env" -require "version" - -class VersionTests < Homebrew::TestCase - def test_accepts_objects_responding_to_to_str - value = stub(to_str: "0.1") - assert_equal "0.1", Version.create(value).to_s - end - - def test_raises_for_non_string_objects - assert_raises(TypeError) { Version.create(1.1) } - assert_raises(TypeError) { Version.create(1) } - assert_raises(TypeError) { Version.create(:symbol) } - end - - def test_detected_from_url? - refute Version.create("1.0").detected_from_url? - assert Version::FromURL.new("1.0").detected_from_url? - end -end - -class VersionTokenTests < Homebrew::TestCase - def test_inspect - assert_equal '#', - Version::Token.new("foo").inspect - end - - def test_to_s - assert_equal "foo", Version::Token.new("foo").to_s - end -end - -class NullVersionTests < Homebrew::TestCase - def test_null_version_is_always_smaller - assert_operator Version::NULL, :<, version("1") - end - - def test_null_version_is_never_greater - refute_operator Version::NULL, :>, version("0") - end - - def test_null_version_is_not_equal_to_itself - refute_eql Version::NULL, Version::NULL - end - - def test_null_version_creates_an_empty_string - assert_eql "", Version::NULL.to_s - end - - def test_null_version_produces_nan_as_a_float - # Float::NAN is not equal to itself so compare object IDs - assert_eql Float::NAN.object_id, Version::NULL.to_f.object_id - end -end - -class VersionNullTokenTests < Homebrew::TestCase - def test_inspect - assert_equal "#", Version::NullToken.new.inspect - end - - def test_comparing_null - assert_operator Version::NullToken.new, :==, Version::NullToken.new - end -end - -class VersionComparisonTests < Homebrew::TestCase - def test_comparing_regular_versions - assert_operator version("0.1"), :==, version("0.1.0") - assert_operator version("0.1"), :<, version("0.2") - assert_operator version("1.2.3"), :>, version("1.2.2") - assert_operator version("1.2.4"), :<, version("1.2.4.1") - - assert_operator version("1.2.3"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3"), :>, version("1.2.3beta2") - assert_operator version("1.2.3"), :>, version("1.2.3rc3") - assert_operator version("1.2.3"), :<, version("1.2.3-p34") - end - - def test_head - assert_operator version("HEAD"), :>, version("1.2.3") - assert_operator version("HEAD-abcdef"), :>, version("1.2.3") - assert_operator version("1.2.3"), :<, version("HEAD") - assert_operator version("1.2.3"), :<, version("HEAD-fedcba") - assert_operator version("HEAD-abcdef"), :==, version("HEAD-fedcba") - assert_operator version("HEAD"), :==, version("HEAD-fedcba") - end - - def test_comparing_alpha_versions - assert_operator version("1.2.3alpha"), :<, version("1.2.3") - assert_operator version("1.2.3"), :<, version("1.2.3a") - assert_operator version("1.2.3alpha4"), :==, version("1.2.3a4") - assert_operator version("1.2.3alpha4"), :==, version("1.2.3A4") - assert_operator version("1.2.3alpha4"), :>, version("1.2.3alpha3") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha5") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha10") - - assert_operator version("1.2.3alpha4"), :<, version("1.2.3beta2") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3rc3") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3") - assert_operator version("1.2.3alpha4"), :<, version("1.2.3-p34") - end - - def test_comparing_beta_versions - assert_operator version("1.2.3beta2"), :==, version("1.2.3b2") - assert_operator version("1.2.3beta2"), :==, version("1.2.3B2") - assert_operator version("1.2.3beta2"), :>, version("1.2.3beta1") - assert_operator version("1.2.3beta2"), :<, version("1.2.3beta3") - assert_operator version("1.2.3beta2"), :<, version("1.2.3beta10") - - assert_operator version("1.2.3beta2"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3beta2"), :<, version("1.2.3rc3") - assert_operator version("1.2.3beta2"), :<, version("1.2.3") - assert_operator version("1.2.3beta2"), :<, version("1.2.3-p34") - end - - def test_comparing_rc_versions - assert_operator version("1.2.3rc3"), :==, version("1.2.3RC3") - assert_operator version("1.2.3rc3"), :>, version("1.2.3rc2") - assert_operator version("1.2.3rc3"), :<, version("1.2.3rc4") - assert_operator version("1.2.3rc3"), :<, version("1.2.3rc10") - - assert_operator version("1.2.3rc3"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3rc3"), :>, version("1.2.3beta2") - assert_operator version("1.2.3rc3"), :<, version("1.2.3") - assert_operator version("1.2.3rc3"), :<, version("1.2.3-p34") - end - - def test_comparing_patchlevel_versions - assert_operator version("1.2.3-p34"), :==, version("1.2.3-P34") - assert_operator version("1.2.3-p34"), :>, version("1.2.3-p33") - assert_operator version("1.2.3-p34"), :<, version("1.2.3-p35") - assert_operator version("1.2.3-p34"), :>, version("1.2.3-p9") - - assert_operator version("1.2.3-p34"), :>, version("1.2.3alpha4") - assert_operator version("1.2.3-p34"), :>, version("1.2.3beta2") - assert_operator version("1.2.3-p34"), :>, version("1.2.3rc3") - assert_operator version("1.2.3-p34"), :>, version("1.2.3") - end - - def test_comparing_unevenly_padded_versions - assert_operator version("2.1.0-p194"), :<, version("2.1-p195") - assert_operator version("2.1-p195"), :>, version("2.1.0-p194") - assert_operator version("2.1-p194"), :<, version("2.1.0-p195") - assert_operator version("2.1.0-p195"), :>, version("2.1-p194") - assert_operator version("2-p194"), :<, version("2.1-p195") - end - - def test_comparing_against_nil - assert_operator version("2.1.0-p194"), :>, nil - end - - def test_comparing_against_strings - assert_operator version("2.1.0-p194"), :==, "2.1.0-p194" - assert_operator version("1"), :==, 1 - end - - def test_comparison_returns_nil_for_non_version - v = version("1.0") - assert_nil v <=> Object.new - assert_raises(ArgumentError) { v > Object.new } - end - - def test_erlang_version - versions = %w[R16B R15B03-1 R15B03 R15B02 R15B01 R14B04 R14B03 - R14B02 R14B01 R14B R13B04 R13B03 R13B02-1].reverse - assert_equal versions, versions.sort_by { |v| version(v) } - end - - def test_hash_equality - v1 = version("0.1.0") - v2 = version("0.1.0") - v3 = version("0.1.1") - - assert_eql v1, v2 - refute_eql v1, v3 - assert_equal v1.hash, v2.hash - - h = { v1 => :foo } - assert_equal :foo, h[v2] - end -end - -class VersionParsingTests < Homebrew::TestCase - def test_pathname_version - 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 - assert_version_nil "http://example.com/blah.tar" - assert_version_nil "foo" - end - - def test_create - v = Version.create("1.20") - refute_predicate v, :head? - assert_equal "1.20", v.to_str - end - - def test_version_all_dots - assert_version_detected "1.14", "http://example.com/foo.bar.la.1.14.zip" - end - - def test_version_underscore_separator - assert_version_detected "1.1", "http://example.com/grc_1.1.tar.gz" - end - - def test_boost_version_style - assert_version_detected "1.39.0", "http://example.com/boost_1_39_0.tar.bz2" - end - - def test_erlang_version_style - assert_version_detected "R13B", "http://erlang.org/download/otp_src_R13B.tar.gz" - end - - def test_another_erlang_version_style - assert_version_detected "R15B01", "https://github.com/erlang/otp/tarball/OTP_R15B01" - end - - def test_yet_another_erlang_version_style - assert_version_detected "R15B03-1", "https://github.com/erlang/otp/tarball/OTP_R15B03-1" - end - - def test_p7zip_version_style - assert_version_detected "9.04", - "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2" - end - - def test_new_github_style - assert_version_detected "1.1.4", "https://github.com/sam-github/libnet/tarball/libnet-1.1.4" - end - - def test_codeload_style - assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" - end - - def test_elasticsearch_alpha_style - assert_version_detected "5.0.0-alpha5", "https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha5/elasticsearch-5.0.0-alpha5.tar.gz" - end - - def test_gloox_beta_style - assert_version_detected "1.0-beta7", "http://camaya.net/download/gloox-1.0-beta7.tar.bz2" - end - - def test_sphinx_beta_style - assert_version_detected "1.10-beta", "http://sphinxsearch.com/downloads/sphinx-1.10-beta.tar.gz" - end - - def test_astyle_verson_style - assert_version_detected "1.23", "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz" - end - - def test_version_dos2unix - assert_version_detected "3.1", "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz" - end - - def test_version_internal_dash - assert_version_detected "1.1-2", "http://example.com/foo-arse-1.1-2.tar.gz" - end - - def test_version_single_digit - assert_version_detected "45", "http://example.com/foo_bar.45.tar.gz" - end - - def test_noseparator_single_digit - assert_version_detected "45", "http://example.com/foo_bar45.tar.gz" - end - - def test_version_developer_that_hates_us_format - assert_version_detected "1.2.3", "http://example.com/foo-bar-la.1.2.3.tar.gz" - end - - def test_version_regular - assert_version_detected "1.21", "http://example.com/foo_bar-1.21.tar.gz" - end - - def test_version_sourceforge_download - assert_version_detected "1.21", "http://sourceforge.net/foo_bar-1.21.tar.gz/download" - assert_version_detected "1.21", "http://sf.net/foo_bar-1.21.tar.gz/download" - end - - def test_version_github - assert_version_detected "1.0.5", "http://github.com/lloyd/yajl/tarball/1.0.5" - end - - def test_version_github_with_high_patch_number - assert_version_detected "1.2.34", "http://github.com/lloyd/yajl/tarball/v1.2.34" - end - - def test_yet_another_version - assert_version_detected "0.15.1b", "http://example.com/mad-0.15.1b.tar.gz" - end - - def test_lame_version_style - assert_version_detected "398-2", "http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz" - end - - def test_ruby_version_style - assert_version_detected "1.9.1-p243", "ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz" - end - - def test_omega_version_style - assert_version_detected "0.80.2", "http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz" - end - - def test_rc_style - assert_version_detected "1.2.2rc1", "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2" - end - - def test_dash_rc_style - assert_version_detected "1.8.0-rc1", "http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz" - end - - def test_angband_version_style - assert_version_detected "3.0.9b", "http://rephial.org/downloads/3.0/angband-3.0.9b-src.tar.gz" - end - - def test_stable_suffix - assert_version_detected "1.4.14b", "http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz" - end - - def test_debian_style_1 - assert_version_detected "3.03", "http://ftp.de.debian.org/debian/pool/main/s/sl/sl_3.03.orig.tar.gz" - end - - def test_debian_style_2 - assert_version_detected "1.01b", "http://ftp.de.debian.org/debian/pool/main/m/mmv/mmv_1.01b.orig.tar.gz" - end - - def test_bottle_style - assert_version_detected "4.8.0", "https://homebrew.bintray.com/bottles/qt-4.8.0.lion.bottle.tar.gz" - end - - def test_versioned_bottle_style - assert_version_detected "4.8.1", "https://homebrew.bintray.com/bottles/qt-4.8.1.lion.bottle.1.tar.gz" - end - - def test_erlang_bottle_style - assert_version_detected "R15B", "https://homebrew.bintray.com/bottles/erlang-R15B.lion.bottle.tar.gz" - end - - def test_another_erlang_bottle_style - assert_version_detected "R15B01", "https://homebrew.bintray.com/bottles/erlang-R15B01.mountain_lion.bottle.tar.gz" - end - - def test_yet_another_erlang_bottle_style - assert_version_detected "R15B03-1", "https://homebrew.bintray.com/bottles/erlang-R15B03-1.mountainlion.bottle.tar.gz" - end - - def test_imagemagick_style - assert_version_detected "6.7.5-7", "http://downloads.sf.net/project/machomebrew/mirror/ImageMagick-6.7.5-7.tar.bz2" - end - - def test_imagemagick_bottle_style - assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.tar.gz" - end - - def test_imagemagick_versioned_bottle_style - assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.1.tar.gz" - end - - def test_dash_version_dash_style - assert_version_detected "3.4", "http://www.antlr.org/download/antlr-3.4-complete.jar" - end - - def test_jenkins_version_style - assert_version_detected "1.486", "http://mirrors.jenkins-ci.org/war/1.486/jenkins.war" - assert_version_detected "0.10.11", "https://github.com/hechoendrupal/DrupalConsole/releases/download/0.10.11/drupal.phar" - end - - def test_apache_version_style - assert_version_detected "1.2.0-rc2", "http://www.apache.org/dyn/closer.cgi?path=/cassandra/1.2.0/apache-cassandra-1.2.0-rc2-bin.tar.gz" - end - - def test_jpeg_style - assert_version_detected "8d", "http://www.ijg.org/files/jpegsrc.v8d.tar.gz" - end - - def test_version_ghc_style - assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-x86_64-apple-darwin.tar.bz2" - assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-i386-apple-darwin.tar.bz2" - end - - def test_pypy_version - assert_version_detected "1.4.1", "http://pypy.org/download/pypy-1.4.1-osx.tar.bz2" - end - - def test_openssl_version - assert_version_detected "0.9.8s", "http://www.openssl.org/source/openssl-0.9.8s.tar.gz" - end - - def test_xaw3d_version - assert_version_detected "1.5E", "ftp://ftp.visi.com/users/hawkeyd/X/Xaw3d-1.5E.tar.gz" - end - - def test_assimp_version - assert_version_detected "2.0.863", "http://downloads.sourceforge.net/project/assimp/assimp-2.0/assimp--2.0.863-sdk.zip" - end - - def test_cmucl_version - assert_version_detected "20c", "http://common-lisp.net/project/cmucl/downloads/release/20c/cmucl-20c-x86-darwin.tar.bz2" - end - - def test_fann_version - assert_version_detected "2.1.0beta", "http://downloads.sourceforge.net/project/fann/fann/2.1.0beta/fann-2.1.0beta.zip" - end - - def test_grads_version - assert_version_detected "2.0.1", "ftp://iges.org/grads/2.0/grads-2.0.1-bin-darwin9.8-intel.tar.gz" - end - - def test_haxe_version - assert_version_detected "2.08", "http://haxe.org/file/haxe-2.08-osx.tar.gz" - end - - def test_imap_version - assert_version_detected "2007f", "ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz" - end - - def test_suite3270_version - assert_version_detected "3.3.12ga7", "http://downloads.sourceforge.net/project/x3270/x3270/3.3.12ga7/suite3270-3.3.12ga7-src.tgz" - end - - def test_wwwoffle_version - assert_version_detected "2.9h", "http://www.gedanken.demon.co.uk/download-wwwoffle/wwwoffle-2.9h.tgz" - end - - def test_synergy_version - assert_version_detected "1.3.6p2", "http://synergy.googlecode.com/files/synergy-1.3.6p2-MacOSX-Universal.zip" - end - - def test_fontforge_version - assert_version_detected "20120731", "http://downloads.sourceforge.net/project/fontforge/fontforge-source/fontforge_full-20120731-b.tar.bz2" - end - - def test_ezlupdate_version - assert_version_detected "2011.10", "https://github.com/downloads/ezsystems/ezpublish-legacy/ezpublish_community_project-2011.10-with_ezc.tar.bz2" - end - - def test_aespipe_version_style - assert_version_detected "2.4c", - "http://loop-aes.sourceforge.net/aespipe/aespipe-v2.4c.tar.bz2" - end - - def test_win_style - assert_version_detected "0.9.17", - "http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.17-w32.zip" - assert_version_detected "1.29", - "http://ftpmirror.gnu.org/libidn/libidn-1.29-win64.zip" - end - - def test_with_arch - assert_version_detected "4.0.18-1", - "http://ftpmirror.gnu.org/mtools/mtools-4.0.18-1.i686.rpm" - assert_version_detected "5.5.7-5", - "http://ftpmirror.gnu.org/autogen/autogen-5.5.7-5.i386.rpm" - assert_version_detected "2.8", - "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x86.zip" - assert_version_detected "2.8", - "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x64.zip" - assert_version_detected "4.0.18", - "http://ftpmirror.gnu.org/mtools/mtools_4.0.18_i386.deb" - end - - def test_opam_version - assert_version_detected "2.18.3", - "https://opam.ocaml.org/archives/lablgtk.2.18.3+opam.tar.gz" - assert_version_detected "1.9", - "https://opam.ocaml.org/archives/sha.1.9+opam.tar.gz" - assert_version_detected "0.99.2", - "https://opam.ocaml.org/archives/ppx_tools.0.99.2+opam.tar.gz" - assert_version_detected "1.0.2", - "https://opam.ocaml.org/archives/easy-format.1.0.2+opam.tar.gz" - end - - def test_no_extension_version - assert_version_detected "1.8.12", "https://waf.io/waf-1.8.12" - assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" - assert_version_detected "0.9.1234", "https://my.datomic.com/downloads/free/0.9.1234" - assert_version_detected "0.9", "https://my.datomic.com/downloads/free/0.9.1t34" - assert_version_detected "1.2.3", "https://my.datomic.com/downloads/free/1.2.3" - end - - def test_dash_separated_version - assert_version_detected "6-20151227", "ftp://gcc.gnu.org/pub/gcc/snapshots/6-20151227/gcc-6-20151227.tar.bz2" - end - - def test_from_url - assert_version_detected "1.2.3", - "http://github.com/foo/bar.git", tag: "v1.2.3" - end -end - -class HeadVersionTests < Homebrew::TestCase - def test_create_head - v1 = Version.create("HEAD-abcdef") - v2 = Version.create("HEAD") - - assert_predicate v1, :head? - assert_predicate v2, :head? - end - - def test_commit_assigned - v = Version.create("HEAD-abcdef") - assert_equal "abcdef", v.commit - assert_equal "HEAD-abcdef", v.to_str - end - - def test_no_commit - v = Version.create("HEAD") - assert_nil v.commit - assert_equal "HEAD", v.to_str - end - - def test_update_commit - v1 = Version.create("HEAD-abcdef") - v2 = Version.create("HEAD") - - v1.update_commit("ffffff") - assert_equal "ffffff", v1.commit - assert_equal "HEAD-ffffff", v1.to_str - - v2.update_commit("ffffff") - assert_equal "ffffff", v2.commit - assert_equal "HEAD-ffffff", v2.to_str - end -end diff --git a/Library/Homebrew/test/test/x11_requirement_test.rb b/Library/Homebrew/test/test/x11_requirement_test.rb deleted file mode 100644 index b82a59e53..000000000 --- a/Library/Homebrew/test/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 diff --git a/Library/Homebrew/test/test_formula_test.rb b/Library/Homebrew/test/test_formula_test.rb new file mode 100644 index 000000000..5ad2db9e9 --- /dev/null +++ b/Library/Homebrew/test/test_formula_test.rb @@ -0,0 +1,30 @@ +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/uninstall_test.rb b/Library/Homebrew/test/uninstall_test.rb new file mode 100644 index 000000000..70a694353 --- /dev/null +++ b/Library/Homebrew/test/uninstall_test.rb @@ -0,0 +1,66 @@ +require "cmd/uninstall" + +class UninstallTests < Homebrew::TestCase + def setup + @dependency = formula("dependency") { url "f-1" } + @dependent = formula("dependent") do + url "f-1" + depends_on "dependency" + end + + [@dependency, @dependent].each { |f| f.installed_prefix.mkpath } + + tab = Tab.empty + tab.tabfile = @dependent.installed_prefix/Tab::FILENAME + tab.runtime_dependencies = [ + { "full_name" => "dependency", "version" => "1" }, + ] + tab.write + + stub_formula_loader @dependency + stub_formula_loader @dependent + end + + def teardown + Homebrew.failed = false + [@dependency, @dependent].each { |f| f.rack.rmtree } + end + + def handle_unsatisfied_dependents + capture_stderr do + opts = { @dependency.rack => [Keg.new(@dependency.installed_prefix)] } + Homebrew.handle_unsatisfied_dependents(opts) + end + end + + def test_check_for_testball_f2s_when_developer + skip "Flaky test" + assert_match "Warning", handle_unsatisfied_dependents + refute_predicate Homebrew, :failed? + end + + def test_check_for_dependents_when_not_developer + skip "Flaky test" + run_as_not_developer do + assert_match "Error", handle_unsatisfied_dependents + assert_predicate Homebrew, :failed? + end + end + + def test_check_for_dependents_when_ignore_dependencies + ARGV << "--ignore-dependencies" + run_as_not_developer do + 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 new file mode 100644 index 000000000..6d5cefc67 --- /dev/null +++ b/Library/Homebrew/test/unlink_test.rb @@ -0,0 +1,10 @@ +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 new file mode 100644 index 000000000..9d9672199 --- /dev/null +++ b/Library/Homebrew/test/unlinkapps_test.rb @@ -0,0 +1,19 @@ +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 new file mode 100644 index 000000000..bbff6ad1c --- /dev/null +++ b/Library/Homebrew/test/unpack_test.rb @@ -0,0 +1,13 @@ +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 new file mode 100644 index 000000000..6b6cec6ce --- /dev/null +++ b/Library/Homebrew/test/update_report_test.rb @@ -0,0 +1,134 @@ +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 new file mode 100644 index 000000000..f3f5dccc7 --- /dev/null +++ b/Library/Homebrew/test/upgrade_test.rb @@ -0,0 +1,12 @@ +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 new file mode 100644 index 000000000..2b1555417 --- /dev/null +++ b/Library/Homebrew/test/uses_test.rb @@ -0,0 +1,16 @@ +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_equal "bar\nbaz", cmd("uses", "--recursive", "foo") + end +end diff --git a/Library/Homebrew/test/utils/tty_test.rb b/Library/Homebrew/test/utils/tty_test.rb new file mode 100644 index 000000000..09f092cbd --- /dev/null +++ b/Library/Homebrew/test/utils/tty_test.rb @@ -0,0 +1,46 @@ +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_test.rb b/Library/Homebrew/test/utils_test.rb new file mode 100644 index 000000000..146f57b49 --- /dev/null +++ b/Library/Homebrew/test/utils_test.rb @@ -0,0 +1,235 @@ +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/"], + die: 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 new file mode 100644 index 000000000..e7ffbc4f6 --- /dev/null +++ b/Library/Homebrew/test/version_test.rb @@ -0,0 +1,8 @@ +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 new file mode 100644 index 000000000..a6e922178 --- /dev/null +++ b/Library/Homebrew/test/versions_test.rb @@ -0,0 +1,530 @@ +require "testing_env" +require "version" + +class VersionTests < Homebrew::TestCase + def test_accepts_objects_responding_to_to_str + value = stub(to_str: "0.1") + assert_equal "0.1", Version.create(value).to_s + end + + def test_raises_for_non_string_objects + assert_raises(TypeError) { Version.create(1.1) } + assert_raises(TypeError) { Version.create(1) } + assert_raises(TypeError) { Version.create(:symbol) } + end + + def test_detected_from_url? + refute Version.create("1.0").detected_from_url? + assert Version::FromURL.new("1.0").detected_from_url? + end +end + +class VersionTokenTests < Homebrew::TestCase + def test_inspect + assert_equal '#', + Version::Token.new("foo").inspect + end + + def test_to_s + assert_equal "foo", Version::Token.new("foo").to_s + end +end + +class NullVersionTests < Homebrew::TestCase + def test_null_version_is_always_smaller + assert_operator Version::NULL, :<, version("1") + end + + def test_null_version_is_never_greater + refute_operator Version::NULL, :>, version("0") + end + + def test_null_version_is_not_equal_to_itself + refute_eql Version::NULL, Version::NULL + end + + def test_null_version_creates_an_empty_string + assert_eql "", Version::NULL.to_s + end + + def test_null_version_produces_nan_as_a_float + # Float::NAN is not equal to itself so compare object IDs + assert_eql Float::NAN.object_id, Version::NULL.to_f.object_id + end +end + +class VersionNullTokenTests < Homebrew::TestCase + def test_inspect + assert_equal "#", Version::NullToken.new.inspect + end + + def test_comparing_null + assert_operator Version::NullToken.new, :==, Version::NullToken.new + end +end + +class VersionComparisonTests < Homebrew::TestCase + def test_comparing_regular_versions + assert_operator version("0.1"), :==, version("0.1.0") + assert_operator version("0.1"), :<, version("0.2") + assert_operator version("1.2.3"), :>, version("1.2.2") + assert_operator version("1.2.4"), :<, version("1.2.4.1") + + assert_operator version("1.2.3"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3"), :>, version("1.2.3beta2") + assert_operator version("1.2.3"), :>, version("1.2.3rc3") + assert_operator version("1.2.3"), :<, version("1.2.3-p34") + end + + def test_head + assert_operator version("HEAD"), :>, version("1.2.3") + assert_operator version("HEAD-abcdef"), :>, version("1.2.3") + assert_operator version("1.2.3"), :<, version("HEAD") + assert_operator version("1.2.3"), :<, version("HEAD-fedcba") + assert_operator version("HEAD-abcdef"), :==, version("HEAD-fedcba") + assert_operator version("HEAD"), :==, version("HEAD-fedcba") + end + + def test_comparing_alpha_versions + assert_operator version("1.2.3alpha"), :<, version("1.2.3") + assert_operator version("1.2.3"), :<, version("1.2.3a") + assert_operator version("1.2.3alpha4"), :==, version("1.2.3a4") + assert_operator version("1.2.3alpha4"), :==, version("1.2.3A4") + assert_operator version("1.2.3alpha4"), :>, version("1.2.3alpha3") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha5") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3alpha10") + + assert_operator version("1.2.3alpha4"), :<, version("1.2.3beta2") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3rc3") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3") + assert_operator version("1.2.3alpha4"), :<, version("1.2.3-p34") + end + + def test_comparing_beta_versions + assert_operator version("1.2.3beta2"), :==, version("1.2.3b2") + assert_operator version("1.2.3beta2"), :==, version("1.2.3B2") + assert_operator version("1.2.3beta2"), :>, version("1.2.3beta1") + assert_operator version("1.2.3beta2"), :<, version("1.2.3beta3") + assert_operator version("1.2.3beta2"), :<, version("1.2.3beta10") + + assert_operator version("1.2.3beta2"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3beta2"), :<, version("1.2.3rc3") + assert_operator version("1.2.3beta2"), :<, version("1.2.3") + assert_operator version("1.2.3beta2"), :<, version("1.2.3-p34") + end + + def test_comparing_rc_versions + assert_operator version("1.2.3rc3"), :==, version("1.2.3RC3") + assert_operator version("1.2.3rc3"), :>, version("1.2.3rc2") + assert_operator version("1.2.3rc3"), :<, version("1.2.3rc4") + assert_operator version("1.2.3rc3"), :<, version("1.2.3rc10") + + assert_operator version("1.2.3rc3"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3rc3"), :>, version("1.2.3beta2") + assert_operator version("1.2.3rc3"), :<, version("1.2.3") + assert_operator version("1.2.3rc3"), :<, version("1.2.3-p34") + end + + def test_comparing_patchlevel_versions + assert_operator version("1.2.3-p34"), :==, version("1.2.3-P34") + assert_operator version("1.2.3-p34"), :>, version("1.2.3-p33") + assert_operator version("1.2.3-p34"), :<, version("1.2.3-p35") + assert_operator version("1.2.3-p34"), :>, version("1.2.3-p9") + + assert_operator version("1.2.3-p34"), :>, version("1.2.3alpha4") + assert_operator version("1.2.3-p34"), :>, version("1.2.3beta2") + assert_operator version("1.2.3-p34"), :>, version("1.2.3rc3") + assert_operator version("1.2.3-p34"), :>, version("1.2.3") + end + + def test_comparing_unevenly_padded_versions + assert_operator version("2.1.0-p194"), :<, version("2.1-p195") + assert_operator version("2.1-p195"), :>, version("2.1.0-p194") + assert_operator version("2.1-p194"), :<, version("2.1.0-p195") + assert_operator version("2.1.0-p195"), :>, version("2.1-p194") + assert_operator version("2-p194"), :<, version("2.1-p195") + end + + def test_comparing_against_nil + assert_operator version("2.1.0-p194"), :>, nil + end + + def test_comparing_against_strings + assert_operator version("2.1.0-p194"), :==, "2.1.0-p194" + assert_operator version("1"), :==, 1 + end + + def test_comparison_returns_nil_for_non_version + v = version("1.0") + assert_nil v <=> Object.new + assert_raises(ArgumentError) { v > Object.new } + end + + def test_erlang_version + versions = %w[R16B R15B03-1 R15B03 R15B02 R15B01 R14B04 R14B03 + R14B02 R14B01 R14B R13B04 R13B03 R13B02-1].reverse + assert_equal versions, versions.sort_by { |v| version(v) } + end + + def test_hash_equality + v1 = version("0.1.0") + v2 = version("0.1.0") + v3 = version("0.1.1") + + assert_eql v1, v2 + refute_eql v1, v3 + assert_equal v1.hash, v2.hash + + h = { v1 => :foo } + assert_equal :foo, h[v2] + end +end + +class VersionParsingTests < Homebrew::TestCase + def test_pathname_version + 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 + assert_version_nil "http://example.com/blah.tar" + assert_version_nil "foo" + end + + def test_create + v = Version.create("1.20") + refute_predicate v, :head? + assert_equal "1.20", v.to_str + end + + def test_version_all_dots + assert_version_detected "1.14", "http://example.com/foo.bar.la.1.14.zip" + end + + def test_version_underscore_separator + assert_version_detected "1.1", "http://example.com/grc_1.1.tar.gz" + end + + def test_boost_version_style + assert_version_detected "1.39.0", "http://example.com/boost_1_39_0.tar.bz2" + end + + def test_erlang_version_style + assert_version_detected "R13B", "http://erlang.org/download/otp_src_R13B.tar.gz" + end + + def test_another_erlang_version_style + assert_version_detected "R15B01", "https://github.com/erlang/otp/tarball/OTP_R15B01" + end + + def test_yet_another_erlang_version_style + assert_version_detected "R15B03-1", "https://github.com/erlang/otp/tarball/OTP_R15B03-1" + end + + def test_p7zip_version_style + assert_version_detected "9.04", + "http://kent.dl.sourceforge.net/sourceforge/p7zip/p7zip_9.04_src_all.tar.bz2" + end + + def test_new_github_style + assert_version_detected "1.1.4", "https://github.com/sam-github/libnet/tarball/libnet-1.1.4" + end + + def test_codeload_style + assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" + end + + def test_elasticsearch_alpha_style + assert_version_detected "5.0.0-alpha5", "https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha5/elasticsearch-5.0.0-alpha5.tar.gz" + end + + def test_gloox_beta_style + assert_version_detected "1.0-beta7", "http://camaya.net/download/gloox-1.0-beta7.tar.bz2" + end + + def test_sphinx_beta_style + assert_version_detected "1.10-beta", "http://sphinxsearch.com/downloads/sphinx-1.10-beta.tar.gz" + end + + def test_astyle_verson_style + assert_version_detected "1.23", "http://kent.dl.sourceforge.net/sourceforge/astyle/astyle_1.23_macosx.tar.gz" + end + + def test_version_dos2unix + assert_version_detected "3.1", "http://www.sfr-fresh.com/linux/misc/dos2unix-3.1.tar.gz" + end + + def test_version_internal_dash + assert_version_detected "1.1-2", "http://example.com/foo-arse-1.1-2.tar.gz" + end + + def test_version_single_digit + assert_version_detected "45", "http://example.com/foo_bar.45.tar.gz" + end + + def test_noseparator_single_digit + assert_version_detected "45", "http://example.com/foo_bar45.tar.gz" + end + + def test_version_developer_that_hates_us_format + assert_version_detected "1.2.3", "http://example.com/foo-bar-la.1.2.3.tar.gz" + end + + def test_version_regular + assert_version_detected "1.21", "http://example.com/foo_bar-1.21.tar.gz" + end + + def test_version_sourceforge_download + assert_version_detected "1.21", "http://sourceforge.net/foo_bar-1.21.tar.gz/download" + assert_version_detected "1.21", "http://sf.net/foo_bar-1.21.tar.gz/download" + end + + def test_version_github + assert_version_detected "1.0.5", "http://github.com/lloyd/yajl/tarball/1.0.5" + end + + def test_version_github_with_high_patch_number + assert_version_detected "1.2.34", "http://github.com/lloyd/yajl/tarball/v1.2.34" + end + + def test_yet_another_version + assert_version_detected "0.15.1b", "http://example.com/mad-0.15.1b.tar.gz" + end + + def test_lame_version_style + assert_version_detected "398-2", "http://kent.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz" + end + + def test_ruby_version_style + assert_version_detected "1.9.1-p243", "ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p243.tar.gz" + end + + def test_omega_version_style + assert_version_detected "0.80.2", "http://www.alcyone.com/binaries/omega/omega-0.80.2-src.tar.gz" + end + + def test_rc_style + assert_version_detected "1.2.2rc1", "http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.2rc1.tar.bz2" + end + + def test_dash_rc_style + assert_version_detected "1.8.0-rc1", "http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz" + end + + def test_angband_version_style + assert_version_detected "3.0.9b", "http://rephial.org/downloads/3.0/angband-3.0.9b-src.tar.gz" + end + + def test_stable_suffix + assert_version_detected "1.4.14b", "http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz" + end + + def test_debian_style_1 + assert_version_detected "3.03", "http://ftp.de.debian.org/debian/pool/main/s/sl/sl_3.03.orig.tar.gz" + end + + def test_debian_style_2 + assert_version_detected "1.01b", "http://ftp.de.debian.org/debian/pool/main/m/mmv/mmv_1.01b.orig.tar.gz" + end + + def test_bottle_style + assert_version_detected "4.8.0", "https://homebrew.bintray.com/bottles/qt-4.8.0.lion.bottle.tar.gz" + end + + def test_versioned_bottle_style + assert_version_detected "4.8.1", "https://homebrew.bintray.com/bottles/qt-4.8.1.lion.bottle.1.tar.gz" + end + + def test_erlang_bottle_style + assert_version_detected "R15B", "https://homebrew.bintray.com/bottles/erlang-R15B.lion.bottle.tar.gz" + end + + def test_another_erlang_bottle_style + assert_version_detected "R15B01", "https://homebrew.bintray.com/bottles/erlang-R15B01.mountain_lion.bottle.tar.gz" + end + + def test_yet_another_erlang_bottle_style + assert_version_detected "R15B03-1", "https://homebrew.bintray.com/bottles/erlang-R15B03-1.mountainlion.bottle.tar.gz" + end + + def test_imagemagick_style + assert_version_detected "6.7.5-7", "http://downloads.sf.net/project/machomebrew/mirror/ImageMagick-6.7.5-7.tar.bz2" + end + + def test_imagemagick_bottle_style + assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.tar.gz" + end + + def test_imagemagick_versioned_bottle_style + assert_version_detected "6.7.5-7", "https://homebrew.bintray.com/bottles/imagemagick-6.7.5-7.lion.bottle.1.tar.gz" + end + + def test_dash_version_dash_style + assert_version_detected "3.4", "http://www.antlr.org/download/antlr-3.4-complete.jar" + end + + def test_jenkins_version_style + assert_version_detected "1.486", "http://mirrors.jenkins-ci.org/war/1.486/jenkins.war" + assert_version_detected "0.10.11", "https://github.com/hechoendrupal/DrupalConsole/releases/download/0.10.11/drupal.phar" + end + + def test_apache_version_style + assert_version_detected "1.2.0-rc2", "http://www.apache.org/dyn/closer.cgi?path=/cassandra/1.2.0/apache-cassandra-1.2.0-rc2-bin.tar.gz" + end + + def test_jpeg_style + assert_version_detected "8d", "http://www.ijg.org/files/jpegsrc.v8d.tar.gz" + end + + def test_version_ghc_style + assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-x86_64-apple-darwin.tar.bz2" + assert_version_detected "7.0.4", "http://www.haskell.org/ghc/dist/7.0.4/ghc-7.0.4-i386-apple-darwin.tar.bz2" + end + + def test_pypy_version + assert_version_detected "1.4.1", "http://pypy.org/download/pypy-1.4.1-osx.tar.bz2" + end + + def test_openssl_version + assert_version_detected "0.9.8s", "http://www.openssl.org/source/openssl-0.9.8s.tar.gz" + end + + def test_xaw3d_version + assert_version_detected "1.5E", "ftp://ftp.visi.com/users/hawkeyd/X/Xaw3d-1.5E.tar.gz" + end + + def test_assimp_version + assert_version_detected "2.0.863", "http://downloads.sourceforge.net/project/assimp/assimp-2.0/assimp--2.0.863-sdk.zip" + end + + def test_cmucl_version + assert_version_detected "20c", "http://common-lisp.net/project/cmucl/downloads/release/20c/cmucl-20c-x86-darwin.tar.bz2" + end + + def test_fann_version + assert_version_detected "2.1.0beta", "http://downloads.sourceforge.net/project/fann/fann/2.1.0beta/fann-2.1.0beta.zip" + end + + def test_grads_version + assert_version_detected "2.0.1", "ftp://iges.org/grads/2.0/grads-2.0.1-bin-darwin9.8-intel.tar.gz" + end + + def test_haxe_version + assert_version_detected "2.08", "http://haxe.org/file/haxe-2.08-osx.tar.gz" + end + + def test_imap_version + assert_version_detected "2007f", "ftp://ftp.cac.washington.edu/imap/imap-2007f.tar.gz" + end + + def test_suite3270_version + assert_version_detected "3.3.12ga7", "http://downloads.sourceforge.net/project/x3270/x3270/3.3.12ga7/suite3270-3.3.12ga7-src.tgz" + end + + def test_wwwoffle_version + assert_version_detected "2.9h", "http://www.gedanken.demon.co.uk/download-wwwoffle/wwwoffle-2.9h.tgz" + end + + def test_synergy_version + assert_version_detected "1.3.6p2", "http://synergy.googlecode.com/files/synergy-1.3.6p2-MacOSX-Universal.zip" + end + + def test_fontforge_version + assert_version_detected "20120731", "http://downloads.sourceforge.net/project/fontforge/fontforge-source/fontforge_full-20120731-b.tar.bz2" + end + + def test_ezlupdate_version + assert_version_detected "2011.10", "https://github.com/downloads/ezsystems/ezpublish-legacy/ezpublish_community_project-2011.10-with_ezc.tar.bz2" + end + + def test_aespipe_version_style + assert_version_detected "2.4c", + "http://loop-aes.sourceforge.net/aespipe/aespipe-v2.4c.tar.bz2" + end + + def test_win_style + assert_version_detected "0.9.17", + "http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.17-w32.zip" + assert_version_detected "1.29", + "http://ftpmirror.gnu.org/libidn/libidn-1.29-win64.zip" + end + + def test_with_arch + assert_version_detected "4.0.18-1", + "http://ftpmirror.gnu.org/mtools/mtools-4.0.18-1.i686.rpm" + assert_version_detected "5.5.7-5", + "http://ftpmirror.gnu.org/autogen/autogen-5.5.7-5.i386.rpm" + assert_version_detected "2.8", + "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x86.zip" + assert_version_detected "2.8", + "http://ftpmirror.gnu.org/libtasn1/libtasn1-2.8-x64.zip" + assert_version_detected "4.0.18", + "http://ftpmirror.gnu.org/mtools/mtools_4.0.18_i386.deb" + end + + def test_opam_version + assert_version_detected "2.18.3", + "https://opam.ocaml.org/archives/lablgtk.2.18.3+opam.tar.gz" + assert_version_detected "1.9", + "https://opam.ocaml.org/archives/sha.1.9+opam.tar.gz" + assert_version_detected "0.99.2", + "https://opam.ocaml.org/archives/ppx_tools.0.99.2+opam.tar.gz" + assert_version_detected "1.0.2", + "https://opam.ocaml.org/archives/easy-format.1.0.2+opam.tar.gz" + end + + def test_no_extension_version + assert_version_detected "1.8.12", "https://waf.io/waf-1.8.12" + assert_version_detected "0.7.1", "https://codeload.github.com/gsamokovarov/jump/tar.gz/v0.7.1" + assert_version_detected "0.9.1234", "https://my.datomic.com/downloads/free/0.9.1234" + assert_version_detected "0.9", "https://my.datomic.com/downloads/free/0.9.1t34" + assert_version_detected "1.2.3", "https://my.datomic.com/downloads/free/1.2.3" + end + + def test_dash_separated_version + assert_version_detected "6-20151227", "ftp://gcc.gnu.org/pub/gcc/snapshots/6-20151227/gcc-6-20151227.tar.bz2" + end + + def test_from_url + assert_version_detected "1.2.3", + "http://github.com/foo/bar.git", tag: "v1.2.3" + end +end + +class HeadVersionTests < Homebrew::TestCase + def test_create_head + v1 = Version.create("HEAD-abcdef") + v2 = Version.create("HEAD") + + assert_predicate v1, :head? + assert_predicate v2, :head? + end + + def test_commit_assigned + v = Version.create("HEAD-abcdef") + assert_equal "abcdef", v.commit + assert_equal "HEAD-abcdef", v.to_str + end + + def test_no_commit + v = Version.create("HEAD") + assert_nil v.commit + assert_equal "HEAD", v.to_str + end + + def test_update_commit + v1 = Version.create("HEAD-abcdef") + v2 = Version.create("HEAD") + + v1.update_commit("ffffff") + assert_equal "ffffff", v1.commit + assert_equal "HEAD-ffffff", v1.to_str + + v2.update_commit("ffffff") + assert_equal "ffffff", v2.commit + assert_equal "HEAD-ffffff", v2.to_str + end +end diff --git a/Library/Homebrew/test/x11_requirement_test.rb b/Library/Homebrew/test/x11_requirement_test.rb new file mode 100644 index 000000000..b82a59e53 --- /dev/null +++ b/Library/Homebrew/test/x11_requirement_test.rb @@ -0,0 +1,31 @@ +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 -- cgit v1.2.3