-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathvcs_test.rb
90 lines (83 loc) · 2.63 KB
/
vcs_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
############################################################################
# Copyright 2009-2019 Benjamin Kellermann #
# #
# This file is part of Dudle. #
# #
# Dudle is free software: you can redistribute it and/or modify it under #
# the terms of the GNU Affero General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# Dudle is distributed in the hope that it will be useful, but WITHOUT ANY #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
# License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with dudle. If not, see <http://www.gnu.org/licenses/>. #
############################################################################
if __FILE__ == $0
require 'test/unit'
require 'pp'
unless ARGV[0]
puts "Usage: ruby #{$0} git"
exit
end
require "vcs_#{ARGV[0]}"
require 'benchmark'
class VCS_test < Test::Unit::TestCase
def setup
@data = %w[foo bar baz spam ham egg]
@history = %w[aaa bbb ccc ddd eee fff]
@repo = "/tmp/vcs_test_#{rand(10_000)}"
Dir.mkdir(@repo)
Dir.chdir(@repo)
VCS.init
File.open('data.txt', 'w').close
VCS.add('data.txt')
@data.each_index { |i|
File.open('data.txt', 'w') { |f| f << @data[i] }
VCS.commit(@history[i])
}
@b = 0
@t = ''
end
def teardown
puts @repo
# Dir.chdir("/")
# %x{rm -rf #{@repo}}
puts "#{@t}: #{@b}"
end
def test_cat
@data.each_with_index { |item, revnominusone|
result = ''
@b += Benchmark.measure {
result = VCS.cat(revnominusone + 1, 'data.txt')
}.total
assert_equal(item, result, "revno: #{revnominusone + 1}")
}
@t = 'cat'
end
def test_revno
r = -1
@b += Benchmark.measure {
r = VCS.revno
}.total
assert_equal(@data.size, r)
@t = 'revno'
end
def test_history
l = nil
@b += Benchmark.measure {
l = VCS.history
}.total
pp l
exit
assert_equal(@data.size, l.size)
@history.each_with_index { |h, revminusone|
assert_equal(h, l[revminusone + 1].comment)
}
@t = 'history'
end
end
end