Skip to content

Commit 5beb596

Browse files
authored
Ignore errno values on Windows tests (flutter#55)
This allows us to run some tests rather than skipping them, which in turn allows us to focus on the more egregious test failures.
1 parent 9895e04 commit 5beb596

File tree

3 files changed

+32
-81
lines changed

3 files changed

+32
-81
lines changed

lib/src/testing/core_matchers.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'package:file/file.dart';
66
import 'package:test/test.dart';
77

8+
import 'internal.dart';
9+
810
/// Matcher that successfully matches against any instance of [Directory].
911
const Matcher isDirectory = const isInstanceOf<Directory>();
1012

@@ -70,7 +72,14 @@ class _FileSystemException extends Matcher {
7072
final Matcher _matcher;
7173

7274
_FileSystemException(dynamic osErrorCode)
73-
: _matcher = osErrorCode == null ? null : wrapMatcher(osErrorCode);
75+
: _matcher = _wrapMatcher(osErrorCode);
76+
77+
static Matcher _wrapMatcher(dynamic osErrorCode) {
78+
if (osErrorCode == null) {
79+
return null;
80+
}
81+
return ignoreOsErrorCodes ? anything : wrapMatcher(osErrorCode);
82+
}
7483

7584
@override
7685
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {

lib/src/testing/internal.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:meta/meta.dart';
6+
7+
/// True if we should ignore OS error codes in our matchers.
8+
@visibleForTesting
9+
bool ignoreOsErrorCodes = false;

test/local_test.dart

Lines changed: 13 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'dart:io' as io;
77

88
import 'package:file/local.dart';
9+
import 'package:file/src/testing/internal.dart';
910
import 'package:test/test.dart';
1011

1112
import 'common_tests.dart';
@@ -29,89 +30,50 @@ void main() {
2930
tmp.deleteSync(recursive: true);
3031
});
3132

33+
setUpAll(() {
34+
if (io.Platform.isWindows) {
35+
// TODO(tvolkert): Remove once all more serious test failures are fixed
36+
// https://github.com/google/file.dart/issues/56
37+
ignoreOsErrorCodes = true;
38+
}
39+
});
40+
41+
tearDownAll(() {
42+
ignoreOsErrorCodes = false;
43+
});
44+
3245
Map<String, List<String>> skipOnPlatform = <String, List<String>>{
3346
'windows': <String>[
3447
'FileSystem > currentDirectory > throwsIfHasNonExistentPathInComplexChain',
3548
'FileSystem > currentDirectory > staysAtRootIfSetToParentOfRoot',
36-
'FileSystem > currentDirectory > throwsIfSetToFilePathSegmentAtTail',
37-
'FileSystem > currentDirectory > throwsIfSetToFilePathSegmentViaTraversal',
3849
'FileSystem > currentDirectory > resolvesLinksIfEncountered',
3950
'FileSystem > currentDirectory > succeedsIfSetToDirectoryLinkAtTail',
40-
'FileSystem > currentDirectory > throwsIfSetToLinkLoop',
4151
'FileSystem > stat > isFileForLinkToFile',
4252
'FileSystem > type > isFileForLinkToFileAndFollowLinksTrue',
4353
'FileSystem > type > isNotFoundForLinkWithCircularReferenceAndFollowLinksTrue',
4454
'Directory > uri',
4555
'Directory > exists > falseIfExistsAsLinkToFile',
4656
'Directory > exists > falseIfNotFoundSegmentExistsThenIsBackedOut',
47-
'Directory > create > throwsIfAlreadyExistsAsFile',
4857
'Directory > create > throwsIfAlreadyExistsAsLinkToFile',
49-
'Directory > create > throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal',
50-
'Directory > create > throwsIfAncestorDoesntExistRecursiveFalse',
51-
'Directory > rename > throwsIfDestinationIsFile',
52-
'Directory > rename > throwsIfDestinationParentFolderDoesntExist',
5358
'Directory > rename > throwsIfDestinationIsNonEmptyDirectory',
54-
'Directory > rename > throwsIfSourceIsFile',
55-
'Directory > rename > throwsIfDestinationIsLinkToNotFound',
5659
'Directory > rename > throwsIfDestinationIsLinkToEmptyDirectory',
57-
'Directory > delete > throwsIfNonEmptyDirectoryExistsAndRecursiveFalse',
58-
'Directory > delete > throwsIfPathReferencesFileAndRecursiveFalse',
5960
'Directory > delete > throwsIfPathReferencesLinkToFileAndRecursiveFalse',
60-
'Directory > delete > throwsIfPathReferencesLinkToNotFoundAndRecursiveFalse',
61-
'Directory > resolveSymbolicLinks > throwsIfLoopInLinkChain',
62-
'Directory > resolveSymbolicLinks > throwsIfPathNotFoundInTraversal',
6361
'Directory > resolveSymbolicLinks > throwsIfPathNotFoundInMiddleThenBackedOut',
64-
'Directory > createTemp > throwsIfDirectoryDoesntExist',
6562
'Directory > createTemp > succeedsWithNestedPathPrefixThatExists',
66-
'Directory > createTemp > throwsWithNestedPathPrefixThatDoesntExist',
67-
'Directory > list > throwsIfDirectoryDoesntExist',
6863
'Directory > list > followsLinksIfFollowLinksTrue',
6964
'Directory > list > returnsLinkObjectsForRecursiveLinkIfFollowLinksTrue',
7065
'File > uri',
71-
'File > create > throwsIfAncestorDoesntExistRecursiveFalse',
7266
'File > create > succeedsIfAlreadyExistsAsLinkToFile',
7367
'File > create > succeedsIfAlreadyExistsAsLinkToNotFoundAtTail',
74-
'File > create > throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal',
7568
'File > create > succeedsIfAlreadyExistsAsLinkToNotFoundInDifferentDirectory',
76-
'File > rename > throwsIfDestinationDoesntExistViaTraversal',
77-
'File > rename > throwsIfDestinationExistsAsDirectory',
7869
'File > rename > succeedsIfDestinationExistsAsLinkToFile',
7970
'File > rename > succeedsIfDestinationExistsAsLinkToNotFound',
80-
'File > rename > throwsIfSourceExistsAsDirectory',
8171
'File > rename > succeedsIfSourceExistsAsLinkToFile',
82-
'File > rename > throwsIfSourceExistsAsLinkToDirectory',
83-
'File > copy > throwsIfDestinationDoesntExistViaTraversal',
84-
'File > copy > throwsIfDestinationExistsAsDirectory',
8572
'File > copy > succeedsIfDestinationExistsAsLinkToFile',
86-
'File > copy > throwsIfDestinationExistsAsLinkToDirectory',
87-
'File > copy > throwsIfSourceExistsAsDirectory',
8873
'File > copy > succeedsIfSourceExistsAsLinkToFile',
8974
'File > copy > succeedsIfSourceIsLinkToFileInDifferentDirectory',
9075
'File > copy > succeedsIfDestinationIsLinkToFileInDifferentDirectory',
91-
'File > open > READ > throwsIfDoesntExistViaTraversal',
92-
'File > open > READ > RandomAccessFile > throwsIfWriteByte',
93-
'File > open > READ > RandomAccessFile > throwsIfWriteFrom',
94-
'File > open > READ > RandomAccessFile > throwsIfWriteString',
95-
'File > open > READ > RandomAccessFile > position > throwsIfSetToNegativeNumber',
96-
'File > open > READ > RandomAccessFile > throwsIfTruncate',
97-
'File > open > WRITE > throwsIfDoesntExistViaTraversal',
98-
'File > open > WRITE > RandomAccessFile > position > throwsIfSetToNegativeNumber',
99-
'File > open > APPEND > throwsIfDoesntExistViaTraversal',
100-
'File > open > APPEND > RandomAccessFile > position > throwsIfSetToNegativeNumber',
101-
'File > open > WRITE_ONLY > throwsIfDoesntExistViaTraversal',
102-
'File > open > WRITE_ONLY > RandomAccessFile > throwsIfReadByte',
103-
'File > open > WRITE_ONLY > RandomAccessFile > throwsIfRead',
104-
'File > open > WRITE_ONLY > RandomAccessFile > throwsIfReadInto',
105-
'File > open > WRITE_ONLY > RandomAccessFile > position > throwsIfSetToNegativeNumber',
106-
'File > open > WRITE_ONLY_APPEND > throwsIfDoesntExistViaTraversal',
107-
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > throwsIfReadByte',
108-
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > throwsIfRead',
109-
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > throwsIfReadInto',
110-
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > position > throwsIfSetToNegativeNumber',
111-
'File > openRead > throwsIfExistsAsDirectory',
11276
'File > openRead > succeedsIfExistsAsLinkToFile',
113-
'File > openWrite > throwsIfExistsAsDirectory',
114-
'File > openWrite > throwsIfExistsAsLinkToDirectory',
11577
'File > openWrite > succeedsIfExistsAsLinkToFile',
11678
'File > openWrite > ioSink > throwsIfEncodingIsNullAndWriteObject',
11779
'File > openWrite > ioSink > allowsChangingEncoding',
@@ -127,48 +89,19 @@ void main() {
12789
'File > openWrite > ioSink > addStream > blocksCallToWriteCharCodeWhileStreamIsActive',
12890
'File > openWrite > ioSink > addStream > blocksCallToWritelnWhileStreamIsActive',
12991
'File > openWrite > ioSink > addStream > blocksCallToFlushWhileStreamIsActive',
130-
'File > readAsBytes > throwsIfExistsAsDirectory',
131-
'File > readAsBytes > throwsIfExistsAsLinkToDirectory',
13292
'File > readAsBytes > succeedsIfExistsAsLinkToFile',
133-
'File > readAsString > throwsIfExistsAsDirectory',
134-
'File > readAsString > throwsIfExistsAsLinkToDirectory',
13593
'File > readAsString > succeedsIfExistsAsLinkToFile',
136-
'File > readAsLines > throwsIfExistsAsDirectory',
137-
'File > readAsLines > throwsIfExistsAsLinkToDirectory',
138-
'File > writeAsBytes > throwsIfExistsAsDirectory',
139-
'File > writeAsBytes > throwsIfExistsAsLinkToDirectory',
14094
'File > writeAsBytes > succeedsIfExistsAsLinkToFile',
141-
'File > writeAsBytes > throwsIfFileModeRead',
142-
'File > writeAsString > throwsIfExistsAsDirectory',
143-
'File > writeAsString > throwsIfExistsAsLinkToDirectory',
14495
'File > writeAsString > succeedsIfExistsAsLinkToFile',
145-
'File > writeAsString > throwsIfFileModeRead',
14696
'File > stat > isFileIfExistsAsLinkToFile',
147-
'File > delete > throwsIfExistsAsDirectoryAndRecursiveFalse',
14897
'File > delete > succeedsIfExistsAsLinkToFileAndRecursiveFalse',
149-
'File > delete > throwsIfExistsAsLinkToDirectoryAndRecursiveFalse',
15098
'Link > uri > whenTargetIsDirectory',
15199
'Link > uri > whenTargetIsFile',
152100
'Link > uri > whenLinkDoesntExist',
153101
'Link > stat > isFileIfTargetIsFile',
154102
'Link > stat > isDirectoryIfTargetIsDirectory',
155-
'Link > delete > throwsIfPathReferencesFileAndRecursiveFalse',
156-
'Link > delete > throwsIfPathReferencesDirectoryAndRecursiveFalse',
157-
'Link > create > throwsIfLinkDoesntExistViaTraversalAndRecursiveFalse',
158103
'Link > create > succeedsIfLinkDoesntExistViaTraversalAndRecursiveTrue',
159-
'Link > create > throwsIfAlreadyExistsAsFile',
160-
'Link > create > throwsIfAlreadyExistsAsDirectory',
161-
'Link > create > throwsIfAlreadyExistsWithSameTarget',
162-
'Link > create > throwsIfAlreadyExistsWithDifferentTarget',
163-
'Link > update > throwsIfPathReferencesFile',
164-
'Link > update > throwsIfPathReferencesDirectory',
165-
'Link > target > throwsIfLinkDoesntExistViaTraversal',
166-
'Link > target > throwsIfPathReferencesFile',
167-
'Link > target > throwsIfPathReferencesDirectory',
168104
'Link > rename > returnsCovariantType',
169-
'Link > rename > throwsIfSourceIsFile',
170-
'Link > rename > throwsIfSourceIsDirectory',
171-
'Link > rename > throwsIfDestinationDoesntExistViaTraversal',
172105
'Link > rename > succeedsIfDestinationExistsAsLinkToFile',
173106
'Link > rename > throwsIfDestinationExistsAsLinkToDirectory',
174107
'Link > rename > succeedsIfDestinationExistsAsLinkToNotFound',

0 commit comments

Comments
 (0)