Skip to content

Commit

Permalink
Add basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
nsubiron committed Mar 4, 2017
1 parent f0ebb1c commit a2312e6
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 18 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ SOURCE = source
default: run test

test: dist
python test.py --script "test*.sh" bin/$(APPNAME).pyz test_cases
@python test.py bin/$(APPNAME).pyz test_cases

run: dist
bin/$(APPNAME).pyz --version
@bin/$(APPNAME).pyz --version

dist: bin/$(APPNAME).pyz

Expand All @@ -18,9 +18,9 @@ clean:

# See http://legacy.python.org/dev/peps/pep-0441/
bin/$(APPNAME).pyz: bin/$(APPNAME).zip
echo '#!/usr/bin/env python' | cat - bin/$(APPNAME).zip > bin/$(APPNAME).pyz
chmod u+x bin/$(APPNAME).pyz
@echo '#!/usr/bin/env python' | cat - bin/$(APPNAME).zip > bin/$(APPNAME).pyz
@chmod u+x bin/$(APPNAME).pyz

bin/$(APPNAME).zip: $(SOURCE)/* setup.py
@mkdir -p bin
python setup.py -d -o bin/$(APPNAME).zip source
@python setup.py -d -o bin/$(APPNAME).zip source
33 changes: 25 additions & 8 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,31 @@
class Logger(object):
def __init__(self, file_stream):
self.file_stream = file_stream
self.current_test = 'null'

def error(self, text):
text = '%s: %s' % (self.current_test, text)
self._write('ERROR: %s' % text)
logging.error(text)

def log_new_test(self, filename, folder):
text = 'running "%s" at "%s"' % (folder, filename)
def info(self, text):
self._write('INFO: %s' % text)
logging.info(text)

def print_command_output(self, output):
def log_new_test(self, filename, folder):
folder = os.path.basename(os.path.normpath(folder))
filename = os.path.splitext(filename)[0]
self.current_test = '.'.join([folder, filename])
text = '%s: running' % self.current_test
self.info(text)

def success(self):
self.info('%s: success' % self.current_test)

def print_command_output(self, output, display_on_screen=False):
self._write(output)
print('\033[30;1m%s\033[0m' % output)
if display_on_screen:
print('\033[30;1m%s\033[0m' % output)

def _write(self, text):
self.file_stream.write(text + '\n')
Expand Down Expand Up @@ -69,7 +81,7 @@ def do_the_test():
'--script',
metavar='FILENAME',
dest='script_filename',
default='test*.sh',
default='*.sh',
help='filename of the script to run on each subfolder (can have wild cards)')
argparser.add_argument(
'--log-file',
Expand All @@ -95,19 +107,24 @@ def do_the_test():
with open(args.log_file, 'w+') as file_stream:
logger = Logger(file_stream)

environmet = {'CONFIGURE_PYZ': os.path.abspath(args.configure_pyz_path)}
environmet = dict(os.environ)
environmet['CONFIGURE_PYZ'] = os.path.abspath(args.configure_pyz_path)
for filename, path in source_walk(args.testdir, args.script_filename):
try:
logger.log_new_test(filename, path)
logger.print_command_output(run_test(filename, path, environmet))
output = run_test(filename, path, environmet)
logger.print_command_output(output)
logger.success()
except subprocess.CalledProcessError as exception:
logger.print_command_output(exception.output)
logger.print_command_output(exception.output, display_on_screen=True)
logger.error(exception)
sys.exit(1)
except Exception as exception:
logger.error(exception)
sys.exit(2)

logger.info("every test terminated successfully")


if __name__ == '__main__':

Expand Down
10 changes: 5 additions & 5 deletions test_cases/standard/test.sh → test_cases/header.include
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

# Header
set -e
echo
echo "--- Starting test ------"
echo "file: $0"
echo "directory: $PWD"
echo "configure.pyz: $CONFIGURE_PYZ"
echo -n "version: "
$CONFIGURE_PYZ --version
echo -n "time-stamp: "
date -R
echo "------------------------"

echo "Nothing to do here, not yet implemented"
set -v
20 changes: 20 additions & 0 deletions test_cases/standard/build_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
source ../header.include

$CONFIGURE_PYZ -f tools/configure.json --makefile

make embed
make debug
./build/bin_debug/myexe

make release
./bin/myexe

make targets
make sublime
make codeblocks
make doxygen

rm -Rf bin build projects
rm -f build.ninja Makefile
find . -regex '.*EmbeddedData\.\(h\|cpp\)' -delete
5 changes: 5 additions & 0 deletions test_cases/standard/source/myexe/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <mylib/mylib.h>

int main() {
mylib::do_the_test();
}
13 changes: 13 additions & 0 deletions test_cases/standard/source/myexe/rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"targets": [
{
"target_name": "myexe",
"type": "executable",
"dependencies":
[
"mylib.a",
"mylib_dependency.a"
]
}
]
}
11 changes: 11 additions & 0 deletions test_cases/standard/source/mylib/mylib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "mylib.h"

#include <mylib_dependency/mylib_dependency.h>

namespace mylib {

void do_the_test() {
mylib_dependency::do_the_test();
}

}
7 changes: 7 additions & 0 deletions test_cases/standard/source/mylib/mylib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace mylib {

void do_the_test();

}
17 changes: 17 additions & 0 deletions test_cases/standard/source/mylib_dependency/mylib_dependency.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "mylib_dependency.h"

#include "EmbeddedData.h"

#include <iostream>
#include <string>

namespace mylib_dependency {

void do_the_test() {
std::string str{
mylib_dependency_resources_data_txt,
mylib_dependency_resources_data_txt + mylib_dependency_resources_data_txt_len};
std::cout << str;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace mylib_dependency {

void do_the_test();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
success!
8 changes: 8 additions & 0 deletions test_cases/standard/source/mylib_dependency/rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"targets": [
{
"type": "static_library",
"embedded_data": ["resources/*"]
}
]
}
38 changes: 38 additions & 0 deletions test_cases/standard/tools/Doxyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
PROJECT_NAME = $project_name
OUTPUT_DIRECTORY = $builddir/doxygen
CREATE_SUBDIRS = YES
FULL_PATH_NAMES = NO
JAVADOC_AUTOBRIEF = YES
LOOKUP_CACHE_SIZE = 3
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
CASE_SENSE_NAMES = YES
SORT_BRIEF_DOCS = YES
WARN_IF_UNDOCUMENTED = NO
WARN_LOGFILE = $builddir/doxygen/warnings.log
INPUT = $sourcedir
FILE_PATTERNS = *.cpp *.cc *.h *.hpp
RECURSIVE = YES
SOURCE_BROWSER = YES
STRIP_CODE_COMMENTS = NO
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
ALPHABETICAL_INDEX = NO
HTML_DYNAMIC_SECTIONS = YES
DISABLE_INDEX = YES
GENERATE_TREEVIEW = YES
FORMULA_FONTSIZE = 12
GENERATE_LATEX = NO
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
INCLUDE_PATH = $sourcedir
INCLUDE_FILE_PATTERNS = *.h *.hpp
HIDE_UNDOC_RELATIONS = NO
HAVE_DOT = YES
TEMPLATE_RELATIONS = YES
CALL_GRAPH = YES
CALLER_GRAPH = YES
DOT_IMAGE_FORMAT = svg
INTERACTIVE_SVG = YES
DOT_MULTI_TARGETS = YES
101 changes: 101 additions & 0 deletions test_cases/standard/tools/configure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
// Settings file for configure.py.
//
// Note: relative paths are searched from the directory from within
// configure.py is called.
//
// $rootpath is also available in this file, it expands to the full path of
// the calling directory.

"variables": {
"project_name": "Standard Test",
"builddir": "build",
"sourcedir": "source",
"projectsdir": "projects",
"doxyfile": "tools/Doxyfile",
"shell": "sh -c"
},

"compiler": {
"cxx": "g++",
"cflags": ["-Wall", "-std=c++14"],
"lflags": ["-Wall", "-Wextra", "-pthread"],
"includes": ["$sourcedir"],
"defines": []
},

"configurations": [
{
"name": "release",

"bin": "bin",
"lib": "$builddir/lib_release",
"obj": "$builddir/obj_release",

"cflags": ["-O3"],
"defines": ["NDEBUG"]
},
{
"name": "debug",

"bin": "$builddir/bin_debug",
"lib": "$builddir/lib_debug",
"obj": "$builddir/obj_debug",

"cflags": ["-O0", "-g"],
"defines": ["_DEBUG"]
}
],

"target_defaults": {
"type": "static_library",
"dependencies": [],
"defines": [],
"include_dirs": [],
"sources": ["*.cpp", "*.cc"],
"headers": ["*.h", "*.hpp"],
"embedded_data": [],
"unused": []
},

// Filename of extra rules for targets under $sourcedir. The contents of these
// files override "target_defaults".
"target_rules_filename": "rules.json",

"ninja_build_filename": "build.ninja",

"makefile_filename": "Makefile",

// Path to the file containing the Ninja rules.
"ninja_rules_filepath": "tools/rules.ninja",

// Default name for the target directly under $sourcedir.
"root_target_name": "root",

// Folders to be included in the Sublime Text project file.
"sublime_project_folders": [
{
"path": ".",
"folder_exclude_patterns": ["$builddir"]
}
],

// Other settings to add to the Sublime Text project file.
"sublime_project_other_settings": {
"SublimeLinter": {
"linters": {
"clang": {
"include_dirs":
[
"$rootpath/$sourcedir",
"$rootpath/$sourcedir/third-party"
],
"extra_flags": "-std=c++14"
}
}
}
},

// Compiler name used in CodeBlocks.
"codeblocks_compiler_name": "gcc"
}
23 changes: 23 additions & 0 deletions test_cases/standard/tools/rules.ninja
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
rule cxx
depfile = $out.d
command = $cxx -MMD -MF $out.d $cflags -c $in -o $out
description = CC $out

rule ar
command = ar crsT $out $in
description = AR $out

rule link
command = $cxx $lflags -o $out $libs
description = LINK $out

rule doxygen
command = doxygen $in
description = Doxygen Documentation

rule sed
command = $shell "sed $
-e 's/\$$project_name/\"$project_name\"/' $
-e 's/\$$sourcedir/$sourcedir/' $
-e 's/\$$builddir/$builddir/' $in > $out"
description = SED $out

0 comments on commit a2312e6

Please sign in to comment.