Skip to content

Commit 4537baa

Browse files
committed
tar: Add unit tests
1 parent 15fcdf8 commit 4537baa

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ let package = Package(
8787
dependencies: [.target(name: "ContainerRegistry")],
8888
resources: [.process("Resources")]
8989
), .testTarget(name: "containertoolTests", dependencies: [.target(name: "containertool")]),
90+
.testTarget(name: "TarTests", dependencies: [.target(name: "Tar")]),
9091
],
9192
swiftLanguageModes: [.v6]
9293
)

Tests/TarTests/TarTests.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftContainerPlugin open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the SwiftContainerPlugin project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import Foundation
16+
import Testing
17+
18+
@testable import Tar
19+
20+
let blocksize = 512
21+
let headerLen = blocksize
22+
let trailerLen = 2 * blocksize
23+
24+
@Suite struct TarUnitTests {
25+
@Test(arguments: [
26+
(input: 0o000, expected: "000000"),
27+
(input: 0o555, expected: "000555"),
28+
(input: 0o750, expected: "000750"),
29+
(input: 0o777, expected: "000777"),
30+
(input: 0o1777, expected: "001777"),
31+
])
32+
func testOctal6(input: Int, expected: String) async throws {
33+
#expect(octal6(input) == expected)
34+
}
35+
36+
@Test(arguments: [
37+
(input: 0, expected: "00000000000"),
38+
(input: 1024, expected: "00000002000"),
39+
(input: 0o2000, expected: "00000002000"),
40+
(input: 1024 * 1024, expected: "00004000000"),
41+
])
42+
func testOctal11(input: Int, expected: String) async throws {
43+
#expect(octal11(input) == expected)
44+
}
45+
}

0 commit comments

Comments
 (0)