Skip to content
This repository was archived by the owner on Oct 9, 2019. It is now read-only.

Remove boost dependency #19

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6973532
Remove dependency on boost
shiva May 4, 2015
f328ffc
Fix README
shiva May 4, 2015
cc53a4f
Xcode project with integrated testing
kylealanhale May 6, 2015
9b6b6c3
regex fix for multiline section support
kylealanhale May 6, 2015
cc4c603
DRYer tag/section construction
kylealanhale May 6, 2015
3e598e8
fixing failing unescape test
kylealanhale May 6, 2015
ae7fc1e
cleaning up commented-out boost code; updating README
kylealanhale May 6, 2015
c7c90b8
further improving multiline section support by collapsing dangling ne…
kylealanhale May 6, 2015
eaca997
using raw strings for more readable tests
kylealanhale May 6, 2015
b643ea5
list sections with nested sections weren't iterating properly; now th…
kylealanhale May 6, 2015
1b2d36d
even better section newline handling
kylealanhale May 6, 2015
a88cd2d
Use copy files instead of headers build phase
kylealanhale Jun 5, 2015
c45900f
Switch to c++0x for Xcode project
kylealanhale Jun 20, 2015
c4def92
Update travis with clang and gcc C++11 support
kylealanhale Jun 20, 2015
d7418db
Add manual test runner to Xcode
kylealanhale Jun 25, 2015
05f8210
Simplify test_change_delimiter
kylealanhale Jun 25, 2015
1304486
Account for difference in GCC's regex implementation
kylealanhale Jun 25, 2015
e0f6fcc
Update dependencies in README
kylealanhale Jun 25, 2015
ce1a4e6
Update build settings
kylealanhale Jul 30, 2015
609a720
Apply project whitespace styles
kylealanhale Jul 30, 2015
3ba0129
Clarify newline skipping
kylealanhale Jul 30, 2015
8a04292
Wrap else clause in braces
kylealanhale Jul 30, 2015
5f13c29
Add comments to new methods
kylealanhale Jul 30, 2015
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
33 changes: 30 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
sudo: false
language: cpp
script: autoreconf -i && ./configure && make check && ./test-program
compiler:
- gcc
- clang
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.9
- g++-4.9
- clang
before_install:
- if [ "$CXX" = "g++" ]; then
export CXX="g++-4.9" CC="gcc-4.9";
export CXXFLAGS="-std=c++11";
elif [ "$CXX" = "clang++" ]; then
export CXXFLAGS="-std=c++11 -stdlib=libc++ -DGTEST_USE_OWN_TR1_TUPLE=1";
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move those into the Makefile and the gtest build utils script? Or is this a specific travis problem? I'd much rather have it close to the actual build if this will be a problem outside of Travis.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are for the sake of Travis, although they're good clues on dependencies needed for building anywhere. However, I believe you have the -DGTEST_USE_OWN_TR1_TUPLE=1 documented already for clang, and I think I added something about gcc-4.9 and c++11, but I'll double check and make sure it's all there somewhere.

install:
- if [ "$CXX" == "clang++" ]; then
svn co --quiet http://llvm.org/svn/llvm-project/libcxx/trunk libcxx;
cd libcxx/lib && bash buildit;
ln -sf libc++.so.1.0 libc++.so.1;
cd "$TRAVIS_BUILD_DIR";
export CXXFLAGS="$CXXFLAGS -L`pwd`/libcxx/lib -I`pwd`/libcxx/include";
export LD_LIBRARY_PATH="`pwd`/libcxx/lib:$LD_LIBRARY_PATH";
fi
before_script:
- sudo apt-get install libgtest-dev libboost-regex-dev build-essential
- ./utils/build_gtest.sh

- autoreconf -i && ./configure && make check
script: ./test-program
3 changes: 1 addition & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
AM_CPPFLAGS = -I$(top_srcdir)/include
LDFLAGS=-lboost_regex-mt
pkginclude_HEADERS = include/plustache/template.hpp include/plustache/context.hpp include/plustache/plustache_types.hpp
check_PROGRAMS = test-program
test_program_CPPFLAGS=-Ivendor/gtest-1.6.0/include -I$(top_srcdir)/include
test_program_LDFLAGS=-Lvendor/gtest-1.6.0/lib/.libs -lgtest -lboost_regex-mt
test_program_LDFLAGS=-Lvendor/gtest-1.6.0/lib/.libs -lgtest

