Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
mason_packages
mason_packages
cli
cli.dSYM
*.o
45 changes: 45 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
language: generic

env:
global:
- ASAN_OPTIONS=suppressions=asan_suppressions.txt

matrix:
include:
- os: linux
sudo: false
env: CXX=g++-5 BUILDTYPE=Release
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'g++-5' ]
- os: linux
sudo: false
env: CXX=clang++-3.8 BUILDTYPE=Release
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'libstdc++6', 'libstdc++-5-dev' ]
- os: linux
sudo: false
env: CXX=clang++-3.8 BUILDTYPE=Debug CXXFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address"
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'libstdc++6', 'libstdc++-5-dev' ]
- os: osx
osx_image: xcode7.3
env: BUILDTYPE=Release

cache: apt

install:
- |
if [[ ${CXX} =~ "clang" ]] && [[ $(uname -s) == "Linux" ]]; then
git clone --depth=1 https://github.com/mapbox/mason.git ./.mason
./.mason/mason install clang 3.8.0
export PATH=$(./.mason/mason prefix clang 3.8.0)/bin:${PATH}
which clang++
fi
script:
- make test
32 changes: 25 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
CC := $(CC)
CXX := $(CXX)
CXXFLAGS := $(CXXFLAGS) -Iinclude -Imason_packages/.link/include -std=c++11
LDFLAGS := $(LDFLAGS) -lboost_program_options -lboost_system

MASON ?= .mason/mason
MASON_HOME := ./mason_packages/.link

RELEASE_FLAGS := -O3 -DNDEBUG
WARNING_FLAGS := -Wall -Wextra -Werror -Wsign-compare -Wfloat-equal -Wfloat-conversion -Wshadow -Wno-unsequenced
DEBUG_FLAGS := -g -O0 -DDEBUG -fno-inline-functions -fno-omit-frame-pointer
MASON ?= .mason/mason

default: test
ifeq ($(BUILDTYPE),Release)
FINAL_FLAGS := -g $(WARNING_FLAGS) $(RELEASE_FLAGS)
else
FINAL_FLAGS := -g $(WARNING_FLAGS) $(DEBUG_FLAGS)
endif

clean:
rm -rf mason_packages
default: cli

cli: mason_packages clean
$(CXX) cli.cpp -o cli -isystem$(MASON_HOME)/include $(CXXFLAGS) $(FINAL_FLAGS) $(LDFLAGS)

test: cli
./tests/cli.test.sh

$(MASON):
git submodule update --init

mason_packages: $(MASON)
$(MASON) install hpp_skel 0.0.1
$(MASON) install hpp_skel 1.0.0 && $(MASON) link hpp_skel 1.0.0
$(MASON) install boost_libprogram_options 1.61.0 && $(MASON) link boost_libprogram_options 1.61.0

clean:
rm -f cli
rm -f *.o

cli: mason_packages
# $(CXX) cli.cpp -o cli -isystem$(MASON_HOME)/include -L$(MASON_HOME)/lib $(CXXFLAGS) $(FINAL_FLAGS) $(LDFLAGS);
clean-mason:
rm -rf mason_packages
50 changes: 44 additions & 6 deletions cli.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
#include <hello_world.hpp>
#include <hello_world/hello_world.hpp>
#include <boost/program_options.hpp>

#include <iostream>
#include <cassert>

using namespace hello_world;
#define VERSION "v0.0.1\n"

int main() {
std::string value = exclaim("hello");
std::clog << value;
return 0;
using namespace boost::program_options;

int main(int argc, char** argv) {
try {
options_description desc("\nusage: cli <phrase>");

desc.add_options()
("help,h", "show help")
("version,v", "show version number")
("phrase,p", value<std::string>(), "Input phrase");

positional_options_description p;
p.add("phrase", 1);
variables_map vm;

auto parser = command_line_parser(argc, argv).options(desc).positional(p);
store(parser.run(), vm);

if (vm.count("help")) {
std::cout << desc;
} else if (vm.count("version")) {
std::cout << VERSION;
} else {
std::string phrase;
if (vm.count("phrase")) {
phrase = vm["phrase"].as<std::string>();
} else {
std::cout << "Error: you must pass in a phrase to be exclaimed." << "\n";
return 1;
}

// use hello_world::exclaim
std::string output(hello_world::exclaim(phrase));
std::cout << output << "\n";

return 0;
}
} catch (std::exception const& ex) {
std::cout << "error: " << ex.what() << "\n";
return -1;
}
}
17 changes: 17 additions & 0 deletions tests/cli.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e
set -o pipefail

# run cli command directly in bash, capture the result and test it
PWD=$(pwd)
RESULT=$($PWD/cli waka)
if [ $RESULT == "!waka!" ]
then
echo "Success."
exit 0
else
echo "Test failed: cli output is not as expected."
echo "EXPECTED: !waka! - ACTUAL: $RESULT"
exit -1
fi