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
Hide 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() {
);
await
creator
.
initializeRepo
();
try
{
await
creator
.
createArchive
();
fail
(
'failed to throw'
);
}
on
Exception
catch
(
e
)
{
expect
(
e
is
PreparePackageException
,
true
);
final
PreparePackageException
exception
=
e
as
PreparePackageException
;
expect
(
exception
.
message
,
contains
(
'The binary
$binPath
was not codesigned!'
));
}
await
expectLater
(
()
=>
creator
.
createArchive
(),
throwsA
(
isA
<
PreparePackageException
>().
having
(
(
PreparePackageException
exception
)
=>
exception
.
message
,
'message'
,
contains
(
'The binary
$binPath
was not codesigned!'
),
)),
);
},
skip:
!
platform
.
isMacOS
);
});
...
...
packages/flutter_test/test/goldens_test.dart
View file @
4881b335
...
...
@@ -183,28 +183,30 @@ void main() {
test
(
'and generates correct output in the correct base location'
,
()
async
{
comparator
=
LocalFileComparator
(
Uri
.
parse
(
'local_test.dart'
),
pathStyle:
fs
.
path
.
style
);
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kColorFailurePngBytes
);
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'% diff detected'
));
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
);
final
io
.
File
test
=
fs
.
file
(
fix
(
'/failures/golden_testImage.png'
)
);
final
io
.
File
isolated
=
fs
.
file
(
fix
(
'/failures/golden_isolatedDiff.png'
)
);
final
io
.
File
masked
=
fs
.
file
(
fix
(
'/failures/golden_maskedDiff.png'
)
);
expect
(
master
.
existsSync
(),
isTrue
);
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
}
await
expectLater
(
()
=>
doComparison
(),
throwsA
(
isA
<
FlutterError
>().
having
(
(
FlutterError
error
)
=>
error
.
message
,
'message'
,
contains
(
'% diff detected'
),
)),
);
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
);
final
io
.
File
test
=
fs
.
file
(
fix
(
'/failures/golden_testImage.png'
)
);
final
io
.
File
isolated
=
fs
.
file
(
fix
(
'/failures/golden_isolatedDiff.png'
)
);
final
io
.
File
masked
=
fs
.
file
(
fix
(
'/failures/golden_maskedDiff.png'
)
);
expect
(
master
.
existsSync
(),
isTrue
);
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
});
test
(
'and generates correct output when files are in a subdirectory'
,
()
async
{
...
...
@@ -212,67 +214,77 @@ void main() {
fs
.
file
(
fix
(
'subdir/golden.png'
))
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(
_kColorFailurePngBytes
);
try
{
await
doComparison
(
'subdir/golden.png'
);
fail
(
'TestFailure expected but not thrown.'
);
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'% diff detected'
));
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
);
final
io
.
File
test
=
fs
.
file
(
fix
(
'/failures/golden_testImage.png'
)
);
final
io
.
File
isolated
=
fs
.
file
(
fix
(
'/failures/golden_isolatedDiff.png'
)
);
final
io
.
File
masked
=
fs
.
file
(
fix
(
'/failures/golden_maskedDiff.png'
)
);
expect
(
master
.
existsSync
(),
isTrue
);
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
}
await
expectLater
(
()
=>
doComparison
(
'subdir/golden.png'
),
throwsA
(
isA
<
FlutterError
>().
having
(
(
FlutterError
error
)
=>
error
.
message
,
'message'
,
contains
(
'% diff detected'
),
)),
);
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
);
final
io
.
File
test
=
fs
.
file
(
fix
(
'/failures/golden_testImage.png'
)
);
final
io
.
File
isolated
=
fs
.
file
(
fix
(
'/failures/golden_isolatedDiff.png'
)
);
final
io
.
File
masked
=
fs
.
file
(
fix
(
'/failures/golden_maskedDiff.png'
)
);
expect
(
master
.
existsSync
(),
isTrue
);
expect
(
test
.
existsSync
(),
isTrue
);
expect
(
isolated
.
existsSync
(),
isTrue
);
expect
(
masked
.
existsSync
(),
isTrue
);
});
test
(
'when golden file does not exist'
,
()
async
{
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
TestFailure
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'Could not be compared against non-existent file'
));
}
await
expectLater
(
()
=>
doComparison
(),
throwsA
(
isA
<
TestFailure
>().
having
(
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'Could not be compared against non-existent file'
),
)),
);
});
test
(
'when images are not the same size'
,
()
async
{
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kSizeFailurePngBytes
);
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'image sizes do not match'
));
}
await
expectLater
(
()
=>
doComparison
(),
throwsA
(
isA
<
FlutterError
>().
having
(
(
FlutterError
error
)
=>
error
.
message
,
'message'
,
contains
(
'image sizes do not match'
),
)),
);
});
test
(
'when pixels do not match'
,
()
async
{
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(
_kColorFailurePngBytes
);
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'% diff detected'
));
}
await
expectLater
(
()
=>
doComparison
(),
throwsA
(
isA
<
FlutterError
>().
having
(
(
FlutterError
error
)
=>
error
.
message
,
'message'
,
contains
(
'% diff detected'
),
)),
);
});
test
(
'when golden bytes are empty'
,
()
async
{
await
fs
.
file
(
fix
(
'/golden.png'
)).
writeAsBytes
(<
int
>[]);
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'null image provided'
));
}
await
expectLater
(
()
=>
doComparison
(),
throwsA
(
isA
<
FlutterError
>().
having
(
(
FlutterError
error
)
=>
error
.
message
,
'message'
,
contains
(
'null image provided'
),
)),
);
});
});
});
...
...
packages/flutter_test/test/matchers_test.dart
View file @
4881b335
...
...
@@ -368,38 +368,44 @@ void main() {
comparator
.
behavior
=
_ComparatorBehavior
.
returnFalse
;
await
tester
.
pumpWidget
(
boilerplate
(
const
Text
(
'hello'
)));
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
fail
(
'TestFailure expected but not thrown'
);
}
on
TestFailure
catch
(
error
)
{
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
expect
(
error
.
message
,
contains
(
'does not match'
));
}
await
expectLater
(
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
throwsA
(
isA
<
TestFailure
>().
having
(
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'does not match'
),
)),
);
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
});
testWidgets
(
'if comparator throws'
,
(
WidgetTester
tester
)
async
{
comparator
.
behavior
=
_ComparatorBehavior
.
throwTestFailure
;
await
tester
.
pumpWidget
(
boilerplate
(
const
Text
(
'hello'
)));
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
fail
(
'TestFailure expected but not thrown'
);
}
on
TestFailure
catch
(
error
)
{
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
expect
(
error
.
message
,
contains
(
'fake message'
));
}
await
expectLater
(
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
throwsA
(
isA
<
TestFailure
>().
having
(
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'fake message'
),
)),
);
expect
(
comparator
.
invocation
,
_ComparatorInvocation
.
compare
);
});
testWidgets
(
'if finder finds no widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
boilerplate
(
Container
()));
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
fail
(
'TestFailure expected but not thrown'
);
}
on
TestFailure
catch
(
error
)
{
expect
(
comparator
.
invocation
,
isNull
);
expect
(
error
.
message
,
contains
(
'no widget was found'
));
}
await
expectLater
(
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
throwsA
(
isA
<
TestFailure
>().
having
(
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'no widget was found'
),
)),
);
expect
(
comparator
.
invocation
,
isNull
);
});
testWidgets
(
'if finder finds multiple widgets'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -407,13 +413,15 @@ void main() {
children:
const
<
Widget
>[
Text
(
'hello'
),
Text
(
'world'
)],
)));
final
Finder
finder
=
find
.
byType
(
Text
);
try
{
await
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
));
fail
(
'TestFailure expected but not thrown'
);
}
on
TestFailure
catch
(
error
)
{
expect
(
comparator
.
invocation
,
isNull
);
expect
(
error
.
message
,
contains
(
'too many widgets'
));
}
await
expectLater
(
()
=>
expectLater
(
finder
,
matchesGoldenFile
(
'foo.png'
)),
throwsA
(
isA
<
TestFailure
>().
having
(
(
TestFailure
error
)
=>
error
.
message
,
'message'
,
contains
(
'too many widgets'
),
)),
);
expect
(
comparator
.
invocation
,
isNull
);
});
});
...
...
packages/flutter_test/test/test_text_input_test.dart
View file @
4881b335
...
...
@@ -43,11 +43,9 @@ void main() {
throw
FlutterError
(
'A fake error occurred during action processing.'
);
});
try
{
await
tester
.
testTextInput
.
receiveAction
(
TextInputAction
.
done
);
fail
(
'Expected a PlatformException, but it was not thrown.'
);
}
catch
(
e
)
{
expect
(
e
,
isA
<
PlatformException
>());
}
await
expectLater
(
()
=>
tester
.
testTextInput
.
receiveAction
(
TextInputAction
.
done
),
throwsA
(
isA
<
PlatformException
>()),
);
});
}
packages/flutter_tools/test/general.shard/cache_test.dart
View file @
4881b335
...
...
@@ -288,20 +288,17 @@ void main() {
processManager:
FakeProcessManager
.
any
(),
logger:
logger
,
);
try
{
await
cache
.
updateAll
(<
DevelopmentArtifact
>{
null
,
});
fail
(
'Mock thrown exception expected'
);
}
on
Exception
{
verify
(
artifact1
.
update
(
any
,
any
,
any
,
any
));
// Don't continue when retrieval fails.
verifyNever
(
artifact2
.
update
(
any
,
any
,
any
,
any
));
expect
(
logger
.
errorText
,
contains
(
'https://flutter.dev/community/china'
),
);
}
await
expectLater
(
()
=>
cache
.
updateAll
(<
DevelopmentArtifact
>{
null
}),
throwsA
(
isA
<
Exception
>()),
);
verify
(
artifact1
.
update
(
any
,
any
,
any
,
any
));
// Don't continue when retrieval fails.
verifyNever
(
artifact2
.
update
(
any
,
any
,
any
,
any
));
expect
(
logger
.
errorText
,
contains
(
'https://flutter.dev/community/china'
),
);
});
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,24 +210,23 @@ void main() {
throwToolExit
(
'fail'
);
}
);
try
{
await
flutterCommand
.
run
();
fail
(
'Mock should make this fail'
);
}
on
ToolExit
{
expect
(
usage
.
events
,
<
TestUsageEvent
>[
const
TestUsageEvent
(
'tool-command-result'
,
'dummy'
,
label:
'fail'
,
),
const
TestUsageEvent
(
'tool-command-max-rss'
,
'dummy'
,
label:
'fail'
,
value:
10
,
),
]);
}
await
expectLater
(
()
=>
flutterCommand
.
run
(),
throwsA
(
isA
<
ToolExit
>()),
);
expect
(
usage
.
events
,
<
TestUsageEvent
>[
const
TestUsageEvent
(
'tool-command-result'
,
'dummy'
,
label:
'fail'
,
),
const
TestUsageEvent
(
'tool-command-max-rss'
,
'dummy'
,
label:
'fail'
,
value:
10
,
),
]);
});
test
(
'FlutterCommandResult.success()'
,
()
async
{
...
...
@@ -435,18 +434,18 @@ void main() {
},
);
try
{
await
flutterCommand
.
run
();
fail
(
'Mock should make this fail'
);
}
on
ToolExit
{
expect
(
usage
.
timings
,
contains
(
const
TestTimingEvent
(
'flutter'
,
'dummy'
,
Duration
(
milliseconds:
1000
),
label:
'fail'
,
)));
}
await
expectLater
(
()
=>
flutterCommand
.
run
(),
throwsA
(
isA
<
ToolExit
>()),
);
expect
(
usage
.
timings
,
contains
(
const
TestTimingEvent
(
'flutter'
,
'dummy'
,
Duration
(
milliseconds:
1000
),
label:
'fail'
,
),
));
});
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