test_program_SOURCES = tests/test_change_delimiter.cpp tests/test_collections_plustache.cpp tests/test_html_escape_plustache.cpp tests/test_inverted_sections.cpp tests/test_multiple_plustache.cpp tests/test_nested_sections_plustache.cpp tests/test_partials_plustache.cpp tests/test_sections_plustache.cpp tests/test_simple_plustache.cpp tests/tests.cpp
test_program_LDADD = .libs/libplustache.a
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -152,5 +152,5 @@ If you get the tr1/tuple error, do:
* plustache executable

## Dependencies
* boost for regex and some other things
* compiler support for C++11's regex implementation (Clang or GCC 4.9+)
* google test for unit testing (included)
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ AC_PROG_CC
AC_PROG_INSTALL

# Checks for libraries.
AC_CHECK_LIB([boost_regex], [main])
AC_CHECK_LIB([gtest], [main])

# Checks for header files.
10 changes: 5 additions & 5 deletions include/plustache/template.hpp
Original file line number Diff line number Diff line change
@@ -8,8 +8,7 @@
#include <iostream>
#include <fstream>
#include <streambuf>
#include <boost/algorithm/string/trim.hpp>
#include <boost/regex.hpp>
#include <regex>

#include <plustache/plustache_types.hpp>
#include <plustache/context.hpp>
@@ -31,9 +30,9 @@ namespace Plustache {
std::string otag;
std::string ctag;
/* regex */
boost::regex tag;
boost::regex section;
boost::regex escape_chars;
std::regex tag;
std::regex section;
std::regex escape_chars;
/* lut for HTML escape chars */
std::map<std::string, std::string> escape_lut;
/* render and helper methods */
@@ -47,6 +46,7 @@ namespace Plustache {
const std::string& closetag);
void compile_data();
std::string get_template(const std::string& tmpl);
void update_tags();
};
} // namespace Plustache
#endif
18 changes: 18 additions & 0 deletions platforms/xcode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Created by https://www.gitignore.io

### Xcode ###
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.xcuserstate

239 changes: 239 additions & 0 deletions platforms/xcode/GoogleTests.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
* Copyright (c) 2013 Matthew Stevens
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// Downloaded from https://github.com/mattstevens/xcode-googletest on 21 Apr 2015 - kah

#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>
#import <gtest/gtest.h>

using testing::TestCase;
using testing::TestInfo;
using testing::TestPartResult;
using testing::UnitTest;

static NSString * const GoogleTestDisabledPrefix = @"DISABLED_";

/**
* A Google Test listener that reports failures to XCTest.
*/
class XCTestListener : public testing::EmptyTestEventListener {
public:
XCTestListener(XCTestCase *testCase) :
_testCase(testCase) {}

void OnTestPartResult(const TestPartResult& test_part_result) {
if (test_part_result.passed())
return;

int lineNumber = test_part_result.line_number();
const char *fileName = test_part_result.file_name();
NSString *path = fileName ? [@(fileName) stringByStandardizingPath] : nil;
NSString *description = @(test_part_result.message());
[_testCase recordFailureWithDescription:description
inFile:path
atLine:(lineNumber >= 0 ? (NSUInteger)lineNumber : 0)
expected:YES];
}

private:
XCTestCase *_testCase;
};

/**
* Test suite used to run Google Test cases.
*
* This test suite skips its own run and instead runs each of its sub-tests. This results
* in the Google Test cases being reported at the same level as other XCTest cases.
*
* Additionally, if a test case has been completely filtered out it is not run at all.
* This eliminates noise from the test report when running only a subset of tests.
*/
@interface GoogleTestSuite : XCTestSuite
@end

@implementation GoogleTestSuite

- (void)performTest:(XCTestSuiteRun *)testRun {
for (XCTest *test in self.tests) {
if (test.testCaseCount > 0) {
[testRun addTestRun:[test run]];
}
}
}

@end

/**
* A test case that executes Google Test, reporting test results to XCTest.
*
* XCTest loads tests by looking for all classes derived from XCTestCase and calling
* +defaultTestSuite on each of them. Normally this method returns an XCTestSuite
* containing an XCTestCase for each method of the receiver whose name begins with "test".
* Instead this class returns a custom test suite that runs an XCTestSuite for each Google
* Test case.
*/
@interface GoogleTests : XCTestCase
@end

@implementation GoogleTests {
NSString *_name;
NSString *_className;
NSString *_methodName;
NSString *_googleTestFilter;
}

