Skip to content

Commit

Permalink
implement PatrolAppService.addSetUpAll and remembering setUpAlls
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Oct 10, 2023
1 parent 7ed9235 commit 5b742a3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public Object[] listDartTests() {
* Throws AssertionError if the test fails.
*/
public RunDartTestResponse runDartTest(String name) {
final String TAG = "PatrolJUnitRunner.runDartTest(" + name + "): ";
final String TAG = "PatrolJUnitRunner.runDartTest(\"" + name + "\"): ";

try {
Logger.INSTANCE.i(TAG + "Requested execution");
Expand Down
30 changes: 23 additions & 7 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,35 @@ void patrolTearDown(Future<void> Function() body) {
}

/// A modification of [setUpAll] that works with Patrol's native automation.
///
/// It keeps track of calls made to setUpAll.
void patrolSetUpAll(Future<void> Function() body) {
setUpAll(() async {
final patrolAppService = PatrolBinding.instance.patrolAppService;

final parentGroupsName = global_state.currentGroupFullName;
patrolAppService.addSetUpAll(parentGroupsName);
final setUpAllName = patrolAppService.addSetUpAll(parentGroupsName);

if (await global_state.isInitialRun) {
// Skip calling body if we're in test discovery phase
print(
"PATROL_DEBUG: Skipping setUpAll '$setUpAllName' because it's test discovery phase",
);
return;
}

// TODO: Skip calling body if it this setUpAll was already executed

final requestedTest = await patrolAppService.testExecutionRequested;

// Skip calling if parentGroupName is not a substring of requestedTestName
if (!requestedTest.startsWith(parentGroupsName)) {
// This is not exhaustive.
return;
}

// final requestedToExecute = await PatrolBinding.instance.patrolAppService
// .waitForExecutionRequest(currentSetUpAllIndex);
await body();

// if (requestedToExecute) {
// await body();
// }
// TODO: Mark this setUpAll as executed
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/patrol/lib/src/global_state.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ignore: implementation_imports
import 'package:flutter/services.dart';
// ignore: implementation_imports
import 'package:test_api/src/backend/invoker.dart';

/// Maximum test case length for ATO, after transformations.
Expand Down
41 changes: 21 additions & 20 deletions packages/patrol/lib/src/native/patrol_app_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class PatrolAppService extends PatrolAppServiceServer {
/// setUpAlls, unlike setUps, aren't executed in the [LiveTest] context.
/// Because of this, we can't depend on the [LiveTest]'s name, so we identify
/// them by the parent group ID instead.
///
/// This is a list of groups containing setUpAllCallbacks with an index
/// appended.
final List<String> setUpAlls = [];

/// A completer that completes with the name of the Dart test file that was
Expand All @@ -83,28 +86,26 @@ class PatrolAppService extends PatrolAppServiceServer {
}

/// Adds a setUpAll callback to the list of all setUpAll callbacks.
void addSetUpAll(String group) {
// Not very optimal, but good enough for now.

setUpAlls.add('$group + ${group.hashCode}');

// for (final setUpAll in setUpAlls) {
// final parts = setUpAll.split(' ');
// final groupName = parts.sublist(0, parts.length - 1).join(' ');

// if (groupName == group) {

// }
///
/// Returns the name under which this setUpAll callback was added.
String addSetUpAll(String group) {
// Not optimal, but good enough for now.

// Go over all groups, checking if the group is already in the list.
var groupIndex = 0;
for (final setUpAll in setUpAlls) {
final parts = setUpAll.split(' ');
final groupName = parts.sublist(0, parts.length - 1).join(' ');

if (groupName == group) {
groupIndex++;
}
}

// final index = parts.last;
// if (setUpAll == group) {
// return;
// }
// }
final name = '$group $groupIndex';

// add an index at the end of setUpAlls
// parent testA 1
// parent testA 2
setUpAlls.add(name);
return name;
}

/// Marks [dartFileName] as completed with the given [passed] status.
Expand Down

0 comments on commit 5b742a3

Please sign in to comment.