Skip to content

Commit

Permalink
refactor(all): update to Dart 3 (#68)
Browse files Browse the repository at this point in the history
* Init.

* Refactoring.

* Update CI.

* Refactoring.

* Format.

* Remove mock generated files.

* Ignore mocks.

* Downgrade to 3.0.0.

* Update CI.

* Revert downgrade.

* refactor(_test): migrate most to Dart 3

Signed-off-by: Gavin Zhao <[email protected]>

* Remove opt null safety and mock support.

* Update _tests.

* ci: automatically detect reporter style

Signed-off-by: Gavin Zhao <[email protected]>

* Fix _tests errors.

* Add _tests to CI.

* Fix _tests.

---------

Signed-off-by: Gavin Zhao <[email protected]>
Co-authored-by: Gavin Zhao <[email protected]>
  • Loading branch information
ykmnkmi and GZGavinZhao authored Nov 29, 2023
1 parent 0f212f7 commit 3149fa1
Show file tree
Hide file tree
Showing 310 changed files with 1,562 additions and 17,110 deletions.
729 changes: 324 additions & 405 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Ignore artifacts generated by "pub".
**/build/
.packages
pubspec.lock
*.log

# Ignore artifacts generated by "firebase"
.firebase/

# Files generated by dart tools.
**/.dart_tool/
**/doc/api/
**/build/
*.log

# melos
# pubspec_overrides.yaml

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion _tests/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ include: ../analysis_options.yaml

analyzer:
errors:
implementation_imports: ignore

# False positives related to missing .template.dart files
# Comment this rules while developing.
argument_type_not_assignable: ignore
invalid_assignment: ignore
return_of_invalid_type: ignore
non_bool_condition: ignore
return_of_invalid_type: ignore
1 change: 1 addition & 0 deletions _tests/dart_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ presets:
paths:
- test/compiler
- test/compiler_integration
- test/source_gen
add_presets: [ci]
51 changes: 26 additions & 25 deletions _tests/lib/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:build_resolvers/build_resolvers.dart';
import 'package:build_test/build_test.dart' hide testBuilder;
import 'package:glob/glob.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
import 'package:ngdart/src/build.dart';
import 'package:ngcompiler/v2/context.dart';
import 'package:ngdart/src/build.dart';
import 'package:test/test.dart';

/// A 'test' build process (similar to the normal one).
final Builder _testAngularBuilder = MultiplexingBuilder([
Expand Down Expand Up @@ -150,9 +150,7 @@ Future<void> compilesExpecting(
include ??= const {};

// Complete list of input sources.
final sources = <String, String>{
inputSource: input,
}..addAll(include);
final sources = <String, String>{inputSource: input, ...include};

// Run the builder.
final records = <Level, List<LogRecord>>{};
Expand All @@ -168,21 +166,24 @@ Future<void> compilesExpecting(
expectLogRecords(records[Level.SEVERE], errors, 'Errors');
expectLogRecords(records[Level.WARNING], warnings, 'Warnings');
expectLogRecords(records[Level.INFO], notices, 'Notices');

if (outputs != null) {
// TODO: Add an output verification or consider a golden file mechanism.
throw UnimplementedError();
}
}

void expectLogRecords(List<LogRecord>? logs, matcher, String reasonPrefix) {
void expectLogRecords(
List<LogRecord>? logs,
Object? matcher,
String reasonPrefix,
) {
if (matcher == null) {
return;
}
logs ??= [];
expect(logs.map(formattedLogMessage), matcher,
reason:
'$reasonPrefix: \n${logs.map((l) => '${formattedLogMessage(l)} at:\n ${l.stackTrace}')}');
expect(
logs.map(formattedLogMessage),
matcher is Iterable ? containsAllInOrder(matcher) : matcher,
reason: '$reasonPrefix: \n${logs.map((l) {
return '${formattedLogMessage(l)} at:\n ${l.stackTrace}';
})}',
);
}

String formattedLogMessage(LogRecord record) {
Expand All @@ -201,17 +202,17 @@ Future<void> compilesNormally(
String? inputSource,
Map<String, String>? include,
Set<AssetId>? runBuilderOn,
}) =>
compilesExpecting(
input,
inputSource: inputSource,
runBuilderOn: runBuilderOn,
include: include,
errors: isEmpty,
warnings: isEmpty,
);
}) {
return compilesExpecting(
input,
inputSource: inputSource,
runBuilderOn: runBuilderOn,
include: include,
);
}

/// Match for a source location, but don't require tests to manage package
/// names.
Matcher containsSourceLocation(int line, int column) =>
contains('line $line, column $column of ');
Matcher containsSourceLocation(int line, int column) {
return contains('line $line, column $column of ');
}
2 changes: 1 addition & 1 deletion _tests/lib/matchers.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:html';

import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:test/test.dart';

/// Matches textual content of an element including children.
Matcher hasTextContent(String expected) => _HasTextContent(expected);
Expand Down
2 changes: 1 addition & 1 deletion _tests/lib/query_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// element that is assigned by the framework.

import 'package:collection/collection.dart';
import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

