From 6a2c29517828fbb08a94a49c5997644d63a8366e Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:16:20 +0100 Subject: [PATCH 01/12] Randomize tests; add `--test-randomize-ordering-seed` option to `sz test`. --- .../lib/src/commands/src/test_command.dart | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart index 6ba7f7858..9e5ab5355 100644 --- a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart +++ b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart @@ -35,6 +35,15 @@ class TestCommand extends ConcurrentCommand { negatable: false, abbr: 'u', ); + argParser.addOption( + 'test-randomize-ordering-seed', + help: ''' +Use the specified seed to randomize the execution order of test cases. +Must be a 32bit unsigned integer or "random". +If "random", pick a random seed to use. +If not passed, do not randomize test case execution order.''', + defaultsTo: 'random', + ); } @override @@ -70,6 +79,8 @@ class TestCommand extends ConcurrentCommand { excludeGoldens: argResults!['exclude-goldens'] as bool, onlyGoldens: argResults!['only-goldens'] as bool, updateGoldens: argResults!['update-goldens'] as bool, + testRandomizeOrderingSeed: + argResults!['test-randomize-ordering-seed'] as String, ); } } @@ -80,6 +91,7 @@ Future runTests( required bool excludeGoldens, required bool onlyGoldens, required bool updateGoldens, + required String testRandomizeOrderingSeed, }) { if (package.isFlutterPackage) { return _runTestsFlutter( @@ -88,6 +100,7 @@ Future runTests( excludeGoldens: excludeGoldens, onlyGoldens: onlyGoldens, updateGoldens: updateGoldens, + testRandomizeOrderingSeed: testRandomizeOrderingSeed, ); } else { return _runTestsDart( @@ -95,6 +108,7 @@ Future runTests( package, excludeGoldens: excludeGoldens, onlyGoldens: onlyGoldens, + testRandomizeOrderingSeed: testRandomizeOrderingSeed, ); } } @@ -106,6 +120,7 @@ Future _runTestsDart( // don't have golden tests. required bool excludeGoldens, required bool onlyGoldens, + required String testRandomizeOrderingSeed, }) async { if (onlyGoldens) { // Golden tests are only run in the flutter package. @@ -115,7 +130,13 @@ Future _runTestsDart( await getPackage(processRunner, package); await processRunner.runCommand( - ['fvm', 'dart', 'test'], + [ + 'fvm', + 'dart', + 'test', + '--test-randomize-ordering-seed', + testRandomizeOrderingSeed + ], workingDirectory: package.location, ); } @@ -126,6 +147,7 @@ Future _runTestsFlutter( required bool excludeGoldens, required bool onlyGoldens, required bool updateGoldens, + required String testRandomizeOrderingSeed, }) async { if (onlyGoldens || !excludeGoldens) { if (!package.hasGoldenTestsDirectory) { @@ -137,6 +159,8 @@ Future _runTestsFlutter( 'fvm', 'flutter', 'test', + '--test-randomize-ordering-seed', + testRandomizeOrderingSeed, 'test_goldens', if (updateGoldens) '--update-goldens', ], From d11af6eac8c730ef1873b92e8f8d58026bd6afb4 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 19:31:08 +0100 Subject: [PATCH 02/12] Add flags to missing callsites --- .../sz_repo_cli/lib/src/commands/src/test_command.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart index 9e5ab5355..7df7680d1 100644 --- a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart +++ b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart @@ -174,7 +174,13 @@ Future _runTestsFlutter( // couldn't find the "test_goldens" directory. if (excludeGoldens || !package.hasGoldenTestsDirectory) { await processRunner.runCommand( - ['fvm', 'flutter', 'test'], + [ + 'fvm', + 'flutter', + 'test', + '--test-randomize-ordering-seed', + testRandomizeOrderingSeed, + ], workingDirectory: package.location, ); return; @@ -192,6 +198,8 @@ Future _runTestsFlutter( 'test_goldens', // Directory for unit and widget tests. 'test', + '--test-randomize-ordering-seed', + testRandomizeOrderingSeed, ], workingDirectory: package.location, ); From 319d8b48df97db6c2a519c856cd0edbd55aa8ec8 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:04:41 +0100 Subject: [PATCH 03/12] Add TEST_RANDOMNESS_SEED dart define --- tools/sz_repo_cli/lib/src/commands/src/test_command.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart index 7df7680d1..975f56315 100644 --- a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart +++ b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart @@ -135,7 +135,8 @@ Future _runTestsDart( 'dart', 'test', '--test-randomize-ordering-seed', - testRandomizeOrderingSeed + testRandomizeOrderingSeed, + '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', ], workingDirectory: package.location, ); @@ -161,6 +162,8 @@ Future _runTestsFlutter( 'test', '--test-randomize-ordering-seed', testRandomizeOrderingSeed, + testRandomizeOrderingSeed, + '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', 'test_goldens', if (updateGoldens) '--update-goldens', ], @@ -180,6 +183,7 @@ Future _runTestsFlutter( 'test', '--test-randomize-ordering-seed', testRandomizeOrderingSeed, + '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', ], workingDirectory: package.location, ); @@ -200,6 +204,7 @@ Future _runTestsFlutter( 'test', '--test-randomize-ordering-seed', testRandomizeOrderingSeed, + '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', ], workingDirectory: package.location, ); From f2622609acff3a64583a66718a15eff3b4a6a5df Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:06:02 +0100 Subject: [PATCH 04/12] Create and use `test_randomness` package. --- app/pubspec.lock | 9 ++- app/pubspec.yaml | 3 +- app/test/feedback/feedback_bloc_test.dart | 2 +- app/test/feedback/feedback_page_test.dart | 2 +- .../group_join_select_courses_bloc_test.dart | 2 +- app/test/holidays/holiday_bloc_unit_test.dart | 2 +- app/test/homework/homework_dialog_test.dart | 2 +- .../teacher_homework_page_widget_test.dart | 4 +- .../school_class_filter_view_test.dart | 3 +- lib/abgabe/abgabe_client_lib/pubspec.lock | 9 ++- lib/abgabe/abgabe_client_lib/pubspec.yaml | 3 +- .../abgabe_client_lib/test/bloc_test.dart | 2 +- .../pubspec.lock | 7 ++ .../lehrer/teacher_homework_page_bloc.dart | 2 +- lib/hausaufgabenheft_logik/pubspec.lock | 9 ++- lib/hausaufgabenheft_logik/pubspec.yaml | 3 +- lib/test_randomness/.gitignore | 73 +++++++++++++++++++ lib/test_randomness/.metadata | 10 +++ lib/test_randomness/analysis_options.yaml | 9 +++ .../lib/src/test_randomness.dart | 43 +++++++++++ lib/test_randomness/lib/test_randomness.dart | 3 + lib/test_randomness/pubspec.lock | 36 +++++++++ lib/test_randomness/pubspec.yaml | 22 ++++++ 23 files changed, 243 insertions(+), 17 deletions(-) create mode 100644 lib/test_randomness/.gitignore create mode 100644 lib/test_randomness/.metadata create mode 100644 lib/test_randomness/analysis_options.yaml create mode 100644 lib/test_randomness/lib/src/test_randomness.dart create mode 100644 lib/test_randomness/lib/test_randomness.dart create mode 100644 lib/test_randomness/pubspec.lock create mode 100644 lib/test_randomness/pubspec.yaml diff --git a/app/pubspec.lock b/app/pubspec.lock index 5c31cc6c2..aea502645 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -1793,7 +1793,7 @@ packages: source: hosted version: "3.2.1" random_string: - dependency: "direct dev" + dependency: transitive description: name: random_string sha256: "03b52435aae8cbdd1056cf91bfc5bf845e9706724dd35ae2e99fa14a1ef79d02" @@ -2167,6 +2167,13 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.9" + test_randomness: + dependency: "direct dev" + description: + path: "../lib/test_randomness" + relative: true + source: path + version: "0.0.1" time: dependency: "direct main" description: diff --git a/app/pubspec.yaml b/app/pubspec.yaml index c31617835..d7e569d3a 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -193,7 +193,8 @@ dev_dependencies: integration_test: sdk: flutter mockito: ^5.4.4 - random_string: ^2.0.1 + test_randomness: + path: ../lib/test_randomness bloc_test: ^9.1.4 bloc_presentation_test: ^1.0.0 path: ^1.8.3 diff --git a/app/test/feedback/feedback_bloc_test.dart b/app/test/feedback/feedback_bloc_test.dart index fa3944f4b..b007cca44 100644 --- a/app/test/feedback/feedback_bloc_test.dart +++ b/app/test/feedback/feedback_bloc_test.dart @@ -9,12 +9,12 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:key_value_store/in_memory_key_value_store.dart'; import 'package:key_value_store/key_value_store.dart'; -import 'package:random_string/random_string.dart' as random; import 'package:sharezone/feedback/src/analytics/feedback_analytics.dart'; import 'package:sharezone/feedback/src/bloc/feedback_bloc.dart'; import 'package:sharezone/feedback/src/cache/cooldown_exception.dart'; import 'package:sharezone/feedback/src/cache/feedback_cache.dart'; import 'package:sharezone/feedback/src/models/user_feedback.dart'; +import 'package:test_randomness/test_randomness.dart' as random; import 'mock_feedback_api.dart'; import 'mock_platform_information_retreiver.dart'; diff --git a/app/test/feedback/feedback_page_test.dart b/app/test/feedback/feedback_page_test.dart index b672b0861..3350fb1f8 100644 --- a/app/test/feedback/feedback_page_test.dart +++ b/app/test/feedback/feedback_page_test.dart @@ -10,12 +10,12 @@ import 'package:bloc_provider/bloc_provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:key_value_store/in_memory_key_value_store.dart'; -import 'package:random_string/random_string.dart' as random; import 'package:sharezone/feedback/feedback_box_page.dart'; import 'package:sharezone/feedback/src/bloc/feedback_bloc.dart'; import 'package:sharezone/feedback/src/cache/cooldown_exception.dart'; import 'package:sharezone/feedback/src/cache/feedback_cache.dart'; import 'package:sharezone/feedback/src/models/user_feedback.dart'; +import 'package:test_randomness/test_randomness.dart' as random; import 'feedback_bloc_test.dart'; import 'mock_feedback_api.dart'; diff --git a/app/test/groups/group_join_select_courses_bloc_test.dart b/app/test/groups/group_join_select_courses_bloc_test.dart index f851888ca..1b88c3be6 100644 --- a/app/test/groups/group_join_select_courses_bloc_test.dart +++ b/app/test/groups/group_join_select_courses_bloc_test.dart @@ -13,12 +13,12 @@ import 'package:design/design.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:group_domain_models/group_domain_models.dart'; import 'package:mockito/annotations.dart'; -import 'package:random_string/random_string.dart'; import 'package:sharezone/groups/group_join/bloc/group_join_bloc.dart'; import 'package:sharezone/groups/group_join/bloc/group_join_select_courses_bloc.dart'; import 'package:sharezone/groups/group_join/models/group_info_with_selection_state.dart'; import 'package:sharezone/groups/group_join/models/group_join_result.dart'; import 'package:sharezone/util/api/connections_gateway.dart'; +import 'package:test_randomness/test_randomness.dart'; import 'group_join_select_courses_bloc_test.mocks.dart'; diff --git a/app/test/holidays/holiday_bloc_unit_test.dart b/app/test/holidays/holiday_bloc_unit_test.dart index 9b4ad49e5..05379e6a6 100644 --- a/app/test/holidays/holiday_bloc_unit_test.dart +++ b/app/test/holidays/holiday_bloc_unit_test.dart @@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:holidays/holidays.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:random_string/random_string.dart' as rdm; +import 'package:test_randomness/test_randomness.dart' as rdm; import 'package:rxdart/subjects.dart'; import 'package:sharezone/holidays/holiday_bloc.dart'; import 'package:user/user.dart'; diff --git a/app/test/homework/homework_dialog_test.dart b/app/test/homework/homework_dialog_test.dart index 6c26ca47b..c889e2fe1 100644 --- a/app/test/homework/homework_dialog_test.dart +++ b/app/test/homework/homework_dialog_test.dart @@ -25,7 +25,7 @@ import 'package:group_domain_models/group_domain_models.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:path/path.dart'; -import 'package:random_string/random_string.dart'; +import 'package:test_randomness/test_randomness.dart'; import 'package:sharezone/homework/homework_dialog/homework_dialog.dart'; import 'package:sharezone/homework/homework_dialog/homework_dialog_bloc.dart'; import 'package:sharezone/main/application_bloc.dart'; diff --git a/app/test/homework/teacher/teacher_homework_page_widget_test.dart b/app/test/homework/teacher/teacher_homework_page_widget_test.dart index 5e5e48515..c1059dbc8 100644 --- a/app/test/homework/teacher/teacher_homework_page_widget_test.dart +++ b/app/test/homework/teacher/teacher_homework_page_widget_test.dart @@ -13,13 +13,12 @@ import 'package:analytics/null_analytics_backend.dart'; import 'package:bloc_provider/bloc_provider.dart'; import 'package:bloc_provider/multi_bloc_provider.dart'; import 'package:common_domain_models/common_domain_models.dart'; -import 'package:flutter/material.dart' hide Color; import 'package:flutter/material.dart' as flutter show Color; +import 'package:flutter/material.dart' hide Color; import 'package:flutter_test/flutter_test.dart'; import 'package:hausaufgabenheft_logik/color.dart'; import 'package:hausaufgabenheft_logik/hausaufgabenheft_logik_lehrer.dart'; import 'package:provider/provider.dart'; -import 'package:random_string/random_string.dart'; import 'package:sharezone/homework/shared/shared.dart'; import 'package:sharezone/homework/teacher/src/teacher_archived_homework_list.dart'; import 'package:sharezone/homework/teacher/src/teacher_homework_bottom_action_bar.dart'; @@ -27,6 +26,7 @@ import 'package:sharezone/homework/teacher/src/teacher_homework_tile.dart'; import 'package:sharezone/homework/teacher/src/teacher_open_homework_list.dart'; import 'package:sharezone/homework/teacher/teacher_homework_page.dart'; import 'package:sharezone/navigation/logic/navigation_bloc.dart'; +import 'package:test_randomness/test_randomness.dart'; class MockTeacherHomeworkPageBloc extends TeacherHomeworkPageBloc { final _queuedStates = Queue(); diff --git a/app/test/timetable/school_class_filter_view_test.dart b/app/test/timetable/school_class_filter_view_test.dart index 938f484d1..75a5528a4 100644 --- a/app/test/timetable/school_class_filter_view_test.dart +++ b/app/test/timetable/school_class_filter_view_test.dart @@ -8,9 +8,8 @@ import 'package:common_domain_models/common_domain_models.dart'; import 'package:flutter_test/flutter_test.dart'; - -import 'package:random_string/random_string.dart'; import 'package:sharezone/timetable/timetable_page/school_class_filter/school_class_filter_view.dart'; +import 'package:test_randomness/test_randomness.dart'; void main() { group('SchoolClassFilterView', () { diff --git a/lib/abgabe/abgabe_client_lib/pubspec.lock b/lib/abgabe/abgabe_client_lib/pubspec.lock index 36fc3e7d2..cd73207ed 100644 --- a/lib/abgabe/abgabe_client_lib/pubspec.lock +++ b/lib/abgabe/abgabe_client_lib/pubspec.lock @@ -1081,7 +1081,7 @@ packages: source: hosted version: "3.2.1" random_string: - dependency: "direct dev" + dependency: transitive description: name: random_string sha256: "03b52435aae8cbdd1056cf91bfc5bf845e9706724dd35ae2e99fa14a1ef79d02" @@ -1241,6 +1241,13 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.1" + test_randomness: + dependency: "direct dev" + description: + path: "../../test_randomness" + relative: true + source: path + version: "0.0.1" time: dependency: transitive description: diff --git a/lib/abgabe/abgabe_client_lib/pubspec.yaml b/lib/abgabe/abgabe_client_lib/pubspec.yaml index 6b6432e63..81772cf59 100644 --- a/lib/abgabe/abgabe_client_lib/pubspec.yaml +++ b/lib/abgabe/abgabe_client_lib/pubspec.yaml @@ -45,6 +45,7 @@ dev_dependencies: sdk: flutter async: ^2.4.1 mockito: ^5.4.4 - random_string: ^2.0.1 + test_randomness: + path: ../../test_randomness sharezone_lints: path: ../../sharezone_lints diff --git a/lib/abgabe/abgabe_client_lib/test/bloc_test.dart b/lib/abgabe/abgabe_client_lib/test/bloc_test.dart index 5a6121618..e44629070 100644 --- a/lib/abgabe/abgabe_client_lib/test/bloc_test.dart +++ b/lib/abgabe/abgabe_client_lib/test/bloc_test.dart @@ -25,7 +25,7 @@ import 'package:common_domain_models/common_domain_models.dart'; import 'package:files_basics/files_models.dart'; import 'package:files_basics/local_file.dart'; -import 'package:random_string/random_string.dart'; +import 'package:test_randomness/test_randomness.dart'; import 'package:rxdart/subjects.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/lib/firebase_hausaufgabenheft_logik/pubspec.lock b/lib/firebase_hausaufgabenheft_logik/pubspec.lock index a33cad724..baadf80a5 100644 --- a/lib/firebase_hausaufgabenheft_logik/pubspec.lock +++ b/lib/firebase_hausaufgabenheft_logik/pubspec.lock @@ -399,6 +399,13 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.1" + test_randomness: + dependency: transitive + description: + path: "../test_randomness" + relative: true + source: path + version: "0.0.1" time: dependency: "direct main" description: diff --git a/lib/hausaufgabenheft_logik/lib/src/lehrer/teacher_homework_page_bloc.dart b/lib/hausaufgabenheft_logik/lib/src/lehrer/teacher_homework_page_bloc.dart index 6daf21807..ce0ec760d 100644 --- a/lib/hausaufgabenheft_logik/lib/src/lehrer/teacher_homework_page_bloc.dart +++ b/lib/hausaufgabenheft_logik/lib/src/lehrer/teacher_homework_page_bloc.dart @@ -14,7 +14,7 @@ import 'package:common_domain_models/common_domain_models.dart'; import 'package:hausaufgabenheft_logik/color.dart'; import 'package:hausaufgabenheft_logik/hausaufgabenheft_logik_lehrer.dart'; import 'package:meta/meta.dart'; -import 'package:random_string/random_string.dart'; +import 'package:test_randomness/test_randomness.dart'; export 'events.dart'; export 'states.dart'; diff --git a/lib/hausaufgabenheft_logik/pubspec.lock b/lib/hausaufgabenheft_logik/pubspec.lock index 9dba12a3b..bbf0aabd0 100644 --- a/lib/hausaufgabenheft_logik/pubspec.lock +++ b/lib/hausaufgabenheft_logik/pubspec.lock @@ -295,7 +295,7 @@ packages: source: hosted version: "2.1.4" random_string: - dependency: "direct main" + dependency: transitive description: name: random_string sha256: "03b52435aae8cbdd1056cf91bfc5bf845e9706724dd35ae2e99fa14a1ef79d02" @@ -437,6 +437,13 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.6" + test_randomness: + dependency: "direct main" + description: + path: "../test_randomness" + relative: true + source: path + version: "0.0.1" typed_data: dependency: transitive description: diff --git a/lib/hausaufgabenheft_logik/pubspec.yaml b/lib/hausaufgabenheft_logik/pubspec.yaml index fe0e71437..e4584efb8 100644 --- a/lib/hausaufgabenheft_logik/pubspec.yaml +++ b/lib/hausaufgabenheft_logik/pubspec.yaml @@ -28,7 +28,8 @@ dependencies: path: ../bloc_base # For teacher fake bloc currently in use (can be removed when bloc is implemented) # https://gitlab.com/codingbrain/sharezone/sharezone-app/-/issues/1460 - random_string: ^2.0.1 + test_randomness: + path: ../test_randomness dev_dependencies: async: ^2.11.0 diff --git a/lib/test_randomness/.gitignore b/lib/test_randomness/.gitignore new file mode 100644 index 000000000..3132dc5ff --- /dev/null +++ b/lib/test_randomness/.gitignore @@ -0,0 +1,73 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins +.packages +.pub-cache/ +.pub/ +build/ + +# Android related +**/android/**/gradle-wrapper.jar +**/android/.gradle +**/android/captures/ +**/android/gradlew +**/android/gradlew.bat +**/android/local.properties +**/android/**/GeneratedPluginRegistrant.java + +# iOS/XCode related +**/ios/**/*.mode1v3 +**/ios/**/*.mode2v3 +**/ios/**/*.moved-aside +**/ios/**/*.pbxuser +**/ios/**/*.perspectivev3 +**/ios/**/*sync/ +**/ios/**/.sconsign.dblite +**/ios/**/.tags* +**/ios/**/.vagrant/ +**/ios/**/DerivedData/ +**/ios/**/Icon? +**/ios/**/Pods/ +**/ios/**/.symlinks/ +**/ios/**/profile +**/ios/**/xcuserdata +**/ios/.generated/ +**/ios/Flutter/App.framework +**/ios/Flutter/Flutter.framework +**/ios/Flutter/Generated.xcconfig +**/ios/Flutter/app.flx +**/ios/Flutter/app.zip +**/ios/Flutter/flutter_assets/ +**/ios/Flutter/flutter_export_environment.sh +**/ios/ServiceDefinitions.json +**/ios/Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!**/ios/**/default.mode1v3 +!**/ios/**/default.mode2v3 +!**/ios/**/default.pbxuser +!**/ios/**/default.perspectivev3 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages diff --git a/lib/test_randomness/.metadata b/lib/test_randomness/.metadata new file mode 100644 index 000000000..f917a52ed --- /dev/null +++ b/lib/test_randomness/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: e70236e36ce1d32067dc68eb55519ec3e14b6b01 + channel: beta + +project_type: package diff --git a/lib/test_randomness/analysis_options.yaml b/lib/test_randomness/analysis_options.yaml new file mode 100644 index 000000000..1e445c14e --- /dev/null +++ b/lib/test_randomness/analysis_options.yaml @@ -0,0 +1,9 @@ +# Copyright (c) 2023 Sharezone UG (haftungsbeschränkt) +# Licensed under the EUPL-1.2-or-later. +# +# You may obtain a copy of the Licence at: +# https://joinup.ec.europa.eu/software/page/eupl +# +# SPDX-License-Identifier: EUPL-1.2 + +include: package:sharezone_lints/analysis_options.yaml diff --git a/lib/test_randomness/lib/src/test_randomness.dart b/lib/test_randomness/lib/src/test_randomness.dart new file mode 100644 index 000000000..4af8abb51 --- /dev/null +++ b/lib/test_randomness/lib/src/test_randomness.dart @@ -0,0 +1,43 @@ +import 'dart:math'; + +import 'package:random_string/random_string.dart' as lib; + +const randomnessSeed = + int.fromEnvironment('TEST_RANDOMNESS_SEED', defaultValue: 0); + +final szSeededTestRandom = Random(randomnessSeed); + +final _randomProvider = lib.CoreRandomProvider.from(szSeededTestRandom); + +/// Generates a random integer where [from] <= [to] inclusive +/// where 0 <= from <= to <= 999999999999999 +int randomBetween( + int from, + int to, +) => + lib.randomBetween(from, to, provider: _randomProvider); + +/// Generates a random string of [length] with characters +/// between ascii [from] to [to]. +/// Defaults to characters of ascii '!' to '~'. +String randomString( + int length, { + int from = lib.asciiStart, + int to = lib.asciiEnd, +}) => + lib.randomString(length, from: from, to: to, provider: _randomProvider); + +/// Generates a random string of [length] with only numeric characters. +String randomNumeric(int length) => + lib.randomNumeric(length, provider: _randomProvider); + +/// Generates a random string of [length] with only alpha characters. +String randomAlpha(int length) => + lib.randomAlpha(length, provider: _randomProvider); + +/// Generates a random string of [length] with alpha-numeric characters. +String randomAlphaNumeric(int length) => + lib.randomAlphaNumeric(length, provider: _randomProvider); + +/// Merge [a] with [b] and shuffle. +String randomMerge(String a, String b) => lib.randomMerge(a, b); diff --git a/lib/test_randomness/lib/test_randomness.dart b/lib/test_randomness/lib/test_randomness.dart new file mode 100644 index 000000000..2d51d909d --- /dev/null +++ b/lib/test_randomness/lib/test_randomness.dart @@ -0,0 +1,3 @@ +library test_randomness; + +export 'src/test_randomness.dart'; diff --git a/lib/test_randomness/pubspec.lock b/lib/test_randomness/pubspec.lock new file mode 100644 index 000000000..a9c652dce --- /dev/null +++ b/lib/test_randomness/pubspec.lock @@ -0,0 +1,36 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + flutter_lints: + dependency: transitive + description: + name: flutter_lints + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 + url: "https://pub.dev" + source: hosted + version: "3.0.1" + lints: + dependency: transitive + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" + random_string: + dependency: "direct main" + description: + name: random_string + sha256: "03b52435aae8cbdd1056cf91bfc5bf845e9706724dd35ae2e99fa14a1ef79d02" + url: "https://pub.dev" + source: hosted + version: "2.3.1" + sharezone_lints: + dependency: "direct dev" + description: + path: "../sharezone_lints" + relative: true + source: path + version: "1.0.0" +sdks: + dart: ">=3.0.0 <4.0.0" diff --git a/lib/test_randomness/pubspec.yaml b/lib/test_randomness/pubspec.yaml new file mode 100644 index 000000000..346934f7a --- /dev/null +++ b/lib/test_randomness/pubspec.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) +# Licensed under the EUPL-1.2-or-later. +# +# You may obtain a copy of the Licence at: +# https://joinup.ec.europa.eu/software/page/eupl +# +# SPDX-License-Identifier: EUPL-1.2 + +name: test_randomness +description: A new Flutter package project. +version: 0.0.1 +publish_to: none + +environment: + sdk: ">=2.12.0 <3.0.0" + +dependencies: + random_string: ^2.3.1 + +dev_dependencies: + sharezone_lints: + path: ../sharezone_lints From f01c02b1b607bb6ec522f4b15b76550ed2b87a55 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:14:22 +0100 Subject: [PATCH 05/12] Use `szSeededTestRandom` in tests. --- .../dashboard/update_reminder_bloc_test.dart | 9 ++++--- app/test/timetable/timetable_bloc_test.dart | 5 ++-- ...ard_item_read_by_users_list_page_test.dart | 6 ++--- .../past_calendrical_events_page_test.dart | 17 ++++++------- .../test/create_homework_util.dart | 14 ++--------- .../random_string/random_string_test.dart | 24 ------------------- 6 files changed, 17 insertions(+), 58 deletions(-) delete mode 100644 lib/sharezone_utils/test/random_string/random_string_test.dart diff --git a/app/test/dashboard/update_reminder_bloc_test.dart b/app/test/dashboard/update_reminder_bloc_test.dart index 8770e38e2..32d4cd789 100644 --- a/app/test/dashboard/update_reminder_bloc_test.dart +++ b/app/test/dashboard/update_reminder_bloc_test.dart @@ -6,12 +6,11 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'dart:math'; - import 'package:flutter_test/flutter_test.dart'; +import 'package:sharezone/changelog/change.dart'; import 'package:sharezone/dashboard/update_reminder/release.dart'; import 'package:sharezone/dashboard/update_reminder/update_reminder_bloc.dart'; -import 'package:sharezone/changelog/change.dart'; +import 'package:test_randomness/test_randomness.dart'; void main() { group('UpdateReminderBloc', () { @@ -139,6 +138,6 @@ void main() { Release _releaseWith({required String version, DateTime? releaseTime}) { return Release( version: Version.parse(name: version), - releaseDate: - releaseTime ?? DateTime(2020, 02, Random.secure().nextInt(25) + 1)); + releaseDate: releaseTime ?? + DateTime(2020, 02, szSeededTestRandom.nextInt(25) + 1)); } diff --git a/app/test/timetable/timetable_bloc_test.dart b/app/test/timetable/timetable_bloc_test.dart index e24c8e881..319be828e 100644 --- a/app/test/timetable/timetable_bloc_test.dart +++ b/app/test/timetable/timetable_bloc_test.dart @@ -6,8 +6,6 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'dart:math'; - import 'package:common_domain_models/common_domain_models.dart'; import 'package:date/src/date.dart'; import 'package:date/weekday.dart'; @@ -19,6 +17,7 @@ import 'package:sharezone/calendrical_events/models/calendrical_event_types.dart import 'package:sharezone/timetable/src/bloc/timetable_bloc.dart'; import 'package:sharezone/timetable/src/models/lesson.dart'; import 'package:sharezone/timetable/timetable_page/school_class_filter/school_class_filter_view.dart'; +import 'package:test_randomness/test_randomness.dart'; import 'package:time/time.dart'; import 'mock/mock_course_gateway.dart'; @@ -50,7 +49,7 @@ void main() { endTime: Time(hour: 10, minute: 0), groupID: groupId, groupType: GroupType.course, - lessonID: Random().nextInt(200).toString(), + lessonID: szSeededTestRandom.nextInt(200).toString(), place: "", teacher: "", weekday: WeekDay.monday, diff --git a/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart b/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart index 1e4c43949..7e1cbe6f1 100644 --- a/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart +++ b/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart @@ -6,8 +6,6 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'dart:math'; - import 'package:bloc_provider/bloc_provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -20,6 +18,7 @@ import 'package:sharezone/blackboard/details/blackboard_item_read_by_users_list/ import 'package:sharezone/blackboard/details/blackboard_item_read_by_users_list/user_view.dart'; import 'package:sharezone/sharezone_plus/subscription_service/subscription_service.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; +import 'package:test_randomness/test_randomness.dart'; import 'package:user/user.dart'; import 'blackboard_item_read_by_users_list_page_test.mocks.dart'; @@ -37,12 +36,11 @@ void main() { late MockSubscriptionService subscriptionService; void setUserViews() { - final random = Random(42); final dummyUsers = [ for (var i = 0; i < 10; i++) UserView( uid: "user$i", - hasRead: random.nextBool(), + hasRead: szSeededTestRandom.nextBool(), typeOfUser: TypeOfUser.student.toReadableString(), name: 'User $i', ) diff --git a/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart b/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart index bdfe013f8..3706a8c10 100644 --- a/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart +++ b/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart @@ -6,8 +6,6 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'dart:math'; - import 'package:design/design.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -21,6 +19,7 @@ import 'package:sharezone/calendrical_events/provider/past_calendrical_events_pa import 'package:sharezone/calendrical_events/provider/past_calendrical_events_page_controller_factory.dart'; import 'package:sharezone/timetable/src/widgets/events/event_view.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; +import 'package:test_randomness/test_randomness.dart'; import 'past_calendrical_events_page_test.mocks.dart'; @@ -32,28 +31,26 @@ import 'past_calendrical_events_page_test.mocks.dart'; void main() { late MockPastCalendricalEventsPageController controller; late MockPastCalendricalEventsPageControllerFactory controllerFactory; - late Random random; EventView randomEventView() { return EventView( - design: Design.random(random), + design: Design.random(szSeededTestRandom), // Generate random date dateText: DateTime( 2021, - random.nextInt(12) + 1, - random.nextInt(28) + 1, + szSeededTestRandom.nextInt(12) + 1, + szSeededTestRandom.nextInt(28) + 1, ).toIso8601String(), event: MockCalendricalEvent(), - groupID: '${random.nextInt(1000)}', - courseName: 'Course ${random.nextInt(1000)}', - title: 'Title ${random.nextInt(1000)}', + groupID: '${szSeededTestRandom.nextInt(1000)}', + courseName: 'Course ${szSeededTestRandom.nextInt(1000)}', + title: 'Title ${szSeededTestRandom.nextInt(1000)}', ); } setUp(() { controller = MockPastCalendricalEventsPageController(); controllerFactory = MockPastCalendricalEventsPageControllerFactory(); - random = Random(42); when(controllerFactory.create()).thenReturn(controller); }); diff --git a/lib/hausaufgabenheft_logik/test/create_homework_util.dart b/lib/hausaufgabenheft_logik/test/create_homework_util.dart index bb5b9e571..6aa2d2631 100644 --- a/lib/hausaufgabenheft_logik/test/create_homework_util.dart +++ b/lib/hausaufgabenheft_logik/test/create_homework_util.dart @@ -6,12 +6,11 @@ // // SPDX-License-Identifier: EUPL-1.2 -import 'dart:math'; - import 'package:common_domain_models/common_domain_models.dart'; import 'package:hausaufgabenheft_logik/src/models/homework/homework.dart'; import 'package:hausaufgabenheft_logik/src/models/homework/models_used_by_homework.dart'; import 'package:hausaufgabenheft_logik/src/views/color.dart'; +import 'package:test_randomness/test_randomness.dart'; HomeworkReadModel createHomework( {Date todoDate = const Date(day: 1, month: 1, year: 2019), @@ -22,7 +21,7 @@ HomeworkReadModel createHomework( bool withSubmissions = false, Color? subjectColor, String abbreviation = 'Abb'}) { - id = id == 'willBeRandom' ? randomString(5) : id; + id = id == 'willBeRandom' ? randomAlphaNumeric(5) : id; return HomeworkReadModel( id: HomeworkId(id), todoDate: todoDate.asDateTime(), @@ -32,12 +31,3 @@ HomeworkReadModel createHomework( status: done ? CompletionStatus.completed : CompletionStatus.open, ); } - -String randomString(int length) { - var rand = Random(); - var codeUnits = List.generate(length, (index) { - return rand.nextInt(33) + 89; - }); - - return String.fromCharCodes(codeUnits); -} diff --git a/lib/sharezone_utils/test/random_string/random_string_test.dart b/lib/sharezone_utils/test/random_string/random_string_test.dart deleted file mode 100644 index f152922d5..000000000 --- a/lib/sharezone_utils/test/random_string/random_string_test.dart +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) -// Licensed under the EUPL-1.2-or-later. -// -// You may obtain a copy of the Licence at: -// https://joinup.ec.europa.eu/software/page/eupl -// -// SPDX-License-Identifier: EUPL-1.2 - -import 'package:flutter_test/flutter_test.dart'; -import 'package:sharezone_utils/random_string.dart'; - -void main() { - test('randomString()', () { - for (int i = 0; i < 50; i++) { - expect(randomString(10), hasLength(10)); - } - }); - - test('randomIDString()', () { - for (int i = 0; i < 50; i++) { - expect(randomIDString(10), hasLength(10)); - } - }); -} From e806efed22afaede6a104f4e7c890bd9f08c218f Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:14:55 +0100 Subject: [PATCH 06/12] Rename to `szTestRandom` --- app/test/dashboard/update_reminder_bloc_test.dart | 4 ++-- app/test/timetable/timetable_bloc_test.dart | 2 +- ...blackboard_item_read_by_users_list_page_test.dart | 2 +- .../page/past_calendrical_events_page_test.dart | 12 ++++++------ lib/test_randomness/lib/src/test_randomness.dart | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/test/dashboard/update_reminder_bloc_test.dart b/app/test/dashboard/update_reminder_bloc_test.dart index 32d4cd789..3804174db 100644 --- a/app/test/dashboard/update_reminder_bloc_test.dart +++ b/app/test/dashboard/update_reminder_bloc_test.dart @@ -138,6 +138,6 @@ void main() { Release _releaseWith({required String version, DateTime? releaseTime}) { return Release( version: Version.parse(name: version), - releaseDate: releaseTime ?? - DateTime(2020, 02, szSeededTestRandom.nextInt(25) + 1)); + releaseDate: + releaseTime ?? DateTime(2020, 02, szTestRandom.nextInt(25) + 1)); } diff --git a/app/test/timetable/timetable_bloc_test.dart b/app/test/timetable/timetable_bloc_test.dart index 319be828e..d1e5c1a3c 100644 --- a/app/test/timetable/timetable_bloc_test.dart +++ b/app/test/timetable/timetable_bloc_test.dart @@ -49,7 +49,7 @@ void main() { endTime: Time(hour: 10, minute: 0), groupID: groupId, groupType: GroupType.course, - lessonID: szSeededTestRandom.nextInt(200).toString(), + lessonID: szTestRandom.nextInt(200).toString(), place: "", teacher: "", weekday: WeekDay.monday, diff --git a/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart b/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart index 7e1cbe6f1..1d740649e 100644 --- a/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart +++ b/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart @@ -40,7 +40,7 @@ void main() { for (var i = 0; i < 10; i++) UserView( uid: "user$i", - hasRead: szSeededTestRandom.nextBool(), + hasRead: szTestRandom.nextBool(), typeOfUser: TypeOfUser.student.toReadableString(), name: 'User $i', ) diff --git a/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart b/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart index 3706a8c10..92421579a 100644 --- a/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart +++ b/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart @@ -34,17 +34,17 @@ void main() { EventView randomEventView() { return EventView( - design: Design.random(szSeededTestRandom), + design: Design.random(szTestRandom), // Generate random date dateText: DateTime( 2021, - szSeededTestRandom.nextInt(12) + 1, - szSeededTestRandom.nextInt(28) + 1, + szTestRandom.nextInt(12) + 1, + szTestRandom.nextInt(28) + 1, ).toIso8601String(), event: MockCalendricalEvent(), - groupID: '${szSeededTestRandom.nextInt(1000)}', - courseName: 'Course ${szSeededTestRandom.nextInt(1000)}', - title: 'Title ${szSeededTestRandom.nextInt(1000)}', + groupID: '${szTestRandom.nextInt(1000)}', + courseName: 'Course ${szTestRandom.nextInt(1000)}', + title: 'Title ${szTestRandom.nextInt(1000)}', ); } diff --git a/lib/test_randomness/lib/src/test_randomness.dart b/lib/test_randomness/lib/src/test_randomness.dart index 4af8abb51..b984bbf5f 100644 --- a/lib/test_randomness/lib/src/test_randomness.dart +++ b/lib/test_randomness/lib/src/test_randomness.dart @@ -5,9 +5,9 @@ import 'package:random_string/random_string.dart' as lib; const randomnessSeed = int.fromEnvironment('TEST_RANDOMNESS_SEED', defaultValue: 0); -final szSeededTestRandom = Random(randomnessSeed); +final szTestRandom = Random(randomnessSeed); -final _randomProvider = lib.CoreRandomProvider.from(szSeededTestRandom); +final _randomProvider = lib.CoreRandomProvider.from(szTestRandom); /// Generates a random integer where [from] <= [to] inclusive /// where 0 <= from <= to <= 999999999999999 From 72edc2a81fe641d76f262c00042579e9f13eca59 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:16:47 +0100 Subject: [PATCH 07/12] Add docs --- lib/test_randomness/lib/src/test_randomness.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/test_randomness/lib/src/test_randomness.dart b/lib/test_randomness/lib/src/test_randomness.dart index b984bbf5f..c66ef0346 100644 --- a/lib/test_randomness/lib/src/test_randomness.dart +++ b/lib/test_randomness/lib/src/test_randomness.dart @@ -2,9 +2,18 @@ import 'dart:math'; import 'package:random_string/random_string.dart' as lib; +/// The seed to use for randomness. +/// +/// This is used to ensure that tests are deterministic. +/// The `TEST_RANDOMNESS_SEED` environment variable will be provided when +/// running `sz test`. const randomnessSeed = int.fromEnvironment('TEST_RANDOMNESS_SEED', defaultValue: 0); +/// The [Random] that should be used for randomness in tests. +/// +/// This is a [Random] that is seeded with [randomnessSeed]. +/// This is used to ensure that tests are deterministic. final szTestRandom = Random(randomnessSeed); final _randomProvider = lib.CoreRandomProvider.from(szTestRandom); From f26812c3af4f5a3e5dd327fe0baec558a3e85bcf Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 20:22:21 +0100 Subject: [PATCH 08/12] Add license header. --- lib/test_randomness/lib/src/test_randomness.dart | 8 ++++++++ lib/test_randomness/lib/test_randomness.dart | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/test_randomness/lib/src/test_randomness.dart b/lib/test_randomness/lib/src/test_randomness.dart index c66ef0346..3adfc9fc1 100644 --- a/lib/test_randomness/lib/src/test_randomness.dart +++ b/lib/test_randomness/lib/src/test_randomness.dart @@ -1,3 +1,11 @@ +// Copyright (c) 2024 Sharezone UG (haftungsbeschränkt) +// Licensed under the EUPL-1.2-or-later. +// +// You may obtain a copy of the Licence at: +// https://joinup.ec.europa.eu/software/page/eupl +// +// SPDX-License-Identifier: EUPL-1.2 + import 'dart:math'; import 'package:random_string/random_string.dart' as lib; diff --git a/lib/test_randomness/lib/test_randomness.dart b/lib/test_randomness/lib/test_randomness.dart index 2d51d909d..636fa7b37 100644 --- a/lib/test_randomness/lib/test_randomness.dart +++ b/lib/test_randomness/lib/test_randomness.dart @@ -1,3 +1,11 @@ +// Copyright (c) 2024 Sharezone UG (haftungsbeschränkt) +// Licensed under the EUPL-1.2-or-later. +// +// You may obtain a copy of the Licence at: +// https://joinup.ec.europa.eu/software/page/eupl +// +// SPDX-License-Identifier: EUPL-1.2 + library test_randomness; export 'src/test_randomness.dart'; From 98f04c2e46a8c409b5eb9a348824a3c8359d2de5 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:47:08 +0100 Subject: [PATCH 09/12] Add `test_randomness` to `licenses_config.yaml`. --- licenses_config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/licenses_config.yaml b/licenses_config.yaml index dbb07ddba..178e63ea7 100644 --- a/licenses_config.yaml +++ b/licenses_config.yaml @@ -85,5 +85,4 @@ packageLicenseOverride: url_launcher_extended: EUPL-1.2-or-later user: EUPL-1.2-or-later util: EUPL-1.2-or-later - - + test_randomness: EUPL-1.2-or-later \ No newline at end of file From 55c128d6432daefd3cc4f7043a39eb80f6f832f0 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:59:17 +0100 Subject: [PATCH 10/12] Use fixed Random in golden tests. --- ...board_item_read_by_users_list_page_test.dart | 6 ++++-- .../page/past_calendrical_events_page_test.dart | 17 ++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart b/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart index 1d740649e..1e4c43949 100644 --- a/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart +++ b/app/test_goldens/blackboard/details/blackboard_item_read_by_users_list_page_test.dart @@ -6,6 +6,8 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'dart:math'; + import 'package:bloc_provider/bloc_provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -18,7 +20,6 @@ import 'package:sharezone/blackboard/details/blackboard_item_read_by_users_list/ import 'package:sharezone/blackboard/details/blackboard_item_read_by_users_list/user_view.dart'; import 'package:sharezone/sharezone_plus/subscription_service/subscription_service.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; -import 'package:test_randomness/test_randomness.dart'; import 'package:user/user.dart'; import 'blackboard_item_read_by_users_list_page_test.mocks.dart'; @@ -36,11 +37,12 @@ void main() { late MockSubscriptionService subscriptionService; void setUserViews() { + final random = Random(42); final dummyUsers = [ for (var i = 0; i < 10; i++) UserView( uid: "user$i", - hasRead: szTestRandom.nextBool(), + hasRead: random.nextBool(), typeOfUser: TypeOfUser.student.toReadableString(), name: 'User $i', ) diff --git a/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart b/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart index 92421579a..bdfe013f8 100644 --- a/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart +++ b/app/test_goldens/calendrical_events/page/past_calendrical_events_page_test.dart @@ -6,6 +6,8 @@ // // SPDX-License-Identifier: EUPL-1.2 +import 'dart:math'; + import 'package:design/design.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -19,7 +21,6 @@ import 'package:sharezone/calendrical_events/provider/past_calendrical_events_pa import 'package:sharezone/calendrical_events/provider/past_calendrical_events_page_controller_factory.dart'; import 'package:sharezone/timetable/src/widgets/events/event_view.dart'; import 'package:sharezone_widgets/sharezone_widgets.dart'; -import 'package:test_randomness/test_randomness.dart'; import 'past_calendrical_events_page_test.mocks.dart'; @@ -31,26 +32,28 @@ import 'past_calendrical_events_page_test.mocks.dart'; void main() { late MockPastCalendricalEventsPageController controller; late MockPastCalendricalEventsPageControllerFactory controllerFactory; + late Random random; EventView randomEventView() { return EventView( - design: Design.random(szTestRandom), + design: Design.random(random), // Generate random date dateText: DateTime( 2021, - szTestRandom.nextInt(12) + 1, - szTestRandom.nextInt(28) + 1, + random.nextInt(12) + 1, + random.nextInt(28) + 1, ).toIso8601String(), event: MockCalendricalEvent(), - groupID: '${szTestRandom.nextInt(1000)}', - courseName: 'Course ${szTestRandom.nextInt(1000)}', - title: 'Title ${szTestRandom.nextInt(1000)}', + groupID: '${random.nextInt(1000)}', + courseName: 'Course ${random.nextInt(1000)}', + title: 'Title ${random.nextInt(1000)}', ); } setUp(() { controller = MockPastCalendricalEventsPageController(); controllerFactory = MockPastCalendricalEventsPageControllerFactory(); + random = Random(42); when(controllerFactory.create()).thenReturn(controller); }); From e39b5c4c7fc909b34cda9368bf1df1d62a28a311 Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:30:02 +0100 Subject: [PATCH 11/12] Fix merge error --- tools/sz_repo_cli/lib/src/commands/src/test_command.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart index 975f56315..3096fbc39 100644 --- a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart +++ b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart @@ -162,7 +162,6 @@ Future _runTestsFlutter( 'test', '--test-randomize-ordering-seed', testRandomizeOrderingSeed, - testRandomizeOrderingSeed, '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', 'test_goldens', if (updateGoldens) '--update-goldens', From bf5de40ae7ec8d415ce24ebeab3f15e0d17a3b2b Mon Sep 17 00:00:00 2001 From: Jonas Sander <29028262+Jonas-Sander@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:29:14 +0100 Subject: [PATCH 12/12] Fix dart test command. --- .../lib/src/commands/src/test_command.dart | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart index 3096fbc39..a2718c49c 100644 --- a/tools/sz_repo_cli/lib/src/commands/src/test_command.dart +++ b/tools/sz_repo_cli/lib/src/commands/src/test_command.dart @@ -7,6 +7,8 @@ // SPDX-License-Identifier: EUPL-1.2 import 'dart:async'; +import 'dart:io'; +import 'dart:math'; import 'package:process_runner/process_runner.dart'; import 'package:sz_repo_cli/src/common/common.dart'; @@ -91,8 +93,14 @@ Future runTests( required bool excludeGoldens, required bool onlyGoldens, required bool updateGoldens, - required String testRandomizeOrderingSeed, + String testRandomizeOrderingSeed = 'random', }) { + // Copied from https://github.com/dart-lang/test/blob/ba64bbbaa26f09e139c26f9ad6409995806aac6e/pkgs/test_core/lib/src/runner/configuration/args.dart#L277 + final seed = testRandomizeOrderingSeed == 'random' + ? Random().nextInt(4294967295) + : int.parse(testRandomizeOrderingSeed).toUnsigned(32); + stdout.writeln('Using seed for test randomization: $seed'); + if (package.isFlutterPackage) { return _runTestsFlutter( processRunner, @@ -100,7 +108,7 @@ Future runTests( excludeGoldens: excludeGoldens, onlyGoldens: onlyGoldens, updateGoldens: updateGoldens, - testRandomizeOrderingSeed: testRandomizeOrderingSeed, + testRandomizeOrderingSeed: seed, ); } else { return _runTestsDart( @@ -108,7 +116,7 @@ Future runTests( package, excludeGoldens: excludeGoldens, onlyGoldens: onlyGoldens, - testRandomizeOrderingSeed: testRandomizeOrderingSeed, + testRandomizeOrderingSeed: seed, ); } } @@ -120,7 +128,7 @@ Future _runTestsDart( // don't have golden tests. required bool excludeGoldens, required bool onlyGoldens, - required String testRandomizeOrderingSeed, + required int testRandomizeOrderingSeed, }) async { if (onlyGoldens) { // Golden tests are only run in the flutter package. @@ -133,10 +141,13 @@ Future _runTestsDart( [ 'fvm', 'dart', + '--define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', 'test', '--test-randomize-ordering-seed', - testRandomizeOrderingSeed, - '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', + '$testRandomizeOrderingSeed', + // --define only works with this flag, seems to be a bug in Dart. + // See: https://github.com/dart-lang/test/issues/1794 + '--use-data-isolate-strategy', ], workingDirectory: package.location, ); @@ -148,7 +159,7 @@ Future _runTestsFlutter( required bool excludeGoldens, required bool onlyGoldens, required bool updateGoldens, - required String testRandomizeOrderingSeed, + required int testRandomizeOrderingSeed, }) async { if (onlyGoldens || !excludeGoldens) { if (!package.hasGoldenTestsDirectory) { @@ -161,7 +172,7 @@ Future _runTestsFlutter( 'flutter', 'test', '--test-randomize-ordering-seed', - testRandomizeOrderingSeed, + '$testRandomizeOrderingSeed', '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', 'test_goldens', if (updateGoldens) '--update-goldens', @@ -181,7 +192,7 @@ Future _runTestsFlutter( 'flutter', 'test', '--test-randomize-ordering-seed', - testRandomizeOrderingSeed, + '$testRandomizeOrderingSeed', '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', ], workingDirectory: package.location, @@ -202,7 +213,7 @@ Future _runTestsFlutter( // Directory for unit and widget tests. 'test', '--test-randomize-ordering-seed', - testRandomizeOrderingSeed, + '$testRandomizeOrderingSeed', '--dart-define=TEST_RANDOMNESS_SEED=$testRandomizeOrderingSeed', ], workingDirectory: package.location,