From 9c507b790fb9cff1c08fab187f6c51fc02df3a88 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Tue, 23 Dec 2014 13:19:14 -0600 Subject: [PATCH] Fix the order of the exception arguments --- opencog/guile/SchemePrimitive.cc | 4 ++-- tests/scm/SCMPrimitiveUTest.cxxtest | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/opencog/guile/SchemePrimitive.cc b/opencog/guile/SchemePrimitive.cc index d2f5bb592b5..5b73d736330 100644 --- a/opencog/guile/SchemePrimitive.cc +++ b/opencog/guile/SchemePrimitive.cc @@ -129,9 +129,9 @@ SCM PrimitiveEnviron::do_call(SCM sfe, SCM arglist) scm_throw( scm_from_locale_symbol("C++-EXCEPTION"), scm_cons( - scm_from_locale_string(msg), + scm_from_locale_string(fe->get_name()), scm_cons( - scm_from_locale_string(fe->get_name()), + scm_from_locale_string(msg), SCM_EOL))); // Hmm. scm_throw never returns. } diff --git a/tests/scm/SCMPrimitiveUTest.cxxtest b/tests/scm/SCMPrimitiveUTest.cxxtest index 13ac6ca84e5..b48c2e86975 100644 --- a/tests/scm/SCMPrimitiveUTest.cxxtest +++ b/tests/scm/SCMPrimitiveUTest.cxxtest @@ -2,7 +2,7 @@ * tests/scm/SCMPrimitiveUTest.cxxtest * * Make sure the scheme primtive extension code works - * Copyright (C) 2009 Linas Vepstas + * Copyright (C) 2009, 2014 Linas Vepstas * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -66,6 +66,7 @@ class SCMPrimitiveUTest : public CxxTest::TestSuite void tearDown(void); void test_H_H(void); + void test_throw(void); }; // Some example class @@ -123,7 +124,7 @@ void SCMPrimitiveUTest::test_H_H(void) // Create the example class, and define a scheme function, // named "bingo", that will call one of its methods - MyExampleClass *mtc = new MyExampleClass(as,42); + MyExampleClass *mtc = new MyExampleClass(as, 42); define_scheme_primitive("bingo", &MyExampleClass::my_func, mtc); // Now, call bingo, with a reasonable argument. Since @@ -151,12 +152,22 @@ void SCMPrimitiveUTest::test_H_H(void) Handle hn = as->addNode(CONCEPT_NODE, "Hello World!"); TSM_ASSERT ("wrong atom entirely ", hn == nnn); - // --------------------------------------------------------------- + delete mtc; + logger().debug("END TEST: %s", __FUNCTION__); +} + +// ============================================================ + +void SCMPrimitiveUTest::test_throw(void) +{ + logger().debug("BEGIN TEST: %s", __FUNCTION__); + // Test the throw of an assertion. This should cause an evaluation // error. (In the shell, stuff would get printed to terminal) + MyExampleClass *mtc = new MyExampleClass(as, 42); define_scheme_primitive("whoops", &MyExampleClass::my_other_func, mtc); std::string trc = eval->eval("(whoops nnn)"); - eval_err = eval->eval_error(); + bool eval_err = eval->eval_error(); TSM_ASSERT ("Failed to observe exception", eval_err); printf("Exception trace was: >>%s<<\n", trc.c_str()); @@ -165,16 +176,16 @@ void SCMPrimitiveUTest::test_H_H(void) // evaluator. std::string out = eval->eval( "(catch #t (lambda () (whoops nnn)) " - " (lambda (key msg name) " + " (lambda (key funcname msg) " " (display \"caught key=\") " " (display key) " " (newline) " + " (display \"caught funcname=\") " + " (display funcname) " + " (newline) " " (display \"caught msg=\") " " (display msg) " " (newline) " - " (display \"caught name=\") " - " (display name) " - " (newline) " " ))"); eval_err = eval->eval_error(); TSM_ASSERT ("Failed to catch exception", not eval_err); @@ -185,6 +196,7 @@ void SCMPrimitiveUTest::test_H_H(void) strlen("caught key=C++-EXCEPTION")); TSM_ASSERT ("Wrong exception message", 0 == msg); + delete mtc; logger().debug("END TEST: %s", __FUNCTION__); }