Skip to content

Commit 05ab41c

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Refactor summary tests in preparation for adding a one-phase summary API.
I will soon be adding an API for generating summaries that generates them in one phase, as opposed to the current two-phase approach of building unlinked summaries and then linking them together. This is will be needed in order to support full type inference of summaries, since full type inference requires examining the contents of block-bodied closures, and it's not worth the effort of trying serialize the contents of block-bodied closures into unlinked summaries. To prepare for this, the summary tests need to be generalized so that during the transition period they will be able to be run with either API. This CL introduces several classes in a new `test_strategies.dart` file: - Interfaces `SummaryBaseTestStrategy`, `SummaryBlackBoxTestStrategy`, and `SummaryLinkerTestStrategy`. These interfaces define the methods that can be invoked by tests of the summary mechanism. - Implementations of those interfaces: `SummaryBlackBoxTestStrategyPrelink`, `SummaryBlackBoxTestStrategyTwoPhase`, and `SummaryLinkerTestStrategyTwoPhase`. These classes provide the ability to drive the summary mechanism in various ways. When the one-phase API is added, more classes will be added to drive it. - A few private classes occupying intermediate positions in the class hierarchy, as well as auxiliary data structures needed by the above classes. The tests themselves have been moved into mixin classes so that they can be applied to any of the implementations above. Change-Id: Iac3585944297f78f184d35de544aa4c8d8abe99a Reviewed-on: https://dart-review.googlesource.com/72320 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent c529503 commit 05ab41c

File tree

8 files changed

+502
-440
lines changed

8 files changed

+502
-440
lines changed

pkg/analyzer/test/src/summary/linker_test.dart

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
import 'package:analyzer/dart/element/type.dart';
66
import 'package:analyzer/src/dart/element/element.dart';
7-
import 'package:analyzer/src/summary/format.dart';
87
import 'package:analyzer/src/summary/idl.dart';
98
import 'package:analyzer/src/summary/link.dart';
109
import 'package:test/test.dart';
1110
import 'package:test_reflective_loader/test_reflective_loader.dart';
1211

13-
import 'summarize_ast_test.dart';
12+
import 'test_strategies.dart';
1413

1514
main() {
1615
defineReflectiveSuite(() {
@@ -19,29 +18,17 @@ main() {
1918
}
2019

2120
@reflectiveTest
22-
class LinkerUnitTest extends SummaryLinkerTest {
23-
Linker linker;
24-
25-
LinkerInputs linkerInputs;
26-
LibraryElementInBuildUnit _testLibrary;
27-
@override
28-
bool get allowMissingFiles => false;
29-
21+
class LinkerUnitTest extends SummaryLinkerTestStrategyTwoPhase
22+
with LinkerUnitTestCases {}
23+
24+
/// Test cases that exercise the summary linker in a white-box fashion.
25+
///
26+
/// These test cases may be mixed into any class derived from
27+
/// [SummaryLinkerTestStrategy], allowing the linker to be unit-tested in a
28+
/// variety of ways.
29+
abstract class LinkerUnitTestCases implements SummaryLinkerTestStrategy {
3030
Matcher get isUndefined => const TypeMatcher<UndefinedElementForLink>();
3131

32-
LibraryElementInBuildUnit get testLibrary => _testLibrary ??=
33-
linker.getLibrary(linkerInputs.testDartUri) as LibraryElementInBuildUnit;
34-
35-
void createLinker(String text, {String path: '/test.dart'}) {
36-
linkerInputs = createLinkerInputs(text, path: path);
37-
Map<String, LinkedLibraryBuilder> linkedLibraries = setupForLink(
38-
linkerInputs.linkedLibraries,
39-
linkerInputs.getUnit,
40-
linkerInputs.getDeclaredVariable);
41-
linker = new Linker(
42-
linkedLibraries, linkerInputs.getDependency, linkerInputs.getUnit);
43-
}
44-
4532
LibraryElementForLink getLibrary(String uri) {
4633
return linker.getLibrary(Uri.parse(uri));
4734
}

pkg/analyzer/test/src/summary/prelinker_test.dart

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,22 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/src/summary/idl.dart';
6-
import 'package:analyzer/src/summary/prelink.dart';
75
import 'package:test_reflective_loader/test_reflective_loader.dart';
86

9-
import 'summarize_ast_test.dart';
107
import 'summary_common.dart';
8+
import 'test_strategies.dart';
119

1210
main() {
1311
defineReflectiveSuite(() {
1412
defineReflectiveTests(PrelinkerTest);
1513
});
1614
}
1715

18-
/**
19-
* Override of [SummaryTest] which verifies the correctness of the prelinker by
20-
* creating summaries from the element model, discarding their prelinked
21-
* information, and then recreating it using the prelinker.
22-
*/
16+
/// Tests for the pre-linker which exercise it using the old (two-phase) summary
17+
/// generation strategy.
18+
///
19+
/// TODO(paulberry): eliminate these tests once we have transitioned over to
20+
/// one-step summary generation.
2321
@reflectiveTest
24-
class PrelinkerTest extends LinkedSummarizeAstTest {
25-
@override
26-
bool get skipFullyLinkedData => true;
27-
28-
@override
29-
void serializeLibraryText(String text, {bool allowErrors: false}) {
30-
super.serializeLibraryText(text, allowErrors: allowErrors);
31-
32-
UnlinkedUnit getPart(String absoluteUri) {
33-
return linkerInputs.getUnit(absoluteUri);
34-
}
35-
36-
UnlinkedPublicNamespace getImport(String absoluteUri) {
37-
return getPart(absoluteUri)?.publicNamespace;
38-
}
39-
40-
linked = new LinkedLibrary.fromBuffer(prelink(
41-
linkerInputs.testDartUri.toString(),
42-
linkerInputs.unlinkedDefiningUnit,
43-
getPart,
44-
getImport,
45-
(String declaredVariable) => null).toBuffer());
46-
validateLinkedLibrary(linked);
47-
}
48-
}
22+
class PrelinkerTest extends SummaryBlackBoxTestStrategyPrelink
23+
with SummaryTestCases {}

pkg/analyzer/test/src/summary/resynthesize_ast_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
2828
import '../context/abstract_context.dart';
2929
import 'element_text.dart';
3030
import 'resynthesize_common.dart';
31-
import 'summary_common.dart';
31+
import 'test_strategies.dart';
3232

3333
main() {
3434
defineReflectiveSuite(() {

pkg/analyzer/test/src/summary/summarize_ast_strong_test.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44

55
import 'package:test_reflective_loader/test_reflective_loader.dart';
66

7-
import 'summarize_ast_test.dart';
7+
import 'summary_common.dart';
8+
import 'test_strategies.dart';
89

910
main() {
1011
defineReflectiveSuite(() {
1112
defineReflectiveTests(LinkedSummarizeAstStrongTest);
1213
});
1314
}
1415

15-
/**
16-
* Override of [LinkedSummarizeAstTest] which uses strong mode.
17-
*/
1816
@reflectiveTest
19-
class LinkedSummarizeAstStrongTest extends LinkedSummarizeAstTest {
17+
class LinkedSummarizeAstStrongTest extends SummaryBlackBoxTestStrategyTwoPhase
18+
with SummaryTestCases {
2019
@override
2120
@failingTest
2221
test_bottom_reference_shared() {

pkg/analyzer/test/src/summary/summarize_ast_test.dart

Lines changed: 0 additions & 251 deletions
This file was deleted.

0 commit comments

Comments
 (0)