- (id)initWithClassName:(NSString *)className methodName:(NSString *)methodName testFilter:(NSString *)filter {
self = [super initWithSelector:@selector(runTest)];
if (self) {
_className = [className copy];
_methodName = [methodName copy];
_name = [NSString stringWithFormat:@"-[%@ %@]", _className, _methodName];
_googleTestFilter = [filter copy];
}
return self;
}

- (NSString *)name {
return _name;
}

/**
* Returns the test name logged to the console for this test.
*/
- (NSString *)nameForLegacyLogging {
return _name;
}

/**
* Returns the class name reported to Xcode for this test.
*/
- (NSString *)testClassName {
return _className;
}

/**
* Returns the method name reported to Xcode for this test.
*/
- (NSString *)testMethodName {
return _methodName;
}

+ (id)defaultTestSuite {
// Pass the command-line arguments to Google Test to support the --gtest options
NSArray *arguments = [[NSProcessInfo processInfo] arguments];

int i = 0;
int argc = (int)[arguments count];
const char **argv = (const char **)calloc((unsigned int)argc + 1, sizeof(const char *));
for (NSString *arg in arguments) {
argv[i++] = [arg UTF8String];
}

testing::InitGoogleTest(&argc, (char **)argv);
UnitTest *googleTest = UnitTest::GetInstance();
testing::TestEventListeners& listeners = googleTest->listeners();
delete listeners.Release(listeners.default_result_printer());
free(argv);

BOOL runDisabledTests = testing::GTEST_FLAG(also_run_disabled_tests);
NSCharacterSet *decimalDigitCharacterSet = [NSCharacterSet decimalDigitCharacterSet];

XCTestSuite *testSuite = [GoogleTestSuite testSuiteWithName:NSStringFromClass([self class])];

for (int testCaseIndex = 0; testCaseIndex < googleTest->total_test_case_count(); testCaseIndex++) {
const TestCase *testCase = googleTest->GetTestCase(testCaseIndex);
NSString *testCaseName = @(testCase->name());

// For typed tests '/' is used to separate the parts of the test case name.
NSArray *testCaseNameComponents = [testCaseName componentsSeparatedByString:@"/"];

if (runDisabledTests == NO) {
BOOL testCaseDisabled = NO;

for (NSString *component in testCaseNameComponents) {
if ([component hasPrefix:GoogleTestDisabledPrefix]) {
testCaseDisabled = YES;
break;
}
}

if (testCaseDisabled) {
continue;
}
}

// Xcode's parsing expects that the test's class and method names are valid
// Objective-C names. If they are not the tests will not be displayed properly in
// the UI. Join the test case name components with '_' rather than '/' to address
// this.
NSString *className = [testCaseNameComponents componentsJoinedByString:@"_"];

XCTestSuite *testCaseSuite = [XCTestSuite testSuiteWithName:className];

for (int testIndex = 0; testIndex < testCase->total_test_count(); testIndex++) {
const TestInfo *testInfo = testCase->GetTestInfo(testIndex);
NSString *testName = @(testInfo->name());
if (runDisabledTests == NO && [testName hasPrefix:GoogleTestDisabledPrefix]) {
continue;
}

// Google Test allows test names starting with a digit, prefix these with an
// underscore to create a valid method name.
NSString *methodName = testName;
if ([methodName length] > 0 && [decimalDigitCharacterSet characterIsMember:[methodName characterAtIndex:0]]) {
methodName = [@"_" stringByAppendingString:methodName];
}

NSString *testFilter = [NSString stringWithFormat:@"%@.%@", testCaseName, testName];

[testCaseSuite addTest:[[self alloc] initWithClassName:className
methodName:methodName
testFilter:testFilter]];
}

[testSuite addTest:testCaseSuite];
}

return testSuite;
}

/**
* Runs a single test.
*/
- (void)runTest {
XCTestListener *listener = new XCTestListener(self);
UnitTest *googleTest = UnitTest::GetInstance();
googleTest->listeners().Append(listener);

testing::GTEST_FLAG(filter) = [_googleTestFilter UTF8String];

(void)RUN_ALL_TESTS();

delete googleTest->listeners().Release(listener);

int totalTestsRun = googleTest->successful_test_count() + googleTest->failed_test_count();
XCTAssertEqual(totalTestsRun, 1, @"Expected to run a single test for filter \"%@\"", _googleTestFilter);
}

@end
Loading