Compare commits

...

7 Commits

Author SHA1 Message Date
Max Howell
9c6f807b0a Merge pull request #77 from ConfusedVorlon/find_hidden_modifier
Find hidden modifier
2021-07-30 12:28:04 -04:00
Rob Jonson
dad3d84040 don't implement hidden(false) for swift < 5
and provide a warning
2021-07-30 17:09:37 +01:00
Rob Jonson
5377bceb5f Update linux test list 2021-07-28 22:29:02 +01:00
Rob Jonson
f593437cf5 make find() configurable to ignore hidden files & directories 2021-07-28 15:12:09 +01:00
Rob Jonson
6e8a42f01d Fix assert error message 2021-07-28 15:06:20 +01:00
Max Howell
13d62c3068 Merge pull request #75 from mxcl/ci/macos-11
[ci] can has macos-11
2021-06-23 12:48:10 -04:00
Max Howell
99a0474b0f [ci] can has macos-11 2021-06-23 12:32:23 -04:00
6 changed files with 71 additions and 27 deletions

View File

@@ -6,26 +6,31 @@ on:
- .github/workflows/ci.yml
schedule:
- cron: '3 3 * * 5' # 3:03 AM, every Friday
concurrency:
group: ${{ github.head_ref || 'push' }}
cancel-in-progress: true
jobs:
smoke:
runs-on: macos-latest
verify-linuxmain:
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
- run: swift test --generate-linuxmain
- run: git diff --exit-code
apple:
runs-on: macos-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-10.15
- macos-11
platform:
- iOS
- tvOS
- macOS
- watchOS
- iOS
- tvOS
- macOS
- watchOS
steps:
- uses: actions/checkout@v2
- uses: mxcl/xcodebuild@v1
@@ -35,25 +40,13 @@ jobs:
warnings-as-errors: true
- uses: codecov/codecov-action@v1
linux-swift-4:
name: linux (${{ matrix.swift }})
runs-on: ubuntu-latest
strategy:
matrix:
swift: ['4.2', '5.0']
container:
image: swift:${{ matrix.swift }}
steps:
- uses: actions/checkout@v2
- run: useradd -ms /bin/bash mxcl
- run: chown -R mxcl .
- run: su mxcl -c 'swift test --parallel'
linux:
runs-on: ubuntu-latest
strategy:
matrix:
swift:
- swift:4.2
- swift:5.0
- swift:5.1
- swift:5.2
- swift:5.3
@@ -62,12 +55,22 @@ jobs:
container:
image: ${{ matrix.swift }}
steps:
- uses: mxcl/get-swift-version@v1
id: swift
- uses: actions/checkout@v2
- run: useradd -ms /bin/bash mxcl
# ^^ we need to be a normal user and not root for the tests to be valid
- run: chown -R mxcl .
- run: su mxcl -c 'swift test --parallel --enable-code-coverage'
# ^^ we need to be a normal user and not root for the tests to be valid
- run: echo ARGS=--enable-code-coverage >> $GITHUB_ENV
if: ${{ steps.swift.outputs.marketing-version > 5 }}
- run: su mxcl -c "swift test --parallel $ARGS"
- name: Generate `.lcov`
if: ${{ steps.swift.outputs.marketing-version > 5 }}
run: |
apt-get -qq update && apt-get -qq install curl
b=$(swift build --show-bin-path)
@@ -77,6 +80,8 @@ jobs:
--ignore-filename-regex='\.build|Tests' \
"$b"/*.xctest \
> info.lcov
- uses: codecov/codecov-action@v1
if: ${{ steps.swift.outputs.marketing-version > 5 }}
with:
file: ./info.lcov

View File

@@ -227,7 +227,7 @@ We provide `find()` for recursive listing:
```swift
for path in Path.home.find() {
// descends all directories, and includes hidden files
// descends all directories, and includes hidden files by default
// so it behaves the same as the terminal command `find`
}
```
@@ -235,7 +235,7 @@ for path in Path.home.find() {
It is configurable:
```swift
for path in Path.home.find().depth(max: 1).extension("swift").type(.file) {
for path in Path.home.find().depth(max: 1).extension("swift").type(.file).hidden(false) {
//
}
```

View File

@@ -31,6 +31,9 @@ public extension Path {
/// The file extensions find operations will return. Files *and* directories unless you filter for `kinds`.
private(set) public var extensions: Set<String>?
/// Whether to return hidden files
public var hidden:Bool = true
}
}
@@ -50,8 +53,12 @@ extension Path.Finder: Sequence, IteratorProtocol {
if enumerator.level < depth.lowerBound {
continue
}
if !hidden, path.basename().hasPrefix(".") {
enumerator.skipDescendants()
continue
}
#endif
if let type = path.type, !types.contains(type) { continue }
if let exts = extensions, !exts.contains(path.extension) { continue }
return path
@@ -114,6 +121,15 @@ public extension Path.Finder {
extensions!.insert(ext)
return self
}
/// Whether to skip hidden files and folders.
func hidden(_ hidden: Bool) -> Path.Finder {
#if os(Linux) && !swift(>=5.0)
fputs("warning: hidden not implemented for Swift < 5\n", stderr)
#endif
self.hidden = hidden
return self
}
/// The return type for `Path.Finder`
enum ControlFlow {

View File

@@ -136,6 +136,28 @@ extension PathTests {
}
}
func testFindHidden() throws {
try Path.mktemp { tmpdir in
let dotFoo = try tmpdir.join(".foo.txt").touch()
let tmpDotA = try tmpdir.join(".a").mkdir()
let tmpDotAFoo = try tmpdir.join(".a").join("foo.txt").touch()
let tmpB = try tmpdir.b.mkdir()
let tmpBFoo = try tmpdir.b.join("foo.txt").touch()
XCTAssertEqual(
Set(tmpdir.find().hidden(true)),
Set([dotFoo,tmpDotA,tmpDotAFoo,tmpB,tmpBFoo]),
relativeTo: tmpdir)
#if !os(Linux) || swift(>=5)
XCTAssertEqual(
Set(tmpdir.find().hidden(false)),
Set([tmpB,tmpBFoo]),
relativeTo: tmpdir)
#endif
}
}
func testFindExtension() throws {
try Path.mktemp { tmpdir in
try tmpdir.join("foo.json").touch()

View File

@@ -29,6 +29,7 @@ extension PathTests {
("testFindDepthRange", testFindDepthRange),
("testFindExecute", testFindExecute),
("testFindExtension", testFindExtension),
("testFindHidden", testFindHidden),
("testFindMaxDepth1", testFindMaxDepth1),
("testFindMaxDepth2", testFindMaxDepth2),
("testFindMinDepth", testFindMinDepth),

View File

@@ -19,7 +19,7 @@ private func logic<P: Pathish>(_ set1: Set<Path>, _ set2: Set<Path>, relativeTo:
if set1 != set2 {
let cvt: (Path) -> String = { $0.relative(to: relativeTo) }
let out1 = set1.map(cvt).sorted()
let out2 = set1.map(cvt).sorted()
let out2 = set2.map(cvt).sorted()
fail("Set(\(out1)) is not equal to Set(\(out2))")
}
}