+ black.write_cache({}, [], black.DEFAULT_LINE_LENGTH)
+
+ def test_check_diff_use_together(self) -> None:
+ with cache_dir():
+ # Files which will be reformatted.
+ src1 = (THIS_DIR / "string_quotes.py").resolve()
+ result = CliRunner().invoke(black.main, [str(src1), "--diff", "--check"])
+ self.assertEqual(result.exit_code, 1)
+
+ # Files which will not be reformatted.
+ src2 = (THIS_DIR / "composition.py").resolve()
+ result = CliRunner().invoke(black.main, [str(src2), "--diff", "--check"])
+ self.assertEqual(result.exit_code, 0)
+
+ # Multi file command.
+ result = CliRunner().invoke(
+ black.main, [str(src1), str(src2), "--diff", "--check"]
+ )
+ 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_broken_symlink(self) -> None:
+ with cache_dir() as workspace:
+ symlink = workspace / "broken_link.py"
+ symlink.symlink_to("nonexistent.py")
+ result = CliRunner().invoke(black.main, [str(workspace.resolve())])
+ self.assertEqual(result.exit_code, 0)
+
+ def test_read_cache_line_lengths(self) -> None:
+ with cache_dir() as workspace:
+ path = (workspace / "file.py").resolve()
+ path.touch()
+ black.write_cache({}, [path], 1)
+ one = black.read_cache(1)
+ self.assertIn(path, one)
+ two = black.read_cache(2)
+ self.assertNotIn(path, two)