Skip to content

Commit 7100e64

Browse files
authored
Add a github actions workflow for dart analysis and tests (#2964)
* add a github actions workflow for analyzing the repo and running known tests * better names, migrate spread collections benchmark to null safety
1 parent 1a24495 commit 7100e64

File tree

6 files changed

+94
-39
lines changed

6 files changed

+94
-39
lines changed

.github/workflows/dart.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Dart CI
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
push:
7+
branches: [master]
8+
9+
env:
10+
PUB_ENVIRONMENT: bot.github
11+
12+
jobs:
13+
analyze:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: dart-lang/setup-dart@v1
18+
with:
19+
sdk: dev
20+
- name: dart pub get (specification)
21+
run: dart pub get
22+
working-directory: specification
23+
- name: dart pub get (working/macros/example)
24+
run: dart pub get
25+
working-directory: working/macros/example
26+
- name: dart pub get (accepted/2.3/spread-collections/benchmarks)
27+
run: dart pub get
28+
working-directory: accepted/2.3/spread-collections/benchmarks
29+
- name: dart pub get (accepted/future-releases/0546-patterns/exhaustiveness_prototype)
30+
run: dart pub get
31+
working-directory: accepted/future-releases/0546-patterns/exhaustiveness_prototype
32+
- name: dart analyze --fatal-infos .
33+
run: dart analyze --fatal-infos .
34+
test:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v3
38+
- uses: dart-lang/setup-dart@v1
39+
with:
40+
sdk: dev
41+
- name: dart pub get (accepted/future-releases/0546-patterns/exhaustiveness_prototype)
42+
run: dart pub get
43+
working-directory: accepted/future-releases/0546-patterns/exhaustiveness_prototype
44+
- name: dart test (accepted/future-releases/0546-patterns/exhaustiveness_prototype)
45+
run: dart test
46+
working-directory: accepted/future-releases/0546-patterns/exhaustiveness_prototype

accepted/2.3/spread-collections/benchmarks/bin/lrhn_benchmark.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
import"dart:collection";
1+
import "dart:collection";
2+
23
void copy1(Map<String, int> from, Map<String, int> to) {
34
for (var entry in from.entries) {
45
to[entry.key] = entry.value;
56
}
67
}
8+
79
void copy2(Map<String, int> from, Map<String, int> to) {
810
for (var key in from.keys) {
9-
to[key] = from[key];
11+
to[key] = from[key]!;
1012
}
1113
}
14+
1215
void copy3(Map<String, int> from, Map<String, int> to) {
13-
var tmp = to;
16+
Map<String, int>? tmp = to;
1417
from.forEach((key, value) {
15-
tmp[key] = value;
18+
tmp![key] = value;
1619
});
1720
tmp = null;
1821
}
22+
1923
void copy4(Map<String, int> from, Map<String, int> to) {
2024
to.addAll(from);
2125
}
@@ -29,15 +33,17 @@ main() {
2933
}
3034
}
3135

32-
int id(int x)=>x;
36+
int id(int x) => x;
3337
var maps = List.generate(100, (n) {
34-
var map = Map<String, int>.fromIterable(Iterable.generate(n * 10), key: (n) =>"#$n");
38+
var map = Map<String, int>.fromIterable(Iterable.generate(n * 10),
39+
key: (n) => "#$n");
3540
if (n % 4 == 1) map = SplayTreeMap<String, int>.from(map);
3641
if (n % 4 == 2) map = HashMap<String, int>.from(map);
3742
return map;
3843
});
3944

40-
void bench(String name, void Function(Map<String, int>, Map<String, int>) action) {
45+
void bench(
46+
String name, void Function(Map<String, int>, Map<String, int>) action) {
4147
var e = 0;
4248
var c = 0;
4349
var sw = Stopwatch()..start();
@@ -49,5 +55,5 @@ void bench(String name, void Function(Map<String, int>, Map<String, int>) action
4955
}
5056
e = sw.elapsedMilliseconds;
5157
} while (e < 2000);
52-
print("$name: ${c/e} entries/ms");
58+
print("$name: ${c / e} entries/ms");
5359
}

