Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 如何编写自制公式的测试?_Testing_Homebrew - Fatal编程技术网

Testing 如何编写自制公式的测试?

Testing 如何编写自制公式的测试?,testing,homebrew,Testing,Homebrew,我自制了一个配方,现在只能在我当地的水龙头上使用。我想向自制核心发送pull请求。现在我需要为我的公式编写测试。如何根据下面的示例编写 test do output = shell_output("#{bin}/balance 2>&1", 64) assert_match "this is balance #{version}", output end 我的公式 #!/usr/bin/env ruby def match files = Dir.glob("*")

我自制了一个配方,现在只能在我当地的水龙头上使用。我想向自制核心发送pull请求。现在我需要为我的公式编写测试。如何根据下面的示例编写

test do
  output = shell_output("#{bin}/balance 2>&1", 64)
  assert_match "this is balance #{version}", output
end
我的公式

#!/usr/bin/env ruby

def match
  files = Dir.glob("*")

  if ARGV.length == 0 
  puts "usage: match <keyword>"
  return
 end

files.each { |x| 
if File.directory?(x) 
    puts "#{x}_ found directory"
    puts "***"
next
end

found = false

File.open(x).each_line.with_index do |line, index|
    if line.include? ARGV[0]
       puts "#{x}_ #{index+1}  #{line}" 
       found = true
    end
end

puts "***" if found  
}
end

match
#/usr/bin/env ruby
def匹配
files=Dir.glob(“*”)
如果ARGV.length==0
放入“用法:匹配”
回来
终止
文件.each{|x|
if File.directory?(x)
将“#{x}”放入已找到的目录
放入“***”
下一个
终止
发现=错误
File.open(x).each_line.with_index do | line,index|
如果第行包含?ARGV[0]
放置“#{x}#{index+1}#{line}”
找到=真
终止
终止
如果找到,则放入“***”
}
终止
火柴
酿造配方

class Match < Formula
desc "Browse all files inside any directory for a keyword"
homepage "https://github.com/aatalyk/homebrew-match"
url ""
sha256 ""

def install
   bin.install "match"     
end
end
类匹配
在自制公式中测试shell命令通常遵循以下情况:

  • 创建可由命令使用的上下文:git存储库、目录层次结构、示例文件等
  • 运行命令
  • 断言结果是正确的
  • 在您的情况下,因为
    match
    是一个
    grep-R
    ,所以您可以创建一组包含某些内容的文件,然后运行
    match
    ,确保它找到正确的文件

    您可以在测试中使用任何Ruby代码以及自制实用程序,如
    shell\u输出(“…命令…”)
    来获取命令的输出

    以下是您可以编写的测试示例:

    class Match < Formula
      # ...
    
      test do
        # Create two dummy files
        (testpath/"file1").write "foo\nbar\nqux"
        (testpath/"file2").write "bar\nabc"
    
        # Ensure `match bar` finds both files
        assert_match "file1_ 2  bar\n***\nfile2_ 1  bar",
          shell_output("#{bin}/match bar")
    
        # Ensure `match abc` finds the second file
        assert_match "file2_ 2  abc", shell_output("#{bin}/match abc")
    
        # Ensure `match idontmatchanything` doesn’t match any of the files
        assert_not_match(/file[12]/,
          shell_output("#{bin}/match idontmatchanything"))
      end
    end
    
    类匹配

    assert\u match“something”,shell\u输出(“command”)
    确保(1)
    命令
    成功运行,以及(2)其输出包含“
    something

    在自制公式中对shell命令的测试通常遵循以下情况:

  • 创建可由命令使用的上下文:git存储库、目录层次结构、示例文件等
  • 运行命令
  • 断言结果是正确的
  • 在您的情况下,因为
    match
    是一个
    grep-R
    ,所以您可以创建一组包含某些内容的文件,然后运行
    match
    ,确保它找到正确的文件

    您可以在测试中使用任何Ruby代码以及自制实用程序,如
    shell\u输出(“…命令…”)
    来获取命令的输出

    以下是您可以编写的测试示例:

    class Match < Formula
      # ...
    
      test do
        # Create two dummy files
        (testpath/"file1").write "foo\nbar\nqux"
        (testpath/"file2").write "bar\nabc"
    
        # Ensure `match bar` finds both files
        assert_match "file1_ 2  bar\n***\nfile2_ 1  bar",
          shell_output("#{bin}/match bar")
    
        # Ensure `match abc` finds the second file
        assert_match "file2_ 2  abc", shell_output("#{bin}/match abc")
    
        # Ensure `match idontmatchanything` doesn’t match any of the files
        assert_not_match(/file[12]/,
          shell_output("#{bin}/match idontmatchanything"))
      end
    end
    
    类匹配

    assert\u match“something”,shell\u输出(“command”)
    确保(1)
    command
    成功运行,并且(2)其输出包含“
    something

    请共享您的完整公式文件。@bfontaine我共享了它,但我指的是自制公式文件,它以
    类Something
    开始,并定义了如何安装软件。@bfontaine现在是它了。请共享您的完整公式文件。@bfontaine我共享了它谢谢,但我是指自制公式文件,它以
    类某物
    开始,并定义了如何安装软件。@bfontaine现在就到了,谢谢,@bfontaine我会检查的,谢谢,@bfontaine我会检查的