Skip to content

Commit

Permalink
Adding a version based on the git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancalhoun committed Mar 4, 2016
1 parent 5a25386 commit 8a09a5b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 2.8)

project(cppunit)

file(STRINGS ${CMAKE_BINARY_DIR}/cppunit_version.txt VERSION)
add_definitions(-DCPPUNIT_VERSION="${VERSION}")

include_directories(
${CMAKE_SOURCE_DIR}/include
)
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ task :clean do
rm_rf 'dist'
end

task :cmake do
file "build/cppunit_version.txt" do
sh "git describe --tags > build/cppunit_version.txt"
end

task :cmake => ['build/cppunit_version.txt'] do
project.cmake!
end

Expand Down
13 changes: 12 additions & 1 deletion src/cppunit/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void CPPUNIT_NS::Options::parse(int argc, const char* argv[])
if(argc > 0)
{
_program = argv[0];
std::string::size_type s = _program.rfind("/\\");
std::string::size_type s = _program.find_last_of("/\\");
if(s != std::string::npos)
_program = _program.substr(s + 1);
}
Expand All @@ -39,6 +39,10 @@ void CPPUNIT_NS::Options::parse(int argc, const char* argv[])
{
_doPrintProgress = false;
}
else if(option == "-v" || option == "--version")
{
exitVersionMessage();
}
else if(option == "-h" || option == "--help")
{
exitHelpMessage();
Expand Down Expand Up @@ -79,13 +83,20 @@ bool CPPUNIT_NS::Options::doPrintVerbose() const
return _doPrintVerbose;
}

void CPPUNIT_NS::Options::exitVersionMessage()
{
_out << _program << ": CppUnit " << CPPUNIT_VERSION << " (" << __DATE__ << ")" << std::endl;
::exit(0);
}

void CPPUNIT_NS::Options::exitHelpMessage(int code)
{
_out << _program << " [options] TEST..." << std::endl;
_out << "CppUnit test driver" << std::endl;
_out << std::endl;

_out << " -h --help Show this help message" << std::endl;
_out << " -v --version Show version banner" << std::endl;
_out << " -V --verbose Enable verbose progress output" << std::endl;
_out << " -w --wait Wait to exit until user presses RETURN" << std::endl;
_out << " -r --no-print-result Disable printing test result" << std::endl;
Expand Down
1 change: 1 addition & 0 deletions src/cppunit/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Options
bool doPrintVerbose() const;

protected:
void exitVersionMessage();
void exitHelpMessage(int code = 0);
void exitErrorMessage(const std::string& option);

Expand Down
10 changes: 10 additions & 0 deletions test/cppunit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ def testCppUnit
}
end

def testCppUnitVersion
Dir.chdir(File.join(File.dirname(__FILE__), '..', 'build', 'test', ENV['CONFIGURATION'].to_s)) {
%w(-v --version).each {|opt|
output = `./cppunit_test #{opt}`
assert_equal 0, $?.exitstatus
assert_match /CppUnit v/, output
}
}
end

def testCppUnitHelp
Dir.chdir(File.join(File.dirname(__FILE__), '..', 'build', 'test', ENV['CONFIGURATION'].to_s)) {
%w(-h --help).each {|opt|
Expand Down

0 comments on commit 8a09a5b

Please sign in to comment.