Skip to content

Commit 672af38

Browse files
authored
chore: project cleanup (#2)
* fix: update README * feat: add basic testing * feat: update ci to support tests
1 parent 7269768 commit 672af38

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ jobs:
2828
run: brew install just
2929

3030
# Debug build for PRs or normal pushes to 'main'
31-
- name: Build (Debug) for PR/Main
31+
- name: Build & Test (Debug) for PR/Main
3232
if: >
3333
github.event_name == 'pull_request' ||
3434
(github.event_name == 'push' && startsWith(github.ref, 'refs/heads/'))
35-
run: just build debug
35+
run: just test
3636

3737
# Release build for Tag pushes
3838
- name: Build (Release) for Tag

Package.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// swift-tools-version: 5.10.0
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
32

43
import PackageDescription
54

@@ -9,10 +8,13 @@ let package = Package(
98
.macOS(.v11)
109
],
1110
targets: [
12-
// Targets are the basic building blocks of a package, defining a module or a test suite.
13-
// Targets can depend on other targets in this package and products from dependencies.
1411
.executableTarget(
1512
name: "teemoji",
16-
resources: [.copy("TeemojiClassifier.mlmodelc")])
13+
resources: [.copy("TeemojiClassifier.mlmodelc")]
14+
),
15+
.testTarget(
16+
name: "TeemojiTests",
17+
dependencies: ["teemoji"]
18+
),
1719
]
1820
)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
You can install `teemoji` via [Homebrew](https://brew.sh/):
1515

1616
```bash
17-
brew install willswire/teemoji
17+
brew install willswire/tap/teemoji
1818
```
1919

2020
## Usage

Tests/TeemojiTests.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import XCTest
2+
3+
import class Foundation.Bundle
4+
5+
final class TeemojiTests: XCTestCase {
6+
/// Helper function to run the Teemoji executable with given input and arguments.
7+
func runTeemoji(input: String, arguments: [String] = []) throws -> String {
8+
let teemojiBinary = productsDirectory.appendingPathComponent("teemoji")
9+
10+
let process = Process()
11+
process.executableURL = teemojiBinary
12+
process.arguments = arguments
13+
14+
let inputPipe = Pipe()
15+
let outputPipe = Pipe()
16+
17+
process.standardInput = inputPipe
18+
process.standardOutput = outputPipe
19+
process.standardError = outputPipe
20+
21+
try process.run()
22+
23+
// Send the input to the process
24+
let inputHandle = inputPipe.fileHandleForWriting
25+
inputHandle.write(input.data(using: .utf8)!)
26+
inputHandle.closeFile()
27+
28+
// Read the output
29+
if let outputData = try outputPipe.fileHandleForReading.readToEnd() {
30+
return String(data: outputData, encoding: .utf8) ?? "UNKNOWN"
31+
} else {
32+
return "UNKNOWN"
33+
}
34+
}
35+
36+
func testBasicEmojiPrediction() throws {
37+
let input = "Hello World"
38+
let output = try runTeemoji(input: input)
39+
// Adjust the test to allow for any predicted emoji
40+
XCTAssertTrue(output.contains("🌍 Hello World"), "Output should contain: Hello World")
41+
}
42+
43+
func testHelpOption() throws {
44+
let output = try runTeemoji(input: "", arguments: ["-h"]) // Ensure correct flag
45+
XCTAssertTrue(output.contains("Usage: teemoji"), "Output should contain usage instructions")
46+
}
47+
48+
// Additional tests could include checking append behavior, etc.
49+
}
50+
51+
/// Returns path to the built products directory.
52+
var productsDirectory: URL {
53+
#if os(macOS)
54+
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
55+
return bundle.bundleURL.deletingLastPathComponent()
56+
}
57+
fatalError("couldn't find the products directory")
58+
#else
59+
return Bundle.main.bundleURL
60+
#endif
61+
}

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ build mode="debug":
77
xcrun coremlcompiler generate Resources/TeemojiClassifier.mlpackage Sources --language Swift
88
xcrun coremlcompiler compile Resources/TeemojiClassifier.mlpackage Sources
99
swift build --configuration {{mode}} --verbose --disable-sandbox
10+
11+
test: (build "debug")
12+
swift test

0 commit comments

Comments
 (0)