@@ -10,8 +10,8 @@ import 'package:flutter_tools/src/build_system/targets/shader_compiler.dart';
10
10
import '../../../src/common.dart' ;
11
11
import '../../../src/fake_process_manager.dart' ;
12
12
13
- const String shaderPath = '/shaders/my_shader.frag' ;
14
- const String notShaderPath = '/shaders/not_a_shader .file' ;
13
+ const String fragPath = '/shaders/my_shader.frag' ;
14
+ const String notFragPath = '/shaders/not_a_frag .file' ;
15
15
const String outputPath = '/output/shaders/my_shader.spv' ;
16
16
17
17
void main () {
@@ -27,35 +27,51 @@ void main() {
27
27
impellerc = artifacts.getHostArtifact (HostArtifact .impellerc).path;
28
28
29
29
fileSystem.file (impellerc).createSync (recursive: true );
30
- fileSystem.file (shaderPath ).createSync (recursive: true );
31
- fileSystem.file (notShaderPath ).createSync (recursive: true );
30
+ fileSystem.file (fragPath ).createSync (recursive: true );
31
+ fileSystem.file (notFragPath ).createSync (recursive: true );
32
32
});
33
33
34
- testWithoutContext ('compileShader returns false for non-shader files' , () async {
34
+ testWithoutContext ('compileShader invokes impellerc for .frag files' , () async {
35
+ final FakeProcessManager processManager = FakeProcessManager .list (< FakeCommand > [
36
+ FakeCommand (
37
+ command: < String > [
38
+ impellerc,
39
+ '--flutter-spirv' ,
40
+ '--spirv=$outputPath ' ,
41
+ '--input=$fragPath ' ,
42
+ '--input-type=frag' ,
43
+ ],
44
+ onRun: () {
45
+ fileSystem.file (outputPath).createSync (recursive: true );
46
+ },
47
+ ),
48
+ ]);
35
49
final ShaderCompiler shaderCompiler = ShaderCompiler (
36
- processManager: FakeProcessManager . empty () ,
50
+ processManager: processManager ,
37
51
logger: logger,
38
52
fileSystem: fileSystem,
39
53
artifacts: artifacts,
40
54
);
41
55
42
56
expect (
43
57
await shaderCompiler.compileShader (
44
- input: fileSystem.file (notShaderPath ),
58
+ input: fileSystem.file (fragPath ),
45
59
outputPath: outputPath,
46
60
),
47
- false ,
61
+ true ,
48
62
);
63
+ expect (fileSystem.file (outputPath).existsSync (), true );
49
64
});
50
65
51
- testWithoutContext ('compileShader returns true for shader files' , () async {
66
+ testWithoutContext ('compileShader invokes impellerc for non-.frag files' , () async {
52
67
final FakeProcessManager processManager = FakeProcessManager .list (< FakeCommand > [
53
68
FakeCommand (
54
69
command: < String > [
55
70
impellerc,
56
71
'--flutter-spirv' ,
57
72
'--spirv=$outputPath ' ,
58
- '--input=$shaderPath ' ,
73
+ '--input=$notFragPath ' ,
74
+ '--input-type=frag' ,
59
75
],
60
76
onRun: () {
61
77
fileSystem.file (outputPath).createSync (recursive: true );
@@ -71,11 +87,41 @@ void main() {
71
87
72
88
expect (
73
89
await shaderCompiler.compileShader (
74
- input: fileSystem.file (shaderPath ),
90
+ input: fileSystem.file (notFragPath ),
75
91
outputPath: outputPath,
76
92
),
77
93
true ,
78
94
);
79
95
expect (fileSystem.file (outputPath).existsSync (), true );
80
96
});
97
+
98
+ testWithoutContext ('compileShader throws an exception when impellerc fails' , () async {
99
+ final FakeProcessManager processManager = FakeProcessManager .list (< FakeCommand > [
100
+ FakeCommand (
101
+ command: < String > [
102
+ impellerc,
103
+ '--flutter-spirv' ,
104
+ '--spirv=$outputPath ' ,
105
+ '--input=$notFragPath ' ,
106
+ '--input-type=frag' ,
107
+ ],
108
+ exitCode: 1 ,
109
+ ),
110
+ ]);
111
+ final ShaderCompiler shaderCompiler = ShaderCompiler (
112
+ processManager: processManager,
113
+ logger: logger,
114
+ fileSystem: fileSystem,
115
+ artifacts: artifacts,
116
+ );
117
+
118
+ await expectLater (
119
+ () => shaderCompiler.compileShader (
120
+ input: fileSystem.file (notFragPath),
121
+ outputPath: outputPath,
122
+ ),
123
+ throwsA (isA <ShaderCompilerException >()),
124
+ );
125
+ expect (fileSystem.file (outputPath).existsSync (), false );
126
+ });
81
127
}
0 commit comments