Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
682e6383
Unverified
Commit
682e6383
authored
5 years ago
by
Ian Hickson
Committed by
GitHub
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor sdk_validation_test (#42064)
parent
1196f91f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
101 deletions
+40
-101
sdk_validation_test.dart
...er_tools/test/general.shard/dart/sdk_validation_test.dart
+40
-101
No files found.
packages/flutter_tools/test/general.shard/dart/sdk_validation_test.dart
View file @
682e6383
...
...
@@ -9,125 +9,64 @@ import 'package:flutter_tools/src/cache.dart';
import
'package:flutter_tools/src/dart/analysis.dart'
;
import
'package:flutter_tools/src/dart/pub.dart'
;
import
'package:flutter_tools/src/dart/sdk.dart'
;
import
'package:meta/meta.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
void
main
(
)
{
group
(
'sdk validation'
,
()
{
AnalysisServer
server
;
Directory
tempDir
;
setUpAll
(()
{
Cache
.
disableLocking
();
tempDir
=
fs
.
systemTempDirectory
.
createTempSync
(
'sdk_validation_test'
).
absolute
;
});
tearDownAll
(()
{
Cache
.
enableLocking
();
tryToDelete
(
tempDir
);
return
server
?.
dispose
();
});
testUsingContext
(
'contains dart:ui'
,
()
async
{
createSampleProject
(
tempDir
,
dartSource:
'''
import '
dart:
ui
' as ui;
void main() {
// ignore: unnecessary_statements
ui.Window;
}
'''
);
await
pubGet
(
context:
PubContext
.
flutterTests
,
directory:
tempDir
.
path
);
server
=
AnalysisServer
(
dartSdkPath
,
<
String
>[
tempDir
.
path
]);
final
int
errorCount
=
await
analyze
(
server
);
expect
(
errorCount
,
0
);
});
testUsingContext
(
'contains dart:html'
,
()
async
{
createSampleProject
(
tempDir
,
dartSource:
'''
import '
dart:
html
' as html;
void main() {
// ignore: unnecessary_statements
html.HttpStatus;
testSampleProject
(
'ui'
,
'Window'
);
testSampleProject
(
'html'
,
'HttpStatus'
);
testSampleProject
(
'js'
,
'allowInterop'
);
testSampleProject
(
'js_util'
,
'jsify'
);
}
'''
);
await
pubGet
(
context:
PubContext
.
flutterTests
,
directory:
tempDir
.
path
);
void
testSampleProject
(
String
lib
,
String
member
)
{
testUsingContext
(
'contains dart:
$lib
'
,
()
async
{
Cache
.
disableLocking
();
final
Directory
projectDirectory
=
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_sdk_validation_
${lib}
_test.'
).
absolute
;
server
=
AnalysisServer
(
dartSdkPath
,
<
String
>[
tempDir
.
path
]);
final
int
errorCount
=
await
analyze
(
server
);
expect
(
errorCount
,
0
);
});
testUsingContext
(
'contains dart:js'
,
()
async
{
createSampleProject
(
tempDir
,
dartSource:
'''
import '
dart:
js
' as js;
void main() {
// ignore: unused_local_variable
var foo = js.allowInterop(null);
}
try
{
final
File
pubspecFile
=
fs
.
file
(
fs
.
path
.
join
(
projectDirectory
.
path
,
'pubspec.yaml'
));
pubspecFile
.
writeAsStringSync
(
'''
name:
${lib}
_project
dependencies:
flutter:
sdk: flutter
'''
);
await
pubGet
(
context:
PubContext
.
flutterTests
,
directory:
tempDir
.
path
);
server
=
AnalysisServer
(
dartSdkPath
,
<
String
>[
tempDir
.
path
]);
final
int
errorCount
=
await
analyze
(
server
);
expect
(
errorCount
,
0
);
});
testUsingContext
(
'contains dart:js_util'
,
()
async
{
createSampleProject
(
tempDir
,
dartSource:
'''
import '
dart:
js_util
' as js_util;
final
File
dartFile
=
fs
.
file
(
fs
.
path
.
join
(
projectDirectory
.
path
,
'lib'
,
'main.dart'
));
dartFile
.
parent
.
createSync
();
dartFile
.
writeAsStringSync
(
'''
import '
dart:
$lib
' as
$lib
;
void main() {
// ignore: unused_local_variable
var bar = js_util.jsify(null);
}
'''
);
await
pubGet
(
context:
PubContext
.
flutterTests
,
directory:
tempDir
.
path
);
server
=
AnalysisServer
(
dartSdkPath
,
<
String
>[
tempDir
.
path
]);
final
int
errorCount
=
await
analyze
(
server
);
expect
(
errorCount
,
0
);
});
},
skip:
true
);
// ignore: unnecessary_statements
$lib
.
$member
;
}
void
createSampleProject
(
Directory
directory
,
{
@required
String
dartSource
})
{
final
File
pubspecFile
=
fs
.
file
(
fs
.
path
.
join
(
directory
.
path
,
'pubspec.yaml'
));
pubspecFile
.
writeAsStringSync
(
'''
name: foo_project
dependencies:
flutter:
sdk: flutter
'''
);
final
File
dartFile
=
fs
.
file
(
fs
.
path
.
join
(
directory
.
path
,
'lib'
,
'main.dart'
));
dartFile
.
parent
.
createSync
();
dartFile
.
writeAsStringSync
(
dartSource
);
await
pubGet
(
context:
PubContext
.
flutterTests
,
directory:
projectDirectory
.
path
);
final
AnalysisServer
server
=
AnalysisServer
(
dartSdkPath
,
<
String
>[
projectDirectory
.
path
]);
try
{
final
int
errorCount
=
await
analyze
(
server
);
expect
(
errorCount
,
0
);
}
finally
{
await
server
.
dispose
();
}
}
finally
{
tryToDelete
(
projectDirectory
);
Cache
.
enableLocking
();
}
});
}
Future
<
int
>
analyze
(
AnalysisServer
server
,
{
bool
printErrors
=
true
}
)
async
{
Future
<
int
>
analyze
(
AnalysisServer
server
)
async
{
int
errorCount
=
0
;
final
Future
<
bool
>
onDone
=
server
.
onAnalyzing
.
where
((
bool
analyzing
)
=>
analyzing
==
false
).
first
;
server
.
onErrors
.
listen
((
FileAnalysisErrors
errors
)
{
if
(
printErrors
)
{
for
(
AnalysisError
error
in
errors
.
errors
)
{
print
(
error
.
toString
().
trim
());
}
final
Future
<
bool
>
onDone
=
server
.
onAnalyzing
.
where
((
bool
analyzing
)
=>
analyzing
==
false
).
first
;
server
.
onErrors
.
listen
((
FileAnalysisErrors
result
)
{
for
(
AnalysisError
error
in
result
.
errors
)
{
print
(
error
.
toString
().
trim
());
}
errorCount
+=
errors
.
errors
.
length
;
errorCount
+=
result
.
errors
.
length
;
});
await
server
.
start
();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment