Skip to content

Commit

Permalink
use test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
adamv committed Aug 1, 2014
1 parent 283f6ad commit 1d9631c
Show file tree
Hide file tree
Showing 85 changed files with 167 additions and 346 deletions.
7 changes: 2 additions & 5 deletions Formula/aamath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ def install
end

test do
IO.popen("#{bin}/aamath", "w+") do |pipe|
pipe.write((prefix/"testcases").read)
pipe.close_write
assert_match /#{Regexp.escape("f(x + h) = f(x) + h f'(x)")}/, pipe.read
end
s = pipe_output("#{bin}/aamath", (prefix/"testcases").read)
assert_match /#{Regexp.escape("f(x + h) = f(x) + h f'(x)")}/, s
end
end

Expand Down
14 changes: 3 additions & 11 deletions Formula/aardvark_shell_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ def install
end

test do
output = `#{bin}/filebase movcpm.com`
assert_equal "movcpm\n", output
assert_equal 0, $?.exitstatus

output = `#{bin}/fileext movcpm.com`
assert_equal "com\n", output
assert_equal 0, $?.exitstatus

output = `#{bin}/realpath .`
assert_equal "#{testpath}\n", output
assert_equal 0, $?.exitstatus
assert_equal "movcpm", shell_output("#{bin}/filebase movcpm.com").strip
assert_equal "com", shell_output("#{bin}/fileext movcpm.com").strip
assert_equal testpath.to_s, shell_output("#{bin}/realpath .").strip
end
end
7 changes: 2 additions & 5 deletions Formula/ack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ def install
end

test do
IO.popen("#{bin}/ack --noenv --nocolor bar -", "w+") do |pipe|
pipe.write "foo\nfoo bar\nbaz"
pipe.close_write
assert_equal "foo bar\n", pipe.read
end
assert_equal "foo bar\n", pipe_output("#{bin}/ack --noenv --nocolor bar -",
"foo\nfoo bar\nbaz")
end
end
7 changes: 2 additions & 5 deletions Formula/aha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ def install
end

test do
IO.popen("#{bin}/aha", "w+") do |pipe|
pipe.write("rainpill")
pipe.close_write
assert_match /color:purple;">rain.*color:blue;">pill/, pipe.read
end
out = pipe_output(bin/"aha", "rainpill")
assert_match /color:purple;">rain.*color:blue;">pill/, out
end
end
4 changes: 1 addition & 3 deletions Formula/algol68g.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def install
print("Hello World")
EOS

output = `#{bin}/a68g #{path}`.strip
assert_equal "Hello World", output
assert_equal 0, $?.exitstatus
assert_equal "Hello World", shell_output("#{bin}/a68g #{path}").strip
end
end
6 changes: 1 addition & 5 deletions Formula/align.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def install
end

test do
IO.popen(bin/"align", "w+") do |pipe|
pipe.write "1 1\n12 12\n"
pipe.close_write
assert_equal " 1 1\n12 12\n", pipe.read
end
assert_equal " 1 1\n12 12\n", pipe_output(bin/"align", "1 1\n12 12\n")
end
end
4 changes: 1 addition & 3 deletions Formula/ansifilter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ def install
path = testpath/"ansi.txt"
path.write "f\x1b[31moo"

output = `#{bin}/ansifilter #{path}`.strip
assert_equal "foo", output
assert_equal 0, $?.exitstatus
assert_equal "foo", shell_output("#{bin}/ansifilter #{path}").strip
end
end
4 changes: 1 addition & 3 deletions Formula/ascii.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def install
end

test do
output = `#{bin}/ascii 0x0a`
assert output.include?("Official name: Line Feed")
assert_equal 0, $?.exitstatus
assert shell_output(bin/"ascii 0x0a").include?("Official name: Line Feed")
end
end
4 changes: 1 addition & 3 deletions Formula/ats2-postiats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def install
implement main0 () = ()
EOS
system "#{bin}/patscc hello.dats -o hello"
IO.popen("./hello", "r") do |pipe|
assert_match "Hello, world!", pipe.read
end
assert_match "Hello, world!", shell_output(testpath/"hello")
end
end
4 changes: 2 additions & 2 deletions Formula/autopano-sift-c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def install
end

test do
pipe = IO.popen("#{bin}/autopano-sift-c")
assert_match /Version #{Regexp.escape(version)}/, pipe.read
assert_match /Version #{Regexp.escape(version)}/,
pipe_output("#{bin}/autopano-sift-c")
end
end
2 changes: 1 addition & 1 deletion Formula/avian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ def install
}
EOS
system 'javac', 'Test.java'
assert_equal 'OK', `avian Test`.strip
assert_equal 'OK', shell_output("#{bin}/avian Test")
end
end
3 changes: 1 addition & 2 deletions Formula/avra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def install

