2016-06-24 2 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 

スキャンスキャンリンクをインストールする方法は、型スキャンと入力し、Enterキーを押し、ターミナルで今 https://github.com/fastlane/fastlane/tree/master/scan

です。スキャンコマンドはすべてを行います。

しかし、私はこの簡単なコードでこのターミナルコマンドを実行したいと思います。私はbwlowような別の迅速ファイルからこの関数を呼び出す

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 
     } 

} 

:このため、私は以下のコードを使用するリンクはこちらHow do I run an terminal command in a swift script? (e.g. xcodebuild)

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

ある

しかし、私はこれを実行した場合、それを私は

01を使用したより

env: scan: No such file or directory 

:エラーの下に表示さ私は私の迅速なコードを実行した場合、それは私のエラーと理由ターミナルコマンドが何であるかエラー

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 

下に示し、より私は私のコードの起動パス

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

にこれを追加し

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

スルーターミナルでうまく走るので、迅速なコードで実行する必要はありません。

お願いします。ありがとうございました。

もう1つ弱点ですが、私はosxでかなり専門家ではありません。最後に

おかげ

+0

は、端末にxcpretty'た '行う見つけるために... xcpretty''への完全なパスを供給してください。 '/ path/to/xcpretty'のように戻ってきます。 –

+0

@あなたの返事に感謝しますが、私のコマンドでエスケープシーケンスについて何を示しているのかはわかりません。もう一度お礼します。 – noor

+0

カラーコードについてのコメントは無視してください...奇妙な書式設定( '4 [36m'などそれはあなたの質問に現れています)。 * –

答えて

0

私はそうスキャンhttps://github.com/fastlane-old/gym/issues/235#event-580661928

でオープンエラーがありますスキャン使用の.plist file.Asから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") 
関連する問題