accepted/2.3/spread-collections/benchmarks/bin/profile.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ final lists = <List<String>>[];
1313
final maps = <Map<String, int>>[];
1414
final mapsWithSplay = <Map<String, int>>[];
1515

16-
String _configuration;
17-
int _length;
16+
late String _configuration;
17+
late int _length;
1818
bool _csvOutput = false;
1919
bool _warmingUp = true;
2020

@@ -136,7 +136,7 @@ void benchmarkMaps(String collection, List<Map<String, int>> maps) {
136136

137137
double benchmarkIterable(
138138
String method, void Function(Iterable<String>, List<String>) action,
139-
[double overhead]) {
139+
[double? overhead]) {
140140
var time = bench(() {
141141
for (var i = 0; i < lists.length; i++) {
142142
var from = lists[i];
@@ -155,7 +155,7 @@ double benchmarkIterable(
155155

156156
double benchmarkList(
157157
String method, void Function(List<String>, List<String>) action,
158-
[double overhead]) {
158+
[double? overhead]) {
159159
var time = bench(() {
160160
for (var i = 0; i < lists.length; i++) {
161161
var from = lists[i];
@@ -177,7 +177,7 @@ double benchmarkMap(
177177
String method,
178178
List<Map<String, int>> maps,
179179
void Function(Map<String, int>, Map<String, int>) action,
180-
[double overhead]) {
180+
[double? overhead]) {
181181
var time = bench(() {
182182
for (var i = 0; i < maps.length; i++) {
183183
var from = maps[i];
@@ -249,7 +249,7 @@ void show(String collection, String method, double overhead, double baseline) {
249249
}
250250

251251
double bestTime(String collection, String method) {
252-
var runs = _runs["$collection $method"];
252+
var runs = _runs["$collection $method"]!;
253253
var min = runs.first;
254254
for (var i = 1; i < runs.length; i++) {
255255
if (runs[i] < min) min = runs[i];
@@ -259,7 +259,7 @@ double bestTime(String collection, String method) {
259259
}
260260

261261
double standardDeviation(String collection, String method) {
262-
var runs = _runs["$collection $method"];
262+
var runs = _runs["$collection $method"]!;
263263

264264
var mean = runs.fold<double>(0.0, (a, b) => a + b) / runs.length;
265265

@@ -281,9 +281,9 @@ void iterableIterator(Iterable<String> from, List<String> to) {
281281
}
282282

283283
void iterableForEach(Iterable<String> from, List<String> to) {
284-
var temp = to;
284+
List<String>? temp = to;
285285
from.forEach((s) {
286-
temp.add(s);
286+
temp!.add(s);
287287
});
288288
temp = null;
289289
}
@@ -317,9 +317,9 @@ void listSubscript(List<String> from, List<String> to) {
317317
}
318318

319319
void listForEach(List<String> from, List<String> to) {
320-
var temp = to;
320+
List<String>? temp = to;
321321
from.forEach((s) {
322-
temp.add(s);
322+
temp!.add(s);
323323
});
324324
temp = null;
325325
}
@@ -334,14 +334,14 @@ void mapEntries(Map<String, int> from, Map<String, int> to) {
334334

335335
void mapKeys(Map<String, int> from, Map<String, int> to) {
336336
for (var key in from.keys) {
337-
to[key] = from[key];
337+
to[key] = from[key]!;
338338
}
339339
}
340340

341341
void mapForEach(Map<String, int> from, Map<String, int> to) {
342-
var temp = to;
342+
Map<String, int>? temp = to;
343343
from.forEach((key, value) {
344-
temp[key] = value;
344+
temp![key] = value;
345345
});
346346
temp = null;
347347
}

accepted/2.3/spread-collections/benchmarks/bin/profile_list_spread.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void main() {
3535

3636
double runBench(
3737
String name, int length, void Function(List<String>, List<String>) action,
38-
[double baseline]) {
38+
[double? baseline]) {
3939
var from = <String>[];
4040
for (var i = 0; i < length; i++) {
4141
from.add(String.fromCharCode(i % 26 + 65));
@@ -63,8 +63,8 @@ double runBench(
6363
}
6464

6565
/// Runs [bench] a number of times and returns the best (highest) result.
66-
double benchBest(
67-
List<List<String>> froms, void Function(List<String>, List<String>) action) {
66+
double benchBest(List<List<String>> froms,
67+
void Function(List<String>, List<String>) action) {
6868
var best = 0.0;
6969
for (var i = 0; i < 4; i++) {
7070
var result = bench(froms, action);
@@ -127,9 +127,9 @@ void addAll(List<String> from, List<String> to) {
127127
}
128128

129129
void forEach(List<String> from, List<String> to) {
130-
var temp = to;
130+
List<String>? temp = to;
131131
from.forEach((s) {
132-
temp.add(s);
132+
temp!.add(s);
133133
});
134134
temp = null;
135135
}

accepted/2.3/spread-collections/benchmarks/bin/profile_map.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ void benchmarks() {
4040
warmup = i < rounds;
4141

4242
var baseline = bench("addEntries", maps, addEntries);
43-
var entriesMap =
44-
bench("iterate entries into map", maps, iterateEntriesIntoNewMap, baseline);
45-
var keysMap = bench("iterate keys into map", maps, iterateKeysIntoNewMap, baseline);
46-
var forEachMap = bench("forEach into map", maps, forEachIntoNewMap, baseline);
43+
var entriesMap = bench(
44+
"iterate entries into map", maps, iterateEntriesIntoNewMap, baseline);
45+
var keysMap =
46+
bench("iterate keys into map", maps, iterateKeysIntoNewMap, baseline);
47+
var forEachMap =
48+
bench("forEach into map", maps, forEachIntoNewMap, baseline);
4749

4850
log();
4951

@@ -87,7 +89,8 @@ List<Map<String, int>> makeMaps(List<int> sizes,
8789
}
8890

8991
double bench(String label, List<Map<String, int>> maps,
90-
void Function(Map<String, int>) action, [double baseline]) {
92+
void Function(Map<String, int>) action,
93+
[double? baseline]) {
9194
var watch = Stopwatch()..start();
9295
for (var i = 0; i < trials; i++) {
9396
for (var i = 0; i < maps.length; i++) {
@@ -101,12 +104,12 @@ double bench(String label, List<Map<String, int>> maps,
101104
return microPerTrial;
102105
}
103106

104-
void log([String label, double microseconds, double baseline]) {
107+
void log([String? label, double? microseconds, double? baseline]) {
105108
if (warmup) return;
106109

107110
if (microseconds != null) {
108111
var perMs = (1000 / microseconds).toStringAsFixed(2);
109-
var output = "${label.padLeft(30)} ${perMs.padLeft(10)} spreads/ms";
112+
var output = "${label!.padLeft(30)} ${perMs.padLeft(10)} spreads/ms";
110113
if (baseline != null) {
111114
var relative = baseline / microseconds;
112115
output += " ${relative.toStringAsFixed(2).padLeft(5)}x";
@@ -144,7 +147,7 @@ void iterateEntriesIntoNewMap(Map<String, int> from) {
144147
void iterateKeys(Map<String, int> from) {
145148
var sum = 0;
146149
for (var key in from.keys) {
147-
sum += from[key];
150+
sum += from[key]!;
148151
}
149152

150153
preventOptimization(sum);
@@ -154,7 +157,7 @@ void iterateKeysIntoNewMap(Map<String, int> from) {
154157
var to = <String, int>{"a": 1, "b": 2};
155158

156159
for (var key in from.keys) {
157-
to[key] = from[key];
160+
to[key] = from[key]!;
158161
}
159162

160163
to["b"] = 3;
@@ -175,9 +178,9 @@ void forEach(Map<String, int> from) {
175178
void forEachIntoNewMap(Map<String, int> from) {
176179
var to = <String, int>{"a": 1, "b": 2};
177180

178-
var temp = to;
181+
Map<String, int>? temp = to;
179182
from.forEach((key, value) {
180-
temp[key] = value;
183+
temp![key] = value;
181184
});
182185
temp = null;
183186

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: benchmarks
22
publish_to: none
33
environment:
4-
sdk: ">=2.3.0 <3.0.0"
4+
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)