Skip to content

Commit

Permalink
Ignore errno values on Windows tests (flutter#55)
Browse files Browse the repository at this point in the history
This allows us to run some tests rather than skipping them, which
in turn allows us to focus on the more egregious test failures.
  • Loading branch information
tvolkert authored Mar 16, 2017
1 parent 9895e04 commit 5beb596
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 81 deletions.
11 changes: 10 additions & 1 deletion lib/src/testing/core_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'package:file/file.dart';
import 'package:test/test.dart';

import 'internal.dart';

/// Matcher that successfully matches against any instance of [Directory].
const Matcher isDirectory = const isInstanceOf<Directory>();

Expand Down Expand Up @@ -70,7 +72,14 @@ class _FileSystemException extends Matcher {
final Matcher _matcher;

_FileSystemException(dynamic osErrorCode)
: _matcher = osErrorCode == null ? null : wrapMatcher(osErrorCode);
: _matcher = _wrapMatcher(osErrorCode);

static Matcher _wrapMatcher(dynamic osErrorCode) {
if (osErrorCode == null) {
return null;
}
return ignoreOsErrorCodes ? anything : wrapMatcher(osErrorCode);
}

@override
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
Expand Down
9 changes: 9 additions & 0 deletions lib/src/testing/internal.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. 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:meta/meta.dart';

/// True if we should ignore OS error codes in our matchers.
@visibleForTesting
bool ignoreOsErrorCodes = false;
93 changes: 13 additions & 80 deletions test/local_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import 'dart:io' as io;

import 'package:file/local.dart';
import 'package:file/src/testing/internal.dart';
import 'package:test/test.dart';

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

setUpAll(() {
if (io.Platform.isWindows) {
// TODO(tvolkert): Remove once all more serious test failures are fixed
// https://github.com/google/file.dart/issues/56
ignoreOsErrorCodes = true;
}
});

tearDownAll(() {
ignoreOsErrorCodes = false;
});

Map<String, List<String>> skipOnPlatform = <String, List<String>>{
'windows': <String>[
'FileSystem > currentDirectory > throwsIfHasNonExistentPathInComplexChain',
'FileSystem > currentDirectory > staysAtRootIfSetToParentOfRoot',
'FileSystem > currentDirectory > throwsIfSetToFilePathSegmentAtTail',
'FileSystem > currentDirectory > throwsIfSetToFilePathSegmentViaTraversal',
'FileSystem > currentDirectory > resolvesLinksIfEncountered',
'FileSystem > currentDirectory > succeedsIfSetToDirectoryLinkAtTail',
'FileSystem > currentDirectory > throwsIfSetToLinkLoop',
'FileSystem > stat > isFileForLinkToFile',
'FileSystem > type > isFileForLinkToFileAndFollowLinksTrue',
'FileSystem > type > isNotFoundForLinkWithCircularReferenceAndFollowLinksTrue',
'Directory > uri',
'Directory > exists > falseIfExistsAsLinkToFile',
'Directory > exists > falseIfNotFoundSegmentExistsThenIsBackedOut',
'Directory > create > throwsIfAlreadyExistsAsFile',
'Directory > create > throwsIfAlreadyExistsAsLinkToFile',
'Directory > create > throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal',
'Directory > create > throwsIfAncestorDoesntExistRecursiveFalse',
'Directory > rename > throwsIfDestinationIsFile',
'Directory > rename > throwsIfDestinationParentFolderDoesntExist',
'Directory > rename > throwsIfDestinationIsNonEmptyDirectory',
'Directory > rename > throwsIfSourceIsFile',
'Directory > rename > throwsIfDestinationIsLinkToNotFound',
'Directory > rename > throwsIfDestinationIsLinkToEmptyDirectory',
'Directory > delete > throwsIfNonEmptyDirectoryExistsAndRecursiveFalse',
'Directory > delete > throwsIfPathReferencesFileAndRecursiveFalse',
'Directory > delete > throwsIfPathReferencesLinkToFileAndRecursiveFalse',
'Directory > delete > throwsIfPathReferencesLinkToNotFoundAndRecursiveFalse',
'Directory > resolveSymbolicLinks > throwsIfLoopInLinkChain',
'Directory > resolveSymbolicLinks > throwsIfPathNotFoundInTraversal',
'Directory > resolveSymbolicLinks > throwsIfPathNotFoundInMiddleThenBackedOut',
'Directory > createTemp > throwsIfDirectoryDoesntExist',
'Directory > createTemp > succeedsWithNestedPathPrefixThatExists',
'Directory > createTemp > throwsWithNestedPathPrefixThatDoesntExist',
'Directory > list > throwsIfDirectoryDoesntExist',
'Directory > list > followsLinksIfFollowLinksTrue',
'Directory > list > returnsLinkObjectsForRecursiveLinkIfFollowLinksTrue',
'File > uri',
'File > create > throwsIfAncestorDoesntExistRecursiveFalse',
'File > create > succeedsIfAlreadyExistsAsLinkToFile',
'File > create > succeedsIfAlreadyExistsAsLinkToNotFoundAtTail',
'File > create > throwsIfAlreadyExistsAsLinkToNotFoundViaTraversal',
'File > create > succeedsIfAlreadyExistsAsLinkToNotFoundInDifferentDirectory',
'File > rename > throwsIfDestinationDoesntExistViaTraversal',
'File > rename > throwsIfDestinationExistsAsDirectory',
'File > rename > succeedsIfDestinationExistsAsLinkToFile',
'File > rename > succeedsIfDestinationExistsAsLinkToNotFound',
'File > rename > throwsIfSourceExistsAsDirectory',
'File > rename > succeedsIfSourceExistsAsLinkToFile',
'File > rename > throwsIfSourceExistsAsLinkToDirectory',
'File > copy > throwsIfDestinationDoesntExistViaTraversal',
'File > copy > throwsIfDestinationExistsAsDirectory',
'File > copy > succeedsIfDestinationExistsAsLinkToFile',
'File > copy > throwsIfDestinationExistsAsLinkToDirectory',
'File > copy > throwsIfSourceExistsAsDirectory',
'File > copy > succeedsIfSourceExistsAsLinkToFile',
'File > copy > succeedsIfSourceIsLinkToFileInDifferentDirectory',
'File > copy > succeedsIfDestinationIsLinkToFileInDifferentDirectory',
'File > open > READ > throwsIfDoesntExistViaTraversal',
'File > open > READ > RandomAccessFile > throwsIfWriteByte',
'File > open > READ > RandomAccessFile > throwsIfWriteFrom',
'File > open > READ > RandomAccessFile > throwsIfWriteString',
'File > open > READ > RandomAccessFile > position > throwsIfSetToNegativeNumber',
'File > open > READ > RandomAccessFile > throwsIfTruncate',
'File > open > WRITE > throwsIfDoesntExistViaTraversal',
'File > open > WRITE > RandomAccessFile > position > throwsIfSetToNegativeNumber',
'File > open > APPEND > throwsIfDoesntExistViaTraversal',
'File > open > APPEND > RandomAccessFile > position > throwsIfSetToNegativeNumber',
'File > open > WRITE_ONLY > throwsIfDoesntExistViaTraversal',
'File > open > WRITE_ONLY > RandomAccessFile > throwsIfReadByte',
'File > open > WRITE_ONLY > RandomAccessFile > throwsIfRead',
'File > open > WRITE_ONLY > RandomAccessFile > throwsIfReadInto',
'File > open > WRITE_ONLY > RandomAccessFile > position > throwsIfSetToNegativeNumber',
'File > open > WRITE_ONLY_APPEND > throwsIfDoesntExistViaTraversal',
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > throwsIfReadByte',
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > throwsIfRead',
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > throwsIfReadInto',
'File > open > WRITE_ONLY_APPEND > RandomAccessFile > position > throwsIfSetToNegativeNumber',
'File > openRead > throwsIfExistsAsDirectory',
'File > openRead > succeedsIfExistsAsLinkToFile',
'File > openWrite > throwsIfExistsAsDirectory',
'File > openWrite > throwsIfExistsAsLinkToDirectory',
'File > openWrite > succeedsIfExistsAsLinkToFile',
'File > openWrite > ioSink > throwsIfEncodingIsNullAndWriteObject',
'File > openWrite > ioSink > allowsChangingEncoding',
Expand All @@ -127,48 +89,19 @@ void main() {
'File > openWrite > ioSink > addStream > blocksCallToWriteCharCodeWhileStreamIsActive',
'File > openWrite > ioSink > addStream > blocksCallToWritelnWhileStreamIsActive',
'File > openWrite > ioSink > addStream > blocksCallToFlushWhileStreamIsActive',
'File > readAsBytes > throwsIfExistsAsDirectory',
'File > readAsBytes > throwsIfExistsAsLinkToDirectory',
'File > readAsBytes > succeedsIfExistsAsLinkToFile',
'File > readAsString > throwsIfExistsAsDirectory',
'File > readAsString > throwsIfExistsAsLinkToDirectory',
'File > readAsString > succeedsIfExistsAsLinkToFile',
'File > readAsLines > throwsIfExistsAsDirectory',
'File > readAsLines > throwsIfExistsAsLinkToDirectory',
'File > writeAsBytes > throwsIfExistsAsDirectory',
'File > writeAsBytes > throwsIfExistsAsLinkToDirectory',
'File > writeAsBytes > succeedsIfExistsAsLinkToFile',
'File > writeAsBytes > throwsIfFileModeRead',
'File > writeAsString > throwsIfExistsAsDirectory',
'File > writeAsString > throwsIfExistsAsLinkToDirectory',
'File > writeAsString > succeedsIfExistsAsLinkToFile',
'File > writeAsString > throwsIfFileModeRead',
'File > stat > isFileIfExistsAsLinkToFile',
'File > delete > throwsIfExistsAsDirectoryAndRecursiveFalse',
'File > delete > succeedsIfExistsAsLinkToFileAndRecursiveFalse',
'File > delete > throwsIfExistsAsLinkToDirectoryAndRecursiveFalse',
'Link > uri > whenTargetIsDirectory',
'Link > uri > whenTargetIsFile',
'Link > uri > whenLinkDoesntExist',
'Link > stat > isFileIfTargetIsFile',
'Link > stat > isDirectoryIfTargetIsDirectory',
'Link > delete > throwsIfPathReferencesFileAndRecursiveFalse',
'Link > delete > throwsIfPathReferencesDirectoryAndRecursiveFalse',
'Link > create > throwsIfLinkDoesntExistViaTraversalAndRecursiveFalse',
'Link > create > succeedsIfLinkDoesntExistViaTraversalAndRecursiveTrue',
'Link > create > throwsIfAlreadyExistsAsFile',
'Link > create > throwsIfAlreadyExistsAsDirectory',
'Link > create > throwsIfAlreadyExistsWithSameTarget',
'Link > create > throwsIfAlreadyExistsWithDifferentTarget',
'Link > update > throwsIfPathReferencesFile',
'Link > update > throwsIfPathReferencesDirectory',
'Link > target > throwsIfLinkDoesntExistViaTraversal',
'Link > target > throwsIfPathReferencesFile',
'Link > target > throwsIfPathReferencesDirectory',
'Link > rename > returnsCovariantType',
'Link > rename > throwsIfSourceIsFile',
'Link > rename > throwsIfSourceIsDirectory',
'Link > rename > throwsIfDestinationDoesntExistViaTraversal',
'Link > rename > succeedsIfDestinationExistsAsLinkToFile',
'Link > rename > throwsIfDestinationExistsAsLinkToDirectory',
'Link > rename > succeedsIfDestinationExistsAsLinkToNotFound',
Expand Down

0 comments on commit 5beb596

Please sign in to comment.