Skip to content

Commit cc0f287

Browse files
kevmooosa1
andauthored
Run non-null-safe tests with Dart 2 (#791)
Co-authored-by: Ömer Sinan Ağacan <[email protected]>
1 parent dd04535 commit cc0f287

File tree

5 files changed

+182
-106
lines changed

5 files changed

+182
-106
lines changed

.github/workflows/dart.yml

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ jobs:
191191
if: "always() && steps.protobuf_pub_upgrade.conclusion == 'success'"
192192
working-directory: protobuf
193193
job_006:
194-
name: "format_analyze; linux; Dart dev; PKG: protoc_plugin; `dart format --output=none --set-exit-if-changed .`, `./../tool/setup.sh`, `make protos`, `dart analyze --fatal-infos`"
194+
name: "format_analyze; linux; Dart dev; PKG: protoc_plugin; `dart format --output=none --set-exit-if-changed .`, `./../tool/setup.sh`, `make protos`, `dart analyze --fatal-infos bin lib test`"
195195
runs-on: ubuntu-latest
196196
steps:
197197
- name: Cache Pub hosted dependencies
198198
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
199199
with:
200200
path: "~/.pub-cache/hosted"
201-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:format-command_0-command_3-analyze_0"
201+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:format-command_0-command_3-analyze_3"
202202
restore-keys: |
203203
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin
204204
os:ubuntu-latest;pub-cache-hosted;sdk:dev
@@ -228,8 +228,8 @@ jobs:
228228
run: make protos
229229
if: "always() && steps.protoc_plugin_pub_upgrade.conclusion == 'success'"
230230
working-directory: protoc_plugin
231-
- name: "protoc_plugin; dart analyze --fatal-infos"
232-
run: dart analyze --fatal-infos
231+
- name: "protoc_plugin; dart analyze --fatal-infos bin lib test"
232+
run: dart analyze --fatal-infos bin lib test
233233
if: "always() && steps.protoc_plugin_pub_upgrade.conclusion == 'success'"
234234
working-directory: protoc_plugin
235235
job_007:
@@ -240,7 +240,7 @@ jobs:
240240
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
241241
with:
242242
path: "~/.pub-cache/hosted"
243-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf;commands:test"
243+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf;commands:test_0"
244244
restore-keys: |
245245
os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf
246246
os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0
@@ -277,7 +277,7 @@ jobs:
277277
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
278278
with:
279279
path: "~/.pub-cache/hosted"
280-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin;commands:command_0-command_3-test"
280+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin;commands:command_0-command_3-test_0"
281281
restore-keys: |
282282
os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin
283283
os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0
@@ -322,7 +322,7 @@ jobs:
322322
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
323323
with:
324324
path: "~/.pub-cache/hosted"
325-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protobuf;commands:test"
325+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protobuf;commands:test_0"
326326
restore-keys: |
327327
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protobuf
328328
os:ubuntu-latest;pub-cache-hosted;sdk:dev
@@ -359,7 +359,7 @@ jobs:
359359
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
360360
with:
361361
path: "~/.pub-cache/hosted"
362-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:command_0-command_3-test"
362+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin;commands:command_0-command_3-test_0"
363363
restore-keys: |
364364
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:protoc_plugin
365365
os:ubuntu-latest;pub-cache-hosted;sdk:dev
@@ -404,7 +404,7 @@ jobs:
404404
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
405405
with:
406406
path: "~/.pub-cache/hosted"
407-
key: "os:macos-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf;commands:test"
407+
key: "os:macos-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf;commands:test_0"
408408
restore-keys: |
409409
os:macos-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf
410410
os:macos-latest;pub-cache-hosted;sdk:2.12.0
@@ -441,7 +441,7 @@ jobs:
441441
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
442442
with:
443443
path: "~/.pub-cache/hosted"
444-
key: "os:macos-latest;pub-cache-hosted;sdk:dev;packages:protobuf;commands:test"
444+
key: "os:macos-latest;pub-cache-hosted;sdk:dev;packages:protobuf;commands:test_0"
445445
restore-keys: |
446446
os:macos-latest;pub-cache-hosted;sdk:dev;packages:protobuf
447447
os:macos-latest;pub-cache-hosted;sdk:dev
@@ -524,3 +524,56 @@ jobs:
524524
- job_004
525525
- job_005
526526
- job_006
527+
job_015:
528+
name: "run_legacy_tests; linux; Dart 2.12.0; PKG: protoc_plugin; `./../tool/setup.sh`, `make protos`, `dart test legacy_tests/generated_message_test.dart`"
529+
runs-on: ubuntu-latest
530+
steps:
531+
- name: Cache Pub hosted dependencies
532+
uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
533+
with:
534+
path: "~/.pub-cache/hosted"
535+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin;commands:command_0-command_3-test_1"
536+
restore-keys: |
537+
os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protoc_plugin
538+
os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0
539+
os:ubuntu-latest;pub-cache-hosted
540+
os:ubuntu-latest
541+
- name: Setup Dart SDK
542+
uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
543+
with:
544+
sdk: "2.12.0"
545+
- id: checkout
546+
name: Checkout repository
547+
uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
548+
- id: protoc_plugin_pub_upgrade
549+
name: protoc_plugin; dart pub upgrade
550+
run: dart pub upgrade
551+
if: "always() && steps.checkout.conclusion == 'success'"
552+
working-directory: protoc_plugin
553+
- name: protoc_plugin; ./../tool/setup.sh
554+
run: ./../tool/setup.sh
555+
if: "always() && steps.protoc_plugin_pub_upgrade.conclusion == 'success'"
556+
working-directory: protoc_plugin
557+
- name: protoc_plugin; make protos
558+
run: make protos
559+
if: "always() && steps.protoc_plugin_pub_upgrade.conclusion == 'success'"
560+
working-directory: protoc_plugin
561+
- name: protoc_plugin; dart test legacy_tests/generated_message_test.dart
562+
run: dart test legacy_tests/generated_message_test.dart
563+
if: "always() && steps.protoc_plugin_pub_upgrade.conclusion == 'success'"
564+
working-directory: protoc_plugin
565+
needs:
566+
- job_001
567+
- job_002
568+
- job_003
569+
- job_004
570+
- job_005
571+
- job_006
572+
- job_007
573+
- job_008
574+
- job_009
575+
- job_010
576+
- job_011
577+
- job_012
578+
- job_013
579+
- job_014
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// @dart=2.11
6+
7+
import 'package:test/test.dart';
8+
9+
import '../out/protos/google/protobuf/unittest.pb.dart';
10+
import '../out/protos/toplevel.pb.dart';
11+
import '../out/protos/toplevel_import.pb.dart' as t;
12+
13+
void main() {
14+
test('testSettersRejectNull', () {
15+
var message = TestAllTypes();
16+
expect(() {
17+
message.optionalString = null;
18+
}, throwsArgumentError);
19+
expect(() {
20+
message.optionalBytes = null;
21+
}, throwsArgumentError);
22+
expect(() {
23+
message.optionalNestedMessage = null;
24+
}, throwsArgumentError);
25+
expect(() {
26+
message.optionalNestedMessage = null;
27+
}, throwsArgumentError);
28+
expect(() {
29+
message.optionalNestedEnum = null;
30+
}, throwsArgumentError);
31+
expect(() {
32+
message.repeatedString.add(null);
33+
}, throwsArgumentError);
34+
expect(() {
35+
message.repeatedBytes.add(null);
36+
}, throwsArgumentError);
37+
expect(() {
38+
message.repeatedNestedMessage.add(null);
39+
}, throwsArgumentError);
40+
expect(() {
41+
message.repeatedNestedMessage.add(null);
42+
}, throwsArgumentError);
43+
expect(() {
44+
message.repeatedNestedEnum.add(null);
45+
}, throwsArgumentError);
46+
});
47+
48+
test('testRepeatedSettersRejectNull', () {
49+
var message = TestAllTypes();
50+
51+
message.repeatedString.addAll(['one', 'two']);
52+
expect(() {
53+
message.repeatedString[1] = null;
54+
}, throwsArgumentError);
55+
56+
message.repeatedBytes.addAll(['one'.codeUnits, 'two'.codeUnits]);
57+
expect(() {
58+
message.repeatedBytes[1] = null;
59+
}, throwsArgumentError);
60+
61+
message.repeatedNestedMessage.addAll([
62+
TestAllTypes_NestedMessage()..bb = 318,
63+
TestAllTypes_NestedMessage()..bb = 456
64+
]);
65+
expect(() {
66+
message.repeatedNestedMessage[1] = null;
67+
}, throwsArgumentError);
68+
69+
message.repeatedNestedEnum
70+
.addAll([TestAllTypes_NestedEnum.FOO, TestAllTypes_NestedEnum.BAR]);
71+
expect(() {
72+
message.repeatedNestedEnum[1] = null;
73+
}, throwsArgumentError);
74+
});
75+
76+
test('testRepeatedAppendRejectsNull', () {
77+
var message = TestAllTypes();
78+
79+
expect(() {
80+
message.repeatedForeignMessage.addAll([ForeignMessage()..c = 12, null]);
81+
}, throwsArgumentError);
82+
83+
expect(() {
84+
message.repeatedForeignEnum.addAll([ForeignEnum.FOREIGN_BAZ, null]);
85+
}, throwsArgumentError);
86+
87+
expect(() {
88+
message.repeatedString.addAll(['one', null]);
89+
}, throwsArgumentError);
90+
91+
expect(() {
92+
message.repeatedBytes.addAll(['one'.codeUnits, null]);
93+
}, throwsArgumentError);
94+
});
95+
96+
test('testToplevel', () {
97+
var message = t.M();
98+
message.t = T();
99+
t.SApi(null);
100+
});
101+
}

protoc_plugin/mono_pkg.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ stages:
55
- format
66
- command: ./../tool/setup.sh
77
- command: make protos
8-
- analyze: --fatal-infos
8+
# Specify directores to exclude legacy_tests
9+
- analyze: --fatal-infos bin lib test
910
sdk: [dev]
1011
- run_tests:
1112
- group:
1213
- command: ./../tool/setup.sh
1314
- command: make protos
1415
- test
1516
sdk: [pubspec, dev]
17+
- run_legacy_tests:
18+
- group:
19+
- command: ./../tool/setup.sh
20+
- command: make protos
21+
- test: legacy_tests/generated_message_test.dart
22+
sdk: [pubspec]

0 commit comments

Comments
 (0)