From 2c280f6b970c3fb34346e5bc79a5d22b91ce242e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 27 Jul 2019 01:05:35 +0200 Subject: [PATCH] Audio: ignore command-line options not related to audio. --- src/Magnum/Audio/Context.cpp | 3 ++- src/Magnum/Audio/Context.h | 4 ++++ src/Magnum/Audio/Test/ContextALTest.cpp | 11 ++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Audio/Context.cpp b/src/Magnum/Audio/Context.cpp index ff4163eab..f2688aca7 100644 --- a/src/Magnum/Audio/Context.cpp +++ b/src/Magnum/Audio/Context.cpp @@ -125,7 +125,8 @@ Context& Context::current() { Context::Context(Int argc, const char** argv): Context(Configuration{}, argc, argv) {} Context::Context(NoCreateT, Int argc, const char** argv) noexcept: _device{}, _context{} { - Utility::Arguments args{"magnum"}; + Utility::Arguments args{"magnum", + Utility::Arguments::Flag::IgnoreUnknownOptions}; args.addOption("log", "default").setHelp("log", "console logging", "default|quiet|verbose") .setFromEnvironment("log") .parse(argc, argv); diff --git a/src/Magnum/Audio/Context.h b/src/Magnum/Audio/Context.h index abb3db5a0..ff5da52a3 100644 --- a/src/Magnum/Audio/Context.h +++ b/src/Magnum/Audio/Context.h @@ -105,6 +105,10 @@ Note that all options are prefixed with `--magnum-` to avoid conflicts with options passed to the application itself. Options that don't have this prefix are completely ignored, see documentation of the @ref Utility-Arguments-delegating "Utility::Arguments" class for details. +Moreover, `--magnum`-prefixed options unrelated to audio (such as those defined +by @ref GL-Context-command-line "GL::Context") are ignored as well. In order to +provide a complete help and command-line argument diagnostic, you should +instantiate this class *after* @ref GL::Context. */ class MAGNUM_AUDIO_EXPORT Context { public: diff --git a/src/Magnum/Audio/Test/ContextALTest.cpp b/src/Magnum/Audio/Test/ContextALTest.cpp index 4f5a44ece..5f28e7669 100644 --- a/src/Magnum/Audio/Test/ContextALTest.cpp +++ b/src/Magnum/Audio/Test/ContextALTest.cpp @@ -40,6 +40,7 @@ struct ContextALTest: TestSuite::Tester { void constructMove(); void quietLog(); + void ignoreUnrelatedOptions(); void extensionsString(); void isExtensionEnabled(); @@ -51,7 +52,8 @@ ContextALTest::ContextALTest() { addInstancedTests({&ContextALTest::quietLog}, 2); - addTests({&ContextALTest::extensionsString, + addTests({&ContextALTest::ignoreUnrelatedOptions, + &ContextALTest::extensionsString, &ContextALTest::isExtensionEnabled}); } @@ -90,6 +92,13 @@ void ContextALTest::quietLog() { CORRADE_COMPARE(out.str().empty(), bool(testCaseInstanceId())); } +void ContextALTest::ignoreUnrelatedOptions() { + const char* argv[] = { "", "--magnum-gpu-validation", "on" }; + + Context context{Containers::arraySize(argv), argv}; + CORRADE_VERIFY(Context::hasCurrent()); +} + void ContextALTest::extensionsString() { Context context;