test do
(testpath/"test.asm").write " .device attiny10\n ldi r16,0x42\n"
output = `#{bin}/avra -l test.lst test.asm`
output = shell_output("#{bin}/avra -l test.lst test.asm")
assert output.include?("Assembly complete with no errors.")
assert_equal 0, $?.exitstatus
assert File.exist?("test.hex")
assert File.read("test.lst").include?("ldi r16,0x42")
end
Expand Down
5 changes: 1 addition & 4 deletions Formula/base64.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ def install
test do
path = testpath/"a.txt"
path.write "hello"

output = `#{bin}/base64 #{path}`.strip
assert_equal "aGVsbG8=", output
assert_equal 0, $?.exitstatus
assert_equal "aGVsbG8=", shell_output("#{bin}/base64 #{path}").strip
end
end
5 changes: 1 addition & 4 deletions Formula/basex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ def install
end

test do
require 'open3'
Open3.popen3("#{bin}/basex", "1 to 10") do |_, stdout, _|
assert_equal "1 2 3 4 5 6 7 8 9 10", stdout.read
end
assert_equal "1 2 3 4 5 6 7 8 9 10", shell_output("#{bin}/basex '1 to 10'")
end
end
4 changes: 1 addition & 3 deletions Formula/bash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def caveats; <<-EOS.undent
end

test do
output = `#{bin}/bash -c "echo hello"`.strip
assert_equal "hello", output
assert_equal 0, $?.exitstatus
assert_equal "hello", shell_output("#{bin}/bash -c \"echo hello\"").strip
end
end
10 changes: 4 additions & 6 deletions Formula/bgrep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ def install

test do
path = testpath/"hi.prg"
code = [0x00, 0xc0, 0xa9, 0x48, 0x20, 0xd2, 0xff,
0xa9, 0x49, 0x20, 0xd2, 0xff, 0x60].pack("C*")
path.open("wb") { |f| f.write code }
path.binwrite [0x00, 0xc0, 0xa9, 0x48, 0x20, 0xd2, 0xff,
0xa9, 0x49, 0x20, 0xd2, 0xff, 0x60].pack("C*")

lines = `#{bin}/bgrep 20d2ff #{path}`.strip.split("\n")
assert_equal ["#{path}: 00000004", "#{path}: 00000009"], lines
assert_equal 0, $?.exitstatus
assert_equal ["#{path}: 00000004", "#{path}: 00000009"],
shell_output("#{bin}/bgrep 20d2ff #{path}").split("\n")
end
end
4 changes: 1 addition & 3 deletions Formula/calc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ def install
end

test do
output = `#{bin}/calc 0xA + 1`.strip
assert_equal "11", output
assert_equal 0, $?.exitstatus
assert_equal "11", shell_output("#{bin}/calc 0xA + 1").strip
end
end
15 changes: 3 additions & 12 deletions Formula/cayley.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,9 @@ def plist; <<-EOS.undent
end

test do
require 'open3'

touch "test.nt"

Open3.popen3("#{bin}/cayley", "repl", "--dbpath=#{testpath}/test.nt") do |stdin, stdout, _|
stdin.write "graph.Vertex().All()"
stdin.close

result = stdout.read.strip

assert !result.include?("Error:")
assert result.include?("Elapsed time:")
end
result = pipe_output("#{bin}/cayley repl --dbpath=#{testpath}/test.nt", "graph.Vertex().All()")
assert !result.include?("Error:")
assert result.include?("Elapsed time:")
end
end
6 changes: 1 addition & 5 deletions Formula/cbmbasic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def install
end

test do
IO.popen("#{bin}/cbmbasic", "w+") do |pipe|
pipe.write("PRINT 1\n")
pipe.close_write
assert_match /READY.\r\n 1/, pipe.read
end
assert_match /READY.\r\n 1/, pipe_output("#{bin}/cbmbasic", "PRINT 1\n")
end
end
3 changes: 1 addition & 2 deletions Formula/ccal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def install
end

test do
output = `#{bin}/ccal 2 2014`
output = shell_output("#{bin}/ccal 2 2014")
assert output.include?("Year JiaWu, Month 1X")
assert_equal 0, $?.exitstatus
end
end
5 changes: 2 additions & 3 deletions Formula/cdecl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def install
end

test do
output = `#{bin}/cdecl explain int *a`.strip
assert_equal "declare a as pointer to int", output
assert_equal 0, $?.exitstatus
assert_equal "declare a as pointer to int",
shell_output("#{bin}/cdecl explain int *a").strip
end
end
3 changes: 1 addition & 2 deletions Formula/check_postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def install
test do
# This test verifies that check_postgres fails correctly, assuming
# that no server is running at that port.
output = `#{bin}/check_postgres --action=connection --port=65432`
output = shell_output("#{bin}/check_postgres --action=connection --port=65432", 2)
assert output.include? "POSTGRES_CONNECTION CRITICAL"
assert_equal 2, $?.exitstatus
end
end
4 changes: 1 addition & 3 deletions Formula/chicken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def install
end

