Browse Source

AnyShaderConverter: test also unknown extension for conversion.

And make it return right after the first error. Also clean up some
old-style code -- the redirection should be restricted to the smallest
scope possible.
pull/495/head
Vladimír Vondruš 5 years ago
parent
commit
bbb6fd69c0
  1. 3
      src/MagnumPlugins/AnyShaderConverter/AnyConverter.cpp
  2. 48
      src/MagnumPlugins/AnyShaderConverter/Test/AnyConverterTest.cpp

3
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

48
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<AbstractConverter> _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<AbstractConverter> 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<AbstractConverter> 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<AbstractConverter> 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<AbstractConverter> 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)

Loading…
Cancel
Save