Skip to content

Commit 37dc566

Browse files
committed
json_serializable_test: cleanup access to test file
1 parent 024881b commit 37dc566

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

json_serializable/test/json_serializable_test.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ library json_serializable.test.json_generator_test;
88
// TODO(kevmoo): test all flavors of `nullable` - class, fields, etc
99

1010
import 'dart:async';
11-
import 'dart:io';
1211

1312
import 'package:analyzer/dart/ast/ast.dart';
14-
import 'package:analyzer/src/string_source.dart';
1513
import 'package:dart_style/dart_style.dart' as dart_style;
1614
import 'package:json_serializable/json_serializable.dart';
1715
import 'package:json_serializable/src/constants.dart';
@@ -34,7 +32,7 @@ Matcher _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher) =>
3432

3533
void main() {
3634
setUpAll(() async {
37-
_compUnit = await _getCompilationUnitForString(getPackagePath());
35+
_compUnit = await _getCompilationUnitForString();
3836
});
3937

4038
group('without wrappers',
@@ -512,14 +510,12 @@ abstract class _$SubTypeSerializerMixin {
512510

513511
final _formatter = new dart_style.DartFormatter();
514512

515-
Future<CompilationUnit> _getCompilationUnitForString(String projectPath) async {
516-
var fileName = 'json_serializable_test_input.dart';
517-
var filePath = p.join(getPackagePath(), 'test', 'src', fileName);
518-
var source =
519-
new StringSource(new File(filePath).readAsStringSync(), fileName);
520-
521-
var context = await getAnalysisContextForProjectPath(projectPath);
513+
Future<CompilationUnit> _getCompilationUnitForString() async {
514+
var context = await getAnalysisContextForProjectPath(getPackagePath());
522515

516+
var fileUri = p.toUri(p.join(
517+
getPackagePath(), 'test', 'src', 'json_serializable_test_input.dart'));
518+
var source = context.sourceFactory.forUri2(fileUri);
523519
var libElement = context.computeLibraryElement(source);
524520
return context.resolveCompilationUnit(source, libElement);
525521
}

0 commit comments

Comments
 (0)