Skip to content

Instantly share code, notes, and snippets.

@PeterHajdu
Created March 14, 2012 12:02
Show Gist options
  • Save PeterHajdu/2036027 to your computer and use it in GitHub Desktop.
Save PeterHajdu/2036027 to your computer and use it in GitHub Desktop.
small helper script for training exercises
trainee should source the with arguments instead of simply execute it
#!/usr/bin/perl
use color;
print color::emph("Checking coverage output\n");
my $error = 0;
sub getCovColor
{
my $percent = shift;
my $line = shift;
chomp $line;
if ( $percent < 50 )
{
$error = 1;
return color::nok( $line ) . " Dude this is shameful. Start writing those tests!";
}
if ( $percent < 90 )
{
$error = 1;
return color::emph( $line ) . " Getting closer, just a few more tests.";
}
return color::ok( $line ) . " Awesome!";
}
sub parseCoverageData {
my $fileName = shift;
my @covData = @_;
$covData[2] =~ /Lines executed:(\d+).*/;
print color::emph( " - $fileName " ) . " -> " . getCovColor( $1, " $1%" ) . "\n";
}
my $isBlockStarted=0;
my @lastBlock = [];
my $lastBlockName = "";
while ( my $line = <STDIN> )
{
next if $line=~/\/usr\/lib/;
if ( $line=~/^File '(.*)'$/ )
{
$isBlockStarted = 1;
$lastBlockName = $1;
@lastBlock = [];
}
next if not $isBlockStarted;
if ( $line=~/^$/ )
{
$isBlockStarted = 0;
parseCoverageData( $lastBlockName, @lastBlock );
}
push( @lastBlock, $line );
}
exit $error;
#!/usr/bin/perl
use color;
print color::emph("Checking cxxtest output\n");
my $error = 0;
while ( my $line = <STDIN> )
{
print color::ok( $line ) if ( $line =~ /OK/ );
if ( $line =~ /Failed|Error/ )
{
print color::nok( $line );
$error = 1;
}
}
exit $error;
#!/usr/bin/perl
use color;
print color::emph("Checking valgrind output\n");
my $error = 0;
sub checkError
{
my $errorNum = shift;
my $line = shift;
return if $errorNum eq 0;
print color::nok( $line );
$error = 1;
}
while ( my $line = <STDIN> )
{
if ( $line=~/ERROR SUMMARY: (\d+) errors from (\d+) contexts/ or
$line=~/.* lost: (\d+) bytes/ or
$line=~/(I)nvalid read/ or
$line=~/(I)nvalid write/ or
$line=~/(I)nvalid free/ )
{
checkError( $1, $line );
}
}
exit $error;
package color;
use strict;
my $defaultColor = "\033[00;00m";
my $green="\033[00;32m";
my $yellow="\033[00;33m";
my $red="\033[00;31m";
sub ok {
return colorize( $green, @_ );
}
sub nok {
return colorize( $red, @_ );
}
sub emph {
return colorize( $yellow, @_ );
}
sub colorize {
my $color = shift;
my $message = shift;
return $color . $message . $defaultColor;
}
1;
CXXFLAGS=-Wall -pedantic -Werror -ftest-coverage -fprofile-arcs
CXX=g++
COVSUMMARY=./covsummary
TEST_SRC=test.cpp
TEST_EXEC=./testFile
TEST_LOG=./testFile.log
VALGRIND_LOG=./mem.log
$(TEST_SRC): $(TST)
cxxtestgen --error-printer -o $(TEST_SRC) $(TST)
$(TEST_EXEC): $(SRC) $(TEST_SRC)
$(CXX) $(CXXFLAGS) $(SRC) $(TEST_SRC) -o $(TEST_EXEC)
test: $(TEST_EXEC)
valgrind --leak-check=full --show-reachable=yes --log-file=$(VALGRIND_LOG) $(TEST_EXEC) | tee $(TEST_LOG)
gcov -b $(SRC) > $(COVSUMMARY)
checktest: test
@cat $(TEST_LOG) | checkTest
checkvalgrind: test
@cat $(VALGRIND_LOG) | checkValgrind
checkcov: test
@cat $(COVSUMMARY) | checkCoverage
check: checktest checkvalgrind checkcov
clean:
rm -rf *~ *.o $(TEST_EXEC) $(TEST_SRC) *.gcno *.gcov *.gcda $(COVSUMMARY) $(TEST_LOG) $(VALGRIND_LOG)
.PHONY: test clean check checktest checkvalgrind checkcov
#!/bin/bash
EXPECTED_ARGS=2
TRAINING_DIR=/home/tacsko/code/training/
if [ $# -ne $EXPECTED_ARGS ]; then
echo "Usage: `basename $0` <username> <exercise name>"
exit 1
fi
EXERCISEDIR=$1_$2
if [ -d $EXERCISEDIR ]; then
echo "Project ($2) already exists for $1."
exit 2
fi
git clone $TRAINING_DIR$2 $EXERCISEDIR
if [ ! $? ]; then
echo "Unable to prepare the sandbox."
exit 3
fi
cd $EXERCISEDIR;
cat README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment