Skip to content

Commit bf64eef

Browse files
authored
[infra] Add test_helpers package (#2385)
1 parent f6ab5f4 commit bf64eef

File tree

32 files changed

+146
-313
lines changed

32 files changed

+146
-313
lines changed

.github/workflows/native.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ on:
1717
- "pkgs/json_syntax_generator/**"
1818
- "pkgs/native_toolchain_c/**"
1919
- "pkgs/repo_lint_rules/**"
20+
- "pkgs/test_helpers/**"
2021
- "tool/**"
2122
push:
2223
branches: [main]
@@ -29,6 +30,7 @@ on:
2930
- "pkgs/json_syntax_generator/**"
3031
- "pkgs/native_toolchain_c/**"
3132
- "pkgs/repo_lint_rules/**"
33+
- "pkgs/test_helpers/**"
3234
- "tool/**"
3335
schedule:
3436
- cron: "0 0 * * 0" # weekly

.github/workflows/objective_c.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ on:
88
- '.github/workflows/objective_c.yaml'
99
- 'pkgs/ffigen/**'
1010
- 'pkgs/objective_c/**'
11+
- 'pkgs/test_helpers/**'
1112
pull_request:
1213
branches: [main, stable]
1314
paths:
1415
- '.github/workflows/objective_c.yaml'
1516
- 'pkgs/ffigen/**'
1617
- 'pkgs/objective_c/**'
18+
- 'pkgs/test_helpers/**'
1719
schedule:
1820
- cron: "0 0 * * 0"
1921

.github/workflows/swift2objc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ on:
77
paths:
88
- '.github/workflows/swift2objc.yaml'
99
- 'pkgs/swift2objc/**'
10+
- 'pkgs/test_helpers/**'
1011
pull_request:
1112
branches: [main, stable]
1213
paths:
1314
- '.github/workflows/swift2objc.yaml'
1415
- 'pkgs/swift2objc/**'
16+
- 'pkgs/test_helpers/**'
1517
schedule:
1618
- cron: "0 0 * * 0"
1719

.github/workflows/swiftgen.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ on:
66
branches: [main, stable]
77
paths:
88
- '.github/workflows/swiftgen.yaml'
9+
- 'pkgs/ffigen/**'
10+
- 'pkgs/objective_c/**'
11+
- 'pkgs/swift2objc/**'
912
- 'pkgs/swiftgen/**'
13+
- 'pkgs/test_helpers/**'
1014
pull_request:
1115
branches: [main, stable]
1216
paths:
@@ -15,6 +19,7 @@ on:
1519
- 'pkgs/objective_c/**'
1620
- 'pkgs/swift2objc/**'
1721
- 'pkgs/swiftgen/**'
22+
- 'pkgs/test_helpers/**'
1823
schedule:
1924
- cron: "0 0 * * 0"
2025

pkgs/code_assets/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ dev_dependencies:
3030
repo_lint_rules:
3131
path: ../repo_lint_rules/
3232
test: ^1.25.15
33+
test_helpers:
34+
path: ../test_helpers/

pkgs/code_assets/test/json_schema/schema_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import 'dart:convert';
88

99
import 'package:json_schema/json_schema.dart';
10+
import 'package:test_helpers/test_helpers.dart';
1011

1112
import 'helpers.dart';
1213

pkgs/data_assets/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ dev_dependencies:
2626
repo_lint_rules:
2727
path: ../repo_lint_rules/
2828
test: ^1.25.15
29+
test_helpers:
30+
path: ../test_helpers

pkgs/data_assets/test/json_schema/schema_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:json_schema/json_schema.dart';
6+
import 'package:test_helpers/test_helpers.dart';
67

78
import 'helpers.dart';
89

pkgs/hooks/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ dev_dependencies:
4242
repo_lint_rules:
4343
path: ../repo_lint_rules/
4444
test: ^1.25.15
45+
test_helpers:
46+
path: ../test_helpers/

pkgs/hooks/test/helpers.dart

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:data_assets/data_assets.dart';
99
import 'package:hooks/hooks.dart';
1010
import 'package:logging/logging.dart';
1111
import 'package:test/test.dart';
12+
import 'package:test_helpers/test_helpers.dart';
1213

1314
const keepTempKey = 'KEEP_TEMPORARY_DIRECTORIES';
1415

@@ -41,58 +42,8 @@ Future<void> inTempDir(
4142
}
4243
}
4344

44-
/// Test files are run in a variety of ways, find this package root in all.
45-
///
46-
/// Test files can be run from source from any working directory. The Dart SDK
47-
/// `tools/test.py` runs them from the root of the SDK for example.
48-
///
49-
/// Test files can be run from dill from the root of package. `package:test`
50-
/// does this.
51-
///
52-
/// https://github.com/dart-lang/test/issues/110
53-
Uri findPackageRoot(String packageName) {
54-
final script = Platform.script;
55-
final fileName = script.name;
56-
if (fileName.endsWith('.dart')) {
57-
// We're likely running from source in the package somewhere.
58-
var directory = script.resolve('.');
59-
while (true) {
60-
final dirName = directory.name;
61-
if (dirName == packageName) {
62-
return directory;
63-
}
64-
final parent = directory.resolve('..');
65-
if (parent == directory) break;
66-
directory = parent;
67-
}
68-
} else if (fileName.endsWith('.dill')) {
69-
// Probably from the package root.
70-
final cwd = Directory.current.uri;
71-
final dirName = cwd.name;
72-
if (dirName == packageName) {
73-
return cwd;
74-
}
75-
}
76-
// Or the workspace root.
77-
final cwd = Directory.current.uri;
78-
final candidate = cwd.resolve('pkgs/$packageName/');
79-
if (Directory.fromUri(candidate).existsSync()) {
80-
return candidate;
81-
}
82-
throw StateError(
83-
"Could not find package root for package '$packageName'. "
84-
'Tried finding the package root via Platform.script '
85-
"'${Platform.script.toFilePath()}' and Directory.current "
86-
"'${Directory.current.uri.toFilePath()}'.",
87-
);
88-
}
89-
9045
Uri packageUri = findPackageRoot('hooks');
9146

92-
extension on Uri {
93-
String get name => pathSegments.where((e) => e != '').last;
94-
}
95-
9647
/// Archiver provided by the environment.
9748
///
9849
/// Provided on Dart CI.

0 commit comments

Comments
 (0)