Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[flutter_tools] add compilation failure tests for new cases added in …
Browse files Browse the repository at this point in the history
…impellerc (#114757)
  • Loading branch information
jonahwilliams authored Nov 7, 2022
1 parent f1cdfa2 commit e4e902d
Showing 1 changed file with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ void main() {
logger = BufferLogger.test();
});

Future<void> testCompileShader(String source) async {
final Directory tmpDir = globals.fs.systemTempDirectory.createTempSync(
'shader_compiler_test.',
);
final File file = tmpDir.childFile('test_shader.frag')
..writeAsStringSync(source);
final ShaderCompiler shaderCompiler = ShaderCompiler(
processManager: globals.processManager,
logger: logger,
fileSystem: globals.fs,
artifacts: globals.artifacts!,
);
await shaderCompiler.compileShader(
input: file,
outputPath: tmpDir.childFile('test_shader.frag.out').path,
target: ShaderTarget.sksl,
json: false,
);
}

testUsingContext('impellerc .iplr output has correct permissions', () async {
if (globals.platform.isWindows) {
return;
Expand Down Expand Up @@ -54,4 +74,66 @@ void main() {
final int expectedMode = int.parse('644', radix: 8);
expect(resultFile.statSync().mode & expectedMode, equals(expectedMode));
});

testUsingContext('Compilation error with in storage', () async {
const String kShaderWithInput = '''
in float foo;
out vec4 fragColor;
void main() {
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
''';

expect(() => testCompileShader(kShaderWithInput), throwsA(isA<ShaderCompilerException>()
.having(
(ShaderCompilerException exception) => exception.message,
'message',
contains('SkSL does not support inputs'),
),
));
});

testUsingContext('Compilation error with UBO', () async {
const String kShaderWithInput = '''
uniform Data {
vec4 foo;
} data;
out vec4 fragColor;
void main() {
fragColor = data.foo;
}
''';

expect(() => testCompileShader(kShaderWithInput), throwsA(isA<ShaderCompilerException>()
.having(
(ShaderCompilerException exception) => exception.message,
'message',
contains('SkSL does not support UBOs or SSBOs'),
),
));
});

testUsingContext('Compilation error with texture arguments besides position or sampler', () async {
const String kShaderWithInput = '''
uniform sampler2D tex;
out vec4 fragColor;
void main() {
fragColor = texture(tex, vec2(0.5, 0.3), 0.5);
}
''';

expect(() => testCompileShader(kShaderWithInput), throwsA(isA<ShaderCompilerException>()
.having(
(ShaderCompilerException exception) => exception.message,
'message',
contains('Only sampler and position arguments are supported in texture() calls'),
),
));
});
}

0 comments on commit e4e902d

Please sign in to comment.