From 30d0decf5852d89964af9b2a31fe435d4ee41483 Mon Sep 17 00:00:00 2001 From: Songlx516 Date: Sat, 5 Sep 2026 23:05:37 +0800 Subject: [PATCH] test(rar): keep real fixtures in fixtures-real/ (make_fixtures wipes fixtures/) tests/make_fixtures.py rmtree()s tests/fixtures on every run-tests.sh invocation, silently deleting the real RAR fixtures. The WinRAR generator now writes tests/fixtures-real/; run-tests.sh passes it as a third argument to test-rar-extract, which resolves v6/volume/encrypted checks against it and falls back to SKIP when absent. --- tests/make-rar-fixtures.bat | 9 ++++++--- tests/run-tests.sh | 6 +++++- tests/test_rar_extract.c | 18 +++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/make-rar-fixtures.bat b/tests/make-rar-fixtures.bat index a46bcb9..7ceda8a 100644 --- a/tests/make-rar-fixtures.bat +++ b/tests/make-rar-fixtures.bat @@ -1,8 +1,9 @@ @echo off REM Generate real RAR fixtures for the v1.9 host test suite. REM Requires WinRAR command-line Rar.exe (ships with normal WinRAR install). -REM Outputs into tests\fixtures\ - rerun any time fixture needs change. -REM NOTE: keep this file pure ASCII (cmd.exe uses the ANSI codepage). +REM Outputs into tests\fixtures-real\ - kept OUT of tests\fixtures\ because +REM tests\make_fixtures.py wipes that directory on every test run. +REM Rerun any time fixture needs change. NOTE: keep this file pure ASCII. setlocal EnableDelayedExpansion set RAREXE= @@ -16,7 +17,9 @@ if "%RAREXE%"=="" ( echo Using: %RAREXE% "%RAREXE%" 2>nul | findstr /c:"RAR " >nul || (echo [ERROR] %RAREXE% does not look like WinRAR & exit /b 1) -set FIX=%~dp0fixtures +set FIX=%~dp0fixtures-real +if exist "%FIX%" rmdir /s /q "%FIX%" +mkdir "%FIX%" set STAGE=%~dp0fixture-stage if exist "%STAGE%" rmdir /s /q "%STAGE%" mkdir "%STAGE%\dir" 2>nul diff --git a/tests/run-tests.sh b/tests/run-tests.sh index bdad6c5..27abaf5 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -96,4 +96,8 @@ RAR_LIBS=() "$BUILD/zip_extract.o" "${objs[@]}" "${rar_objs[@]}" "${RAR_LIBS[@]}" "$BUILD/test-zip-extract" "$ROOT/tests/fixtures" "$BUILD/work-zip" -"$BUILD/test-rar-extract" "$ROOT/tests/fixtures" "$BUILD/work-rar" +# Real RAR fixtures (v6 / multi-volume / encrypted) live in fixtures-real/, +# generated by tests/make-rar-fixtures.bat (WinRAR required); fixtures/ +# itself is wiped by make_fixtures.py on every run. +"$BUILD/test-rar-extract" "$ROOT/tests/fixtures" "$BUILD/work-rar" \ + "$ROOT/tests/fixtures-real" diff --git a/tests/test_rar_extract.c b/tests/test_rar_extract.c index 8db3ab6..e03b369 100644 --- a/tests/test_rar_extract.c +++ b/tests/test_rar_extract.c @@ -28,6 +28,7 @@ #include "posix_compat.h" static const char *g_fixtures; +static const char *g_fixtures_real; static char g_work[4096]; static int g_failures; static int g_checks; @@ -37,6 +38,11 @@ fixture_path(char *out, size_t size, const char *name) { snprintf(out, size, "%s/%s", g_fixtures, name); } +static void +fixture_real_path(char *out, size_t size, const char *name) { + snprintf(out, size, "%s/%s", g_fixtures_real, name); +} + static void work_path(char *out, size_t size, const char *name) { snprintf(out, size, "%s/%s", g_work, name); @@ -315,7 +321,7 @@ test_real_archives(void) { zipx_result_t res; zipx_status_t st; char src[4096]; - fixture_path(src, sizeof(src), "basic-v6.rar"); + fixture_real_path(src, sizeof(src), "basic-v6.rar"); if(exists(src)) { memset(&res, 0, sizeof(res)); st = rar_extract(src, dst, ZIPX_CONFLICT_FAIL, @@ -343,7 +349,7 @@ test_real_archives(void) { zipx_result_t res; zipx_status_t st; char src[4096]; - fixture_path(src, sizeof(src), "basic-rar4.rar"); + fixture_real_path(src, sizeof(src), "basic-rar4.rar"); if(exists(src)) { memset(&res, 0, sizeof(res)); st = rar_extract(src, dst, ZIPX_CONFLICT_FAIL, @@ -369,7 +375,7 @@ test_real_archives(void) { zipx_result_t res; zipx_status_t st; char src[4096]; - fixture_path(src, sizeof(src), "vol.part1.rar"); + fixture_real_path(src, sizeof(src), "vol.part1.rar"); if(exists(src)) { memset(&res, 0, sizeof(res)); st = rar_extract(src, dst, ZIPX_CONFLICT_FAIL, @@ -396,7 +402,7 @@ test_real_archives(void) { zipx_result_t res; zipx_status_t st; char src[4096]; - fixture_path(src, sizeof(src), "enc-v6.rar"); + fixture_real_path(src, sizeof(src), "enc-v6.rar"); if(exists(src)) { memset(&res, 0, sizeof(res)); st = rar_extract(src, dst, ZIPX_CONFLICT_FAIL, @@ -416,10 +422,12 @@ test_real_archives(void) { int main(int argc, char **argv) { if(argc < 3) { - fprintf(stderr, "usage: %s \n", argv[0]); + fprintf(stderr, "usage: %s [real-fixtures-dir]\n", + argv[0]); return 2; } g_fixtures = argv[1]; + g_fixtures_real = (argc >= 4) ? argv[3] : argv[1]; snprintf(g_work, sizeof(g_work), "%s", argv[2]); mkdir(g_work, 0777);