diff options
| author | Xu Cheng | 2016-03-05 20:03:43 +0800 |
|---|---|---|
| committer | Xu Cheng | 2016-03-06 13:51:06 +0800 |
| commit | 9f96e41b40f52313fbc7832df631827f5e3bcacb (patch) | |
| tree | cdaabac2acce883a57092bf13e85c61e70129b11 /Library/Homebrew/test | |
| parent | a2d0d88bf1915734e1540bef4c9d6c1b403379c7 (diff) | |
| download | brew-9f96e41b40f52313fbc7832df631827f5e3bcacb.tar.bz2 | |
tap: add methods to get git related information
These methods will be used in `brew --version`, `brew config`
and `brew doctor` after core/formula separation.
Closes Homebrew/homebrew#49796.
Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/test_tap.rb | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/Library/Homebrew/test/test_tap.rb b/Library/Homebrew/test/test_tap.rb index 278132bad..6438e0808 100644 --- a/Library/Homebrew/test/test_tap.rb +++ b/Library/Homebrew/test/test_tap.rb @@ -1,6 +1,8 @@ require "testing_env" class TapTest < Homebrew::TestCase + include FileUtils + def setup @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" @path.mkpath @@ -16,7 +18,7 @@ class TapTest < Homebrew::TestCase EOS @alias_file = @path/"Aliases/bar" @alias_file.parent.mkpath - FileUtils.ln_s @formula_file, @alias_file + ln_s @formula_file, @alias_file (@path/"formula_renames.json").write <<-EOS.undent { "oldname": "foo" } EOS @@ -25,14 +27,21 @@ class TapTest < Homebrew::TestCase EOS @cmd_file = @path/"cmd/brew-tap-cmd.rb" @cmd_file.parent.mkpath - FileUtils.touch @cmd_file - FileUtils.chmod 0755, @cmd_file + touch @cmd_file + chmod 0755, @cmd_file @manpage_file = @path/"man/man1/brew-tap-cmd.1" @manpage_file.parent.mkpath - FileUtils.touch @manpage_file + 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" @@ -41,6 +50,8 @@ class TapTest < Homebrew::TestCase system "git", "commit", "-m", "init" end end + ensure + ENV.replace(env) end def teardown @@ -74,7 +85,7 @@ class TapTest < Homebrew::TestCase t = Tap.new("someone", "foo") path = Tap::TAP_DIRECTORY/"someone/homebrew-foo" path.mkpath - FileUtils.cd path do + cd path do shutup { system "git", "init" } system "git", "remote", "add", "origin", "https://github.com/someone/homebrew-foo" @@ -123,6 +134,26 @@ class TapTest < Homebrew::TestCase refute_predicate version_tap, :private? 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 %r{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 ENV["HOMEBREW_GITHUB_API_TOKEN"] assert_predicate @tap, :private? @@ -174,6 +205,8 @@ class TapTest < Homebrew::TestCase end class CoreFormulaRepositoryTest < Homebrew::TestCase + include FileUtils + def setup @repo = CoreFormulaRepository.new end @@ -204,7 +237,7 @@ class CoreFormulaRepositoryTest < Homebrew::TestCase EOS @alias_file = @repo.alias_dir/"bar" @alias_file.parent.mkpath - FileUtils.ln_s @formula_file, @alias_file + ln_s @formula_file, @alias_file assert_equal [@formula_file], @repo.formula_files assert_equal ["foo"], @repo.formula_names |
