1
0
mirror of https://github.com/upx/upx.git synced 2025-08-11 22:52:30 +08:00

src: add --version-short option; support doctest --dt-XXX options; cleanups

This commit is contained in:
Markus F.X.J. Oberhumer
2022-10-23 23:09:13 +02:00
parent fff53efc05
commit 283c1cf931
7 changed files with 61 additions and 23 deletions

View File

@ -161,7 +161,7 @@ endif()
# "make test"
#***********************************************************************
if (NOT CMAKE_CROSSCOMPILING)
if(NOT CMAKE_CROSSCOMPILING)
include(CTest)
set(exe ${CMAKE_EXECUTABLE_SUFFIX})
set(upx_self_exe "$<TARGET_FILE:upx>")

View File

@ -778,7 +778,7 @@ void show_head();
void show_help(int verbose=0);
void show_license();
void show_usage();
void show_version(int);
void show_version(bool one_line=false);
// compress.cpp
unsigned upx_adler32(const void *buf, unsigned len, unsigned adler=1);

View File

@ -376,18 +376,18 @@ void show_license(void)
//
**************************************************************************/
void show_version(int x)
void show_version(bool one_line)
{
FILE *fp = stdout;
const char *v;
UNUSED(x);
UNUSED(v);
fprintf(fp, "upx %s\n", UPX_VERSION_STRING
#if defined(UPX_VERSION_GITREV)
"-git-" UPX_VERSION_GITREV
#endif
);
if (one_line)
return;
#if (WITH_NRV)
v = upx_nrv_version_string();
if (v != nullptr && v[0])

View File

@ -419,10 +419,11 @@ static int do_option(int optc, const char *arg) {
set_cmd(CMD_VERSION);
break;
case 'V' + 256:
case 998:
/* according to GNU standards */
set_term(stdout);
opt->console = CON_FILE;
show_version(0);
show_version(optc == 998 ? true : false);
e_exit(EXIT_OK);
break;
@ -760,6 +761,11 @@ static int do_option(int optc, const char *arg) {
opt->o_unix.force_pie = true;
break;
#if !defined(DOCTEST_CONFIG_DISABLE)
case 999: // doctest --dt-XXX option
break;
#endif
case '\0':
return -1;
case ':':
@ -923,6 +929,35 @@ int main_get_options(int argc, char **argv) {
{"8mib-ram", 0x10, N, 673},
{"8mb-ram", 0x10, N, 673},
#if !defined(DOCTEST_CONFIG_DISABLE)
// [doctest] Query flags - the program quits after them. Available:
{"dt-c", 0x10, N, 999},
{"dt-count", 0x10, N, 999},
{"dt-h", 0x10, N, 999},
{"dt-help", 0x10, N, 999},
{"dt-lr", 0x10, N, 999},
{"dt-list-reporters", 0x10, N, 999},
{"dt-ltc", 0x10, N, 999},
{"dt-list-test-cases", 0x10, N, 999},
{"dt-lts", 0x10, N, 999},
{"dt-list-test-suites", 0x10, N, 999},
{"dt-v", 0x10, N, 999},
{"dt-version", 0x10, N, 999},
// [doctest] Bool options - can be used like flags and true is assumed. Available:
{"dt-d", 0x12, N, 999},
{"dt-duration", 0x12, N, 999},
{"dt-e", 0x12, N, 999},
{"dt-exit", 0x12, N, 999},
{"dt-m", 0x12, N, 999},
{"dt-minimal", 0x12, N, 999},
{"dt-nt", 0x12, N, 999},
{"dt-no-throw", 0x12, N, 999},
{"dt-nr", 0x12, N, 999},
{"dt-no-run", 0x12, N, 999},
{"dt-s", 0x12, N, 999},
{"dt-success", 0x12, N, 999},
#endif
{nullptr, 0, nullptr, 0}
};
@ -1100,6 +1135,8 @@ static void first_options(int argc, char **argv) {
}
if (strcmp(argv[i], "--version") == 0)
do_option('V' + 256, argv[i]);
if (strcmp(argv[i], "--version-short") == 0)
do_option(998, argv[i]);
}
for (i = 1; i < n; i++)
if (strcmp(argv[i], "--help") == 0)
@ -1195,7 +1232,7 @@ int upx_main(int argc, char *argv[]) {
e_exit(EXIT_OK);
break;
case CMD_VERSION:
show_version(1);
show_version();
e_exit(EXIT_OK);
break;
default:

View File

@ -57,6 +57,8 @@ void options_t::reset() {
#endif
o->verbose = 2;
opt->o_unix.osabi0 = 3; // 3 == ELFOSABI_LINUX
o->win32_pe.compress_exports = 1;
o->win32_pe.compress_icons = 2;
o->win32_pe.compress_resources = -1;

View File

@ -42,38 +42,35 @@ bool upx_doctest_check(int argc, char **argv) {
bool minimal = true; // only show failing tests
bool duration = false; // show timings
bool success = false; // show all tests
#if DEBUG
minimal = false;
#endif
e = getenv("UPX_DEBUG_DOCTEST_VERBOSE");
if (e && e[0] && strcmp(e, "0") != 0) {
if (e && e[0]) {
minimal = false;
if (strcmp(e, "2") == 0)
if (strcmp(e, "0") == 0) {
minimal = true;
} else if (strcmp(e, "2") == 0) {
duration = true;
if (strcmp(e, "3") == 0) {
} else if (strcmp(e, "3") == 0) {
duration = true;
success = true;
}
}
#if DEBUG
minimal = false;
// duration = true;
#endif
doctest::Context context;
#if 0
if (argc > 0 && argv != nullptr)
context.applyCommandLine(argc, argv);
#else
UNUSED(argc);
UNUSED(argv);
#endif
if (minimal)
context.setOption("dt-minimal", true);
if (duration)
context.setOption("dt-duration", true);
if (success)
context.setOption("dt-success", true);
// this requires that main_get_options() understands "--dt-XXX" options
if (argc > 0 && argv != nullptr)
context.applyCommandLine(argc, argv);
int r = context.run();
if (context.shouldExit() || r != 0)
return false;
#endif
#endif // DOCTEST_CONFIG_DISABLE
return true;
}

View File

@ -30,11 +30,13 @@
**************************************************************************/
#define DOCTEST_CONFIG_IMPLEMENT
#if !defined(UPX_DOCTEST_CONFIG_MULTITHREADING)
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
#endif
#if defined(__MSDOS__) && defined(__DJGPP__)
#define DOCTEST_CONFIG_NO_POSIX_SIGNALS
#endif
#define DOCTEST_CONFIG_NO_UNPREFIXED_OPTIONS
#if !defined(DOCTEST_CONFIG_DISABLE)
#include <doctest/parts/doctest.cpp>
#endif