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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
diff --git a/tests/t0601-read.c b/tests/t0601-read.c
index 4373fbc..98ab74f 100644
--- a/tests/t0601-read.c
+++ b/tests/t0601-read.c
@@ -5,9 +5,6 @@
#include <git2/odb.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_INDEX2_ENTRY_COUNT 1437
diff --git a/tests/t0602-write.c b/tests/t0602-write.c
index 247aae9..7f12990 100644
--- a/tests/t0602-write.c
+++ b/tests/t0602-write.c
@@ -5,8 +5,6 @@
#include <git2/odb.h>
#include <git2/index.h>
-#define TEST_INDEX_PATH "../resources/testrepo.git/index"
-
int filecmp(const char *filename1, const char *filename2)
{
git_file file1, file2;
diff --git a/tests/t0603-sort.c b/tests/t0603-sort.c
index 1b32a5d..21e1301 100644
--- a/tests/t0603-sort.c
+++ b/tests/t0603-sort.c
@@ -5,8 +5,6 @@
#include <git2/odb.h>
#include <git2/index.h>
-#define TEST_INDEX_PATH "../t0600-objects/index"
-
/*
void print_entries(git_index *index)
{
diff --git a/tests/test_helpers.h b/tests/test_helpers.h
index 6574e39..7551fff 100644
--- a/tests/test_helpers.h
+++ b/tests/test_helpers.h
@@ -29,8 +29,10 @@
#include "test_lib.h"
#include <git2.h>
-#define ODB_FOLDER "../resources/testrepo.git/objects/"
-#define REPOSITORY_FOLDER "../resources/testrepo.git/"
+#define ODB_FOLDER (TEST_RESOURCES "/testrepo.git/objects/")
+#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 {
unsigned char *bytes; /* (compressed) bytes stored in object store */
diff --git a/wscript b/wscript
index 97aae84..34492be 100644
--- a/wscript
+++ b/wscript
@@ -12,174 +12,175 @@ CFLAGS_WIN32_L_DBG = ['/DEBUG']
ALL_LIBS = ['z', 'crypto', 'pthread']
def options(opt):
- opt.load('compiler_c')
- opt.add_option('--sha1', action='store', default='builtin',
- help="Use the builtin SHA1 routines (builtin), the \
+ opt.load('compiler_c')
+ opt.add_option('--sha1', action='store', default='builtin',
+ help="Use the builtin SHA1 routines (builtin), the \
PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)")
- opt.add_option('--debug', action='store_true', default=False,
- help='Compile with debug symbols')
- 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')
- opt.add_option('--arch', action='store', default='x86',
- help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)')
+ opt.add_option('--debug', action='store_true', default=False,
+ help='Compile with debug symbols')
+ 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')
+ opt.add_option('--arch', action='store', default='x86',
+ help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)')
def configure(conf):
- # load the MSVC configuration flags
- if conf.options.msvc:
- conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc]
+ # load the MSVC configuration flags
+ if 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
- conf.load('compiler_c')
+ # default configuration for C programs
+ conf.load('compiler_c')
- dbg = conf.options.debug
- zlib_name = 'z'
+ dbg = conf.options.debug
+ 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':
- conf.env.PLATFORM = 'win32'
+ if conf.env.DEST_OS == 'win32':
+ conf.env.PLATFORM = 'win32'
- if conf.env.CC_NAME == 'msvc':
- conf.env.CFLAGS = CFLAGS_WIN32 + (CFLAGS_WIN32_DBG if dbg else [])
- conf.env.LINKFLAGS += CFLAGS_WIN32_L_DBG if dbg else []
- conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB', 'ZLIB_WINAPI']
- zlib_name = 'zlibwapi'
+ if conf.env.CC_NAME == 'msvc':
+ conf.env.CFLAGS = CFLAGS_WIN32 + (CFLAGS_WIN32_DBG if dbg else [])
+ conf.env.LINKFLAGS += CFLAGS_WIN32_L_DBG if dbg else []
+ conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB', 'ZLIB_WINAPI']
+ zlib_name = 'zlibwapi'
- elif conf.env.CC_NAME == 'gcc':
- conf.check(features='c cprogram', lib='pthread', uselib_store='pthread')
+ elif conf.env.CC_NAME == 'gcc':
+ conf.check(features='c cprogram', lib='pthread', uselib_store='pthread')
- else:
- conf.env.PLATFORM = 'unix'
+ else:
+ conf.env.PLATFORM = 'unix'
- # check for Z lib
- conf.check(features='c cprogram', lib=zlib_name, uselib_store='z', install_path=None)
+ # check for Z lib
+ conf.check(features='c cprogram', lib=zlib_name, uselib_store='z', install_path=None)
- if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']:
- ctx.fatal('Invalid SHA1 option')
+ if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']:
+ ctx.fatal('Invalid SHA1 option')
- # check for libcrypto (openssl) if we are using its SHA1 functions
- if conf.options.sha1 == 'openssl':
- conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto')
- conf.env.DEFINES += ['OPENSSL_SHA1']
+ # check for libcrypto (openssl) if we are using its SHA1 functions
+ if conf.options.sha1 == 'openssl':
+ conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto')
+ conf.env.DEFINES += ['OPENSSL_SHA1']
- elif conf.options.sha1 == 'ppc':
- conf.env.DEFINES += ['PPC_SHA1']
+ elif conf.options.sha1 == 'ppc':
+ conf.env.DEFINES += ['PPC_SHA1']
- conf.env.sha1 = conf.options.sha1
+ conf.env.sha1 = conf.options.sha1
def build(bld):
- # command '[build|clean|install|uninstall]-static'
- if bld.variant == 'static':
- build_library(bld, 'cstlib')
+ # command '[build|clean|install|uninstall]-static'
+ if bld.variant == 'static':
+ build_library(bld, 'cstlib')
- # command '[build|clean|install|uninstall]-shared'
- elif bld.variant == 'shared':
- build_library(bld, 'cshlib')
+ # command '[build|clean|install|uninstall]-shared'
+ elif bld.variant == 'shared':
+ build_library(bld, 'cshlib')
- # command '[build|clean]-tests'
- elif bld.variant == 'tests':
- build_library(bld, 'cstlib')
- build_tests(bld)
+ # command '[build|clean]-tests'
+ elif bld.variant == 'tests':
+ build_library(bld, 'cstlib')
+ build_tests(bld)
- # command 'build|clean|install|uninstall': by default, run
- # the same command for both the static and the shared lib
- else:
- from waflib import Options
- Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
+ # command 'build|clean|install|uninstall': by default, run
+ # the same command for both the static and the shared lib
+ else:
+ from waflib import Options
+ Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
def build_library(bld, lib_str):
- directory = bld.path
-
- sources = directory.ant_glob('src/*.c')
-
- # Compile platform-dependant code
- # E.g. src/unix/*.c
- # src/win32/*.c
- sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM)
-
- # SHA1 methods source
- if bld.env.sha1 == "ppc":
- sources.append('src/ppc/sha1.c')
- else:
- sources.append('src/block-sha1/sha1.c')
-
- features = ['c', lib_str]
-
- #------------------------------
- # Build the main library
- #------------------------------
-
- # either as static or shared;
- bld(features=features,
- source=sources,
- target='git2',
- includes='src',
- install_path='${LIBDIR}',
- use=ALL_LIBS
- )
-
- # On Unix systems, build the Pkg-config entry file
- if bld.env.PLATFORM == 'unix':
- bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""",
- source='libgit2.pc.in',
- target='libgit2.pc',
- install_path='${LIBDIR}/pkgconfig',
- )
-
- # Install headers
- bld.install_files('${PREFIX}/include', directory.find_node('src/git2.h'))
- bld.install_files('${PREFIX}/include/git2', directory.ant_glob('src/git2/*.h'))
+ directory = bld.path
+
+ sources = directory.ant_glob('src/*.c')
+
+ # Compile platform-dependant code
+ # E.g. src/unix/*.c
+ # src/win32/*.c
+ sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM)
+
+ # SHA1 methods source
+ if bld.env.sha1 == "ppc":
+ sources.append('src/ppc/sha1.c')
+ else:
+ sources.append('src/block-sha1/sha1.c')
+
+ features = ['c', lib_str]
+
+ #------------------------------
+ # Build the main library
+ #------------------------------
+
+ # either as static or shared;
+ bld(features=features,
+ source=sources,
+ target='git2',
+ includes='src',
+ install_path='${LIBDIR}',
+ use=ALL_LIBS
+ )
+
+ # On Unix systems, build the Pkg-config entry file
+ if bld.env.PLATFORM == 'unix':
+ bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""",
+ source='libgit2.pc.in',
+ target='libgit2.pc',
+ install_path='${LIBDIR}/pkgconfig',
+ )
+
+ # Install headers
+ bld.install_files('${PREFIX}/include', directory.find_node('src/git2.h'))
+ bld.install_files('${PREFIX}/include/git2', directory.ant_glob('src/git2/*.h'))
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):
- import os
-
- if bld.is_install:
- return
-
- directory = bld.path
-
- # 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'):
- 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)
- if bld.cmd == 'clean-tests': # cleanup; delete the generated TOC file
- test_toc_file.delete()
- 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(
- source=[test_file, 'tests/test_main.c'],
- target=test_name,
- includes=['src', 'tests'],
- defines=['TEST_TOC="%s.toc"' % test_name],
- install_path=None,
- stlib=['git2'], # link with the git2 static lib we've just compiled'
- stlibpath=[directory.find_node('build/tests/').abspath(), directory.abspath()],
- use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
- # libraries which are not enabled won't link
- )
+ import os
+
+ if bld.is_install:
+ return
+
+ 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')
+
+ # Build all tests in the tests/ folder
+ 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)
+ if bld.cmd == 'clean-tests': # cleanup; delete the generated TOC file
+ test_toc_file.delete()
+ 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(
+ source=[test_file, 'tests/test_main.c'],
+ target=test_name,
+ includes=['src', 'tests'],
+ defines=['TEST_TOC="%s.toc"' % test_name, 'TEST_RESOURCES="%s"' % resources_path],
+ install_path=None,
+ stlib=['git2'], # link with the git2 static lib we've just compiled'
+ stlibpath=[directory.find_node('build/tests/').abspath(), directory.abspath()],
+ use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
+ # libraries which are not enabled won't link
+ )
class _test(BuildContext):
- cmd = 'test'
- fun = 'test'
+ cmd = 'test'
+ fun = 'test'
def test(bld):
- from waflib import Options
- Options.commands = ['build-tests', 'run-tests'] + Options.commands
+ from waflib import Options
+ Options.commands = ['build-tests', 'run-tests'] + Options.commands
class _build_doc(Context):
cmd = 'doxygen'
@@ -196,43 +197,42 @@ def build_docs(ctx):
ctx.exec_command("git checkout master")
class _run_tests(Context):
- cmd = 'run-tests'
- fun = 'run_tests'
+ cmd = 'run-tests'
+ fun = 'run_tests'
def run_tests(ctx):
- import shutil, sys
+ import shutil, tempfile, sys
- failed = False
- test_folder = ctx.path.make_node('tests/tmp/')
- test_folder.mkdir()
- test_glob = 'build/tests/t????-*'
+ failed = False
+ test_folder = tempfile.mkdtemp()
+ test_glob = 'build/tests/t????-*'
- if sys.platform == 'win32':
- test_glob = 'build/tests/t????-*.exe'
+ if sys.platform == 'win32':
+ test_glob += '.exe'
- for test in ctx.path.ant_glob(test_glob):
- if ctx.exec_command(test.abspath(), cwd=test_folder.abspath()) != 0:
- failed = True
- break
+ for test in ctx.path.ant_glob(test_glob):
+ if ctx.exec_command(test.abspath(), cwd=test_folder) != 0:
+ failed = True
+ break
- shutil.rmtree(test_folder.abspath())
+ shutil.rmtree(test_folder)
- if failed:
- ctx.fatal('Test run failed')
+ if failed:
+ ctx.fatal('Test run failed')
CONTEXTS = {
- 'build' : BuildContext,
- 'clean' : CleanContext,
- 'install' : InstallContext,
- 'uninstall' : UninstallContext
+ 'build' : BuildContext,
+ 'clean' : CleanContext,
+ 'install' : InstallContext,
+ 'uninstall' : UninstallContext
}
def build_command(command):
- ctx, var = command.split('-')
- class _gen_command(CONTEXTS[ctx]):
- cmd = command
- variant = var
+ ctx, var = command.split('-')
+ class _gen_command(CONTEXTS[ctx]):
+ cmd = command
+ variant = var
build_command('build-static')
build_command('build-shared')