2012-03-29 20 views
3

我試圖讓googletest運行在我的C++項目上,其中一部分涉及到使用EXPECT_THROW(statement, expected_exception);。我在選擇「Apple LLVM Compiler 3.0」時使用了XCode。所有這些都在Snow Leopard 10.6.8,XCode 4.2上。自己在xcode llvm中捕獲所有其他捕獲(...)

我無法用明確的虛擬情況EXPECT_THROW(throw std::runtime_error(), std::runtime_error);

即使擴展宏(1114 GTEST_TEST_THROW_從GTEST /內部/ GTEST-internal.h)後獲得這些測試通過,

bool gtest_caught_expected = false; 
    try { 
     // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); 
     throw std::runtime_error("sigh"); 
    } 
    // catch (expected_exception const&) { 
    catch (std::runtime_error const& e){ 
     std::cout << "const ref caught" << std::endl; 
     gtest_caught_expected = true; 
    } 
    // added by me to check it wasn't a const& issue 
    catch (std::runtime_error e){ 
     std::cout << "type caught" << std::endl; 
     gtest_caught_expected = true; 
    } 
    catch (...) { 
     //gtest_msg.value = 
     // "Expected: " #statement " throws an exception of type " 
     //#expected_exception ".\n Actual: it throws a different type."; 
     //goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); 
     std::cout << "unknown caught" << std::endl;   
    } 

則設置在gdb一個破發點與catch catch和步進通過,我可以看到catch(runtime_errors)被跳過,並且正在執行的catch(...)。如果我註釋掉catch(...)塊,則會執行正確的catch(std::runtime_error const& e)語句。

將我的編譯器設置爲「LLVM GCC 4.2」可以解決這個問題,但我想定位到clang ++。

我的單獨的EXPECT_THROW測試用例在命令行上用clang ++手工編譯時工作,所以我認爲它必須是一些深奧的xcode或llvm設置?或者,也許一些LLVM是如何將我的runtime_error變成其他類型的?我嘗試了一個catch throw,但可以在這種情況下獲取任何類型的信息。

以前有沒有經歷過這個或有什麼想法?

編輯:

所以我也與libprofile_rt.dylib連接,與編譯器標誌-fprofile-arcs -fprofile-coverage一起。刪除編譯器標誌-fprofile-arcs刪除了該問題。 Annyoing,因爲它打破了我的報道報道。

(與librpofile_rt.a鏈接有同樣的問題)

當然我不希望看到這一點,因爲LLVM據說使用googletest他們的測試案例的唯一一個?

不確定是否應該將此作爲答案發布,或者如果有人知道更多可能會出現並提供真正的解決方案。

+0

不是答案,但你通常應該通過非const引用捕獲,而不是通過const引用或值。 – Potatoswatter 2012-03-29 07:07:43

+0

你可能想嘗試更新版本的clang;從Apple LLVM編譯器3.0開始,對異常處理進行了一些重大修復。 – servn 2012-04-01 22:10:23

+0

是的,它很容易走下自建路徑,但不適合與團隊整合,除非每個人都做好準備...... – Soup 2012-04-05 10:18:11

回答

0

等了一會兒,看起來好像沒有一個已知的解決方法,所以我會發布我的答案如上。它可能會在Xcode 4.3中修復。

所以我還連接了libprofile_rt.dylib以及編譯器標誌-fprofile-arcs -fprofile-coverage。刪除編譯器標誌-fprofile-arcs移除了問題。 Annyoing,因爲它打破了我的報道報道。

(與librpofile_rt.a鏈接有同樣的問題)

當然我不希望看到這一點,因爲LLVM據說使用googletest他們的測試案例的唯一一個?