@@ -8,6 +8,9 @@ def some_files(tmpdir):
88 tmpdir .join ('f1' ).write_binary (b'foo\n bar\n ' )
99 tmpdir .join ('f2' ).write_binary (b'[INFO] hi\n ' )
1010 tmpdir .join ('f3' ).write_binary (b"with'quotes\n " )
11+ tmpdir .join ('f4' ).write_binary (b'foo\n pattern\n bar\n ' )
12+ tmpdir .join ('f5' ).write_binary (b'[INFO] hi\n pattern\n bar' )
13+ tmpdir .join ('f6' ).write_binary (b"pattern\n barwith'foo\n " )
1114 with tmpdir .as_cwd ():
1215 yield
1316
@@ -30,6 +33,58 @@ def test_main(cap_out, pattern, expected_retcode, expected_out):
3033 assert out == expected_out
3134
3235
36+ @pytest .mark .usefixtures ('some_files' )
37+ def test_negate_by_line_no_match (cap_out ):
38+ ret = pygrep .main (('pattern\n bar' , 'f4' , 'f5' , 'f6' , '--negate' ))
39+ out = cap_out .get ()
40+ assert ret == 1
41+ assert out == 'f4\n f5\n f6\n '
42+
43+
44+ @pytest .mark .usefixtures ('some_files' )
45+ def test_negate_by_line_two_match (cap_out ):
46+ ret = pygrep .main (('foo' , 'f4' , 'f5' , 'f6' , '--negate' ))
47+ out = cap_out .get ()
48+ assert ret == 1
49+ assert out == 'f5\n '
50+
51+
52+ @pytest .mark .usefixtures ('some_files' )
53+ def test_negate_by_line_all_match (cap_out ):
54+ ret = pygrep .main (('pattern' , 'f4' , 'f5' , 'f6' , '--negate' ))
55+ out = cap_out .get ()
56+ assert ret == 0
57+ assert out == ''
58+
59+
60+ @pytest .mark .usefixtures ('some_files' )
61+ def test_negate_by_file_no_match (cap_out ):
62+ ret = pygrep .main (('baz' , 'f4' , 'f5' , 'f6' , '--negate' , '--multiline' ))
63+ out = cap_out .get ()
64+ assert ret == 1
65+ assert out == 'f4\n f5\n f6\n '
66+
67+
68+ @pytest .mark .usefixtures ('some_files' )
69+ def test_negate_by_file_one_match (cap_out ):
70+ ret = pygrep .main (
71+ ('foo\n pattern' , 'f4' , 'f5' , 'f6' , '--negate' , '--multiline' ),
72+ )
73+ out = cap_out .get ()
74+ assert ret == 1
75+ assert out == 'f5\n f6\n '
76+
77+
78+ @pytest .mark .usefixtures ('some_files' )
79+ def test_negate_by_file_all_match (cap_out ):
80+ ret = pygrep .main (
81+ ('pattern\n bar' , 'f4' , 'f5' , 'f6' , '--negate' , '--multiline' ),
82+ )
83+ out = cap_out .get ()
84+ assert ret == 0
85+ assert out == ''
86+
87+
3388@pytest .mark .usefixtures ('some_files' )
3489def test_ignore_case (cap_out ):
3590 ret = pygrep .main (('--ignore-case' , 'info' , 'f1' , 'f2' , 'f3' ))
0 commit comments