簡體   English   中英

Ruby:如何在1.9.3中將選項傳遞給test :: unit

[英]Ruby: How to pass options to test::unit in 1.9.3

我想運行一個測試文件:

# xxx.rb
require 'test/unit'; class XTest < Test::Unit::TestCase; def test_xxx; end; end

直到紅寶石1.9.2

ruby -Itest -e "require './xxx.rb'" - -v

做了這項工作,我突然得到1.9.3:

/usr/local/rvm/rubies/ruby-1.9.3-rc1/lib/ruby/1.9.1/test/unit.rb:167:in
`block in non_options': file not found: - (ArgumentError)

(它嘗試加載不存在的文件“-”)

有什么想法如何使詳細模式返回/傳遞選項到test :: unit嗎?

正確的輸出如下所示:

Loaded suite -e
Started
test_xxx(XTest): .

嘗試使用雙破折號:

ruby -Itest -e "require './xxx.rb'" -- -v

或這樣(無破折號,不需要):

ruby -Itest xxx.rb -v

為了解釋,我認為在您的示例中,您使用的是一個破折號,通常表示“將stdin用作文件”。 您可以這樣做,例如:

cat xxx.rb | ruby -Itest - -v

雙破折號用於停止參數解析,因此將-v傳遞給測試單元。 至於為什么帶單破折號的示例可以達到1.9.3 ...我猜想在1.9.3之前,ruby在指定stdin時沒有那么嚴格,但stdin上沒有任何內容(如你沒有)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM