From 52a583ce6d3aba54c85c8f64d4b1565526e9f938 Mon Sep 17 00:00:00 2001
From: David-Sarah Hopwood <david-sarah@jacaranda.org>
Date: Thu, 3 Jan 2013 03:19:52 +0000
Subject: [PATCH] Add test for anti-Ubuntu-crash-reporter exception-catching
 code. fixes #1746

Signed-off-by: David-Sarah Hopwood <david-sarah@jacaranda.org>
---
 src/allmydata/test/test_cli.py | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py
index b6a592e9..ccf5fddc 100644
--- a/src/allmydata/test/test_cli.py
+++ b/src/allmydata/test/test_cli.py
@@ -2,10 +2,10 @@
 import os.path
 from twisted.trial import unittest
 from cStringIO import StringIO
-import urllib, re
+import urllib, re, sys
 import simplejson
 
-from mock import patch
+from mock import patch, Mock, call
 
 from allmydata.util import fileutil, hashutil, base32, keyutil
 from allmydata import uri
@@ -582,6 +582,27 @@ class CLI(CLITestMixin, unittest.TestCase):
         for file in listdir_unicode(unicode(basedir)):
             self.failUnlessIn(normalize(file), filenames)
 
+    def test_exception_catcher(self):
+        self.basedir = "cli/exception_catcher"
+
+        runner_mock = Mock()
+        sys_exit_mock = Mock()
+        stderr = StringIO()
+        self.patch(sys, "argv", ["tahoe"])
+        self.patch(runner, "runner", runner_mock)
+        self.patch(sys, "exit", sys_exit_mock)
+        self.patch(sys, "stderr", stderr)
+        exc = Exception("canary")
+
+        def call_runner(args, install_node_control=True):
+            raise exc
+        runner_mock.side_effect = call_runner
+
+        runner.run()
+        self.failUnlessEqual(runner_mock.call_args_list, [call([], install_node_control=True)])
+        self.failUnlessEqual(sys_exit_mock.call_args_list, [call(1)])
+        self.failUnlessIn(str(exc), stderr.getvalue())
+
 
 class Help(unittest.TestCase):
     def test_get(self):
-- 
2.45.2