1# 2# diffoscope: in-depth comparison of files, archives, and directories 3# 4# Copyright © 2017, 2019-2020 Chris Lamb <lamby@debian.org> 5# 6# diffoscope is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10# 11# diffoscope is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with diffoscope. If not, see <https://www.gnu.org/licenses/>. 18 19import os 20import pytest 21 22from diffoscope.main import main 23 24 25def run(capsys, *args): 26 with pytest.raises(SystemExit) as exc: 27 main( 28 args 29 + tuple( 30 os.path.join(os.path.dirname(__file__), "data", x) 31 for x in ("test1.tar", "test2.tar") 32 ) 33 ) 34 35 out, err = capsys.readouterr() 36 37 assert err == "" 38 39 return exc.value.code, out 40 41 42def test_none(capsys): 43 ret, out = run(capsys) 44 45 assert ret == 1 46 assert "── dir/text" in out 47 assert "── dir/link" in out 48 49 50def test_all(capsys): 51 ret, out = run(capsys, "--exclude=*") 52 53 assert ret == 0 54 assert out == "" 55 56 57def test_specific(capsys): 58 ret, out = run(capsys, "--exclude=dir/text") 59 60 assert ret == 1 61 assert "── dir/text" not in out 62 assert "── dir/link" in out 63 64 65def test_specific_case(capsys): 66 ret, out = run(capsys, "--exclude=dir/TEXT") 67 68 assert ret == 1 69 assert "── dir/text" in out 70 assert "── dir/link" in out 71 72 73def test_multiple(capsys): 74 ret, out = run(capsys, "--exclude=dir/text", "--exclude=dir/link") 75 76 assert ret == 1 77 assert "── dir/text" not in out 78 assert "── dir/link" not in out 79 80 81def test_nomatch(capsys): 82 ret, out = run(capsys, "--exclude=nomatch") 83 84 assert ret == 1 85 assert "── dir/text" in out 86 assert "── dir/link" in out 87 88 89def test_wildcard(capsys): 90 ret, out = run(capsys, "--exclude=*link") 91 92 assert ret == 1 93 assert "── dir/text" in out 94 assert "── dir/link" not in out 95