Răsfoiți Sursa

Print content of description backup on exit

Change-Id: I9607035c8ee5e5f4423b7526c67f384cfebb2f1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2079708
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Josip Sokcevic 5 ani în urmă
părinte
comite
953278adbf
2 a modificat fișierele cu 26 adăugiri și 0 ștergeri
  1. 4 0
      git_cl.py
  2. 22 0
      tests/git_cl_test.py

+ 4 - 0
git_cl.py

@@ -133,6 +133,10 @@ _IS_BEING_TESTED = False
 def DieWithError(message, change_desc=None):
   if change_desc:
     SaveDescriptionBackup(change_desc)
+    print('\n ** Content of CL description **\n' +
+          '='*72 +  '\n' +
+          change_desc.description + '\n' +
+          '='*72 + '\n')
 
   print(message, file=sys.stderr)
   sys.exit(1)

+ 22 - 0
tests/git_cl_test.py

@@ -179,6 +179,28 @@ class SystemExitMock(Exception):
 
 
 class TestGitClBasic(unittest.TestCase):
+  def setUp(self):
+    mock.patch('sys.exit', side_effect=SystemExitMock).start()
+    mock.patch('sys.stdout', StringIO()).start()
+    mock.patch('sys.stderr', StringIO()).start()
+    self.addCleanup(mock.patch.stopall)
+
+  def test_die_with_error(self):
+    with self.assertRaises(SystemExitMock):
+      git_cl.DieWithError('foo', git_cl.ChangeDescription('lorem ipsum'))
+    self.assertEqual(sys.stderr.getvalue(), 'foo\n')
+    self.assertTrue('saving CL description' in sys.stdout.getvalue())
+    self.assertTrue('Content of CL description' in sys.stdout.getvalue())
+    self.assertTrue('lorem ipsum' in sys.stdout.getvalue())
+    sys.exit.assert_called_once_with(1)
+
+  def test_die_with_error_no_desc(self):
+    with self.assertRaises(SystemExitMock):
+      git_cl.DieWithError('foo')
+    self.assertEqual(sys.stderr.getvalue(), 'foo\n')
+    self.assertEqual(sys.stdout.getvalue(), '')
+    sys.exit.assert_called_once_with(1)
+
   def test_fetch_description(self):
     cl = git_cl.Changelist(issue=1, codereview_host='host')
     cl.description = 'x'