Skip to content

Commit

Permalink
Fix the zlib-ng failing tests, for real
Browse files Browse the repository at this point in the history
I failed to properly account for the case in which the two string are
completely equal.

(cherry picked from commit 4b31974)
  • Loading branch information
tristan957 authored and eli-schwartz committed Jul 26, 2024
1 parent 4df1254 commit 808730a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 10 additions & 7 deletions test cases/linuxlike/1 pkg-config/prog-checkver.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#include <string.h>

static bool check_version(const char *zlib_ver, const char *found_zlib) {
if (zlib_ver == found_zlib)
return true;

if (strcmp(zlib_ver, found_zlib) == 0)
return true;

#ifdef ZLIBNG_VERSION
const char *ptr = strstr(zlib_ver, found_zlib);

Expand All @@ -16,22 +22,19 @@ static bool check_version(const char *zlib_ver, const char *found_zlib) {
* that FOUND_ZLIB is the start of ZLIB_VERSION, so compare the rest.
*/
ptr += strlen(found_zlib);
if (strcmp(ptr, ".zlib-ng") != 0)
return false;
#else
if (strcmp(zlib_ver, found_zlib) != 0)
return false;
if (strcmp(ptr, ".zlib-ng") == 0)
return true;
#endif

return true;
return false;
}

int main(void) {
void * something = deflate;
if (!check_version(ZLIB_VERSION, FOUND_ZLIB)) {
printf("Meson found '%s' but zlib is '%s'\n", FOUND_ZLIB, ZLIB_VERSION);
#ifdef ZLIBNG_VERSION
puts("Note that in the case of zlib-ng, a version suffix of .zlib-ng is expected\n");
puts("Note that in the case of zlib-ng, a version suffix of .zlib-ng is expected");
#endif
return 2;
}
Expand Down
17 changes: 10 additions & 7 deletions test cases/linuxlike/13 cmake dependency/prog-checkver.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#include <string.h>

static bool check_version(const char *zlib_ver, const char *found_zlib) {
if (zlib_ver == found_zlib)
return true;

if (strcmp(zlib_ver, found_zlib) == 0)
return true;

#ifdef ZLIBNG_VERSION
const char *ptr = strstr(zlib_ver, found_zlib);

Expand All @@ -16,22 +22,19 @@ static bool check_version(const char *zlib_ver, const char *found_zlib) {
* that FOUND_ZLIB is the start of ZLIB_VERSION, so compare the rest.
*/
ptr += strlen(found_zlib);
if (strcmp(ptr, ".zlib-ng") != 0)
return false;
#else
if (strcmp(zlib_ver, found_zlib) != 0)
return false;
if (strcmp(ptr, ".zlib-ng") == 0)
return true;
#endif

return true;
return false;
}

int main(void) {
void * something = deflate;
if (!check_version(ZLIB_VERSION, FOUND_ZLIB)) {
printf("Meson found '%s' but zlib is '%s'\n", FOUND_ZLIB, ZLIB_VERSION);
#ifdef ZLIBNG_VERSION
puts("Note that in the case of zlib-ng, a version suffix of .zlib-ng is expected\n");
puts("Note that in the case of zlib-ng, a version suffix of .zlib-ng is expected");
#endif
return 2;
}
Expand Down

0 comments on commit 808730a

Please sign in to comment.