Commit 2cd6d686 by Vicent Marti

Tests now run with the resources folder as a hardcoded path

Each tests expects a "TEST_RESOURCES" define with the full path to the
resources folder.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 6c14d641
...@@ -5,9 +5,6 @@ ...@@ -5,9 +5,6 @@
#include <git2/odb.h> #include <git2/odb.h>
#include <git2/index.h> #include <git2/index.h>
#define TEST_INDEX_PATH "../resources/testrepo.git/index"
#define TEST_INDEX2_PATH "../resources/gitgit.index"
#define TEST_INDEX_ENTRY_COUNT 109 #define TEST_INDEX_ENTRY_COUNT 109
#define TEST_INDEX2_ENTRY_COUNT 1437 #define TEST_INDEX2_ENTRY_COUNT 1437
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include <git2/odb.h> #include <git2/odb.h>
#include <git2/index.h> #include <git2/index.h>
#define TEST_INDEX_PATH "../resources/testrepo.git/index"
int filecmp(const char *filename1, const char *filename2) int filecmp(const char *filename1, const char *filename2)
{ {
git_file file1, file2; git_file file1, file2;
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include <git2/odb.h> #include <git2/odb.h>
#include <git2/index.h> #include <git2/index.h>
#define TEST_INDEX_PATH "../t0600-objects/index"
/* /*
void print_entries(git_index *index) void print_entries(git_index *index)
{ {
......
...@@ -29,8 +29,10 @@ ...@@ -29,8 +29,10 @@
#include "test_lib.h" #include "test_lib.h"
#include <git2.h> #include <git2.h>
#define ODB_FOLDER "../resources/testrepo.git/objects/" #define ODB_FOLDER (TEST_RESOURCES "/testrepo.git/objects/")
#define REPOSITORY_FOLDER "../resources/testrepo.git/" #define REPOSITORY_FOLDER (TEST_RESOURCES "/testrepo.git/")
#define TEST_INDEX_PATH (TEST_RESOURCES "/testrepo.git/index")
#define TEST_INDEX2_PATH (TEST_RESOURCES "/gitgit.index")
typedef struct object_data { typedef struct object_data {
unsigned char *bytes; /* (compressed) bytes stored in object store */ unsigned char *bytes; /* (compressed) bytes stored in object store */
......
...@@ -12,174 +12,175 @@ CFLAGS_WIN32_L_DBG = ['/DEBUG'] ...@@ -12,174 +12,175 @@ CFLAGS_WIN32_L_DBG = ['/DEBUG']
ALL_LIBS = ['z', 'crypto', 'pthread'] ALL_LIBS = ['z', 'crypto', 'pthread']
def options(opt): def options(opt):
opt.load('compiler_c') opt.load('compiler_c')
opt.add_option('--sha1', action='store', default='builtin', opt.add_option('--sha1', action='store', default='builtin',
help="Use the builtin SHA1 routines (builtin), the \ help="Use the builtin SHA1 routines (builtin), the \
PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)") PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)")
opt.add_option('--debug', action='store_true', default=False, opt.add_option('--debug', action='store_true', default=False,
help='Compile with debug symbols') help='Compile with debug symbols')
opt.add_option('--msvc', action='store', default=None, opt.add_option('--msvc', action='store', default=None,
help='Force a specific MSVC++ version (7.1, 8.0, 9.0, 10.0), if more than one is installed') help='Force a specific MSVC++ version (7.1, 8.0, 9.0, 10.0), if more than one is installed')
opt.add_option('--arch', action='store', default='x86', opt.add_option('--arch', action='store', default='x86',
help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)') help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)')
def configure(conf): def configure(conf):
# load the MSVC configuration flags # load the MSVC configuration flags
if conf.options.msvc: if conf.options.msvc:
conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc] conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc]
conf.env['MSVC_TARGETS'] = [conf.options.arch] conf.env['MSVC_TARGETS'] = [conf.options.arch]
# default configuration for C programs # default configuration for C programs
conf.load('compiler_c') conf.load('compiler_c')
dbg = conf.options.debug dbg = conf.options.debug
zlib_name = 'z' zlib_name = 'z'
conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else []) conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else [])
if conf.env.DEST_OS == 'win32': if conf.env.DEST_OS == 'win32':
conf.env.PLATFORM = 'win32' conf.env.PLATFORM = 'win32'
if conf.env.CC_NAME == 'msvc': if conf.env.CC_NAME == 'msvc':
conf.env.CFLAGS = CFLAGS_WIN32 + (CFLAGS_WIN32_DBG if dbg else []) conf.env.CFLAGS = CFLAGS_WIN32 + (CFLAGS_WIN32_DBG if dbg else [])
conf.env.LINKFLAGS += CFLAGS_WIN32_L_DBG if dbg else [] conf.env.LINKFLAGS += CFLAGS_WIN32_L_DBG if dbg else []
conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB', 'ZLIB_WINAPI'] conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB', 'ZLIB_WINAPI']
zlib_name = 'zlibwapi' zlib_name = 'zlibwapi'
elif conf.env.CC_NAME == 'gcc': elif conf.env.CC_NAME == 'gcc':
conf.check(features='c cprogram', lib='pthread', uselib_store='pthread') conf.check(features='c cprogram', lib='pthread', uselib_store='pthread')
else: else:
conf.env.PLATFORM = 'unix' conf.env.PLATFORM = 'unix'
# check for Z lib # check for Z lib
conf.check(features='c cprogram', lib=zlib_name, uselib_store='z', install_path=None) conf.check(features='c cprogram', lib=zlib_name, uselib_store='z', install_path=None)
if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']: if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']:
ctx.fatal('Invalid SHA1 option') ctx.fatal('Invalid SHA1 option')
# check for libcrypto (openssl) if we are using its SHA1 functions # check for libcrypto (openssl) if we are using its SHA1 functions
if conf.options.sha1 == 'openssl': if conf.options.sha1 == 'openssl':
conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto') conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto')
conf.env.DEFINES += ['OPENSSL_SHA1'] conf.env.DEFINES += ['OPENSSL_SHA1']
elif conf.options.sha1 == 'ppc': elif conf.options.sha1 == 'ppc':
conf.env.DEFINES += ['PPC_SHA1'] conf.env.DEFINES += ['PPC_SHA1']
conf.env.sha1 = conf.options.sha1 conf.env.sha1 = conf.options.sha1
def build(bld): def build(bld):
# command '[build|clean|install|uninstall]-static' # command '[build|clean|install|uninstall]-static'
if bld.variant == 'static': if bld.variant == 'static':
build_library(bld, 'cstlib') build_library(bld, 'cstlib')
# command '[build|clean|install|uninstall]-shared' # command '[build|clean|install|uninstall]-shared'
elif bld.variant == 'shared': elif bld.variant == 'shared':
build_library(bld, 'cshlib') build_library(bld, 'cshlib')
# command '[build|clean]-tests' # command '[build|clean]-tests'
elif bld.variant == 'tests': elif bld.variant == 'tests':
build_library(bld, 'cstlib') build_library(bld, 'cstlib')
build_tests(bld) build_tests(bld)
# command 'build|clean|install|uninstall': by default, run # command 'build|clean|install|uninstall': by default, run
# the same command for both the static and the shared lib # the same command for both the static and the shared lib
else: else:
from waflib import Options from waflib import Options
Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
def build_library(bld, lib_str): def build_library(bld, lib_str):
directory = bld.path directory = bld.path
sources = directory.ant_glob('src/*.c') sources = directory.ant_glob('src/*.c')
# Compile platform-dependant code # Compile platform-dependant code
# E.g. src/unix/*.c # E.g. src/unix/*.c
# src/win32/*.c # src/win32/*.c
sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM) sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM)
# SHA1 methods source # SHA1 methods source
if bld.env.sha1 == "ppc": if bld.env.sha1 == "ppc":
sources.append('src/ppc/sha1.c') sources.append('src/ppc/sha1.c')
else: else:
sources.append('src/block-sha1/sha1.c') sources.append('src/block-sha1/sha1.c')
features = ['c', lib_str] features = ['c', lib_str]
#------------------------------ #------------------------------
# Build the main library # Build the main library
#------------------------------ #------------------------------
# either as static or shared; # either as static or shared;
bld(features=features, bld(features=features,
source=sources, source=sources,
target='git2', target='git2',
includes='src', includes='src',
install_path='${LIBDIR}', install_path='${LIBDIR}',
use=ALL_LIBS use=ALL_LIBS
) )
# On Unix systems, build the Pkg-config entry file # On Unix systems, build the Pkg-config entry file
if bld.env.PLATFORM == 'unix': if bld.env.PLATFORM == 'unix':
bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""", bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""",
source='libgit2.pc.in', source='libgit2.pc.in',
target='libgit2.pc', target='libgit2.pc',
install_path='${LIBDIR}/pkgconfig', install_path='${LIBDIR}/pkgconfig',
) )
# Install headers # Install headers
bld.install_files('${PREFIX}/include', directory.find_node('src/git2.h')) bld.install_files('${PREFIX}/include', directory.find_node('src/git2.h'))
bld.install_files('${PREFIX}/include/git2', directory.ant_glob('src/git2/*.h')) bld.install_files('${PREFIX}/include/git2', directory.ant_glob('src/git2/*.h'))
def grep_test_header(text, test_file): def grep_test_header(text, test_file):
return '\n'.join(l for l in test_file.read().splitlines() if text in l) return '\n'.join(l for l in test_file.read().splitlines() if text in l)
def build_tests(bld): def build_tests(bld):
import os import os
if bld.is_install: if bld.is_install:
return return
directory = bld.path directory = bld.path
resources_path = directory.find_node('tests/resources/').abspath()
# Common object with the Test library methods
bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper') # Common object with the Test library methods
bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper')
# Build all tests in the tests/ folder
for test_file in directory.ant_glob('tests/t????-*.c'): # Build all tests in the tests/ folder
test_name, _ = os.path.splitext(os.path.basename(test_file.abspath())) for test_file in directory.ant_glob('tests/t????-*.c'):
test_name, _ = os.path.splitext(os.path.basename(test_file.abspath()))
# Preprocess table of contents for each test
test_toc_file = directory.make_node('tests/%s.toc' % test_name) # Preprocess table of contents for each test
if bld.cmd == 'clean-tests': # cleanup; delete the generated TOC file test_toc_file = directory.make_node('tests/%s.toc' % test_name)
test_toc_file.delete() if bld.cmd == 'clean-tests': # cleanup; delete the generated TOC file
elif bld.cmd == 'build-tests': # build; create TOC test_toc_file.delete()
test_toc_file.write(grep_test_header('BEGIN_TEST', test_file)) elif bld.cmd == 'build-tests': # build; create TOC
test_toc_file.write(grep_test_header('BEGIN_TEST', test_file))
# Build individual test (don't run)
bld.program( # Build individual test (don't run)
source=[test_file, 'tests/test_main.c'], bld.program(
target=test_name, source=[test_file, 'tests/test_main.c'],
includes=['src', 'tests'], target=test_name,
defines=['TEST_TOC="%s.toc"' % test_name], includes=['src', 'tests'],
install_path=None, defines=['TEST_TOC="%s.toc"' % test_name, 'TEST_RESOURCES="%s"' % resources_path],
stlib=['git2'], # link with the git2 static lib we've just compiled' install_path=None,
stlibpath=[directory.find_node('build/tests/').abspath(), directory.abspath()], stlib=['git2'], # link with the git2 static lib we've just compiled'
use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know stlibpath=[directory.find_node('build/tests/').abspath(), directory.abspath()],
# libraries which are not enabled won't link use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
) # libraries which are not enabled won't link
)
class _test(BuildContext): class _test(BuildContext):
cmd = 'test' cmd = 'test'
fun = 'test' fun = 'test'
def test(bld): def test(bld):
from waflib import Options from waflib import Options
Options.commands = ['build-tests', 'run-tests'] + Options.commands Options.commands = ['build-tests', 'run-tests'] + Options.commands
class _build_doc(Context): class _build_doc(Context):
cmd = 'doxygen' cmd = 'doxygen'
...@@ -196,43 +197,42 @@ def build_docs(ctx): ...@@ -196,43 +197,42 @@ def build_docs(ctx):
ctx.exec_command("git checkout master") ctx.exec_command("git checkout master")
class _run_tests(Context): class _run_tests(Context):
cmd = 'run-tests' cmd = 'run-tests'
fun = 'run_tests' fun = 'run_tests'
def run_tests(ctx): def run_tests(ctx):
import shutil, sys import shutil, tempfile, sys
failed = False failed = False
test_folder = ctx.path.make_node('tests/tmp/') test_folder = tempfile.mkdtemp()
test_folder.mkdir() test_glob = 'build/tests/t????-*'
test_glob = 'build/tests/t????-*'
if sys.platform == 'win32': if sys.platform == 'win32':
test_glob = 'build/tests/t????-*.exe' test_glob += '.exe'
for test in ctx.path.ant_glob(test_glob): for test in ctx.path.ant_glob(test_glob):
if ctx.exec_command(test.abspath(), cwd=test_folder.abspath()) != 0: if ctx.exec_command(test.abspath(), cwd=test_folder) != 0:
failed = True failed = True
break break
shutil.rmtree(test_folder.abspath()) shutil.rmtree(test_folder)
if failed: if failed:
ctx.fatal('Test run failed') ctx.fatal('Test run failed')
CONTEXTS = { CONTEXTS = {
'build' : BuildContext, 'build' : BuildContext,
'clean' : CleanContext, 'clean' : CleanContext,
'install' : InstallContext, 'install' : InstallContext,
'uninstall' : UninstallContext 'uninstall' : UninstallContext
} }
def build_command(command): def build_command(command):
ctx, var = command.split('-') ctx, var = command.split('-')
class _gen_command(CONTEXTS[ctx]): class _gen_command(CONTEXTS[ctx]):
cmd = command cmd = command
variant = var variant = var
build_command('build-static') build_command('build-static')
build_command('build-shared') build_command('build-shared')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment