Skip to content

move generated test code from out/ to test/gen/ #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions protoc_plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
pubspec.lock

# Other generated files
test/gen/

# Legacy (can be deleted locally)
out/
15 changes: 3 additions & 12 deletions protoc_plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PLUGIN_SRC = \
bin/protoc_plugin.dart \
lib/**/*.dart

OUTPUT_DIR=out
OUTPUT_DIR=test/gen
PLUGIN_NAME=protoc-gen-dart
PLUGIN_PATH=bin/$(PLUGIN_NAME)

Expand Down Expand Up @@ -67,7 +67,7 @@ TEST_PROTO_LIST = \
toplevel_import \
toplevel \
using_any
TEST_PROTO_DIR=$(OUTPUT_DIR)/protos
TEST_PROTO_DIR=$(OUTPUT_DIR)
TEST_PROTO_LIBS=$(foreach f, $(TEST_PROTO_LIST), \
$(TEST_PROTO_DIR)/$(f).pb.dart \
$(TEST_PROTO_DIR)/$(f).pbjson.dart)
Expand All @@ -81,16 +81,7 @@ $(TEST_PROTO_LIBS): $(PLUGIN_SRC) $(TEST_PROTO_SRCS)
mkdir -p $(TEST_PROTO_DIR)

protoc\
--dart_out="disable_constructor_args:$(TEST_PROTO_DIR)"\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we no longer disable_constror_args? Is it not necessary?

Maybe we could rely on g3 tests for this. In g3 disable_constructor_args is the default as it causes binary size bloat.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're generating two versions of the test protos output for this one option - I'm just trying to dial things back a bit (we don't do this for other options). The disable_constructor_args option is tested in protoc_plugin/test/file_generator_test.dart and a bit in message_generator_test.dart.

Given the history in the changelog It sounds like having ctor args is the default externally, and not having them is the default internally.

-I$(TEST_PROTO_SRC_DIR)\
-Iprotos\
--plugin=protoc-gen-dart=$(realpath $(PLUGIN_PATH))\
$(TEST_PROTO_SRCS)

mkdir -p $(TEST_PROTO_DIR)/constructor_args

protoc\
--dart_out="$(TEST_PROTO_DIR)/constructor_args"\
--dart_out="$(TEST_PROTO_DIR)"\
-I$(TEST_PROTO_SRC_DIR)\
-Iprotos\
--plugin=protoc-gen-dart=$(realpath $(PLUGIN_PATH))\
Expand Down
8 changes: 4 additions & 4 deletions protoc_plugin/test/any_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import 'package:protobuf/protobuf.dart';
import 'package:test/test.dart';

import '../out/protos/google/protobuf/any.pb.dart';
import '../out/protos/service.pb.dart';
import '../out/protos/toplevel.pb.dart' as toplevel;
import '../out/protos/using_any.pb.dart';
import 'gen/google/protobuf/any.pb.dart';
import 'gen/service.pb.dart';
import 'gen/toplevel.pb.dart' as toplevel;
import 'gen/using_any.pb.dart';

void main() {
test('pack -> unpack', () {
Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/test/coded_buffer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'package:test/test.dart';

import '../out/protos/entity.pb.dart';
import 'gen/entity.pb.dart';

void main() {
test('Does not reuse input buffer for bytes fields', () {
Expand Down
119 changes: 119 additions & 0 deletions protoc_plugin/test/constructor_args_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';

import 'gen/google/protobuf/unittest.pb.dart';
import 'gen/google/protobuf/unittest_import.pb.dart';
import 'gen/map_field.pb.dart';
import 'test_util.dart';

void main() {
group('map_field', () {
test('Constructor map arguments accept key-value iterators', () {
final msg = TestMap(
stringToInt32Field: [
MapEntry('a', 1),
MapEntry('b', 2),
MapEntry('a', 3)
],
int32ToStringField: {1: 'hi'}.entries,
);
expect(msg.stringToInt32Field['a'], 3);
expect(msg.stringToInt32Field['b'], 2);
expect(msg.int32ToStringField[1], 'hi');
});
});

group('generated_message', () {
test('Named arguments in constructors', () {
final value = TestAllTypes(
optionalInt32: 101,
optionalInt64: make64(102),
optionalUint32: 103,
optionalUint64: make64(104),
optionalSint32: 105,
optionalSint64: make64(106),
optionalFixed32: 107,
optionalFixed64: make64(108),
optionalSfixed32: 109,
optionalSfixed64: make64(110),
optionalFloat: 111.0,
optionalDouble: 112.0,
optionalBool: true,
optionalString: '115',
optionalBytes: '116'.codeUnits,
optionalGroup: TestAllTypes_OptionalGroup(a: 117),
optionalNestedMessage: TestAllTypes_NestedMessage(bb: 118),
optionalForeignMessage: ForeignMessage(c: 119),
optionalImportMessage: ImportMessage(d: 120),
optionalNestedEnum: TestAllTypes_NestedEnum.BAZ,
optionalForeignEnum: ForeignEnum.FOREIGN_BAZ,
optionalImportEnum: ImportEnum.IMPORT_BAZ,
optionalStringPiece: '124',
optionalCord: '125',
repeatedInt32: [201, 301],
repeatedInt64: [make64(202), make64(302)],
repeatedUint32: [203, 303],
repeatedUint64: [make64(204), make64(304)],
repeatedSint32: [205, 305],
repeatedSint64: [make64(206), make64(306)],
repeatedFixed32: [207, 307],
repeatedFixed64: [make64(208), make64(308)],
repeatedSfixed32: [209, 309],
repeatedSfixed64: [make64(210), make64(310)],
repeatedFloat: [211.0, 311.0],
repeatedDouble: [212.0, 312.0],
repeatedBool: [true, false],
repeatedString: ['215', '315'],
repeatedBytes: ['216'.codeUnits, '316'.codeUnits],
repeatedGroup: [
TestAllTypes_RepeatedGroup(a: 217),
TestAllTypes_RepeatedGroup(a: 317)
],
repeatedNestedMessage: [
TestAllTypes_NestedMessage(bb: 218),
TestAllTypes_NestedMessage(bb: 318)
],
repeatedForeignMessage: [
ForeignMessage(c: 219),
ForeignMessage(c: 319)
],
repeatedImportMessage: [ImportMessage(d: 220), ImportMessage(d: 320)],
repeatedNestedEnum: [
TestAllTypes_NestedEnum.BAR,
TestAllTypes_NestedEnum.BAZ
],
repeatedForeignEnum: [ForeignEnum.FOREIGN_BAR, ForeignEnum.FOREIGN_BAZ],
repeatedImportEnum: [ImportEnum.IMPORT_BAR, ImportEnum.IMPORT_BAZ],
repeatedStringPiece: ['224', '324'],
repeatedCord: ['225', '325'],
defaultInt32: 401,
defaultInt64: make64(402),
defaultUint32: 403,
defaultUint64: make64(404),
defaultSint32: 405,
defaultSint64: make64(406),
defaultFixed32: 407,
defaultFixed64: make64(408),
defaultSfixed32: 409,
defaultSfixed64: make64(410),
defaultFloat: 411.0,
defaultDouble: 412.0,
defaultBool: false,
defaultString: '415',
defaultBytes: '416'.codeUnits,
defaultNestedEnum: TestAllTypes_NestedEnum.FOO,
defaultForeignEnum: ForeignEnum.FOREIGN_FOO,
defaultImportEnum: ImportEnum.IMPORT_FOO,
defaultStringPiece: '424',
defaultCord: '425',
);

// Convert the message with constructor arguments to the message without
// constructor arguments, to be able to reuse `assertAllFieldsSet`.
assertAllFieldsSet(TestAllTypes.fromBuffer(value.writeToBuffer()));
});
});
}
2 changes: 1 addition & 1 deletion protoc_plugin/test/default_value_escape_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'package:test/test.dart';

import '../out/protos/default_value_escape.pb.dart';
import 'gen/default_value_escape.pb.dart';

void main() {
test('default values are escaped properly', () {
Expand Down
5 changes: 2 additions & 3 deletions protoc_plugin/test/deprecations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import 'golden_file.dart';

void main() {
test('Deprecated annotation generation for messages', () {
final actual = File('out/protos/deprecations.pb.dart').readAsStringSync();
final actual = File('test/gen/deprecations.pb.dart').readAsStringSync();
expectMatchesGoldenFile(actual, 'test/goldens/deprecations');
});

test('Deprecated annotation generation for enums', () {
final actual = File('out/protos/constructor_args/deprecations.pbenum.dart')
.readAsStringSync();
final actual = File('test/gen/deprecations.pbenum.dart').readAsStringSync();
expectMatchesGoldenFile(actual, 'test/goldens/deprecations.pbenum');
});
}
6 changes: 3 additions & 3 deletions protoc_plugin/test/descriptor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:protobuf/protobuf.dart';
import 'package:protoc_plugin/src/gen/google/protobuf/descriptor.pb.dart';
import 'package:test/test.dart';

import '../out/protos/custom_option.pb.dart';
import '../out/protos/custom_option.pbjson.dart';
import '../out/protos/google/protobuf/unittest.pbjson.dart';
import 'gen/custom_option.pb.dart';
import 'gen/custom_option.pbjson.dart';
import 'gen/google/protobuf/unittest.pbjson.dart';

void main() {
test('Can decode message descriptor', () {
Expand Down
5 changes: 2 additions & 3 deletions protoc_plugin/test/doc_comments_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import 'golden_file.dart';

void main() {
test('Doc comment generation for messages', () {
final actual = File('out/protos/doc_comments.pb.dart').readAsStringSync();
final actual = File('test/gen/doc_comments.pb.dart').readAsStringSync();
expectMatchesGoldenFile(actual, 'test/goldens/doc_comments');
});

test('Doc comment generation for enums', () {
final actual = File('out/protos/constructor_args/doc_comments.pbenum.dart')
.readAsStringSync();
final actual = File('test/gen/doc_comments.pbenum.dart').readAsStringSync();
expectMatchesGoldenFile(actual, 'test/goldens/doc_comments.pbenum');
});
}
2 changes: 1 addition & 1 deletion protoc_plugin/test/duration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:fixnum/fixnum.dart';
import 'package:test/test.dart';

import '../out/protos/google/protobuf/duration.pb.dart' as pb;
import 'gen/google/protobuf/duration.pb.dart' as pb;

void main() {
test('core duration -> proto duration', () {
Expand Down
14 changes: 7 additions & 7 deletions protoc_plugin/test/extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import 'package:protobuf/protobuf.dart';
import 'package:test/test.dart';

import '../out/protos/ExtensionEnumNameConflict.pb.dart';
import '../out/protos/ExtensionNameConflict.pb.dart';
import '../out/protos/enum_extension.pb.dart';
import '../out/protos/extend_unittest.pb.dart';
import '../out/protos/google/protobuf/unittest.pb.dart';
import '../out/protos/nested_extension.pb.dart';
import '../out/protos/non_nested_extension.pb.dart';
import 'gen/ExtensionEnumNameConflict.pb.dart';
import 'gen/ExtensionNameConflict.pb.dart';
import 'gen/enum_extension.pb.dart';
import 'gen/extend_unittest.pb.dart';
import 'gen/google/protobuf/unittest.pb.dart';
import 'gen/nested_extension.pb.dart';
import 'gen/non_nested_extension.pb.dart';
import 'test_util.dart';

Matcher throwsArgError(String expectedMessage) =>
Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/test/extension_unknown_interaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:protobuf/protobuf.dart';
import 'package:test/test.dart';

import '../out/protos/google/protobuf/unittest.pb.dart';
import 'gen/google/protobuf/unittest.pb.dart';

void main() {
test('setExtension clears unknown field with same tag number', () {
Expand Down
4 changes: 2 additions & 2 deletions protoc_plugin/test/freeze_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import 'package:fixnum/fixnum.dart';
import 'package:test/test.dart';

import '../out/protos/entity.pb.dart';
import '../out/protos/nested_message.pb.dart';
import 'gen/entity.pb.dart';
import 'gen/nested_message.pb.dart';

void main() {
test('testFreezingNestedFields', () {
Expand Down
Loading