Compare commits

...

6 Commits

Author SHA1 Message Date
Matyáš Kříž d69116fe88 Update SwiftPM info in README. 2020-02-22 21:08:41 +01:00
Matyáš Kříž 670781ff92 Drastically shorten needed command to get the `run` script. 2020-02-22 20:28:50 +01:00
Matyáš Kříž 227b68b55c Add instructions on how to obtain the `run` script. 2020-02-22 20:28:50 +01:00
Matyáš Kříž e271f53fc4 Remove unwanted space. 2020-02-22 20:28:50 +01:00
Matyáš Kříž f58cda6c03 Add SwiftPM section to the `README.md`. 2020-02-22 20:28:50 +01:00
Matyáš Kříž cc18f23f80 Add Swift Package Manager support. 2020-02-22 20:28:50 +01:00
3 changed files with 82 additions and 6 deletions

22
Package.swift Normal file
View File

@ -0,0 +1,22 @@
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "Cuckoo",
products: [
.library(
name: "Cuckoo",
targets: ["Cuckoo"]),
],
targets: [
.target(
name: "Cuckoo",
dependencies: [],
path: "Source"),
.testTarget(
name: "CuckooTests",
dependencies: ["Cuckoo"],
path: "Tests"),
]
)

View File

@ -87,8 +87,63 @@ Input files can be also specified directly in `Run script` in `Input Files` form
Note: All paths in the Run script must be absolute. Variable `PROJECT_DIR` automatically points to your project directory.
**Remember to include paths to inherited Classes and Protocols for mocking/stubbing parent and grandparents.**
#### Swift Package Manager
To use Cuckoo with Apple's Swift package manager, add the following as a dependency to your `Package.swift`:
```swift
.package(url: "https://github.com/Brightify/Cuckoo.git", .upToNextMajor(from: "1.3.0"))
```
after that add `"Cuckoo"` as a dependency of the test target.
If you're unsure, take a look at this example `PackageDescription`:
```swift
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "Friendlyst",
products: [
.library(
name: "Friendlyst",
targets: ["Friendlyst"]),
],
dependencies: [
.package(url: "https://github.com/Brightify/Cuckoo.git", .upToNextMajor(from: "1.3.0"))
],
targets: [
.target(
name: "Friendlyst",
dependencies: [],
path: "Source"),
.testTarget(
name: "FriendlystTests",
dependencies: ["Cuckoo"],
path: "Tests"),
]
)
```
Cuckoo relies on a script that is currently not downloadable using SwiftPM. However, for convenience, you can copy this line into the terminal to download the latest `run` script. Unfortunately if there are changes in the `run` script, you'll need to execute this line again.
```Bash
curl https://raw.githubusercontent.com/Brightify/Cuckoo/master/run > run && chmod +x run
```
When you're all set, use the same `Run script` phase as above and replace
```Bash
"${PODS_ROOT}/Cuckoo/run"
```
with
```Bash
"${PROJECT_DIR}/run" --download
```
The `--download` option is necessary because the `Generator` sources are not cloned in your project (they're in DerivedData, out of reach). You can add a version (e.g. 1.3.0) after it to get a specific version of the `cuckoo_generator`. Use `--clean` as well to replace the current `cuckoo_generator` if you're changing versions.
#### Carthage
To use Cuckoo with [Carthage](https://github.com/Carthage/Carthage) add in your Cartfile this line:
To use Cuckoo with [Carthage](https://github.com/Carthage/Carthage) add this line to your Cartfile:
```
github "Brightify/Cuckoo"
```
@ -102,7 +157,7 @@ with
"Carthage/Checkouts/Cuckoo/run"
```
Also don't forget to add the Framework into your project's test target.
Don't forget to add the Framework into your project.
### 2. Usage
Usage of Cuckoo is similar to [Mockito](http://mockito.org/) and [Hamcrest](http://hamcrest.org/). However, there are some differences and limitations caused by generating the mocks and Swift language itself. List of all the supported features can be found below. You can find complete examples in [tests](Tests).

7
run
View File

@ -11,7 +11,7 @@ function perform_curl {
fi
DOWNLOAD_URL=$(curl "${CURL_OPTIONS[@]}" "$1" | grep -oe '"browser_download_url":\s*"[^" ]*"' | grep -oe 'http[^" ]*' | grep "$FILE_NAME" | head -1)
if [[ -z "$DOWNLOAD_URL" ]]; then
echo "Error: Failed to fetch download URL for the Cuckoo Generator."
exit 1
@ -74,13 +74,13 @@ case $1 in
fi
shift
;;
-c|--clean)
CLEAN=1
echo "Performing clean build."
shift
;;
*)
POSITIONAL+=("$1") # save it in an array for later
shift
@ -110,4 +110,3 @@ do
done
echo $INPUT_FILES | xargs "$FILE_PATH"