CQ. Use inline expected diagnostics in PubspecDiagnosticTest(s).

Change-Id: Id6f8305c0f5e92ee48cf9c0ac1adc5c2e3a2d490
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/511240
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2026-06-11 09:51:05 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 84088f6a8b
commit 4473de2a5d
23 changed files with 358 additions and 382 deletions
@@ -206,6 +206,11 @@ class NodeTextExpectationsCollector {
methodName: 'assertRuleDiagnosticsInFiles',
argument: _ArgumentMapEntryValue(mapArgument: _ArgumentIndex(0)),
),
_AssertMethod(
className: 'PubspecDiagnosticTest',
methodName: 'assertDiagnostics',
argument: _ArgumentIndex(0),
),
_AssertMethod(
className: 'ResolutionTest',
methodName: 'assertDartObjectText',
@@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AssetDirectoryDoesNotExistTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@@ -17,7 +18,7 @@ main() {
class AssetDirectoryDoesNotExistTest extends PubspecDiagnosticTest {
test_assetDirectoryDoesExist_noError() {
newFolder('/sample/assets/logos');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -26,14 +27,13 @@ flutter:
}
test_assetDirectoryDoesNotExist_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
- assets/logos/
''',
[diag.assetDirectoryDoesNotExist],
);
// ^^^^^^^^^^^^^
// [diag.assetDirectoryDoesNotExist] The asset directory 'assets/logos/' doesn't exist.
''');
}
}
@@ -2,34 +2,34 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AssetDoesNotExistTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class AssetDoesNotExistTest extends PubspecDiagnosticTest {
test_assetDoesNotExist_path_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
- assets/my_icon.png
''',
[diag.assetDoesNotExist],
);
// ^^^^^^^^^^^^^^^^^^
// [diag.assetDoesNotExist] The asset file 'assets/my_icon.png' doesn't exist.
''');
}
test_assetDoesNotExist_path_inRoot_noError() {
newFile('/sample/assets/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -39,7 +39,7 @@ flutter:
test_assetDoesNotExist_path_inSubdir_noError() {
newFile('/sample/assets/images/2.0x/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -47,23 +47,23 @@ flutter:
''');
}
@failingTest
// TODO(scheglov): Support package assets.
@skippedTest
test_assetDoesNotExist_uri_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
- packages/icons/my_icon.png
''',
[diag.assetDoesNotExist],
);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^
// [diag.assetDoesNotExist] The asset file 'packages/icons/my_icon.png' doesn't exist.
''');
}
test_assetDoesNotExist_uri_noError() {
// TODO(brianwilkerson): Create a package named `icons` that contains the
// referenced file, and a `.packages` file that references that package.
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -2,44 +2,43 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AssetFieldNotListTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class AssetFieldNotListTest extends PubspecDiagnosticTest {
test_assetFieldNotList_error_empty() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
''',
[diag.assetFieldNotList],
);
// ^
// [diag.assetFieldNotList][column 9][length 0] The value of the 'assets' field is expected to be a list of relative file paths.
''');
}
test_assetFieldNotList_error_string() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets: assets/my_icon.png
''',
[diag.assetFieldNotList],
);
// ^^^^^^^^^^^^^^^^^^
// [diag.assetFieldNotList] The value of the 'assets' field is expected to be a list of relative file paths.
''');
}
test_assetFieldNotList_noError() {
newFile('/sample/assets/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AssetMissingPathTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@@ -17,7 +18,7 @@ main() {
class AssetMissingPathTest extends PubspecDiagnosticTest {
test_assetHasPath() {
newFile('/sample/assets/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -28,15 +29,13 @@ flutter:
}
test_assetMissingPath() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
- flavors:
// [diag.assetMissingPath][column 7][length 27] Asset map entry must contain a 'path' field.
- premium
''',
[diag.assetMissingPath],
);
''');
}
}
@@ -2,34 +2,34 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AssetNotStringOrMapTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class AssetNotStringOrMapTest extends PubspecDiagnosticTest {
test_assetNotString_error_int() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
- 23
''',
[diag.assetNotStringOrMap],
);
// ^^
// [diag.assetNotStringOrMap] An asset value is required to be a file path (string) or map.
''');
}
test_assetNotString_error_map() {
newFile('/sample/assets/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -40,20 +40,19 @@ flutter:
}
test_assetNotString_error_null() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
-
''',
[diag.assetNotStringOrMap],
);
// ^
// [diag.assetNotStringOrMap][column 5][length 0] An asset value is required to be a file path (string) or map.
''');
}
test_assetNotString_noError() {
newFile('/sample/assets/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -2,46 +2,45 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AssetPathNotStringTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class AssetPathNotStringTest extends PubspecDiagnosticTest {
test_pathIsList() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
- path: [one, two, three]
''',
[diag.assetPathNotString],
);
// ^^^^^^^^^^^^^^^^^
// [diag.assetPathNotString] Asset paths are required to be file paths (strings).
''');
}
test_pathIsNull() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter:
assets:
- path:
''',
[diag.assetNotString],
);
// ^
// [diag.assetNotString][column 11][length 0] Assets are required to be file paths (strings).
''');
}
test_pathIsString() {
newFile('/sample/assets/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -2,38 +2,38 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(DependenciesFieldNotMapTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class DependenciesFieldNotMapTest extends PubspecDiagnosticTest {
test_dependenciesField_empty() {
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
''');
}
test_dependenciesFieldNotMap_error_bool() {
assertErrors(
'''
assertDiagnostics('''
name: sample
dependencies: true
''',
[diag.dependenciesFieldNotMap],
);
// ^^^^
// [diag.dependenciesFieldNotMap] The value of the 'dependencies' field is expected to be a map.
''');
}
test_dependenciesFieldNotMap_noError() {
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
a: any
@@ -41,12 +41,11 @@ dependencies:
}
test_devDependenciesFieldNotMap_dev_error_bool() {
assertErrors(
'''
assertDiagnostics('''
name: sample
dev_dependencies: true
''',
[diag.dependenciesFieldNotMap],
);
// ^^^^
// [diag.dependenciesFieldNotMap] The value of the 'dev_dependencies' field is expected to be a map.
''');
}
}
@@ -2,59 +2,52 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(DeprecatedFieldTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class DeprecatedFieldTest extends PubspecDiagnosticTest {
test_deprecated_author() {
assertErrors(
'''
assertDiagnostics('''
name: sample
author: foo
''',
[diag.deprecatedField],
);
// [diag.deprecatedField][column 1][length 6] The 'author' field is no longer used and can be removed.
''');
}
test_deprecated_authors() {
assertErrors(
'''
assertDiagnostics('''
name: sample
authors:
// [diag.deprecatedField][column 1][length 7] The 'authors' field is no longer used and can be removed.
- foo
- bar
''',
[diag.deprecatedField],
);
''');
}
test_deprecated_transformers() {
assertErrors(
'''
assertDiagnostics('''
name: sample
transformers:
// [diag.deprecatedField][column 1][length 12] The 'transformers' field is no longer used and can be removed.
- foo
''',
[diag.deprecatedField],
);
''');
}
test_deprecated_web() {
assertErrors(
'''
assertDiagnostics('''
name: sample
web: foo
''',
[diag.deprecatedField],
);
// [diag.deprecatedField][column 1][length 3] The 'web' field is no longer used and can be removed.
''');
}
}
@@ -2,26 +2,27 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(FlutterFieldNotMapTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class FlutterFieldNotMapTest extends PubspecDiagnosticTest {
test_flutterField_empty_noError() {
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
''');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
@@ -29,18 +30,17 @@ flutter:
}
test_flutterFieldNotMap_error_bool() {
assertErrors(
'''
assertDiagnostics('''
name: sample
flutter: true
''',
[diag.flutterFieldNotMap],
);
// ^^^^
// [diag.flutterFieldNotMap] The value of the 'flutter' field is expected to be a map.
''');
}
test_flutterFieldNotMap_noError() {
newFile('/sample/assets/my_icon.png', '');
assertNoErrors('''
assertDiagnostics('''
name: sample
flutter:
assets:
@@ -2,22 +2,22 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(IgnoreDiagnosticTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class IgnoreDiagnosticTest extends PubspecDiagnosticTest {
test_comma_separated() {
assertErrors(
'''
assertDiagnostics('''
name: sample
version: 0.1.0
dependencies:
@@ -26,13 +26,13 @@ dependencies:
path: doesnt/exist
bar:
git: git@github.com:foo/bar.git
''',
[diag.invalidDependency],
);
// ^^^
// [diag.invalidDependency] Publishable packages can't have 'git' dependencies.
''');
}
test_file() {
assertNoErrors('''
assertDiagnostics('''
# ignore_for_file: invalid_dependency
name: sample
version: 0.1.0
@@ -45,8 +45,7 @@ dependencies:
}
test_line_previous() {
assertErrors(
'''
assertDiagnostics('''
name: sample
version: 0.1.0
dependencies:
@@ -55,38 +54,38 @@ dependencies:
git: git@github.com:foo/foo.git
bar:
git: git@github.com:foo/bar.git
''',
[diag.invalidDependency],
);
// ^^^
// [diag.invalidDependency] Publishable packages can't have 'git' dependencies.
''');
}
test_line_same() {
assertErrors(
'''
assertDiagnostics('''
name: sample
version: 0.1.0
dependencies:
foo:
git: git@github.com:foo/foo.git
// ^^^
// [diag.invalidDependency] Publishable packages can't have 'git' dependencies.
bar:
git: git@github.com:foo/bar.git # ignore: invalid_dependency
''',
[diag.invalidDependency],
);
''');
}
test_noIgnores() {
assertErrors(
'''
assertDiagnostics('''
name: sample
version: 0.1.0
dependencies:
foo:
git: git@github.com:foo/foo.git
// ^^^
// [diag.invalidDependency] Publishable packages can't have 'git' dependencies.
bar:
git: git@github.com:foo/bar.git
''',
[diag.invalidDependency, diag.invalidDependency],
);
// ^^^
// [diag.invalidDependency] Publishable packages can't have 'git' dependencies.
''');
}
}
@@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(InvalidDependencyTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@@ -17,7 +18,7 @@ main() {
class InvalidDependencyTest extends PubspecDiagnosticTest {
test_dependencyGit_malformed_empty() {
// TODO(pq): consider validating.
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -27,7 +28,7 @@ dependencies:
test_dependencyGit_malformed_list() {
// TODO(pq): consider validating.
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -38,7 +39,7 @@ dependencies:
test_dependencyGit_malformed_scalar() {
// TODO(pq): consider validating.
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -47,7 +48,7 @@ dependencies:
}
test_dependencyGit_noVersion_valid() {
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -58,22 +59,21 @@ dependencies:
}
test_dependencyGit_version_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
version: 0.1.0
dependencies:
foo:
git:
// ^^^
// [diag.invalidDependency] Publishable packages can't have 'git' dependencies.
url: git@github.com:foo/foo.git
path: path/to/foo
''',
[diag.invalidDependency],
);
''');
}
test_dependencyGit_version_valid() {
assertNoErrors('''
assertDiagnostics('''
name: sample
version: 0.1.0
publish_to: none
@@ -87,7 +87,7 @@ dependencies:
test_dependencyGitPath() {
// git paths are not validated
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -99,7 +99,7 @@ dependencies:
test_dependencyPath_malformed_empty() {
// TODO(pq): consider validating.
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -109,7 +109,7 @@ dependencies:
test_dependencyPath_malformed_list() {
// TODO(pq): consider validating.
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -123,7 +123,7 @@ dependencies:
newPubspecYamlFile('/foo', '''
name: foo
''');
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -136,7 +136,7 @@ dependencies:
newPubspecYamlFile('/foo', '''
name: foo
''');
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -149,7 +149,7 @@ dependencies:
newPubspecYamlFile('/foo', '''
name: foo
''');
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -162,16 +162,15 @@ dependencies:
newPubspecYamlFile('/foo', '''
name: foo
''');
assertErrors(
'''
assertDiagnostics('''
name: sample
version: 0.1.0
dependencies:
foo:
path: /foo
''',
[diag.invalidDependency],
);
// ^^^^
// [diag.invalidDependency] Publishable packages can't have 'path' dependencies.
''');
}
test_dependencyPath_version_valid() {
@@ -179,7 +178,7 @@ dependencies:
newPubspecYamlFile('/foo', '''
name: foo
''');
assertNoErrors('''
assertDiagnostics('''
name: sample
version: 0.1.0
publish_to: none
@@ -190,14 +189,14 @@ dependencies:
}
test_devDependenciesField_empty() {
assertNoErrors('''
assertDiagnostics('''
name: sample
dev_dependencies:
''');
}
test_devDependenciesFieldNotMap_dev_noError() {
assertNoErrors('''
assertDiagnostics('''
name: sample
dev_dependencies:
a: any
@@ -206,7 +205,7 @@ dev_dependencies:
test_devDependencyGit_version_no_error() {
// Git paths are OK in dev_dependencies
assertNoErrors('''
assertDiagnostics('''
name: sample
version: 0.1.0
dev_dependencies:
@@ -2,21 +2,22 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(PlatformsFieldTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class PlatformsFieldTest extends PubspecDiagnosticTest {
test_empty_platforms_is_allowed() {
assertNoErrors('''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms: {} # I don't think you should ever do this!
@@ -24,54 +25,49 @@ platforms: {} # I don't think you should ever do this!
}
test_invalid_platforms_field() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
- android
// [diag.invalidPlatformsField][column 3][length 26] The 'platforms' field must be a map with platforms as keys.
- ios
- web
''',
[diag.invalidPlatformsField],
);
''');
}
test_invalid_platforms_field_bool() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms: true
''',
[diag.invalidPlatformsField],
);
// ^^^^
// [diag.invalidPlatformsField] The 'platforms' field must be a map with platforms as keys.
''');
}
test_invalid_platforms_field_empty_list() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms: []
''',
[diag.invalidPlatformsField],
);
// ^^
// [diag.invalidPlatformsField] The 'platforms' field must be a map with platforms as keys.
''');
}
test_invalid_platforms_field_num() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms: 42
''',
[diag.invalidPlatformsField],
);
// ^^
// [diag.invalidPlatformsField] The 'platforms' field must be a map with platforms as keys.
''');
}
test_subset_of_supported_platforms_is_allowed() {
assertNoErrors('''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
@@ -82,7 +78,7 @@ platforms:
}
test_supported_platforms_are_allowed() {
assertNoErrors('''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
@@ -96,26 +92,24 @@ platforms:
}
test_unknown_platform() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
windåse:
''',
[diag.unknownPlatform],
);
//^^^^^^^
// [diag.unknownPlatform] The platform 'windåse' is not a recognized platform.
''');
}
test_unknown_platform_capitalization() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
Windows:
''',
[diag.unknownPlatform],
);
//^^^^^^^
// [diag.unknownPlatform] The platform 'Windows' is not a recognized platform.
''');
}
}
@@ -2,25 +2,30 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(MissingNameTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class MissingNameTest extends PubspecDiagnosticTest {
test_missingName_error() {
assertErrors('', [diag.missingName]);
assertDiagnostics(
'''
// [diag.missingName][column 1][length 0] The 'name' field is required but missing.''',
);
}
test_missingName_noError() {
assertNoErrors('''
assertDiagnostics('''
name: sample
''');
}
@@ -2,30 +2,30 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NameNotStringTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class NameNotStringTest extends PubspecDiagnosticTest {
test_nameNotString_error_int() {
assertErrors(
'''
assertDiagnostics('''
name: 42
''',
[diag.nameNotString],
);
// ^^
// [diag.nameNotString] The value of the 'name' field is required to be a string.
''');
}
test_nameNotString_noError() {
assertNoErrors('''
assertDiagnostics('''
name: sample
''');
}
@@ -2,41 +2,40 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(PathDoesNotExistTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class PathDoesNotExistTest extends PubspecDiagnosticTest {
test_dependencyPathDoesNotExist_path_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
dependencies:
foo:
path: does/not/exist
''',
[diag.pathDoesNotExist],
);
// ^^^^^^^^^^^^^^
// [diag.pathDoesNotExist] The path 'does/not/exist' doesn't exist.
''');
}
test_devDependencyPathDoesNotExist_path_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
dev_dependencies:
foo:
path: does/not/exist
''',
[diag.pathDoesNotExist],
);
// ^^^^^^^^^^^^^^
// [diag.pathDoesNotExist] The path 'does/not/exist' doesn't exist.
''');
}
test_devDependencyPathExists() {
@@ -44,7 +43,7 @@ dev_dependencies:
newPubspecYamlFile('/foo', '''
name: foo
''');
assertNoErrors('''
assertDiagnostics('''
name: sample
dev_dependencies:
foo:
@@ -53,35 +52,35 @@ dev_dependencies:
}
test_screenshotPathDoesNotExist_path_error() {
assertErrors(
'''
assertDiagnostics('''
name: foo
screenshots:
- description: '...'
path: example/screenshots/no.webp
''',
[diag.pathDoesNotExist],
);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [diag.pathDoesNotExist] The path 'example/screenshots/no.webp' doesn't exist.
''');
}
test_screenshotPathDoesNotExist_path_error_multiple() {
assertErrors(
'''
assertDiagnostics('''
name: foo
screenshots:
- description: '...'
path: example/screenshots/no.webp
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [diag.pathDoesNotExist] The path 'example/screenshots/no.webp' doesn't exist.
- description: '...'
path: example/screenshots/no.webp
''',
[diag.pathDoesNotExist, diag.pathDoesNotExist],
);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [diag.pathDoesNotExist] The path 'example/screenshots/no.webp' doesn't exist.
''');
}
test_screenshotPathExists() {
newFolder('/sample/example');
newFile('/sample/example/yes.webp', '');
assertNoErrors('''
assertDiagnostics('''
name: foo
screenshots:
- description: '...'
@@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(PathNotPosixTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@@ -20,16 +21,15 @@ class PathNotPosixTest extends PubspecDiagnosticTest {
newPubspecYamlFile('/foo', '''
name: foo
''');
assertErrors(
r'''
assertDiagnostics(r'''
name: sample
version: 0.1.0
publish_to: none
dependencies:
foo:
path: \foo
''',
[diag.pathNotPosix],
);
// ^^^^
// [diag.pathNotPosix] The path '\foo' isn't a POSIX-style path.
''');
}
}
@@ -2,14 +2,15 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(PathPubspecDoesNotExistTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@@ -17,15 +18,14 @@ main() {
class PathPubspecDoesNotExistTest extends PubspecDiagnosticTest {
test_dependencyPath_pubspecDoesNotExist() {
newFolder('/foo');
assertErrors(
'''
assertDiagnostics('''
name: sample
dependencies:
foo:
path: /foo
''',
[diag.pathPubspecDoesNotExist],
);
// ^^^^
// [diag.pathPubspecDoesNotExist] The directory '/foo' doesn't contain a pubspec.
''');
}
test_dependencyPath_pubspecExists() {
@@ -33,7 +33,7 @@ dependencies:
newPubspecYamlFile('/foo', '''
name: foo
''');
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
foo:
@@ -2,21 +2,22 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(PlatformValueDisallowedTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class PlatformValueDisallowedTest extends PubspecDiagnosticTest {
test_subset_of_supported_platforms_is_allowed() {
assertNoErrors('''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
@@ -27,92 +28,85 @@ platforms:
}
test_value_for_platform_key_disallowed() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
android:
ios:
web: "chrome" # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// ^^^^^^^^
// [diag.platformValueDisallowed] Keys in the `platforms` field can't have values.
''');
}
test_value_for_platform_key_disallowed_empty_list() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
android:
ios:
web: [] # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// ^^
// [diag.platformValueDisallowed] Keys in the `platforms` field can't have values.
''');
}
test_value_for_platform_key_disallowed_empty_map() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
android:
ios:
web: {} # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// ^^
// [diag.platformValueDisallowed] Keys in the `platforms` field can't have values.
''');
}
test_value_for_platform_key_disallowed_false() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
android:
ios:
web: False # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// ^^^^^
// [diag.platformValueDisallowed] Keys in the `platforms` field can't have values.
''');
}
test_value_for_platform_key_disallowed_int() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
android:
ios:
web: 42 # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// ^^
// [diag.platformValueDisallowed] Keys in the `platforms` field can't have values.
''');
}
test_value_for_platform_key_disallowed_list_int() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
android:
ios:
web: [1,2,3] # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// ^^^^^^^
// [diag.platformValueDisallowed] Keys in the `platforms` field can't have values.
''');
}
test_value_for_platform_key_disallowed_list_string() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
@@ -120,15 +114,13 @@ platforms:
ios:
web:
- foo
// [diag.platformValueDisallowed][column 4][length 42] Keys in the `platforms` field can't have values.
- bar # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
''');
}
test_value_for_platform_key_disallowed_map() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
@@ -136,22 +128,20 @@ platforms:
ios:
web:
foo: bar # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// [diag.platformValueDisallowed][column 5][length 36] Keys in the `platforms` field can't have values.
''');
}
test_value_for_platform_key_disallowed_true() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
android:
ios:
web: True # <-- this is not allowed
''',
[diag.platformValueDisallowed],
);
// ^^^^
// [diag.platformValueDisallowed] Keys in the `platforms` field can't have values.
''');
}
}
@@ -2,21 +2,22 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(UnknownPlatformsTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class UnknownPlatformsTest extends PubspecDiagnosticTest {
test_subset_of_supported_platforms_is_allowed() {
assertNoErrors('''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
@@ -27,7 +28,7 @@ platforms:
}
test_supported_platforms_are_allowed() {
assertNoErrors('''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
@@ -41,74 +42,68 @@ platforms:
}
test_unknown_platform_bool() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
True:
''',
[diag.unknownPlatform],
);
//^^^^
// [diag.unknownPlatform] The platform 'true' is not a recognized platform.
''');
}
test_unknown_platform_browser() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
browser: # the correct platform is "web"
''',
[diag.unknownPlatform],
);
//^^^^^^^
// [diag.unknownPlatform] The platform 'browser' is not a recognized platform.
''');
}
test_unknown_platform_int() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
33:
''',
[diag.unknownPlatform],
);
//^^
// [diag.unknownPlatform] The platform '33' is not a recognized platform.
''');
}
test_unknown_platform_list() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
[1, 2]:
''',
[diag.unknownPlatform],
);
//^^^^^^
// [diag.unknownPlatform] The platform '[1, 2]' is not a recognized platform.
''');
}
test_unknown_platform_null() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
null:
''',
[diag.unknownPlatform],
);
//^^^^
// [diag.unknownPlatform] The platform 'null' is not a recognized platform.
''');
}
test_unknown_platform_win32() {
assertErrors(
'''
assertDiagnostics('''
name: foo
version: 1.0.0
platforms:
win32: # the correct platform is "windows"
''',
[diag.unknownPlatform],
);
//^^^^^
// [diag.unknownPlatform] The platform 'win32' is not a recognized platform.
''');
}
}
@@ -2,47 +2,46 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(UnnecessaryDevDependencyTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class UnnecessaryDevDependencyTest extends PubspecDiagnosticTest {
test_unnecessaryDevDependency_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
dependencies:
a: any
dev_dependencies:
a: any
''',
[diag.unnecessaryDevDependency],
);
//^
// [diag.unnecessaryDevDependency] The dev dependency on a is unnecessary because there is also a normal dependency on that package.
''');
}
test_unnecessaryDevDependency_error_null() {
assertErrors(
'''
assertDiagnostics('''
name: sample
dependencies:
null: any
dev_dependencies:
null: any
''',
[diag.unnecessaryDevDependency],
);
//^^^^
// [diag.unnecessaryDevDependency] The dev dependency on null is unnecessary because there is also a normal dependency on that package.
''');
}
test_unnecessaryDevDependency_noError() {
assertNoErrors('''
assertDiagnostics('''
name: sample
dependencies:
a: any
@@ -2,33 +2,33 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../pubspec_test_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(WorkspaceFieldTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class WorkspaceFieldTest extends PubspecDiagnosticTest {
test_workspaceGlob_baseMissing_error() {
assertErrors(
'''
assertDiagnostics('''
name: sample
workspace:
- packages/*
''',
[diag.pathDoesNotExist],
);
// ^^^^^^^^^^
// [diag.pathDoesNotExist] The path 'packages' doesn't exist.
''');
}
test_workspaceGlob_braces_baseExists_noError() {
newFolder('/sample/packages');
assertNoErrors('''
assertDiagnostics('''
name: sample
workspace:
- packages/{a,b}
@@ -37,7 +37,7 @@ workspace:
test_workspaceGlob_nestedBase_baseExists_noError() {
newFolder('/sample/apps/nested');
assertNoErrors('''
assertDiagnostics('''
name: sample
workspace:
- apps/nested/*
@@ -46,7 +46,7 @@ workspace:
test_workspaceGlob_noBase_noError() {
// Pattern starts with a glob character — no base directory to check.
assertNoErrors('''
assertDiagnostics('''
name: sample
workspace:
- '*'
@@ -55,7 +55,7 @@ workspace:
test_workspaceGlob_questionMark_baseExists_noError() {
newFolder('/sample/packages');
assertNoErrors('''
assertDiagnostics('''
name: sample
workspace:
- packages/pkg?
@@ -64,7 +64,7 @@ workspace:
test_workspaceGlob_star_baseExists_noError() {
newFolder('/sample/packages');
assertNoErrors('''
assertDiagnostics('''
name: sample
workspace:
- packages/*
@@ -72,53 +72,49 @@ workspace:
}
test_workspaceIsList() {
assertErrors(
'''
assertDiagnostics('''
name: sample
workspace: package1
''',
[diag.workspaceFieldNotList],
);
// ^^^^^^^^
// [diag.workspaceFieldNotList] The value of the 'workspace' field is required to be a list of relative file paths.
''');
}
test_workspaceValueIsNotString() {
newFolder('/sample/package1');
assertErrors(
'''
assertDiagnostics('''
name: sample
workspace:
- 23
''',
[diag.workspaceValueNotString],
);
// ^^
// [diag.workspaceValueNotString] Workspace entries are required to be directory paths (strings).
''');
}
test_workspaceValueIsNotSubDirectory() {
newFolder('/sample/package1');
assertErrors(
'''
assertDiagnostics('''
name: sample
workspace:
- /sample2
''',
[diag.workspaceValueNotSubdirectory],
);
// ^^^^^^^^
// [diag.workspaceValueNotSubdirectory] Workspace values must be a relative path of a subdirectory of '/sample'.
''');
}
test_workspaceValueIsNull() {
assertErrors(
'''
assertDiagnostics('''
name: sample
workspace:
-
''',
[diag.workspaceValueNotString],
);
// ^
// [diag.workspaceValueNotString][column 5][length 0] Workspace entries are required to be directory paths (strings).
''');
}
test_workspaceValueIsString() {
newFolder('/sample/package1');
assertNoErrors('''
assertDiagnostics('''
name: sample
workspace:
- package1
@@ -127,7 +123,7 @@ workspace:
test_workspaceValueIsSubDirectory() {
newFolder('/sample/package1');
assertNoErrors('''
assertDiagnostics('''
name: sample
workspace:
- package1
@@ -2,36 +2,43 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/error/error.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/source/file_source.dart';
import 'package:analyzer/src/pubspec/pubspec_validator.dart';
import 'package:analyzer_testing/resource_provider_mixin.dart';
import 'package:analyzer_testing/src/expected_diagnostics.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
import '../../generated/test_support.dart';
import '../../util/diff.dart';
import '../dart/resolution/node_text_expectations.dart';
class PubspecDiagnosticTest with ResourceProviderMixin {
/// Assert that when the validator is used on the given [content] the
/// [expectedCodes] are produced.
void assertErrors(String content, List<DiagnosticCode> expectedCodes) {
/// Assert that pubspec validator diagnostics match the inline diagnostic
/// markers in [content].
void assertDiagnostics(String content) {
var cleanContent = removeDiagnosticExpectations(content);
var diagnostics = _validate(cleanContent);
var actual = updateExpectedDiagnostics(
content: cleanContent,
actualDiagnostics: diagnostics,
);
if (actual != content) {
NodeTextExpectationsCollector.add(actual);
printPrettyDiff(content, actual);
fail('See the difference above.');
}
}
List<Diagnostic> _validate(String content) {
var pubspecFile = newFile('/sample/pubspec.yaml', content);
var source = FileSource(pubspecFile);
YamlNode node = loadYamlNode(content);
GatheringDiagnosticListener listener = GatheringDiagnosticListener();
listener.addAll(
validatePubspec(
contents: node,
source: source,
provider: resourceProvider,
// TODO(sigurdm): Can/should we pass analysisOptions here?
),
return validatePubspec(
contents: node,
source: source,
provider: resourceProvider,
// TODO(sigurdm): Can/should we pass analysisOptions here?
);
listener.assertErrorsWithCodes(expectedCodes);
}
/// Assert that when the validator is used on the given [content] no errors
/// are produced.
void assertNoErrors(String content) {
assertErrors(content, []);
}
}