diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2021-11-30 21:09:57 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-30 21:09:57 -0500 |
| commit | 6fdb1b2f55da9593576b096ee2eecce61995fb51 (patch) | |
| tree | bfd2ca7930f2643b0ada9b9f4935f832fdf1c18a /tests | |
| parent | f9c4dc10d90732cfbe2271dd58b01dd8f4003d15 (diff) | |
| parent | 84083dcc8bd41332ccac9d7b537f3e254d79011c (diff) | |
| download | libgit2-6fdb1b2f55da9593576b096ee2eecce61995fb51.tar.gz | |
Merge pull request #6122 from libgit2/ethomson/cleanup
Minor code cleanups
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | tests/core/copy.c | 1 | ||||
| -rw-r--r-- | tests/core/env.c | 1 | ||||
| -rw-r--r-- | tests/core/link.c | 1 | ||||
| -rw-r--r-- | tests/core/mkdir.c | 1 | ||||
| -rw-r--r-- | tests/core/sha1.c | 28 | ||||
| -rw-r--r-- | tests/core/stat.c | 1 | ||||
| -rw-r--r-- | tests/core/utf8.c | 1 | ||||
| -rw-r--r-- | tests/path/win32.c | 1 |
9 files changed, 21 insertions, 20 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 84df92a45..2272dec98 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -38,7 +38,7 @@ set_source_files_properties( add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS}) set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90) -set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR}) +set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) @@ -62,9 +62,9 @@ endif() function(ADD_CLAR_TEST name) if(NOT USE_LEAK_CHECKER STREQUAL "OFF") - add_test(${name} "${libgit2_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${libgit2_BINARY_DIR}/libgit2_tests" ${ARGN}) + add_test(${name} "${CMAKE_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${CMAKE_BINARY_DIR}/libgit2_tests" ${ARGN}) else() - add_test(${name} "${libgit2_BINARY_DIR}/libgit2_tests" ${ARGN}) + add_test(${name} "${CMAKE_BINARY_DIR}/libgit2_tests" ${ARGN}) endif() endfunction(ADD_CLAR_TEST) diff --git a/tests/core/copy.c b/tests/core/copy.c index b03d71083..6d22b503d 100644 --- a/tests/core/copy.c +++ b/tests/core/copy.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" #include "futils.h" -#include "path.h" #include "posix.h" void test_core_copy__file(void) diff --git a/tests/core/env.c b/tests/core/env.c index 88c5c6aa3..8ba9b9124 100644 --- a/tests/core/env.c +++ b/tests/core/env.c @@ -1,7 +1,6 @@ #include "clar_libgit2.h" #include "futils.h" #include "sysdir.h" -#include "path.h" #ifdef GIT_WIN32 #define NUM_VARS 5 diff --git a/tests/core/link.c b/tests/core/link.c index 6ab79b2a8..a1e2706b2 100644 --- a/tests/core/link.c +++ b/tests/core/link.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" #include "posix.h" -#include "path.h" #ifdef GIT_WIN32 # include "win32/reparse.h" diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c index 8d4b9afd6..58a4cfcdb 100644 --- a/tests/core/mkdir.c +++ b/tests/core/mkdir.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" #include "futils.h" -#include "path.h" #include "posix.h" static void cleanup_basic_dirs(void *ref) diff --git a/tests/core/sha1.c b/tests/core/sha1.c index 92582d69a..9ccdaab3c 100644 --- a/tests/core/sha1.c +++ b/tests/core/sha1.c @@ -13,7 +13,7 @@ void test_core_sha1__cleanup(void) cl_fixture_cleanup(FIXTURE_DIR); } -static int sha1_file(git_oid *out, const char *filename) +static int sha1_file(unsigned char *out, const char *filename) { git_hash_ctx ctx; char buf[2048]; @@ -31,7 +31,7 @@ static int sha1_file(git_oid *out, const char *filename) cl_assert_equal_i(0, read_len); p_close(fd); - ret = git_hash_final(out->id, &ctx); + ret = git_hash_final(out, &ctx); git_hash_ctx_cleanup(&ctx); return ret; @@ -39,26 +39,32 @@ static int sha1_file(git_oid *out, const char *filename) void test_core_sha1__sum(void) { - git_oid oid, expected; + unsigned char expected[GIT_HASH_SHA1_SIZE] = { + 0x4e, 0x72, 0x67, 0x9e, 0x3e, 0xa4, 0xd0, 0x4e, 0x0c, 0x64, + 0x2f, 0x02, 0x9e, 0x61, 0xeb, 0x80, 0x56, 0xc7, 0xed, 0x94 + }; + unsigned char actual[GIT_HASH_SHA1_SIZE]; - cl_git_pass(sha1_file(&oid, FIXTURE_DIR "/hello_c")); - git_oid_fromstr(&expected, "4e72679e3ea4d04e0c642f029e61eb8056c7ed94"); - cl_assert_equal_oid(&expected, &oid); + cl_git_pass(sha1_file(actual, FIXTURE_DIR "/hello_c")); + cl_assert_equal_i(0, memcmp(expected, actual, GIT_HASH_SHA1_SIZE)); } /* test that sha1 collision detection works when enabled */ void test_core_sha1__detect_collision_attack(void) { - git_oid oid, expected; + unsigned char actual[GIT_HASH_SHA1_SIZE]; + unsigned char expected[GIT_HASH_SHA1_SIZE] = { + 0x38, 0x76, 0x2c, 0xf7, 0xf5, 0x59, 0x34, 0xb3, 0x4d, 0x17, + 0x9a, 0xe6, 0xa4, 0xc8, 0x0c, 0xad, 0xcc, 0xbb, 0x7f, 0x0a + }; #ifdef GIT_SHA1_COLLISIONDETECT GIT_UNUSED(&expected); - cl_git_fail(sha1_file(&oid, FIXTURE_DIR "/shattered-1.pdf")); + cl_git_fail(sha1_file(actual, FIXTURE_DIR "/shattered-1.pdf")); cl_assert_equal_s("SHA1 collision attack detected", git_error_last()->message); #else - cl_git_pass(sha1_file(&oid, FIXTURE_DIR "/shattered-1.pdf")); - git_oid_fromstr(&expected, "38762cf7f55934b34d179ae6a4c80cadccbb7f0a"); - cl_assert_equal_oid(&expected, &oid); + cl_git_pass(sha1_file(actual, FIXTURE_DIR "/shattered-1.pdf")); + cl_assert_equal_i(0, memcmp(expected, actual, GIT_HASH_SHA1_SIZE)); #endif } diff --git a/tests/core/stat.c b/tests/core/stat.c index 022380ba6..210072fe3 100644 --- a/tests/core/stat.c +++ b/tests/core/stat.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" #include "futils.h" -#include "path.h" #include "posix.h" void test_core_stat__initialize(void) diff --git a/tests/core/utf8.c b/tests/core/utf8.c index 021828e9e..e1987b8d6 100644 --- a/tests/core/utf8.c +++ b/tests/core/utf8.c @@ -1,4 +1,5 @@ #include "clar_libgit2.h" +#include "utf8.h" void test_core_utf8__char_length(void) { diff --git a/tests/path/win32.c b/tests/path/win32.c index ff166395d..64d8d8e08 100644 --- a/tests/path/win32.c +++ b/tests/path/win32.c @@ -1,6 +1,5 @@ #include "clar_libgit2.h" -#include "path.h" #ifdef GIT_WIN32 #include "win32/path_w32.h" |
