Skip to content

Instantly share code, notes, and snippets.

@pogin503
Last active December 28, 2015 09:49
Show Gist options
  • Save pogin503/7481963 to your computer and use it in GitHub Desktop.
Save pogin503/7481963 to your computer and use it in GitHub Desktop.
Google Testを楽に試すためのシェルスクリプト
./make_google_test.sh testdir
cd testdir/build
./test_exec.sh
#!/bin/sh
DIR1=./$1
DIR2=./$1/$1
mkdir -p $DIR1
mkdir -p $DIR1/build
mkdir -p $DIR2
{
echo "cmake_minimum_required(VERSION 2.8)"
echo "add_subdirectory(${1})"
} > $DIR1/CMakeLists.txt
{
echo "set(GTEST_ROOT \$ENV{HOME}/usr/src/gtest-1.7.0)"
echo "include_directories("
echo " \${GTEST_ROOT}/include"
echo " )"
echo "add_executable(${1} ${1}.cpp)"
echo "target_link_libraries(${1}"
echo " pthread"
echo " \${GTEST_ROOT}/build/libgtest.a"
echo " \${GTEST_ROOT}/build/libgtest_main.a"
echo " )"
} > $DIR2/CMakeLists.txt
{
echo "#!/bin/sh"
echo "cmake .."
echo "make"
echo "./${1}/${1}"
} > $DIR1/build/test_exec.sh
chmod +x $DIR1/build/test_exec.sh
{
echo "#include <gtest/gtest.h>"
echo ""
echo "int add(int x, int y){"
echo " return x+y;"
echo "}"
echo ""
echo "TEST(${1}Test,Test1){"
echo " ASSERT_EQ(2,add(1,1));"
echo "}"
} > $DIR2/$1.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment