예제 #1
0
    def testStack(self):
        interp = interpreter.defaultInterpreter()
        env = interpreter.defaultEnvironment()

        errors = []

        def handle(interp):
            framenames = [x.name for x in interp.frames]
            errors.append(O.simplify(framenames))
            raise

        #First, let's muck up the stack:
        E.set(env, '*exc-handler*', None)
        self.assertRaises(ZeroDivisionError,
                          interp.evalString,
                          '''
                          (defun (ham) (eggs))
                          (defun (eggs) (/ 1 0))
                          (ham)
                          ''',
                          env)

        # Now, let's see if it was cleaned properly (and that our
        # handler can work):
        E.set(env, '*exc-handler*', handle)

        self.assertRaises(ZeroDivisionError,
                          interp.evalString,
                          '''
                          (defun (foo) (bar))
                          (defun (bar) (/ 1 0))
                          (foo)
                          ''',
                          env)
        self.assertEquals(errors, [['foo', 'bar']])
예제 #2
0
 def testExcHandler(self):
     env = interpreter.defaultEnvironment()
     es('(defun (my-exc-handler exc message frames) (l:append exc))', env)
     es('(def l [])', env)
     es('(set *exc-handler* my-exc-handler)', env)
     es('(/ 1 0)', env)
     self.assertEquals(es('l', env), ["ZeroDivisionError"])
예제 #3
0
    def testMaxInstructions(self):
        env = interpreter.defaultEnvironment()

        es('(+ 1 2)', env, maxInstructions=4)

        E.set(env, '*exc-handler*', None)
        self.assertRaises(interpreter.TooManyInstructions,
                          es, '(+ 1 2 3)', env, maxInstructions=4)