gpt4 book ai didi

xcode - 使用 xcodebuild 和 xcpretty 命令从 .plist 生成 html 报告

转载 作者:行者123 更新时间:2023-11-30 13:18:25 26 4
gpt4 key购买 nike

首先,我的最终目标是使用 xcodebuild 命令从 .plist 文件生成 html 报告。

但是,我的 osx 项目遇到了问题。我的环境是

osx 10.11 el captain, xcode 7.3 and swift 2.2

我已经安装了扫描来解决这个问题。扫描安装方式

gem install scan

扫描链接为https://github.com/fastlane/fastlane/tree/master/scan

现在在终端中,输入 scan 并按 Enter 键。扫描命令将完成所有操作。

但我想通过我的 swift 代码运行这个终端命令。为此,我使用以下代码:

import Foundation

class Command{

func terminalCommand(args: String...) -> Int32 {
let task = NSTask()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.currentDirectoryPath = "path to my osx project"
task.launch()
task.waitUntilExit()
return task.terminationStatus
}

}

我从另一个 swift 文件(如 bwlow)调用此函数:

let main = Command()
main.terminalCommand("scan")

链接在这里How do I run an terminal command in a swift script? (e.g. xcodebuild)

但是如果我运行这个,它会显示以下错误:

env: scan: No such file or directory

比我用的

which scan and it returns /usr/local/bin/scan

我将其添加到我的代码启动路径

 task.launchPath = "/usr/local/bin/scan"

如果我运行我的 swift 代码,它会显示以下错误

    16:50:29]: [33mxcrun xcodebuild -list -project ./ios-ui-automation-demo.xcodeproj[0m

+-----------------------+------------------------------------+
| [32mSummary for scan 0.8.0[0m |
+-----------------------+------------------------------------+
| project | ./ios-ui-automation-demo.xcodeproj |
| scheme | ios-ui-automation-demo |
| clean | false |
| code_coverage | false |
| address_sanitizer | false |
| skip_build | false |
| output_directory | ./fastlane/test_output |
| output_types | html,junit |
| buildlog_path | ~/Library/Logs/scan |
| open_report | false |
| skip_slack | false |
| slack_only_on_failure | false |
| use_clang_report_name | false |
+-----------------------+------------------------------------+

[16:50:34]: [4m[36m$ set -o pipefail && env NSUnbufferedIO=YES xcodebuild -scheme ios-ui-automation-demo -project ./ios-ui-automation-demo.xcodeproj -destination 'platform=iOS Simulator,id=841044C8-5637-4652-BDC9-3BAB05248F15' build test | tee '/Users/me/Library/Logs/scan/ios-ui-automation-demo-ios-ui-automation-demo.log' | xcpretty [0m[0m
[16:50:34]: ▸ [35mLoading...[0m
[16:50:34]: ▸ [35msh: xcpretty: command not found[0m

我的错误是什么,为什么终端命令没有在 swift 代码中运行,因为它通过终端运行良好。

请您提供任何帮助或建议,我们将不胜感激。

还有一个弱点,我对 osx 不是很专家。

谢谢

最佳答案

最后我找到了一种从 .plist 文件生成 html 报告的方法。当我使用扫描时,扫描 https://github.com/fastlane-old/gym/issues/235#event-580661928 中出现打开错误

所以,我尝试了另一种方式......使用xcpretty。代码如下:

import Foundation

class command{

func runCommand(workingDirectory: String? = nil,
stdin: NSPipe? = nil,
stdout: NSPipe? = nil,
stderr: NSPipe? = nil,
args: String...) -> Int32 {
let task = NSTask()

task.launchPath = "/usr/bin/env"
task.arguments = args

if let workingDirectory = workingDirectory {
task.currentDirectoryPath = workingDirectory
}

if let stdin = stdin { task.standardInput = stdin }
if let stdout = stdout { task.standardOutput = stdout }
if let stderr = stderr { task.standardError = stderr }

task.launch()
task.waitUntilExit()
return (task.terminationStatus)
}
}

现在调用函数:

let pipe = NSPipe()
let generateHtmlReport = command()

//omit "workingDirectory:" in Swift 2.2, only use the value
generateHtmlReport.runCommand(workingDirectory: "/Users/Desktop/XCode/Test/",
stdout: pipe,
args: "xcodebuild","test",
"-project","proj.xcodeproj",
"-scheme","projScheme",
"-destination","platform=iOS Simulator,name=iPad Air")

//omit "workingDirectory:" in Swift 2.2, only use the value
generateHtmlReport.runCommand(workingDirectory: "/Users/Desktop/XCode/Test/",
stdin: pipe,
args: "/usr/local/bin/xcpretty",
"--report","html",
"--output",
"/Desktop/test_output/report.html")

关于xcode - 使用 xcodebuild 和 xcpretty 命令从 .plist 生成 html 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38011829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com