|
| 1 | +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:analyzer/src/error/codes.dart'; |
| 6 | +import 'package:meta/meta.dart'; |
| 7 | +import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 8 | + |
| 9 | +import '../../generated/test_support.dart'; |
| 10 | +import '../dart/resolution/driver_resolution.dart'; |
| 11 | + |
| 12 | +main() { |
| 13 | + defineReflectiveSuite(() { |
| 14 | + defineReflectiveTests(InconsistentLanguageVersionOverrideTest); |
| 15 | + }); |
| 16 | +} |
| 17 | + |
| 18 | +@reflectiveTest |
| 19 | +class InconsistentLanguageVersionOverrideTest extends DriverResolutionTest { |
| 20 | + CompileTimeErrorCode get _errorCode => |
| 21 | + CompileTimeErrorCode.INCONSISTENT_LANGUAGE_VERSION_OVERRIDE; |
| 22 | + |
| 23 | + test_both_different() async { |
| 24 | + await _checkLibraryAndPart( |
| 25 | + libraryContent: r''' |
| 26 | +// @dart = 2.5 |
| 27 | +part 'b.dart'; |
| 28 | +''', |
| 29 | + partContent: r''' |
| 30 | +// @dart = 2.6 |
| 31 | +part of 'a.dart'; |
| 32 | +''', |
| 33 | + partErrors: [ |
| 34 | + error(_errorCode, 0, 14), |
| 35 | + ], |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + test_both_same() async { |
| 40 | + await _checkLibraryAndPart( |
| 41 | + libraryContent: r''' |
| 42 | +// @dart = 2.5 |
| 43 | +part 'b.dart'; |
| 44 | +''', |
| 45 | + partContent: r''' |
| 46 | +// @dart = 2.5 |
| 47 | +part of 'a.dart'; |
| 48 | +''', |
| 49 | + partErrors: [], |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + test_none() async { |
| 54 | + await _checkLibraryAndPart( |
| 55 | + libraryContent: r''' |
| 56 | +part 'b.dart'; |
| 57 | +''', |
| 58 | + partContent: r''' |
| 59 | +part of 'a.dart'; |
| 60 | +''', |
| 61 | + partErrors: [], |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + test_onlyLibrary() async { |
| 66 | + await _checkLibraryAndPart( |
| 67 | + libraryContent: r''' |
| 68 | +// @dart = 2.5 |
| 69 | +part 'b.dart'; |
| 70 | +''', |
| 71 | + partContent: r''' |
| 72 | +part of 'a.dart'; |
| 73 | +''', |
| 74 | + partErrors: [ |
| 75 | + error(_errorCode, 0, 7), |
| 76 | + ], |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + test_onlyPart() async { |
| 81 | + await _checkLibraryAndPart( |
| 82 | + libraryContent: r''' |
| 83 | +part 'b.dart'; |
| 84 | +''', |
| 85 | + partContent: r''' |
| 86 | +// @dart = 2.5 |
| 87 | +part of 'a.dart'; |
| 88 | +''', |
| 89 | + partErrors: [ |
| 90 | + error(_errorCode, 0, 14), |
| 91 | + ], |
| 92 | + ); |
| 93 | + } |
| 94 | + |
| 95 | + Future<void> _checkLibraryAndPart({ |
| 96 | + @required String libraryContent, |
| 97 | + @required String partContent, |
| 98 | + @required List<ExpectedError> partErrors, |
| 99 | + }) async { |
| 100 | + var libraryPath = convertPath('/test/lib/a.dart'); |
| 101 | + var partPath = convertPath('/test/lib/b.dart'); |
| 102 | + |
| 103 | + newFile(libraryPath, content: libraryContent); |
| 104 | + |
| 105 | + newFile(partPath, content: partContent); |
| 106 | + |
| 107 | + await resolveFile(libraryPath); |
| 108 | + |
| 109 | + await assertErrorsInFile2(partPath, partErrors); |
| 110 | + } |
| 111 | +} |
0 commit comments