@@ -7,32 +7,49 @@ class TestLogger < Test::Unit::TestCase
77 def setup
88 set_file_paths
99 end
10-
10+
11+ def missing_log_entry
12+ 'Did not find expected log entry.'
13+ end
14+
15+ def unexpected_log_entry
16+ 'Unexpected log entry found'
17+ end
18+
1119 def test_logger
1220 log = Tempfile . new ( 'logfile' )
1321 log . close
14-
22+
1523 logger = Logger . new ( log . path )
1624 logger . level = Logger ::DEBUG
17-
25+
1826 @git = Git . open ( @wdir , :log => logger )
1927 @git . branches . size
20-
28+
2129 logc = File . read ( log . path )
22- assert ( /INFO -- : git ['"]--git-dir=[^'"]+['"] ['"]--work-tree=[^'"]+['"] ['"]-c['"] ['"]color.ui=false['"] branch ['"]-a['"]/ . match ( logc ) )
23- assert ( /DEBUG -- : cherry\n diff_over_patches\n \* git_grep/m . match ( logc ) )
2430
31+ expected_log_entry = /INFO -- : git (?<global_options>.*?) branch ['"]-a['"]/
32+ assert_match ( expected_log_entry , logc , missing_log_entry )
33+
34+ expected_log_entry = /DEBUG -- : cherry/
35+ assert_match ( expected_log_entry , logc , missing_log_entry )
36+ end
37+
38+ def test_logging_at_info_level_should_not_show_debug_messages
2539 log = Tempfile . new ( 'logfile' )
2640 log . close
2741 logger = Logger . new ( log . path )
2842 logger . level = Logger ::INFO
29-
43+
3044 @git = Git . open ( @wdir , :log => logger )
3145 @git . branches . size
32-
46+
3347 logc = File . read ( log . path )
34- assert ( /INFO -- : git ['"]--git-dir=[^'"]+['"] ['"]--work-tree=[^'"]+['"] ['"]-c['"] ['"]color.ui=false['"] branch ['"]-a['"]/ . match ( logc ) )
35- assert ( !/DEBUG -- : cherry\n diff_over_patches\n \* git_grep/m . match ( logc ) )
48+
49+ expected_log_entry = /INFO -- : git (?<global_options>.*?) branch ['"]-a['"]/
50+ assert_match ( expected_log_entry , logc , missing_log_entry )
51+
52+ expected_log_entry = /DEBUG -- : cherry/
53+ assert_not_match ( expected_log_entry , logc , unexpected_log_entry )
3654 end
37-
3855end
0 commit comments