@@ -7,32 +7,49 @@ class TestLogger < Test::Unit::TestCase
7
7
def setup
8
8
set_file_paths
9
9
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
+
11
19
def test_logger
12
20
log = Tempfile . new ( 'logfile' )
13
21
log . close
14
-
22
+
15
23
logger = Logger . new ( log . path )
16
24
logger . level = Logger ::DEBUG
17
-
25
+
18
26
@git = Git . open ( @wdir , :log => logger )
19
27
@git . branches . size
20
-
28
+
21
29
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 ) )
24
30
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
25
39
log = Tempfile . new ( 'logfile' )
26
40
log . close
27
41
logger = Logger . new ( log . path )
28
42
logger . level = Logger ::INFO
29
-
43
+
30
44
@git = Git . open ( @wdir , :log => logger )
31
45
@git . branches . size
32
-
46
+
33
47
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 )
36
54
end
37
-
38
55
end
0 commit comments