[NEW] Adding Bazaar support: Add commits.rb and head.rb adapter modules with unit...
[obnox/ohloh/ohloh_scm.git] / test / unit / bzr_commits_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 module Scm::Adapters
4         class BzrCommitsTest < Scm::Test
5
6                 def test_commit_count
7                         with_bzr_repository('bzr') do |bzr|
8                                 assert_equal 6, bzr.commit_count
9                                 assert_equal 6, bzr.commit_count(0)
10                                 assert_equal 5, bzr.commit_count(1)
11                                 assert_equal 1, bzr.commit_count(5)
12                                 assert_equal 0, bzr.commit_count(6)
13                         end
14                 end
15
16                 def test_commit_tokens
17                         with_bzr_repository('bzr') do |bzr|
18                                 assert_equal ['1', '2', '3', '4', '5', '6'], bzr.commit_tokens
19                                 assert_equal ['2', '3', '4', '5', '6'], bzr.commit_tokens(1)
20                                 assert_equal ['6'], bzr.commit_tokens(5)
21                                 assert_equal [], bzr.commit_tokens(6)
22                         end
23                 end
24
25                 def test_commits
26                         with_bzr_repository('bzr') do |bzr|
27                                 assert_equal ['1', '2', '3', '4', '5', '6'], bzr.commits.collect { |c| c.token }
28                                 assert_equal ['6'], bzr.commits(5).collect { |c| c.token }
29                                 assert_equal [], bzr.commits(6).collect { |c| c.token }
30
31                                 # Check that the diffs are not populated
32                                 assert_equal [], bzr.commits.first.diffs
33                         end
34                 end
35
36                 def test_each_commit
37                         with_bzr_repository('bzr') do |bzr|
38                                 commits = []
39                                 bzr.each_commit do |c|
40                                         assert c.committer_name
41                                         assert c.committer_date.is_a?(Time)
42                                         assert c.message.length > 0
43                                         assert c.diffs.any?
44                                         # Check that the diffs are populated
45                                         c.diffs.each do |d|
46                                                 assert d.action =~ /^[MAD]$/
47                                                 assert d.path.length > 0
48                                         end
49                                         commits << c
50                                 end
51
52                                 # Make sure we cleaned up after ourselves
53                                 assert !FileTest.exist?(bzr.log_filename)
54
55                                 # Verify that we got the commits in forward chronological order
56                                 assert_equal ['1', '2', '3', '4', '5', '6'], commits.collect{ |c| c.token }
57                         end
58                 end
59         end
60 end
61