test do
output = `'#{bin}/csi' -e '(print (* 5 5))'`
assert_equal "25", output.strip
assert $?.success?
assert_equal "25", shell_output("#{bin}/csi -e '(print (* 5 5))'").strip
end
end
3 changes: 2 additions & 1 deletion Formula/chkrootkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def install
end

test do
assert_equal "chkrootkit version #{version}", `#{bin}/chkrootkit -V 2>&1`.strip
assert_equal "chkrootkit version #{version}",
shell_output("#{bin}/chkrootkit -V 2>&1", 1).strip
end
end
4 changes: 1 addition & 3 deletions Formula/cksfv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def install
path = testpath/"foo"
path.write "abcd"

lines = `#{bin}/cksfv #{path}`.split("\n")
assert lines.include?("#{path} ED82CD11")
assert_equal 0, $?.exitstatus
assert shell_output("#{bin}/cksfv #{path}").include?("#{path} ED82CD11")
end
end
8 changes: 2 additions & 6 deletions Formula/cloog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ def install
0
EOS

require 'open3'
Open3.popen3("#{bin}/cloog", "/dev/stdin") do |stdin, stdout, _|
stdin.write(cloog_source)
stdin.close
assert_match /Generated from \/dev\/stdin by CLooG/, stdout.read
end
output = pipe_output("#{bin}/cloog /dev/stdin", cloog_source)
assert_match /Generated from \/dev\/stdin by CLooG/, output
end
end
3 changes: 1 addition & 2 deletions Formula/cowsay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ def install
end

test do
output = `#{bin}/cowsay moo`
output = shell_output("#{bin}/cowsay moo")
assert output.include?("moo") # bubble
assert output.include?("^__^") # cow
assert_equal 0, $?.exitstatus
end
end
3 changes: 1 addition & 2 deletions Formula/cpmtools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def install
system "#{bin}/cpmcp -f ibm-3740 #{image} #{src} 0:foo"

# check for the file in the cp/m directory
assert `#{bin}/cpmls -f ibm-3740 #{image}`.include?("foo")
assert_equal 0, $?.exitstatus
assert shell_output("#{bin}/cpmls -f ibm-3740 #{image}").include?("foo")

# copy the file back out of the image
dest = testpath/"bar"
Expand Down
4 changes: 1 addition & 3 deletions Formula/css-crush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def install
p { color: $(foo); }
EOS

output = `#{bin}/csscrush #{path}`.strip
assert_equal "p{color:#123456}", output
assert_equal 0, $?.exitstatus
assert_equal "p{color:#123456}", shell_output("#{bin}/csscrush #{path}").strip
end
end
7 changes: 2 additions & 5 deletions Formula/csv-fix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ def install
end

test do
IO.popen("#{bin}/csvfix trim", "w+") do |pipe|
pipe.write "foo , bar \n"
pipe.close_write
assert_equal %{"foo","bar"\n}, pipe.read
end
assert_equal %{"foo","bar"\n},
pipe_output("#{bin}/csvfix trim", "foo , bar \n")
end
end
7 changes: 2 additions & 5 deletions Formula/csvprintf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ def install
end

test do
IO.popen("#{bin}/csvprintf -i '%2$s %1$s\n'", "w+") do |pipe|
pipe.write "Last,First\nSmith,Fred\n"
pipe.close_write
assert_equal "Fred Smith\n", pipe.read
end
assert_equal "Fred Smith\n",
pipe_output("#{bin}/csvprintf -i '%2$s %1$s\n'", "Last,First\nSmith,Fred\n")
end
end
2 changes: 1 addition & 1 deletion Formula/dart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def caveats; <<-EOS.undent
}
EOS

assert_equal "test message\n", `#{bin}/dart sample.dart`
assert_equal "test message\n", shell_output("#{bin}/dart sample.dart")
end
end
2 changes: 1 addition & 1 deletion Formula/dasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def install
EOS

system bin/"dasm", path
code = File.open(testpath/"a.out", "rb") { |f| f.read.unpack("C*") }
code = (testpath/"a.out").binread.unpack("C*")
assert_equal [0x00, 0xc0, 0x4c, 0xe2, 0xfc], code
end
end
5 changes: 2 additions & 3 deletions Formula/ddate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def install
end

test do
out = `#{bin}/ddate 20 6 2014`
assert_equal "Sweetmorn, Confusion 25, 3180 YOLD\n", out
assert_equal 0, $?.exitstatus
output = shell_output("#{bin}/ddate 20 6 2014").strip
assert_equal "Sweetmorn, Confusion 25, 3180 YOLD", output
end
end
Loading

0 comments on commit 1d9631c

Please sign in to comment.