From d242d1368f05c0099bc1c8f74c571a663ae0a0cf Mon Sep 17 00:00:00 2001 From: David Martos Date: Thu, 1 Feb 2024 22:22:51 +0100 Subject: [PATCH] Fix gen_defaults test randomness (#142743) This PR improves the gen_defaults tests to not be tied to a particular order of execution. Since there is a global class that holds the state of the used/not used tokens, we need to clear this logger before each test. Fixes https://github.com/flutter/flutter/issues/142716 cc @zanderso @QuncCccccc *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* --- dev/tools/gen_defaults/test/gen_defaults_test.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev/tools/gen_defaults/test/gen_defaults_test.dart b/dev/tools/gen_defaults/test/gen_defaults_test.dart index 63b125faa7..7844aff829 100644 --- a/dev/tools/gen_defaults/test/gen_defaults_test.dart +++ b/dev/tools/gen_defaults/test/gen_defaults_test.dart @@ -19,8 +19,16 @@ import 'package:test/test.dart'; void main() { final TokenLogger logger = tokenLogger; + // Required init with empty at least once to init late fields. + // Then we can use the `clear` method. logger.init(allTokens: {}, versionMap: >{}); + setUp(() { + // Cleanup the global token logger before each test, to not be tied to a particular + // test order. + logger.clear(); + }); + test('Templates will append to the end of a file', () { final Directory tempDir = Directory.systemTemp.createTempSync('gen_defaults'); try {