From 2d9eaafa97e967c8974a6321dcc442a90192140f Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 7 May 2018 19:12:47 +0200 Subject: [PATCH] Output something when no files are reformatted (#190) Just executing ``black`` without any argument does not print any message to stdout or stderr. It's rather confusing, because the user doesn't know what happened. In ``len(sources) == 0`` case, black now prints ``No paths given. Nothing to do``. Signed-off-by: Christian Heimes --- black.py | 1 + tests/test_black.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/black.py b/black.py index fdefb74..f235afe 100644 --- a/black.py +++ b/black.py @@ -192,6 +192,7 @@ def main( write_back = WriteBack.YES report = Report(check=check, quiet=quiet) if len(sources) == 0: + out("No paths given. Nothing to do 😴") ctx.exit(0) return diff --git a/tests/test_black.py b/tests/test_black.py index 02926d1..5e17faf 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -636,6 +636,12 @@ class BlackTestCase(unittest.TestCase): ) self.assertEqual(result.exit_code, 1) + def test_no_files(self) -> None: + with cache_dir(): + # Without an argument, black exits with error code 0. + result = CliRunner().invoke(black.main, []) + self.assertEqual(result.exit_code, 0) + def test_read_cache_line_lengths(self) -> None: with cache_dir() as workspace: path = (workspace / "file.py").resolve() -- 2.39.5