Skip to content

Commit

Permalink
Run type system verification tests for non-canary mode as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Gringauze committed Jul 25, 2023
1 parent eac89b3 commit d48b456
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 67 deletions.
66 changes: 66 additions & 0 deletions dwds/test/instances/common/instance_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,72 @@ import '../../fixtures/context.dart';
import '../../fixtures/project.dart';
import 'test_inspector.dart';

void runTypeSystemVerificationTests({
required TestSdkConfigurationProvider provider,
required CompilationMode compilationMode,
required bool canaryFeatures,
required bool debug,
}) {
final project = TestProject.testScopesWithSoundNullSafety;

group('$compilationMode |', () {
final context = TestContext(project, provider);
late AppInspector inspector;

setUpAll(() async {
setCurrentLogWriter(debug: debug);
await context.setUp(
canaryFeatures: canaryFeatures,
compilationMode: compilationMode,
);
final chromeProxyService = context.service;
inspector = chromeProxyService.inspector;
});

tearDownAll(() async {
await context.tearDown();
});

final url = 'org-dartlang-app:///example/scopes/main.dart';

String libraryName(CompilationMode compilationMode) =>
compilationMode == CompilationMode.frontendServer
? "example/scopes/main.dart"
: "example/scopes/main";

String libraryVariableTypeExpression(
String variable,
CompilationMode compilationMode,
) =>
'''
(function() {
var dart = ${globalLoadStrategy.loadModuleSnippet}('dart_sdk').dart;
var libraryName = '${libraryName(compilationMode)}';
var library = dart.getModuleLibraries(libraryName)['$url'];
var x = library['$variable'];
return dart.getReifiedType(x);
})();
''';

group('compiler', () {
setUp(() => setCurrentLogWriter(debug: debug));

test('uses correct type system', () async {
final remoteObject = await inspector.jsEvaluate(
libraryVariableTypeExpression(
'libraryPublicFinal',
compilationMode,
),
);
expect(
remoteObject.json['className'],
canaryFeatures ? 'dart_rti.Rti.new' : 'Function',
);
});
});
});
}

void runTests({
required TestSdkConfigurationProvider provider,
required CompilationMode compilationMode,
Expand Down
69 changes: 2 additions & 67 deletions dwds/test/instances/instance_canary_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
@Tags(['daily'])
@Timeout(Duration(minutes: 2))

import 'package:dwds/src/debugging/inspector.dart';
import 'package:dwds/src/loaders/strategy.dart';
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:test_common/test_sdk_configuration.dart';

import '../fixtures/context.dart';
import '../fixtures/project.dart';
import 'common/instance_common.dart';

void main() {
Expand All @@ -28,9 +24,10 @@ void main() {
tearDownAll(provider.dispose);

for (var compilationMode in CompilationMode.values) {
_runCanaryModeVerificationTests(
runTypeSystemVerificationTests(
provider: provider,
compilationMode: compilationMode,
canaryFeatures: canaryFeatures,
debug: debug,
);

Expand All @@ -43,65 +40,3 @@ void main() {
}
});
}

void _runCanaryModeVerificationTests({
required TestSdkConfigurationProvider provider,
required CompilationMode compilationMode,
required bool debug,
}) {
final project = TestProject.testScopesWithSoundNullSafety;

group('$compilationMode |', () {
final context = TestContext(project, provider);
late AppInspector inspector;

setUpAll(() async {
setCurrentLogWriter(debug: debug);
await context.setUp(
canaryFeatures: true,
compilationMode: compilationMode,
);
final chromeProxyService = context.service;
inspector = chromeProxyService.inspector;
});

tearDownAll(() async {
await context.tearDown();
});

final url = 'org-dartlang-app:///example/scopes/main.dart';

String libraryName(CompilationMode compilationMode) =>
compilationMode == CompilationMode.frontendServer
? "example/scopes/main.dart"
: "example/scopes/main";

String libraryVariableTypeExpression(
String variable,
CompilationMode compilationMode,
) =>
'''
(function() {
var dart = ${globalLoadStrategy.loadModuleSnippet}('dart_sdk').dart;
var libraryName = '${libraryName(compilationMode)}';
var library = dart.getModuleLibraries(libraryName)['$url'];
var x = library['$variable'];
return dart.getReifiedType(x);
})();
''';

group('compiler', () {
setUp(() => setCurrentLogWriter(debug: debug));

test('uses new type system', () async {
final remoteObject = await inspector.jsEvaluate(
libraryVariableTypeExpression(
'libraryPublicFinal',
compilationMode,
),
);
expect(remoteObject.json['className'], 'dart_rti.Rti.new');
});
});
});
}
7 changes: 7 additions & 0 deletions dwds/test/instances/instance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ void main() {
tearDownAll(provider.dispose);

for (var compilationMode in CompilationMode.values) {
runTypeSystemVerificationTests(
provider: provider,
compilationMode: compilationMode,
canaryFeatures: canaryFeatures,
debug: debug,
);

runTests(
provider: provider,
compilationMode: compilationMode,
Expand Down

0 comments on commit d48b456

Please sign in to comment.