43 std::vector<std::string> expectedErrors;
44 constexpr char kExpectedErrorsStart[] =
"/*%%*";
45 constexpr char kExpectedErrorsEnd[] =
"*%%*/";
46 if (
const char* startPtr = strstr(shaderString, kExpectedErrorsStart)) {
47 startPtr += strlen(kExpectedErrorsStart);
48 if (
const char* endPtr = strstr(startPtr, kExpectedErrorsEnd)) {
50 std::stringstream stream{std::string{startPtr, endPtr}};
51 while (stream.good()) {
52 expectedErrors.push_back({});
53 std::getline(stream, expectedErrors.back(),
'\n');
54 if (expectedErrors.back().empty()) {
55 expectedErrors.pop_back();
61 return expectedErrors;
66 const std::vector<std::string>& expectedErrors,
67 std::string reportedErrors) {
70 std::string originalErrors = reportedErrors;
71 bool reportOriginalErrors =
false;
72 for (
const std::string& expectedError : expectedErrors) {
74 size_t pos = reportedErrors.find(expectedError.c_str());
75 if (
pos == std::string::npos) {
76 ERRORF(r,
"%s: Expected an error that wasn't reported:\n%s\n",
78 reportOriginalErrors =
true;
83 reportedErrors.erase(0,
pos + expectedError.size());
87 if (reportOriginalErrors) {
88 ERRORF(r,
"%s: The following errors were reported:\n%s\n",
99 "sksl/errors/InvalidBackendBindingFlagsGL.sksl",
100 "sksl/errors/InvalidThreadgroupRTS.rts",
101 "sksl/errors/LastFragColorWithoutCaps.sksl",
102 "sksl/errors/MeshFragmentWithShader.mfrag",
103 "sksl/errors/MeshFragmentWithBlender.mfrag",
104 "sksl/errors/MeshFragmentWithColorFilter.mfrag",
105 "sksl/errors/StaticIfTest.sksl",
106 "sksl/errors/StaticSwitchConditionalBreak.sksl",
107 "sksl/errors/StaticSwitchTest.sksl",
108 "sksl/errors/StaticSwitchWithConditionalBreak.sksl",
109 "sksl/errors/StaticSwitchWithConditionalContinue.sksl",
110 "sksl/errors/StaticSwitchWithConditionalReturn.sksl",
112 "sksl/errors/ComputeUniform.compute",
113 "sksl/errors/DuplicateBinding.compute",
114 "sksl/errors/InvalidThreadgroupCompute.compute",
115 "sksl/errors/UnspecifiedBinding.compute",
117 "sksl/runtime_errors/ReservedNameISampler2D.rts",
119#ifdef SK_ENABLE_OPTIMIZE_SIZE
120 "sksl/errors/ArrayInlinedIndexOutOfRange.sksl",
121 "sksl/errors/MatrixInlinedIndexOutOfRange.sksl",
122 "sksl/errors/OverflowInlinedLiteral.sksl",
123 "sksl/errors/VectorInlinedIndexOutOfRange.sksl",
126 if (kTestsToSkip->contains(testFile)) {
127 INFOF(r,
"%s: skipped in SK_ENABLE_OPTIMIZE_SIZE mode", testFile);
137 std::string shaderString{
reinterpret_cast<const char*
>(shaderData->bytes()),
145 std::unique_ptr<SkSL::Program> program =
compiler.convertProgram(kind, std::move(shaderString),
150 ERRORF(r,
"%s: Expected failure, but compiled successfully",
159 const char* extension,
160 const std::function<
void(
const char*)>&
run) {
172 iterate_dir(
"sksl/errors/",
".sksl", [&](
const char* path) {
178 iterate_dir(
"sksl/errors/",
".compute", [&](
const char* path) {
184 iterate_dir(
"sksl/errors/",
".mvert", [&](
const char* path) {
190 iterate_dir(
"sksl/errors/",
".mfrag", [&](
const char* path) {
196 iterate_dir(
"sksl/errors/",
".rts", [&](
const char* path) {
199 iterate_dir(
"sksl/runtime_errors/",
".rts", [&](
const char* path) {
205 iterate_dir(
"sksl/runtime_errors/",
".rtcf", [&](
const char* path) {
211 iterate_dir(
"sksl/runtime_errors/",
".rtb", [&](
const char* path) {
sk_sp< SkData > GetResourceAsData(const char *resource)
SkString GetResourcePath(const char *resource)
static void iterate_dir(const char *directory, const char *extension, const std::function< void(const char *)> &run)
static void check_expected_errors(skiatest::Reporter *r, const char *testFile, const std::vector< std::string > &expectedErrors, std::string reportedErrors)
static void test_expect_fail(skiatest::Reporter *r, const char *testFile, SkSL::ProgramKind kind)
static std::vector< std::string > get_expected_errors(const char *shaderString)
#define DEF_TEST(name, reporter)
#define INFOF(REPORTER,...)
SK_SPI bool next(SkString *name, bool getDir=false)
static SkString Join(const char *rootPath, const char *relativePath)
static SkString Basename(const char *fullPath)
const char * c_str() const