/
test_logger.rb
55 lines (40 loc) · 1.32 KB
/
test_logger.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
#!/usr/bin/env ruby
require 'logger'
require File.dirname(__FILE__) + '/../test_helper'
class TestLogger < Test::Unit::TestCase
def setup
set_file_paths
end
def missing_log_entry
'Did not find expected log entry.'
end
def unexpected_log_entry
'Unexpected log entry found'
end
def test_logger
log = Tempfile.new('logfile')
log.close
logger = Logger.new(log.path)
logger.level = Logger::DEBUG
@git = Git.open(@wdir, :log => logger)
@git.branches.size
logc = File.read(log.path)
expected_log_entry = /INFO -- : git (?<global_options>.*?) branch ['"]-a['"]/
assert_match(expected_log_entry, logc, missing_log_entry)
expected_log_entry = /DEBUG -- : cherry/
assert_match(expected_log_entry, logc, missing_log_entry)
end
def test_logging_at_info_level_should_not_show_debug_messages
log = Tempfile.new('logfile')
log.close
logger = Logger.new(log.path)
logger.level = Logger::INFO
@git = Git.open(@wdir, :log => logger)
@git.branches.size
logc = File.read(log.path)
expected_log_entry = /INFO -- : git (?<global_options>.*?) branch ['"]-a['"]/
assert_match(expected_log_entry, logc, missing_log_entry)
expected_log_entry = /DEBUG -- : cherry/
assert_not_match(expected_log_entry, logc, unexpected_log_entry)
end
end