【问题标题】:How can I format a new string from Rake's FileList?如何格式化来自 Rake 的 FileList 的新字符串?
【发布时间】:2011-01-07 23:56:58
【问题描述】:

我正在编写一个 rakefile,需要同时针对多个测试 dll 运行 mstest。我需要它只运行一次 mstest,因为我只需要一个 TRX 文件。为了针对多个测试 dll 运行 mstest,我需要能够在同一命令中添加多个 /testcontainer:some.test.dll 实例。这是我当前的 rake 任务:

task :tests do
    testDlls = FileList.new("#{BUILD_PATH}/*.Specs.dll")
sh "#{MSTEST_PATH} /testcontainer:#{testDlls}"      
end

例如,testDlls 有 test1.dll、test2.dll 和 test3.dll。上述任务输出:

c:\msbuild\msbuild.exe /testcontainer:test1.dll test2.dll test3.dll

我需要的是:

c:\msbuild\msbuild.exe /testcontainer:test1.dll /testcontainer:test2.dll /testcontainer:test3.dll

我怎样才能得到我想要的输出?

【问题讨论】:

    标签: ruby rake rakefile


    【解决方案1】:

    应该可以的:

    require 'shellwords'
    task :tests do
        testDlls = FileList.new("#{BUILD_PATH}/*.Specs.dll")
        ary = Shellwords.shellwords(testDlls.to_s)
        sh "#{MSTEST_PATH} #{ary.map {|dll| '/testcontainer:' + dll}.join(' ')"      
    end
    

    【讨论】:

    • 看起来很有希望,但我遇到了另一个错误。你的第四行抛出这个:未定义的方法scan' for #<Rake::FileList:0x5162d0> C:/Ruby192/lib/ruby/1.9.1/shellwords.rb:35:in shellsplit'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    相关资源
    最近更新 更多