2016-06-24 135 views
0

首先,我的最終目標是使用xcodebuild命令從.plist文件生成html報告。使用xcodebuild和xcpretty命令從.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

現在,在終端,掃描類型,然後按回車。掃描命令將完成一切。

但我想通過我的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 
     } 

} 

我呼籲來自像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 

什麼是我的錯誤,爲什麼端子命令不能在快速代碼中運行,因爲它通過終端運行良好。

請,任何幫助或任何建議將不勝感激。

還有一個弱點,我在osx上不是很專業。

感謝

+0

嘗試提供的完整路徑'xcpretty'來找到做'這xcpretty'在終端。它應該返回爲'/ path/to/xcpretty'之類的東西。 –

+0

@ I'L'l感謝您的回覆,但我不清楚您在我的命令中指出了什麼逃生順序......再次感謝 – noor

+0

忽略關於顏色代碼的評論......這是關於奇怪的格式('4 [36m'等等這是顯示在你的問題);關於使用完整路徑的新評論是重要的。* –

回答

0

最後我找到了一種方法來生成的.plist file.As我使用的掃描有在掃描https://github.com/fastlane-old/gym/issues/235#event-580661928

打開錯誤所以,我以另一種方式試圖HTML報告....使用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) 
    } 
} 

現在所說的funcion:

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")