Skip to content

More test cleanup, removed unused dependency #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies:
analyzer: '>=0.29.10 <0.32.0'
build: '>=0.9.0 <0.13.0'
build_config: ^0.2.6
cli_util: ^0.1.0

# Use a tight version constraint to ensure that a constraint on
# `json_annotation`. Properly constrains all features it provides.
Expand Down
53 changes: 4 additions & 49 deletions json_serializable/test/analysis_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@
import 'dart:async';
import 'dart:io';

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart' hide File;
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/source/package_map_resolver.dart';
import 'package:analyzer/source/pub_package_map_provider.dart';
import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_io.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:cli_util/cli_util.dart' as cli;
import 'package:path/path.dart' as p;

/// [foundFiles] is the list of files to consider for the context.
Future<AnalysisContext> getAnalysisContextForProjectPath(
String projectPath, List<String> foundFiles) async {
String projectPath) async {
// TODO: fail more clearly if this...fails
var sdkPath = cli.getSdkPath();
var sdkPath = _getSdkPath();

var resourceProvider = PhysicalResourceProvider.INSTANCE;
var sdk = new FolderBasedDartSdk(
Expand All @@ -44,9 +40,6 @@ Future<AnalysisContext> getAnalysisContextForProjectPath(
..analysisOptions = options
..sourceFactory = new SourceFactory(resolvers);

// ensures all libraries defined by the set of files are resolved
_getLibraryElements(foundFiles, context).toList();

return context;
}

Expand All @@ -71,43 +64,5 @@ UriResolver _getPackageResolver(String projectPath, FolderBasedDartSdk sdk) {
PhysicalResourceProvider.INSTANCE, packageMap);
}

LibraryElement getLibraryElementForSourceFile(
AnalysisContext context, String sourcePath) {
Source source = new FileBasedSource(new JavaFile(sourcePath));

var libs = context.getLibrariesContaining(source);

if (libs.length > 1) {
throw new Exception("We don't support multiple libraries for a source.");
}

if (libs.isEmpty) {
return null;
}

var libSource = libs.single;

// using `getLibraryElement` because the library should already be computed
// If not, it's a bug in usage
return context.getLibraryElement(libSource);
}

// may return `null` if [path] doesn't refer to a library.
/// [dartFiles] is a [Stream] of paths to [.dart] files.
Iterable<LibraryElement> _getLibraryElements(
List<String> dartFiles, AnalysisContext context) =>
dartFiles
.map((path) => _getLibraryElement(path, context))
.where((lib) => lib != null);

LibraryElement _getLibraryElement(String path, AnalysisContext context) {
Source source = new FileBasedSource(new JavaFile(path));
if (context.computeKindOf(source) == SourceKind.LIBRARY) {
return context.computeLibraryElement(source);
}
return null;
}

String getFileBasedSourcePath(FileBasedSource source) {
return p.fromUri(source.uri);
}
/// Return the path to the current Dart SDK.
String _getSdkPath() => p.dirname(p.dirname(Platform.resolvedExecutable));
6 changes: 1 addition & 5 deletions json_serializable/test/json_serializable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'package:source_gen/source_gen.dart';
import 'package:test/test.dart';

import 'analysis_utils.dart';
import 'src/io.dart';
import 'test_utils.dart';

void main() {
Expand Down Expand Up @@ -419,10 +418,7 @@ Future<CompilationUnit> _getCompilationUnitForString(String projectPath) async {
var source =
new StringSource(new File(filePath).readAsStringSync(), 'test content');

var foundFiles = await getDartFiles(projectPath,
searchList: [p.join(getPackagePath(), 'test', 'test_files')]);

var context = await getAnalysisContextForProjectPath(projectPath, foundFiles);
var context = await getAnalysisContextForProjectPath(projectPath);

var libElement = context.computeLibraryElement(source);
return context.resolveCompilationUnit(source, libElement);
Expand Down
114 changes: 0 additions & 114 deletions json_serializable/test/src/io.dart

This file was deleted.