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
0407a318
Unverified
Commit
0407a318
authored
Feb 26, 2020
by
Jenn Magder
Committed by
GitHub
Feb 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace clean command test functions with test groups (#51508)
parent
cd97f23a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
75 deletions
+88
-75
clean_test.dart
...lutter_tools/test/commands.shard/hermetic/clean_test.dart
+88
-75
No files found.
packages/flutter_tools/test/commands.shard/hermetic/clean_test.dart
View file @
0407a318
...
...
@@ -18,86 +18,99 @@ import '../../src/common.dart';
import
'../../src/context.dart'
;
void
main
(
)
{
void
test1
()
{
final
MemoryFileSystem
fs
=
MemoryFileSystem
();
final
MockXcodeProjectInterpreter
mockXcodeProjectInterpreter
=
MockXcodeProjectInterpreter
();
final
MockXcode
mockXcode
=
MockXcode
();
final
Directory
currentDirectory
=
fs
.
currentDirectory
;
final
Directory
buildDirectory
=
currentDirectory
.
childDirectory
(
'build'
);
buildDirectory
.
createSync
(
recursive:
true
);
final
FlutterProject
projectUnderTest
=
FlutterProject
.
fromDirectory
(
currentDirectory
);
projectUnderTest
.
ios
.
xcodeWorkspace
.
createSync
(
recursive:
true
);
projectUnderTest
.
macos
.
xcodeWorkspace
.
createSync
(
recursive:
true
);
projectUnderTest
.
dartTool
.
createSync
(
recursive:
true
);
projectUnderTest
.
android
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
ios
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
linux
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
macos
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
windows
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
testUsingContext
(
'
$CleanCommand
removes build and .dart_tool and ephemeral directories, cleans Xcode'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
await
CleanCommand
().
runCommand
();
expect
(
buildDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
dartTool
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
android
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
ios
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
linux
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
macos
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
windows
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
verify
(
xcodeProjectInterpreter
.
cleanWorkspace
(
any
,
'Runner'
)).
called
(
2
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Xcode:
()
=>
mockXcode
,
XcodeProjectInterpreter:
()
=>
mockXcodeProjectInterpreter
,
group
(
'clean command'
,
()
{
MockXcode
mockXcode
;
setUp
(()
{
mockXcode
=
MockXcode
();
});
}
void
test2
()
{
final
MockXcode
mockXcode
=
MockXcode
();
final
MockPlatform
windowsPlatform
=
MockPlatform
();
testUsingContext
(
'
$CleanCommand
prints a helpful error message on Windows'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
false
);
when
(
windowsPlatform
.
isWindows
).
thenReturn
(
true
);
final
MockFile
mockFile
=
MockFile
();
when
(
mockFile
.
existsSync
()).
thenReturn
(
true
);
when
(
mockFile
.
deleteSync
(
recursive:
true
)).
thenThrow
(
const
FileSystemException
(
'Deletion failed'
));
final
CleanCommand
command
=
CleanCommand
();
command
.
deleteFile
(
mockFile
);
expect
(
testLogger
.
errorText
,
contains
(
'A program may still be using a file'
));
verify
(
mockFile
.
deleteSync
(
recursive:
true
)).
called
(
1
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
windowsPlatform
,
Xcode:
()
=>
mockXcode
,
group
(
'general'
,
()
{
MemoryFileSystem
fs
;
MockXcodeProjectInterpreter
mockXcodeProjectInterpreter
;
Directory
buildDirectory
;
FlutterProject
projectUnderTest
;
setUp
(()
{
fs
=
MemoryFileSystem
();
mockXcodeProjectInterpreter
=
MockXcodeProjectInterpreter
();
final
Directory
currentDirectory
=
fs
.
currentDirectory
;
buildDirectory
=
currentDirectory
.
childDirectory
(
'build'
);
buildDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
=
FlutterProject
.
fromDirectory
(
currentDirectory
);
projectUnderTest
.
ios
.
xcodeWorkspace
.
createSync
(
recursive:
true
);
projectUnderTest
.
macos
.
xcodeWorkspace
.
createSync
(
recursive:
true
);
projectUnderTest
.
dartTool
.
createSync
(
recursive:
true
);
projectUnderTest
.
android
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
ios
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
linux
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
macos
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
projectUnderTest
.
windows
.
ephemeralDirectory
.
createSync
(
recursive:
true
);
});
testUsingContext
(
'
$CleanCommand
removes build and .dart_tool and ephemeral directories, cleans Xcode'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
true
);
await
CleanCommand
().
runCommand
();
expect
(
buildDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
dartTool
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
android
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
ios
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
linux
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
macos
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
expect
(
projectUnderTest
.
windows
.
ephemeralDirectory
.
existsSync
(),
isFalse
);
verify
(
xcodeProjectInterpreter
.
cleanWorkspace
(
any
,
'Runner'
)).
called
(
2
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Xcode:
()
=>
mockXcode
,
XcodeProjectInterpreter:
()
=>
mockXcodeProjectInterpreter
,
});
});
testUsingContext
(
'
$CleanCommand
handles missing permissions;'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
false
);
final
MockFile
mockFile
=
MockFile
();
when
(
mockFile
.
existsSync
()).
thenThrow
(
const
FileSystemException
(
'OS error: Access Denied'
));
when
(
mockFile
.
path
).
thenReturn
(
'foo.dart'
);
final
CleanCommand
command
=
CleanCommand
();
command
.
deleteFile
(
mockFile
);
expect
(
testLogger
.
errorText
,
contains
(
'Cannot clean foo.dart'
));
verifyNever
(
mockFile
.
deleteSync
(
recursive:
true
));
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
windowsPlatform
,
Xcode:
()
=>
mockXcode
,
group
(
'Windows'
,
()
{
MockPlatform
windowsPlatform
;
setUp
(()
{
windowsPlatform
=
MockPlatform
();
});
testUsingContext
(
'
$CleanCommand
prints a helpful error message on Windows'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
false
);
when
(
windowsPlatform
.
isWindows
).
thenReturn
(
true
);
final
MockFile
mockFile
=
MockFile
();
when
(
mockFile
.
existsSync
()).
thenReturn
(
true
);
when
(
mockFile
.
deleteSync
(
recursive:
true
)).
thenThrow
(
const
FileSystemException
(
'Deletion failed'
));
final
CleanCommand
command
=
CleanCommand
();
command
.
deleteFile
(
mockFile
);
expect
(
testLogger
.
errorText
,
contains
(
'A program may still be using a file'
));
verify
(
mockFile
.
deleteSync
(
recursive:
true
)).
called
(
1
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
windowsPlatform
,
Xcode:
()
=>
mockXcode
,
});
testUsingContext
(
'
$CleanCommand
handles missing permissions;'
,
()
async
{
when
(
mockXcode
.
isInstalledAndMeetsVersionCheck
).
thenReturn
(
false
);
final
MockFile
mockFile
=
MockFile
();
when
(
mockFile
.
existsSync
()).
thenThrow
(
const
FileSystemException
(
'OS error: Access Denied'
));
when
(
mockFile
.
path
).
thenReturn
(
'foo.dart'
);
final
CleanCommand
command
=
CleanCommand
();
command
.
deleteFile
(
mockFile
);
expect
(
testLogger
.
errorText
,
contains
(
'Cannot clean foo.dart'
));
verifyNever
(
mockFile
.
deleteSync
(
recursive:
true
));
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
windowsPlatform
,
Xcode:
()
=>
mockXcode
,
});
});
}
test1
();
test2
();
});
}
class
MockFile
extends
Mock
implements
File
{}
...
...
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