Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@eagi223
CreatedApril 5, 2019 21:28
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist
    Save eagi223/0ba30b0b36b18f4de07943d9228dd73a to your computer and use it in GitHub Desktop.
    Google Test (C++ Unit Testing Framework) Setup Script for Mac
    #!/bin/bash
    # This script does no error handling and is built pretty specifically to my project.
    # You're welcome to use it if it works for you, but it's mainly here as a reference.
    # The steps that matter are:
    # 1) g++ -std=c++11 -isystem $GOOGLETEST_DIR/include -I$GOOGLETEST_DIR -pthread -c $GOOGLETEST_DIR/src/gtest-all.cc -o gtest-all.o
    # 2) libtool -static -o libgtest.a gtest-all.o
    echo"**************************"
    echo"Starting Google Test Setup"
    echo"**************************"
    echo
    # Create the util directory if not already present
    if [!-d"./util" ]
    then
    $(mkdir build)
    fi
    # Git Clone the repo into the util directory if not already present
    if [!-d"./util/googletest" ]
    then
    $(git clone https://github.com/google/googletest.git util/googletest)
    fi
    GOOGLETEST_DIR="./util/googletest/googletest"
    # Create a build directory if not already present
    if [!-d"./build" ]
    then
    $(mkdir build)
    fi
    # Create a gtest directory in the build directory if not already present
    if [!-d"./build/gtest" ]
    then
    $(mkdir build/gtest)
    fi
    # Compile the Google Test Library
    $(g++ -std=c++11 -isystem$GOOGLETEST_DIR/include -I$GOOGLETEST_DIR -pthread -c$GOOGLETEST_DIR/src/gtest-all.cc -o build/gtest/gtest-all.o)
    # Link the static library
    # In the docs, this step is done using the following command
    # myshell$ ar -rv libgtest.a gtest-all.o
    # This DID NOT work on my Mac... so I replaced it with the following which seems to work nicely
    $(libtool -static -o ./build/gtest/libgtest.a ./build/gtest/gtest-all.o)
    @eagi223
    Copy link
    Author

    All that is required is adding this script to your main project directory, giving it execute permissions (e.g. running$ chmod 777 googleTestSetup.sh, then$ ./googleTestSetup.sh). Then you can compile your test cases with the normalg++ -std=c++11 -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a \ -o your_test

    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp