+
+
+GlslCompilerTest::GlslCompilerTest()
+{
+ load_all_test_cases("glsl");
+ for(const auto &tc: test_cases)
+ add(&GlslCompilerTest::run_test_case, &tc, tc.name);
+}
+
+void GlslCompilerTest::run_test_case(const TestCase *test_case)
+{
+ GL::SL::Compiler compiler(GL::SL::Features::all());
+ try
+ {
+ compiler.set_source(test_case->source, "<test>");
+ if(test_case->compile_mode==GL::SL::Compiler::PROGRAM)
+ compiler.specialize(test_case->spec_values);
+ compiler.compile(test_case->compile_mode);
+ }
+ catch(const GL::SL::invalid_shader_source &exc)
+ {
+ if(!test_case->expected_error.empty())
+ {
+ debug("Errors from compile:");
+ debug(exc.what());
+ verify_error(exc.what(), test_case->expected_error);
+ return;
+ }
+ throw;
+ }
+
+ if(!test_case->expected_error.empty())
+ fail("Error expected but none thrown");
+
+ auto stages = compiler.get_stages();
+ for(auto s: stages)
+ {
+ auto i = test_case->expected_output.find(s);
+ if(i==test_case->expected_output.end())
+ fail(format("Compiler produced extra stage %s", GL::SL::Stage::get_stage_name(s)));
+
+ string output = compiler.get_stage_glsl(s);
+ debug(format("Output for stage %s:", GL::SL::Stage::get_stage_name(s)));
+ auto lines = split_fields(output, '\n');
+ for(unsigned j=0; j<lines.size(); ++j)
+ debug(format("%3d: %s", j+1, lines[j]));
+
+ verify_output(output, i->second);
+ }
+
+ for(const auto &s: test_case->expected_output)
+ if(find(stages, s.first)==stages.end())
+ fail(format("Compiler didn't produce stage %s", GL::SL::Stage::get_stage_name(s.first)));
+}