Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4881b335
Unverified
Commit
4881b335
authored
May 12, 2021
by
Alexandre Ardhuin
Committed by
GitHub
May 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use throwsA matcher instead of try-catch-fail (#82290)
parent
e621ebfb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
168 additions
and
154 deletions
+168
-154
prepare_package_test.dart
dev/bots/test/prepare_package_test.dart
+8
-8
goldens_test.dart
packages/flutter_test/test/goldens_test.dart
+80
-68
matchers_test.dart
packages/flutter_test/test/matchers_test.dart
+36
-28
test_text_input_test.dart
packages/flutter_test/test/test_text_input_test.dart
+4
-6
cache_test.dart
packages/flutter_tools/test/general.shard/cache_test.dart
+11
-14
flutter_command_test.dart
...tools/test/general.shard/runner/flutter_command_test.dart
+29
-30
No files found.
dev/bots/test/prepare_package_test.dart
View file @
4881b335
...
@@ -274,14 +274,14 @@ void main() {
...
@@ -274,14 +274,14 @@ void main() {
);
);
await
creator
.
initializeRepo
();
await
creator
.
initializeRepo
();
try
{
await
expectLater
(
await
creator
.
createArchive
();
()
=>
creator
.
createArchive
(),
fail
(
'failed to throw'
);
throwsA
(
isA
<
PreparePackageException
>().
having
(
}
on
Exception
catch
(
e
)
{
(
PreparePackageException
exception
)
=>
exception
.
message
,
expect
(
e
is
PreparePackageException
,
true
);
'message'
,
final
PreparePackageException
exception
=
e
as
PreparePackageException
;
contains
(
'The binary
$binPath
was not codesigned!'
),
expect
(
exception
.
message
,
contains
(
'The binary
$binPath
was not codesigned!'
));
)),
}
);
},
skip:
!
platform
.
isMacOS
);
},
skip:
!
platform
.
isMacOS
);
});
});
...
...
packages/flutter_test/test/goldens_test.dart
View file @
4881b335
...
@@ -183,11 +183,14 @@ void main() {
...
@@ -183,11 +183,14 @@ void main() {
test
(
'and generates correct output in the correct base location'
,
()
async
{
test
(
'and generates correct output in the correct base location'
,
()
async
{
comparator
=
LocalFileComparator
(
Uri
.
parse
(
'local_test.dart'
),
pathStyle:
fs
.
path
.
style
);
comparator
=
LocalFileComparator
(
Uri
.
parse
(
'local_test.dart'
),
pathStyle:
fs
.
path
.
style
);
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kColorFailurePngBytes
);
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kColorFailurePngBytes
);
try
{
await
expectLater
(
await
doComparison
();
()
=>
doComparison
(),
fail
(
'TestFailure expected but not thrown.'
);
throwsA
(
isA
<
FlutterError
>().
having
(
}
on
FlutterError
catch
(
error
)
{
(
FlutterError
error
)
=>
error
.
message
,
expect
(
error
.
message
,
contains
(
'% diff detected'
));
'message'
,
contains
(
'% diff detected'
),
)),
);
final
io
.
File
master
=
fs
.
file
(
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
fix
(
'/failures/golden_masterImage.png'
)
);
);
...
@@ -204,7 +207,6 @@ void main() {
...
@@ -204,7 +207,6 @@ void main() {
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
}
});
});
test
(
'and generates correct output when files are in a subdirectory'
,
()
async
{
test
(
'and generates correct output when files are in a subdirectory'
,
()
async
{
...
@@ -212,11 +214,14 @@ void main() {
...
@@ -212,11 +214,14 @@ void main() {
fs
.
file
(
fix
(
'subdir/golden.png'
))
fs
.
file
(
fix
(
'subdir/golden.png'
))
..
createSync
(
recursive:
true
)
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(
_kColorFailurePngBytes
);
..
writeAsBytesSync
(
_kColorFailurePngBytes
);
try
{
await
expectLater
(
await
doComparison
(
'subdir/golden.png'
);
()
=>
doComparison
(
'subdir/golden.png'
),
fail
(
'TestFailure expected but not thrown.'
);
throwsA
(
isA
<
FlutterError
>().
having
(
}
on
FlutterError
catch
(
error
)
{
(
FlutterError
error
)
=>
error
.
message
,
expect
(
error
.
message
,
contains
(
'% diff detected'
));
'message'
,
contains
(
'% diff detected'
),
)),
);
final
io
.
File
master
=
fs
.
file
(
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
fix
(
'/failures/golden_masterImage.png'
)
);
);
...
@@ -233,46 +238,53 @@ void main() {
...
@@ -233,46 +238,53 @@ void main() {
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
}
});
});
test
(
'when golden file does not exist'
,
()
async
{
test
(
'when golden file does not exist'
,
()
async
{
try
{
await
expectLater
(
await
doComparison
();
()
=>
doComparison
(),
fail
(
'TestFailure expected but not thrown.'
);
throwsA
(
isA
<
TestFailure
>().
having
(
}
on
TestFailure
catch
(
error
)
{
(
TestFailure
error
)
=>
error
.
message
,
expect
(
error
.
message
,
contains
(
'Could not be compared against non-existent file'
));
'message'
,
}
contains
(
'Could not be compared against non-existent file'
),
)),
);
});
});
test
(
'when images are not the same size'
,
()
async
{
test
(
'when images are not the same size'
,
()
async
{
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kSizeFailurePngBytes
);
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kSizeFailurePngBytes
);
try
{
await
expectLater
(
await
doComparison
();
()
=>
doComparison
(),
fail
(
'TestFailure expected but not thrown.'
);
throwsA
(
isA
<
FlutterError
>().
having
(
}
on
FlutterError
catch
(
error
)
{
(
FlutterError
error
)
=>
error
.
message
,
expect
(
error
.
message
,
contains
(
'image sizes do not match'
));
'message'
,
}
contains
(
'image sizes do not match'
),
)),
);
});
});
test
(
'when pixels do not match'
,
()
async
{
test
(
'when pixels do not match'
,
()
async
{
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kColorFailurePngBytes
);
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kColorFailurePngBytes
);
try
{
await
expectLater
(
await
doComparison
();
()
=>
doComparison
(),
fail
(
'TestFailure expected but not thrown.'
);
throwsA
(
isA
<
FlutterError
>().
having
(
}
on
FlutterError
catch
(
error
)
{
(
FlutterError
error
)
=>
error
.
message
,
expect
(
error
.
message
,
contains
(
'% diff detected'
));
'message'
,
}
contains
(
'% diff detected'
),
)),
);
});
});
test
(
'when golden bytes are empty'
,
()
async
{
test
(
'when golden bytes are empty'
,
()
async
{
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(<
int
>[]);
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(<
int
>[]);
try
{
await
expectLater
(
await
doComparison
();
()
=>
doComparison
(),
fail
(
'TestFailure expected but not thrown.'
);
throwsA
(
isA
<
FlutterError
>().
having
(
}
on
FlutterError
catch
(
error
)
{
(
FlutterError
error
)
=>
error
.
message
,
expect
(
error
.
message
,
contains
(
'null image provided'
));
'message'
,
}
contains
(
'null image provided'
),
)),
);
});
});
});
});
});
});
...
...
packages/flutter_test/test/matchers_test.dart
View file @
4881b335
...
@@ -368,38 +368,44 @@ void main() {
...
@@ -368,38 +368,44 @@ void main() {
comparator
.
behavior
=
_ComparatorBehavior
.
returnFalse
;
comparator
.
behavior
=
_ComparatorBehavior
.
returnFalse
;
await
tester
.
pumpWidget
(
boilerplate
(
const
Text
(
'hello'
)));
await
tester
.
pumpWidget
(
boilerplate
(
const
Text
(
'hello'
)));
final
Finder
finder
=
find
.
byType
(
Text
);
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
fail
(
'TestFailure expected but not thrown'
);
throwsA
(
isA
<
TestFailure
>().
having
(
}
on
TestFailure
catch
(
error
)
{
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'does not match'
),
)),
);
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
expect
(
error
.
message
,
contains
(
'does not match'
));
}
});
});
testWidgets
(
'if comparator throws'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'if comparator throws'
,
(
WidgetTester
tester
)
async
{
comparator
.
behavior
=
_ComparatorBehavior
.
throwTestFailure
;
comparator
.
behavior
=
_ComparatorBehavior
.
throwTestFailure
;
await
tester
.
pumpWidget
(
boilerplate
(
const
Text
(
'hello'
)));
await
tester
.
pumpWidget
(
boilerplate
(
const
Text
(
'hello'
)));
final
Finder
finder
=
find
.
byType
(
Text
);
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
fail
(
'TestFailure expected but not thrown'
);
throwsA
(
isA
<
TestFailure
>().
having
(
}
on
TestFailure
catch
(
error
)
{
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'fake message'
),
)),
);
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
expect
(
error
.
message
,
contains
(
'fake message'
));
}
});
});
testWidgets
(
'if finder finds no widgets'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'if finder finds no widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
boilerplate
(
Container
()));
await
tester
.
pumpWidget
(
boilerplate
(
Container
()));
final
Finder
finder
=
find
.
byType
(
Text
);
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
fail
(
'TestFailure expected but not thrown'
);
throwsA
(
isA
<
TestFailure
>().
having
(
}
on
TestFailure
catch
(
error
)
{
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'no widget was found'
),
)),
);
expect
(
comparator
.
invocation
,
isNull
);
expect
(
comparator
.
invocation
,
isNull
);
expect
(
error
.
message
,
contains
(
'no widget was found'
));
}
});
});
testWidgets
(
'if finder finds multiple widgets'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'if finder finds multiple widgets'
,
(
WidgetTester
tester
)
async
{
...
@@ -407,13 +413,15 @@ void main() {
...
@@ -407,13 +413,15 @@ void main() {
children:
const
<
Widget
>[
Text
(
'hello'
),
Text
(
'world'
)],
children:
const
<
Widget
>[
Text
(
'hello'
),
Text
(
'world'
)],
)));
)));
final
Finder
finder
=
find
.
byType
(
Text
);
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
fail
(
'TestFailure expected but not thrown'
);
throwsA
(
isA
<
TestFailure
>().
having
(
}
on
TestFailure
catch
(
error
)
{
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'too many widgets'
),
)),
);
expect
(
comparator
.
invocation
,
isNull
);
expect
(
comparator
.
invocation
,
isNull
);
expect
(
error
.
message
,
contains
(
'too many widgets'
));
}
});
});
});
});
...
...
packages/flutter_test/test/test_text_input_test.dart
View file @
4881b335
...
@@ -43,11 +43,9 @@ void main() {
...
@@ -43,11 +43,9 @@ void main() {
throw
FlutterError
(
'A fake error occurred during action processing.'
);
throw
FlutterError
(
'A fake error occurred during action processing.'
);
});
});
try
{
await
expectLater
(
await
tester
.
testTextInput
.
receiveAction
(
TextInputAction
.
done
);
()
=>
tester
.
testTextInput
.
receiveAction
(
TextInputAction
.
done
),
fail
(
'Expected a PlatformException, but it was not thrown.'
);
throwsA
(
isA
<
PlatformException
>()),
}
catch
(
e
)
{
);
expect
(
e
,
isA
<
PlatformException
>());
}
});
});
}
}
packages/flutter_tools/test/general.shard/cache_test.dart
View file @
4881b335
...
@@ -288,12 +288,10 @@ void main() {
...
@@ -288,12 +288,10 @@ void main() {
processManager:
FakeProcessManager
.
any
(),
processManager:
FakeProcessManager
.
any
(),
logger:
logger
,
logger:
logger
,
);
);
try
{
await
expectLater
(
await
cache
.
updateAll
(<
DevelopmentArtifact
>{
()
=>
cache
.
updateAll
(<
DevelopmentArtifact
>{
null
}),
null
,
throwsA
(
isA
<
Exception
>()),
});
);
fail
(
'Mock thrown exception expected'
);
}
on
Exception
{
verify
(
artifact1
.
update
(
any
,
any
,
any
,
any
));
verify
(
artifact1
.
update
(
any
,
any
,
any
,
any
));
// Don't continue when retrieval fails.
// Don't continue when retrieval fails.
verifyNever
(
artifact2
.
update
(
any
,
any
,
any
,
any
));
verifyNever
(
artifact2
.
update
(
any
,
any
,
any
,
any
));
...
@@ -301,7 +299,6 @@ void main() {
...
@@ -301,7 +299,6 @@ void main() {
logger
.
errorText
,
logger
.
errorText
,
contains
(
'https://flutter.dev/community/china'
),
contains
(
'https://flutter.dev/community/china'
),
);
);
}
});
});
testWithoutContext
(
'Invalid URI for FLUTTER_STORAGE_BASE_URL throws ToolExit'
,
()
async
{
testWithoutContext
(
'Invalid URI for FLUTTER_STORAGE_BASE_URL throws ToolExit'
,
()
async
{
...
...
packages/flutter_tools/test/general.shard/runner/flutter_command_test.dart
View file @
4881b335
...
@@ -210,10 +210,10 @@ void main() {
...
@@ -210,10 +210,10 @@ void main() {
throwToolExit
(
'fail'
);
throwToolExit
(
'fail'
);
}
}
);
);
try
{
await
expectLater
(
await
flutterCommand
.
run
();
()
=>
flutterCommand
.
run
(),
fail
(
'Mock should make this fail'
);
throwsA
(
isA
<
ToolExit
>()),
}
on
ToolExit
{
);
expect
(
usage
.
events
,
<
TestUsageEvent
>[
expect
(
usage
.
events
,
<
TestUsageEvent
>[
const
TestUsageEvent
(
const
TestUsageEvent
(
'tool-command-result'
,
'tool-command-result'
,
...
@@ -227,7 +227,6 @@ void main() {
...
@@ -227,7 +227,6 @@ void main() {
value:
10
,
value:
10
,
),
),
]);
]);
}
});
});
test
(
'FlutterCommandResult.success()'
,
()
async
{
test
(
'FlutterCommandResult.success()'
,
()
async
{
...
@@ -435,18 +434,18 @@ void main() {
...
@@ -435,18 +434,18 @@ void main() {
},
},
);
);
try
{
await
expectLater
(
await
flutterCommand
.
run
();
()
=>
flutterCommand
.
run
(),
fail
(
'Mock should make this fail'
);
throwsA
(
isA
<
ToolExit
>()),
}
on
ToolExit
{
);
expect
(
usage
.
timings
,
contains
(
expect
(
usage
.
timings
,
contains
(
const
TestTimingEvent
(
const
TestTimingEvent
(
'flutter'
,
'flutter'
,
'dummy'
,
'dummy'
,
Duration
(
milliseconds:
1000
),
Duration
(
milliseconds:
1000
),
label:
'fail'
,
label:
'fail'
,
)));
),
}
));
});
});
testUsingContext
(
'reports null safety analytics when reportNullSafety is true'
,
()
async
{
testUsingContext
(
'reports null safety analytics when reportNullSafety is true'
,
()
async
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment