Commits

Brian Curtin committed b35df62

Make a double-init raise RuntimeError. Includes a test.

Comments (0)

Files changed (2)

 
     char *keywords[] = {"dir", "name", "type", NULL};
 
-    if (DbgHelp != NULL) /* Already enabled. */
-        Py_RETURN_NONE;
+    if (DbgHelp != NULL) { /* Already enabled. */
+        PyErr_SetString(PyExc_RuntimeError, "Can only enable once");
+        return NULL;
+    }
 
     DbgHelp = LoadLibrary("DbgHelp.dll");
     if (DbgHelp == NULL)

tests/test_options.py

 class EnableOptions(unittest.TestCase):
     def setUp(self):
         self.dir = tempfile.mkdtemp()
-        print(self.dir)
 
     def tearDown(self):
         return
         # formula, and I guess it still depends on the particular crash.
         self.assertNotEqual(get_size(contents[0]), get_size(contents[1]))
 
+    def test_double_enable(self):
+        # Make sure a double initialization raises RuntimeError
+        # There might be a better way that I'm not aware of, but we can
+        # at least make sure a RuntimeError comes through stderr.
+        proc = subprocess.Popen([sys.executable, "-c",
+                          "import minidumper, tester;"
+                          "minidumper.enable(dir=r'{0}');"
+                          "minidumper.enable(dir=r'{0}');".format(self.dir)],
+                                stderr=subprocess.PIPE)
+        stderr = proc.stderr.read().decode(sys.getfilesystemencoding())
+        self.addCleanup(proc.stderr.close)
+        self.assertIn("RuntimeError", stderr)
+
 
 if __name__ == "__main__":
     unittest.main()