Skip to content

Instantly share code, notes, and snippets.

@bartekpacia
Last active April 22, 2023 20:21
Show Gist options
  • Save bartekpacia/d1e5bac5b74331f98777148933ffb707 to your computer and use it in GitHub Desktop.
Save bartekpacia/d1e5bac5b74331f98777148933ffb707 to your computer and use it in GitHub Desktop.
patrol bundling stuff
fun DartTestGroup.listFlatDartFiles(): List<String> {
val files = mutableListOf<String>()
for (group in groupsList) {
files.addAll(group.listGroups())
}
return files.filter { it.endsWith(".dart") }
}
// Recursively lists groups in this group.
private fun DartTestGroup.listGroups(): List<String> {
val groups = mutableListOf<String>(this.name)
for (group in groupsList) {
groups.addAll(group.listGroups())
}
return groups
}
package pl.leancode.patrol
import org.junit.Test
import pl.leancode.patrol.contracts.dartTestCase
import pl.leancode.patrol.contracts.dartTestGroup
import kotlin.test.assertContentEquals
// TODO: Make sure these tests are run on CI
class DartTestGroupExtensionsTest {
@Test
fun `listDartFilesFlat() lists the Dart test files in the integration_test directory`() {
// ── permissions
// ├── permissions_location_test.dart
// └── permissions_many_test.dart
// ── sign_in
// ├── sign_in_email_test.dart
// ├── sign_in_facebook_test.dart
// └── sign_in_google_test.dart
// ── example_test.dart
val dartTestGroup = dartTestGroup {
name = "root"
groups += listOf(
dartTestGroup {
name = "permissions"
groups += listOf(
dartTestGroup {
name = "permissions_location_test.dart"
tests += listOf(
dartTestCase {
name = "accepts location permission"
}
)
},
dartTestGroup {
name = "permissions_many_test.dart"
tests += listOf(
dartTestCase {
name = "accepts various permissions"
}
)
}
)
},
dartTestGroup {
name = "sign_in"
groups += listOf(
dartTestGroup {
name = "sign_in_email_test.dart"
tests += listOf(
dartTestCase {
name = "signs in with email"
}
)
},
dartTestGroup {
name = "sign_in_facebook_test.dart"
tests += listOf(
dartTestCase {
name = "signs in with facebook"
}
)
},
dartTestGroup {
name = "sign_in_google_test.dart"
tests += listOf(
dartTestCase {
name = "signs in with google"
}
)
}
)
},
dartTestGroup {
name = "example_test.dart"
tests += listOf(
dartTestCase {
name = "some example test"
}
)
}
)
}
val dartTestFiles = dartTestGroup.listFlatDartFiles()
println(dartTestFiles)
assertContentEquals(
listOf(
"permissions_location_test.dart",
"permissions_many_test.dart",
"sign_in_email_test.dart",
"sign_in_facebook_test.dart",
"sign_in_google_test.dart",
"example_test.dart"
),
dartTestFiles,
)
}
}
/// Recursively prints test groups and test cases.
///
/// [entry] is either a [DartTestGroup] or DartTestCase.
void describe(DartTestGroup entry, {int level = 0}) {
final padding = ' ' * level;
print(
'$padding Group: ${entry.name} (${entry.groups.length} groups, ${entry.tests.length} tests)',
);
print('$padding Groups: ${entry.groups.isEmpty ? 'none' : ''}');
for (final groupEntry in entry.groups) {
describe(groupEntry, level: level + 1);
}
print('$padding Tests: ${entry.tests.isEmpty ? 'none' : ''}');
for (final test in entry.tests) {
print('$padding Test: ${test.name}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment