我开始学习如何使用GTest来测试一些Cpp和C库:
https://github.com/google/googletest
我正在使用g ++版本
在我的macbook上尝试GTestGet-ChildItem [a-z][a-z]_[0-9][0-9][0-9][0-9] -Directory
安装成功,例如在<?php
class Handler extends ExceptionHandler
{
// ... snipped
public function render($request, Exception $e)
{
if ($e instanceof NotFoundHttpException) {
$closestUri = $this->closestUri($request->path());
if ($closestUri) {
return redirect($closestUri);
}
}
return parent::render($request, $e);
}
protected function closestUri($notFoundUri)
{
$availableRoutePaths = [];
foreach (Route::getRoutes() as $route) {
$availableRoutePaths[] = $route->getPath();
}
$closest = null;
$shortest = -1;
foreach ($availableRoutePaths as $availableRoutePath) {
$lev = levenshtein($notFoundUri, $availableRoutePaths);
if ($lev == 0) {
$closest = $word;
$shortest = 0;
break;
}
if ($lev <= $shortest || $shortest < 0) {
$closest = $word;
$shortest = $lev;
}
}
return $closest;
}
// ... snipped
}
之后:
$ g++ --version
g++ (Homebrew GCC 4.9.4_1) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
几个月前我一直在关注本教程,https://www.youtube.com/watch?v=nbFXI9SDfbk
以下是最小的工作示例:
sudo make install
以下是建议编译的方式:
...
-- Installing: /usr/local/lib/libgtest.a
-- Installing: /usr/local/lib/libgtest_main.a
...
上面有库,这个版本的#include <iostream>
#include <gtest/gtest.h>
using namespace std;
int main(int argc, char **argv){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
应该内置$ g++ Test.cpp -lgtest -lgtest_main -pthread
个功能。由于我不理解的原因,我收到了大量的链接错误。有没有明显的原因导致链接不起作用?
这是错误,截断大小:
g++