Boost.Test 吐出垃圾而不是可读的错误消息

发布于 2025-01-03 02:07:18 字数 896 浏览 1 评论 0原文

我正在使用 Boost.Test 但测试失败。这很有趣,但结果却很可怕。这是 Boost.Test 的输出:

$ zwja/Build/Products/Debug/test ;出口; <
运行 2 个测试用例...
/Users/daknok/Desktop/libxxqlite/test/DatabaseTest.cpp:32:“P”中出现错误
                                                                      `??k??k
                                                                             ???k?%??k??k
         我
          p??k???k?": 
*** 在测试套件“主测试套件”中检测到 1 个故障

这是我失败的测试用例:

BOOST_AUTO_TEST_CASE(Querying) {
  BOOST_CHECK_NO_THROW({
    XXQLite::Database db;
    XXQLite::Query query1 = db.createQuery("CREATE TABLE Foo (Id PRIMARY KEY)");
    XXQLite::Query query2
      = db.createQuery("SELECT * FROM Foo WHERE Id=? OR Id=? OR Id=?",
                       1, 2, 3);
  });
}

我真的不知道这里发生了什么。这些奇怪的、不可读的错误消息可能是什么原因造成的? Boost 不喜欢我的代码吗?我的 Boost 安装有问题吗?

I am using Boost.Test and my test fails. That's fun and all, but the results are horrifying. This is the output of Boost.Test:

$ zwja/Build/Products/Debug/test ; exit;                                     <
Running 2 test cases...
/Users/daknok/Desktop/libxxqlite/test/DatabaseTest.cpp:32: error in "P
                                                                      `??k??k
                                                                             ???k?%??k??k
         l
          p??k????k?": 
*** 1 failure detected in test suite "Master Test Suite"

Here is my failing test case:

BOOST_AUTO_TEST_CASE(Querying) {
  BOOST_CHECK_NO_THROW({
    XXQLite::Database db;
    XXQLite::Query query1 = db.createQuery("CREATE TABLE Foo (Id PRIMARY KEY)");
    XXQLite::Query query2
      = db.createQuery("SELECT * FROM Foo WHERE Id=? OR Id=? OR Id=?",
                       1, 2, 3);
  });
}

I really have no idea what's going on here. What could be the cause of these strange, unreadable error messages? Did Boost not like my code? Is there something wrong with my Boost installation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾城月光淡如水﹏ 2025-01-10 02:07:18

根据此处的示例,问号之间的内容是您传递给 BOOST_AUTO_TEST_CASE 的内容:

BOOST_AUTO_TEST_CASE( test )
{
    BOOST_CHECK_NO_THROW( throw my_exception() );
}

输出:

Running 1 test case...
test.cpp(8): error in "test": exception thrown by throw my_exception()

也就是说,对于您来说,它应该打印“查询”。这个名字有什么来头吗?如果改成别的东西还能用吗?

另请尝试查看预处理器输出。如果您使用的是 gcc,请使用 -E 标志。

According to the example here, the thing between the question marks is what you passed to BOOST_AUTO_TEST_CASE:

BOOST_AUTO_TEST_CASE( test )
{
    BOOST_CHECK_NO_THROW( throw my_exception() );
}

Output:

Running 1 test case...
test.cpp(8): error in "test": exception thrown by throw my_exception()

That is, for you it should print "Querying". Anything going on with that name? Does it work if you change it to something else?

Also try looking at your preprocessor output. If you're using gcc, use the -E flag.

苍风燃霜 2025-01-10 02:07:18

看来你有某种内存损坏。进行干净的构建。尝试 valgrind。尝试不同的升压释放。

It appears you have some kind of memory corruption. Do a clean build. Try valgrind. Try different boost release.

盗心人 2025-01-10 02:07:18

首先,您的代码并不能完全帮助您找到哪个调用正在抛出异常或通常会给您带来悲伤。因此,我建议您使用类似“那样”的方法

BOOST_AUTO_TEST_CASE(Querying) {
  XXQLite::Database db;
  XXQLite::Query query1;
  XXQLite::Query query2;
  BOOST_CHECK_NO_THROW(query1 = db.createQuery("CREATE TABLE Foo (Id PRIMARY KEY)");
  BOOST_CHECK_NO_THROW(query2 = db.createQuery("SELECT * FROM Foo WHERE Id=? OR Id=? OR Id=?", 1, 2, 3));
}

,这样您就能更好地找出确切是什么语句导致了问题。它可以是声明之一,例如Database dbQuery query1。它可能是 db.createQuery 调用之一。

Firstly your code doesn't quite help you find which of the calls is throwing an exception or generally giving you grief. So I'd suggest instead something like

BOOST_AUTO_TEST_CASE(Querying) {
  XXQLite::Database db;
  XXQLite::Query query1;
  XXQLite::Query query2;
  BOOST_CHECK_NO_THROW(query1 = db.createQuery("CREATE TABLE Foo (Id PRIMARY KEY)");
  BOOST_CHECK_NO_THROW(query2 = db.createQuery("SELECT * FROM Foo WHERE Id=? OR Id=? OR Id=?", 1, 2, 3));
}

That way you'll have better luck finding out exactly what statement caused problems. It could be one of the declarations e.g. Database db, Query query1. It could be one of the calls db.createQuery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文