/// A mixin for components that receive a list of child elements/directives.
abstract class HasChildren<T> {
Expand Down
4 changes: 2 additions & 2 deletions _tests/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sdk:
- 2.19.6
- pubspec
- dev

stages:
- build:
- command: dart run build_runner build --fail-on-severe
- unit_test:
- command: dart run test -P vm
- command: dart test -P vm
- command: dart run build_runner test --fail-on-severe -- -P browser
36 changes: 21 additions & 15 deletions _tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@ description: Tests for AngularDart.
publish_to: none

environment:
sdk: ">=2.18.0 <3.0.0"
sdk: ">=3.1.0 <4.0.0"

dependencies:
build_resolvers: ^2.1.0
build_test: ^2.1.6
collection: ^1.17.0
ngdart: ^8.0.0-dev.1
ngtest: ^5.0.0-dev.1
test: ^1.22.2
build: ^2.4.1
build_resolvers: ^2.4.1
build_test: ^2.2.1
collection: ^1.18.0
glob: ^2.1.2
js: ^0.6.7
logging: ^1.2.0
ngcompiler: ^3.0.0-dev.2
ngdart: ^8.0.0-dev.3
ngtest: ^5.0.0-dev.2
source_gen: ^1.4.0
test: ^1.24.4

dev_dependencies:
analyzer: ^5.4.0
build_runner: ^2.3.3
build_web_compilers: ^3.2.7
csslib: 0.17.2
lints: ^2.0.1
meta: ^1.8.0
mockito: ^5.3.2
analyzer: ^6.0.0
build_runner: ^2.4.6
build_web_compilers: ^4.0.4
csslib: ^1.0.0
lints: ^2.1.0
meta: ^1.11.0
mockito: ^5.4.3
package_config: ^2.1.0
source_span: ^1.9.1
source_span: ^1.10.0
term_glyph: ^1.2.1
2 changes: 1 addition & 1 deletion _tests/test/bootstrap/run_app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'dart:async';
import 'dart:html';

import 'package:js/js.dart';
import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:test/test.dart';

import 'run_app_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/directives/for_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ library angular2.test.common.directives.for_test;

import 'dart:async';

import 'package:test/test.dart';
import 'package:_tests/matchers.dart';
import 'package:ngdart/angular.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

import 'for_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/directives/if_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:ngdart/src/runtime/check_binding.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

import 'if_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/directives/ng_class_test.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:html';

import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

import 'ng_class_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/directives/ng_style_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

import 'ng_style_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/directives/ng_switch_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

import 'ng_switch_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/directives/ng_template_outlet_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:test/test.dart';
import 'package:_tests/matchers.dart';
import 'package:ngdart/angular.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

import 'ng_template_outlet_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/pipes/date_pipe_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:test/test.dart';
import 'package:ngdart/angular.dart';
import 'package:test/test.dart';

void main() {
group('DatePipe', () {
Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/pipes/lowercase_pipe_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:test/test.dart';
import 'package:ngdart/src/common/pipes/lowercase_pipe.dart';
import 'package:test/test.dart';

void main() {
group('LowerCasePipe', () {
Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/pipes/number_pipe_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:test/test.dart';
import 'package:ngdart/src/common/pipes/number_pipe.dart';
import 'package:test/test.dart';

void main() {
group('Number pipes', () {
Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/pipes/replace_pipe_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:test/test.dart';
import 'package:ngdart/src/common/pipes/invalid_pipe_argument_exception.dart';
import 'package:ngdart/src/common/pipes/replace_pipe.dart';
import 'package:test/test.dart';

final someNumber = 42;
final str = 'Douglas Adams';
Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/pipes/slice_pipe_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:test/test.dart';
import 'package:_tests/matchers.dart';
import 'package:ngdart/angular.dart';
import 'package:ngtest/angular_test.dart';
import 'package:test/test.dart';

import 'slice_pipe_test.template.dart' as ng;

Expand Down
2 changes: 1 addition & 1 deletion _tests/test/common/pipes/uppercase_pipe_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:test/test.dart';
import 'package:ngdart/src/common/pipes/uppercase_pipe.dart';
import 'package:test/test.dart';

void main() {
group('UpperCasePipe', () {
Expand Down
16 changes: 7 additions & 9 deletions _tests/test/compiler/analyzed_class_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @dart=2.9

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/visitor.dart';
import 'package:test/test.dart';
import 'package:ngcompiler/v1/src/compiler/analyzed_class.dart';
import 'package:ngcompiler/v1/src/compiler/expression_parser/ast.dart';
import 'package:test/test.dart';

import '../resolve_util.dart';

Expand Down Expand Up @@ -84,7 +82,7 @@ void main() {
final int eight = 8;
}
''');
var analyzedClass = AnalyzedClass(library.getClass('SubComponent'));
var analyzedClass = AnalyzedClass(library.getClass('SubComponent')!);
final sevenExpr = PropertyRead(ImplicitReceiver(), 'seven');
final eightExpr = PropertyRead(ImplicitReceiver(), 'eight');
final someNumberExpr = PropertyRead(ImplicitReceiver(), 'someNumber');
Expand All @@ -98,26 +96,26 @@ void main() {
Future<AnalyzedClass> analyzeClass(String source) async {
final library = await resolve(source);
final visitor = AnalyzedClassVisitor();
return library.accept(visitor);
return library.accept(visitor)!;
}

class AnalyzedClassVisitor extends RecursiveElementVisitor<AnalyzedClass> {
@override
AnalyzedClass visitClassElement(ClassElement element) {
AnalyzedClass? visitClassElement(ClassElement element) {
return AnalyzedClass(element);
}

@override
AnalyzedClass visitCompilationUnitElement(CompilationUnitElement element) {
AnalyzedClass? visitCompilationUnitElement(CompilationUnitElement element) {
return _visitAll(element.classes);
}

@override
AnalyzedClass visitLibraryElement(LibraryElement element) {
AnalyzedClass? visitLibraryElement(LibraryElement element) {
return _visitAll(element.units);
}

AnalyzedClass _visitAll(List<Element> elements) {
AnalyzedClass? _visitAll(List<Element> elements) {
for (var element in elements) {
final analyzedClass = element.accept(this);
if (analyzedClass != null) return analyzedClass;
Expand Down
Loading

0 comments on commit 3149fa1

Please sign in to comment.