Skip to content

Commit

Permalink
Convert more tests to include diagnostic location information
Browse files Browse the repository at this point in the history
Change-Id: If0d0dec8839fd6f836cff2b5f021cc8c40969b0b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105140
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
bwilkerson authored and commit-bot@chromium.org committed Jun 6, 2019
1 parent a8a0aff commit 7e933ab
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void main() {
}

test_namedConstructor() async {
await assertErrorCodesInCode(r'''
await assertErrorsInCode(r'''
import 'package:meta/meta.dart';
class A {
@literal
Expand All @@ -71,11 +71,14 @@ class A {
void main() {
var a = A.named();
}
''', [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR]);
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 95, 1),
error(HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR, 99, 9),
]);
}

test_nonConstContext() async {
await assertErrorCodesInCode(r'''
await assertErrorsInCode(r'''
import 'package:meta/meta.dart';
class A {
@literal
Expand All @@ -84,7 +87,10 @@ class A {
void main() {
var a = A();
}
''', [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR]);
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 89, 1),
error(HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR, 93, 3),
]);
}

test_unconstableCreation() async {
Expand All @@ -102,7 +108,7 @@ void main() {
}

test_usingNew() async {
await assertErrorCodesInCode(r'''
await assertErrorsInCode(r'''
import 'package:meta/meta.dart';
class A {
@literal
Expand All @@ -111,6 +117,9 @@ class A {
void main() {
var a = new A();
}
''', [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW]);
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 89, 1),
error(HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW, 93, 7),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ class NonConstantIfElementConditionFromDeferredLibraryTest
test_inList_deferred() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const bool c = true;''');
await assertErrorCodesInCode(
await assertErrorsInCode(
r'''
import 'lib1.dart' deferred as a;
f() {
return const [if(a.c) 0];
}''',
analysisOptions.experimentStatus.constant_update_2018
? [
CompileTimeErrorCode
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY
error(
CompileTimeErrorCode
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
59,
3),
]
: [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
: [
error(CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT, 56, 9),
]);
}

test_inList_nonConst() async {
Expand All @@ -50,32 +55,39 @@ f() {
test_inList_notDeferred() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const bool c = true;''');
await assertErrorCodesInCode(
await assertErrorsInCode(
r'''
import 'lib1.dart' as a;
f() {
return const [if(a.c) 0];
}''',
analysisOptions.experimentStatus.constant_update_2018
? []
: [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
: [
error(CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT, 47, 9),
]);
}

test_inMap_deferred() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const bool c = true;''');
await assertErrorCodesInCode(
await assertErrorsInCode(
r'''
import 'lib1.dart' deferred as a;
f() {
return const {if(a.c) 0 : 0};
}''',
analysisOptions.experimentStatus.constant_update_2018
? [
CompileTimeErrorCode
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY
error(
CompileTimeErrorCode
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
59,
3),
]
: [CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT]);
: [
error(CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT, 56, 13),
]);
}

test_inMap_notConst() async {
Expand All @@ -91,32 +103,39 @@ f() {
test_inMap_notDeferred() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const bool c = true;''');
await assertErrorCodesInCode(
await assertErrorsInCode(
r'''
import 'lib1.dart' as a;
f() {
return const {if(a.c) 0 : 0};
}''',
analysisOptions.experimentStatus.constant_update_2018
? []
: [CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT]);
: [
error(CompileTimeErrorCode.NON_CONSTANT_MAP_ELEMENT, 47, 13),
]);
}

test_inSet_deferred() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const bool c = true;''');
await assertErrorCodesInCode(
await assertErrorsInCode(
r'''
import 'lib1.dart' deferred as a;
f() {
return const {if(a.c) 0};
}''',
analysisOptions.experimentStatus.constant_update_2018
? [
CompileTimeErrorCode
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY
error(
CompileTimeErrorCode
.NON_CONSTANT_IF_ELEMENT_CONDITION_FROM_DEFERRED_LIBRARY,
59,
3),
]
: [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT]);
: [
error(CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT, 56, 9),
]);
}

test_inSet_notConst() async {
Expand All @@ -132,15 +151,17 @@ f() {
test_inSet_notDeferred() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const bool c = true;''');
await assertErrorCodesInCode(
await assertErrorsInCode(
r'''
import 'lib1.dart' as a;
f() {
return const {if(a.c) 0};
}''',
analysisOptions.experimentStatus.constant_update_2018
? []
: [CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT]);
: [
error(CompileTimeErrorCode.NON_CONSTANT_SET_ELEMENT, 47, 9),
]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,66 @@ class NonConstantListElementFromDeferredLibraryTest
// reports wrong error code (which is not crucial to fix)
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const int c = 1;''');
await assertErrorCodesInCode(r'''
await assertErrorsInCode(r'''
import 'lib1.dart' deferred as a;
const cond = true;
var v = const [ if (cond) 'a' else a.c ];
''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
''', [
error(
CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY,
0,
0),
]);
}

test_const_ifElement_thenTrue_deferredThen() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const int c = 1;''');
await assertErrorCodesInCode(
await assertErrorsInCode(
r'''
import 'lib1.dart' deferred as a;
const cond = true;
var v = const [ if (cond) a.c ];
''',
analysisOptions.experimentStatus.constant_update_2018
? [
CompileTimeErrorCode
.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY
error(
CompileTimeErrorCode
.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY,
79,
3),
]
: [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
: [
error(CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT, 69, 13),
]);
}

test_const_topLevel_deferred() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const int c = 1;''');
await assertErrorCodesInCode(r'''
await assertErrorsInCode(r'''
import 'lib1.dart' deferred as a;
var v = const [a.c];
''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
''', [
error(
CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY,
49,
3),
]);
}

test_const_topLevel_deferred_nested() async {
newFile(convertPath('/test/lib/lib1.dart'), content: r'''
const int c = 1;''');
await assertErrorCodesInCode(r'''
await assertErrorsInCode(r'''
import 'lib1.dart' deferred as a;
var v = const [a.c + 1];
''', [CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY]);
''', [
error(
CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY,
49,
7),
]);
}
}

Expand Down
Loading

0 comments on commit 7e933ab

Please sign in to comment.