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
d355611d
Commit
d355611d
authored
Nov 09, 2015
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #61 from Hixie/dart-tests
Port test logic to Dart.
parents
1cadf125
3419068c
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
220 additions
and
154 deletions
+220
-154
CONTRIBUTING.md
CONTRIBUTING.md
+20
-18
run_tests
dev/run_tests
+0
-43
sky_test.dart
packages/flutter_tools/bin/sky_test.dart
+0
-11
application_package.dart
packages/flutter_tools/lib/src/application_package.dart
+2
-0
artifacts.dart
packages/flutter_tools/lib/src/artifacts.dart
+22
-1
build_configuration.dart
packages/flutter_tools/lib/src/build_configuration.dart
+14
-2
flutter_command.dart
packages/flutter_tools/lib/src/commands/flutter_command.dart
+6
-3
flutter_command_runner.dart
...lutter_tools/lib/src/commands/flutter_command_runner.dart
+105
-56
test.dart
packages/flutter_tools/lib/src/commands/test.dart
+49
-19
device.dart
packages/flutter_tools/lib/src/device.dart
+1
-0
test.sh
travis/test.sh
+1
-1
No files found.
CONTRIBUTING.md
View file @
d355611d
...
...
@@ -87,25 +87,27 @@ Testing the `flutter` package is currently a bit harder because we don't yet
support testing the
`flutter`
package with pre-built binaries. To test the
package, you'll need to follow the
[
instructions below
](
#working-on-the-engine-and-the-framework-at-the-same-time
)
for working with this repository and the Flutter engine repository
simultaneously and then run the following command:
simultaneously and then run the following command (assuming the
`flutter/bin`
directory is in your path):
*
`
./dev/run_tests
--debug`
*
`
flutter test
--debug`
Creating a workflow for running the test with a prebuilt binary is
[
Issue #56
](
https://github.com/flutter/flutter/issues/56
)
. If you want
to run
a single test individually:
[
Issue #56
](
https://github.com/flutter/flutter/issues/56
)
. If you want
to run
a single test individually:
*
`
./dev/run_tests --debug test/harness/
trivial_test.dart`
*
`
flutter test --debug
trivial_test.dart`
Note: The tests are headless, you won't see any UI. You can use
`print`
to
generate console output or you can interact with the DartVM via observatory at
[
http://localhost:8181/
](
http://localhost:8181/
)
.
Note: The tests are headless, you won't see any UI. You can use
`print`
to generate console output or you can interact with the DartVM
via observatory at
[
http://localhost:8181/
](
http://localhost:8181/
)
.
Adding a test
-------------
To add a test, simply create a file whose name ends with
`_test.dart`
in the
`packags/unit/test`
directory. The test should have a
`main`
function and use
the
`test`
package.
To add a test, simply create a file whose name ends with
`_test.dart`
in the
`packages/unit/test`
directory. The test should have a
`main`
function and use
the
`test`
package.
Contributing code
-----------------
...
...
@@ -120,7 +122,7 @@ To start working on a patch:
and
[
design principles
](
https://github.com/flutter/engine/blob/master/sky/specs/design.md
)
before working on anything non-trivial. These guidelines are intended to keep
the code consistent and avoid common pitfalls.
*
`git commit -a -m "<your
brief but
informative commit message>"`
*
`git commit -a -m "<your informative commit message>"`
*
`git push origin name_of_your_branch`
To send us a pull request:
...
...
@@ -163,15 +165,15 @@ the following steps.
(e.g.,
`out/Debug`
). To run examples on Android, build one of the Android
configurations (e.g.,
`out/android_Debug`
).
You should now be able to run the tests against your locally built
engine using
the
`./dev/run_tests`
script. To run one of the examples on your device using
your locally built engine, use the
`--engine-src-path`
option to the
`flutter`
tool:
You should now be able to run the tests against your locally built
engine using the
`flutter test --debug`
command. To run one of the
examples on your device using your locally built engine, use the
`--debug`
option to the
`flutter`
tool:
*
`flutter start --
engine-src-path /foo/bar/engine/src
`
*
`flutter start --
debug
`
Eventually, the
`--local-build`
flag for the
`flutter`
command will
automatically set the correct engine src path (see
[
Issue #57
](
https://github.com/flutter/flutter/issues/57
)
)
.
If you want to test the release version instead of the debug version,
use
`--release`
instead of
`--debug`
.
Making a breaking change to the engine
--------------------------------------
...
...
dev/run_tests
deleted
100755 → 0
View file @
1cadf125
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import
os
import
sys
import
subprocess
import
argparse
FLUTTER_ROOT
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
FLUTTER
=
os
.
path
.
join
(
FLUTTER_ROOT
,
'bin'
,
'flutter'
)
UNIT_DIR
=
os
.
path
.
join
(
FLUTTER_ROOT
,
'packages'
,
'unit'
)
TESTS_DIR
=
os
.
path
.
join
(
UNIT_DIR
,
'test'
)
DEFAULT_ENGINE_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
FLUTTER_ROOT
,
'..'
,
'engine'
,
'src'
))
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Runs Flutter unit tests'
)
parser
.
add_argument
(
'--engine-src-path'
,
default
=
DEFAULT_ENGINE_DIR
)
parser
.
add_argument
(
'--config'
,
default
=
'Debug'
)
parser
.
add_argument
(
'--debug'
,
dest
=
'config'
,
action
=
'store_const'
,
const
=
'Debug'
)
parser
.
add_argument
(
'--release'
,
dest
=
'config'
,
action
=
'store_const'
,
const
=
'Release'
)
args
,
remaining
=
parser
.
parse_known_args
()
build_dir
=
os
.
path
.
join
(
os
.
path
.
abspath
(
args
.
engine_src_path
),
'out'
,
args
.
config
)
if
not
remaining
:
for
root
,
dirs
,
files
in
os
.
walk
(
TESTS_DIR
):
remaining
.
extend
(
os
.
path
.
join
(
root
,
f
)
for
f
in
files
if
f
.
endswith
(
"_test.dart"
))
if
os
.
environ
[
'TERM'
]
==
'dumb'
:
remaining
=
[
'--no-color'
]
+
remaining
return
subprocess
.
call
([
FLUTTER
,
'test'
,
'--build-dir=
%
s'
%
build_dir
]
+
remaining
,
cwd
=
UNIT_DIR
)
if
__name__
==
'__main__'
:
sys
.
exit
(
main
())
packages/flutter_tools/bin/sky_test.dart
deleted
100644 → 0
View file @
1cadf125
// Copyright 2015 The Chromium Authors. 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:sky_tools/src/test/loader.dart'
as
loader
;
import
'package:test/src/executable.dart'
as
executable
;
main
(
List
<
String
>
args
)
{
loader
.
installHook
();
return
executable
.
main
(
args
);
}
packages/flutter_tools/lib/src/application_package.dart
View file @
d355611d
...
...
@@ -74,6 +74,7 @@ class ApplicationPackageStore {
return
iOS
;
case
TargetPlatform
.
iOSSimulator
:
return
iOSSimulator
;
case
TargetPlatform
.
mac
:
case
TargetPlatform
.
linux
:
return
null
;
}
...
...
@@ -110,6 +111,7 @@ class ApplicationPackageStore {
iOSSimulator
=
new
IOSApp
(
localPath:
path
.
join
(
config
.
buildDir
,
IOSApp
.
_defaultName
));
break
;
case
TargetPlatform
.
mac
:
case
TargetPlatform
.
linux
:
break
;
}
...
...
packages/flutter_tools/lib/src/artifacts.dart
View file @
d355611d
...
...
@@ -34,6 +34,8 @@ String _getNameForTargetPlatform(TargetPlatform platform) {
return
'ios-arm'
;
case
TargetPlatform
.
iOSSimulator
:
return
'ios-x64'
;
case
TargetPlatform
.
mac
:
return
'darwin-x64'
;
case
TargetPlatform
.
linux
:
return
'linux-x64'
;
}
...
...
@@ -158,12 +160,31 @@ class ArtifactStore {
// These values are initialized by FlutterCommandRunner on startup.
static
String
flutterRoot
;
static
String
packageRoot
;
static
String
packageRoot
=
'packages'
;
static
bool
get
isPackageRootValid
{
return
FileSystemEntity
.
isDirectorySync
(
packageRoot
);
}
static
void
ensurePackageRootIsValid
()
{
if
(!
isPackageRootValid
)
{
String
message
=
'
$packageRoot
is not a valid directory.'
;
if
(
packageRoot
==
'packages'
)
{
if
(
FileSystemEntity
.
isFileSync
(
'pubspec.yaml'
))
message
+=
'
\n
Did you run `pub get` in this directory?'
;
else
message
+=
'
\n
Did you run this command from the same directory as your pubspec.yaml file?'
;
}
stderr
.
writeln
(
message
);
throw
new
ProcessExit
(
2
);
}
}
static
String
_engineRevision
;
static
String
get
engineRevision
{
if
(
_engineRevision
==
null
)
{
ensurePackageRootIsValid
();
File
revisionFile
=
new
File
(
path
.
join
(
packageRoot
,
'sky_engine'
,
'REVISION'
));
if
(
revisionFile
.
existsSync
())
_engineRevision
=
revisionFile
.
readAsStringSync
();
...
...
packages/flutter_tools/lib/src/build_configuration.dart
View file @
d355611d
...
...
@@ -24,6 +24,7 @@ enum TargetPlatform {
android
,
iOS
,
iOSSimulator
,
mac
,
linux
,
}
...
...
@@ -36,12 +37,21 @@ HostPlatform getCurrentHostPlatform() {
return
HostPlatform
.
linux
;
}
TargetPlatform
getCurrentHostPlatformAsTarget
(
)
{
if
(
Platform
.
isMacOS
)
return
TargetPlatform
.
mac
;
if
(
Platform
.
isLinux
)
return
TargetPlatform
.
linux
;
_logging
.
warning
(
'Unsupported host platform, defaulting to Linux'
);
return
TargetPlatform
.
linux
;
}
class
BuildConfiguration
{
BuildConfiguration
.
prebuilt
({
this
.
hostPlatform
,
this
.
targetPlatform
,
this
.
deviceId
})
:
type
=
BuildType
.
prebuilt
,
buildDir
=
null
;
})
:
type
=
BuildType
.
prebuilt
,
buildDir
=
null
,
testable
=
false
;
BuildConfiguration
.
local
({
this
.
type
,
...
...
@@ -49,7 +59,8 @@ class BuildConfiguration {
this
.
targetPlatform
,
String
enginePath
,
String
buildPath
,
this
.
deviceId
this
.
deviceId
,
this
.
testable
:
false
})
:
buildDir
=
path
.
normalize
(
path
.
join
(
enginePath
,
buildPath
))
{
assert
(
type
==
BuildType
.
debug
||
type
==
BuildType
.
release
);
}
...
...
@@ -59,4 +70,5 @@ class BuildConfiguration {
final
TargetPlatform
targetPlatform
;
final
String
buildDir
;
final
String
deviceId
;
final
bool
testable
;
}
packages/flutter_tools/lib/src/commands/flutter_command.dart
View file @
d355611d
...
...
@@ -8,6 +8,7 @@ import 'dart:io';
import
'package:args/command_runner.dart'
;
import
'../application_package.dart'
;
import
'../build_configuration.dart'
;
import
'../device.dart'
;
import
'../toolchain.dart'
;
import
'flutter_command_runner.dart'
;
...
...
@@ -18,19 +19,21 @@ abstract class FlutterCommand extends Command {
/// Whether this command needs to be run from the root of a project.
bool
get
requiresProjectRoot
=>
true
;
List
<
BuildConfiguration
>
get
buildConfigurations
=>
runner
.
buildConfigurations
;
Future
downloadApplicationPackages
()
async
{
if
(
applicationPackages
==
null
)
applicationPackages
=
await
ApplicationPackageStore
.
forConfigs
(
runner
.
buildConfigurations
);
applicationPackages
=
await
ApplicationPackageStore
.
forConfigs
(
buildConfigurations
);
}
Future
downloadToolchain
()
async
{
if
(
toolchain
==
null
)
toolchain
=
await
Toolchain
.
forConfigs
(
runner
.
buildConfigurations
);
toolchain
=
await
Toolchain
.
forConfigs
(
buildConfigurations
);
}
void
connectToDevices
()
{
if
(
devices
==
null
)
devices
=
new
DeviceStore
.
forConfigs
(
runner
.
buildConfigurations
);
devices
=
new
DeviceStore
.
forConfigs
(
buildConfigurations
);
}
Future
downloadApplicationPackagesAndConnectToDevices
()
async
{
...
...
packages/flutter_tools/lib/src/commands/flutter_command_runner.dart
View file @
d355611d
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/commands/test.dart
View file @
d355611d
...
...
@@ -9,36 +9,66 @@ import 'package:logging/logging.dart';
import
'package:path/path.dart'
as
path
;
import
'package:test/src/executable.dart'
as
executable
;
import
'flutter_command.dart'
;
import
'../artifacts.dart'
;
import
'../build_configuration.dart'
;
import
'../test/loader.dart'
as
loader
;
import
'flutter_command.dart'
;
final
Logger
_logging
=
new
Logger
(
'sky_tools.test'
);
class
TestCommand
extends
FlutterCommand
{
final
String
name
=
'test'
;
final
String
description
=
'Runs Flutter unit tests for the current project (requires a local build of the engine)
.'
;
String
get
name
=>
'test'
;
String
get
description
=>
'Runs Flutter unit tests for the current project. At least one of --debug and --release must be set
.'
;
TestCommand
()
{
argParser
.
addOption
(
'build-dir'
,
help:
'The directory in which to find a prebuilt engine'
);
}
bool
get
requiresProjectRoot
=>
false
;
String
get
_shellPath
{
if
(
Platform
.
isLinux
)
return
path
.
join
(
argResults
[
'build-dir'
],
'sky_shell'
);
if
(
Platform
.
isMacOS
)
return
path
.
join
(
argResults
[
'build-dir'
],
'SkyShell.app'
,
'Contents'
,
'MacOS'
,
'SkyShell'
);
String
getShellPath
(
TargetPlatform
platform
,
String
buildPath
)
{
switch
(
platform
)
{
case
TargetPlatform
.
linux
:
return
path
.
join
(
buildPath
,
'sky_shell'
);
case
TargetPlatform
.
mac
:
return
path
.
join
(
buildPath
,
'SkyShell.app'
,
'Contents'
,
'MacOS'
,
'SkyShell'
);
default
:
throw
new
Exception
(
'Unsupported platform.'
);
}
}
@override
Future
<
int
>
runInProject
()
async
{
loader
.
shellPath
=
_shellPath
;
List
<
String
>
testArgs
=
argResults
.
rest
.
toList
();
Directory
testDir
=
new
Directory
(
path
.
join
(
ArtifactStore
.
flutterRoot
,
'packages/unit/test'
));
if
(
testArgs
.
isEmpty
)
{
testArgs
.
addAll
(
testDir
.
listSync
(
recursive:
true
,
followLinks:
false
)
.
where
((
FileSystemEntity
entity
)
=>
entity
.
path
.
endsWith
(
'_test.dart'
)
&&
FileSystemEntity
.
isFileSync
(
entity
.
path
))
.
map
((
FileSystemEntity
entity
)
=>
path
.
absolute
(
entity
.
path
)));
}
testArgs
.
insert
(
0
,
'--'
);
if
(
Platform
.
environment
[
'TERM'
]
==
'dumb'
)
testArgs
.
insert
(
0
,
'--no-color'
);
List
<
BuildConfiguration
>
configs
=
buildConfigurations
;
bool
foundOne
=
false
;
String
currentDirectory
=
Directory
.
current
.
path
;
Directory
.
current
=
testDir
.
path
;
// TODO(ianh): Verify that this directory has had 'pub get' run in it at least once.
loader
.
installHook
();
for
(
BuildConfiguration
config
in
configs
)
{
if
(!
config
.
testable
)
continue
;
foundOne
=
true
;
loader
.
shellPath
=
path
.
join
(
currentDirectory
,
getShellPath
(
config
.
targetPlatform
,
config
.
buildDir
));
if
(!
FileSystemEntity
.
isFileSync
(
loader
.
shellPath
))
{
_logging
.
severe
(
'Cannot find Flutter S
hell at
${loader.shellPath}
'
);
_logging
.
severe
(
'Cannot find Flutter s
hell at
${loader.shellPath}
'
);
return
1
;
}
loader
.
installHook
(
);
await
executable
.
main
(
argResults
.
rest
);
await
executable
.
main
(
testArgs
);
if
(
exitCode
!=
0
)
return
exitCode
;
}
if
(!
foundOne
)
{
stderr
.
writeln
(
'At least one of --debug or --release must be set, to specify the local build products to test.'
);
return
1
;
}
return
0
;
}
}
\ No newline at end of file
packages/flutter_tools/lib/src/device.dart
View file @
d355611d
...
...
@@ -920,6 +920,7 @@ class DeviceStore {
assert
(
iOSSimulator
==
null
);
iOSSimulator
=
new
IOSSimulator
();
break
;
case
TargetPlatform
.
mac
:
case
TargetPlatform
.
linux
:
break
;
}
...
...
travis/test.sh
View file @
d355611d
...
...
@@ -6,4 +6,4 @@ set -ex
(
cd
packages/flx
;
pub global run tuneup check
;
pub run
test
-j1
)
(
cd
packages/newton
;
pub global run tuneup check
;
pub run
test
-j1
)
./
dev/run_tests
--engine-src-path
bin/cache/travis
./
bin/flutter
test
--engine-src-path
bin/cache/travis
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