diff --git a/src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp b/src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp index 959de54ce..226612626 100644 --- a/src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp +++ b/src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp @@ -236,10 +236,11 @@ bool AnyConverter::doConvertFileToFile(const Stage stage, const Containers::Stri const Containers::StringView formatFrom = stringForFormat( _state->inputFormat != Format::Unspecified ? _state->inputFormat : formatForExtension("ShaderTools::AnyConverter::convertFileToFile():", from) ); + if(formatFrom.isEmpty()) return {}; const Containers::StringView formatTo = stringForFormat( _state->outputFormat != Format::Unspecified ? _state->outputFormat : formatForExtension("ShaderTools::AnyConverter::convertFileToFile():", to) ); - if(formatFrom.isEmpty() || formatTo.isEmpty()) return {}; + if(formatTo.isEmpty()) return {}; /* Decide on a plugin name based on the format. This might result in invalid combinations such as SpirvToGlslShaderConverter which can't be diff --git a/src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp b/src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp index 3bea57e53..0bc8e2975 100644 --- a/src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp +++ b/src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp @@ -44,6 +44,7 @@ struct AnyConverterTest: TestSuite::Tester { explicit AnyConverterTest(); void validate(); + void validateUnknown(); void validateNotSupported(); void validatePreprocessNotSupported(); void validatePropagateFlags(); @@ -52,6 +53,8 @@ struct AnyConverterTest: TestSuite::Tester { void validatePropagatePreprocess(); void convert(); + void convertUnknownInput(); + void convertUnknownOutput(); void convertNotSupported(); void convertPreprocessNotSupported(); void convertDebugInfoNotSupported(); @@ -68,8 +71,6 @@ struct AnyConverterTest: TestSuite::Tester { void detectConvert(); void detectConvertExplicitFormat(); - void unknown(); - /* Explicitly forbid system-wide plugin dependencies. Tests that need those have their own manager. */ PluginManager::Manager _manager{"nonexistent"}; @@ -100,6 +101,7 @@ constexpr struct { AnyConverterTest::AnyConverterTest() { addTests({&AnyConverterTest::validate, + &AnyConverterTest::validateUnknown, &AnyConverterTest::validateNotSupported, &AnyConverterTest::validatePreprocessNotSupported, &AnyConverterTest::validatePropagateFlags, @@ -108,6 +110,8 @@ AnyConverterTest::AnyConverterTest() { &AnyConverterTest::validatePropagatePreprocess, &AnyConverterTest::convert, + &AnyConverterTest::convertUnknownInput, + &AnyConverterTest::convertUnknownOutput, &AnyConverterTest::convertNotSupported, &AnyConverterTest::convertPreprocessNotSupported, &AnyConverterTest::convertDebugInfoNotSupported, @@ -129,8 +133,6 @@ AnyConverterTest::AnyConverterTest() { addTests({&AnyConverterTest::detectConvertExplicitFormat}); - addTests({&AnyConverterTest::unknown}); - /* Load the plugin directly from the build tree. Otherwise it's static and already loaded. */ #ifdef ANYSHADERCONVERTER_PLUGIN_FILENAME @@ -159,6 +161,16 @@ void AnyConverterTest::validate() { std::make_pair(true, Utility::formatString("WARNING: {}:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved", filename))); } +void AnyConverterTest::validateUnknown() { + Containers::Pointer converter = _manager.instantiate("AnyShaderConverter"); + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_COMPARE(converter->validateFile({}, "dead.cg"), + std::make_pair(false, "")); + CORRADE_COMPARE(out.str(), "ShaderTools::AnyConverter::validateFile(): cannot determine the format of dead.cg\n"); +} + void AnyConverterTest::validateNotSupported() { CORRADE_SKIP("No plugin that would support just validation exists."); } @@ -310,6 +322,24 @@ void AnyConverterTest::convert() { "WARNING: {}:10: 'reserved__identifier' : identifiers containing consecutive underscores (\"__\") are reserved\n", inputFilename)); } +void AnyConverterTest::convertUnknownInput() { + Containers::Pointer converter = _manager.instantiate("AnyShaderConverter"); + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_VERIFY(!converter->convertFileToFile({}, "dead.cg", "whatever.osl")); + CORRADE_COMPARE(out.str(), "ShaderTools::AnyConverter::convertFileToFile(): cannot determine the format of dead.cg\n"); +} + +void AnyConverterTest::convertUnknownOutput() { + Containers::Pointer converter = _manager.instantiate("AnyShaderConverter"); + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_VERIFY(!converter->convertFileToFile({}, "file.spv", "whatever.osl")); + CORRADE_COMPARE(out.str(), "ShaderTools::AnyConverter::convertFileToFile(): cannot determine the format of whatever.osl\n"); +} + void AnyConverterTest::convertNotSupported() { CORRADE_SKIP("No plugin that would support just conversion exists."); } @@ -635,16 +665,6 @@ void AnyConverterTest::detectConvertExplicitFormat() { #endif } -void AnyConverterTest::unknown() { - std::ostringstream output; - Error redirectError{&output}; - - Containers::Pointer converter = _manager.instantiate("AnyShaderConverter"); - CORRADE_COMPARE(converter->validateFile({}, "dead.cg"), - std::make_pair(false, "")); - CORRADE_COMPARE(output.str(), "ShaderTools::AnyConverter::validateFile(): cannot determine the format of dead.cg\n"); -} - }}}} CORRADE_TEST_MAIN(Magnum::ShaderTools::Test::AnyConverterTest)