Permalink
Browse files

port remaining tests

  • Loading branch information...
1 parent ec3e41c commit 105018a543c80351f98668f34ff1b8d95665c2b1 @nzoschke committed Dec 11, 2012
Showing with 131 additions and 160 deletions.
  1. +1 −1 Rakefile
  2. +0 −132 tests/unit/ferret
  3. +129 −0 tests/unit/test_bash.rb
  4. +1 −27 tests/unit/test_ferret.rb
View
@@ -5,5 +5,5 @@ require "rake/testtask"
task default: :test
Rake::TestTask.new :test do |t|
- t.pattern = "./tests/unit/test_ferret.rb"
+ t.pattern = "./tests/unit/test_*.rb"
end
View
@@ -1,132 +0,0 @@
-#!/usr/bin/env ruby
-require_relative "test_helper"
-
-class TestFerret < TestBase
- def test_bash_true
- bash(name: :true, stdin: <<-'EOF')
- true
- EOF
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=true i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=true i=0 status=0 measure=ferret-test.ferret.true.success
-app=ferret-test.ferret xid=deadbeef fn=true i=0 val=100 measure=ferret-test.ferret.true.uptime
-app=ferret-test.ferret xid=deadbeef fn=true i=0 at=return val=X.Y measure=ferret-test.ferret.true.time
-EOF
- end
-
- def test_bash_false
- assert_raises(SystemExit) do
- bash(name: :false, stdin: <<-'EOF')
- false
- EOF
- end
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=false i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=false i=0 status=1 measure=ferret-test.ferret.false.failure
-app=ferret-test.ferret xid=deadbeef fn=false i=0 val=0 measure=ferret-test.ferret.false.uptime
-app=ferret-test.ferret xid=deadbeef fn=false i=0 at=return val=X.Y
-EOF
- end
-
- def test_bash_retry
- assert_raises(SystemExit) do
- bash(retry: 2, name: :false, stdin: <<-'EOF')
- false
- EOF
- end
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=false i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=false i=0 status=1
-app=ferret-test.ferret xid=deadbeef fn=false i=0 at=return val=X.Y
-app=ferret-test.ferret xid=deadbeef fn=false i=1 at=enter
-app=ferret-test.ferret xid=deadbeef fn=false i=1 status=1 measure=ferret-test.ferret.false.failure
-app=ferret-test.ferret xid=deadbeef fn=false i=1 val=0 measure=ferret-test.ferret.false.uptime
-app=ferret-test.ferret xid=deadbeef fn=false i=1 at=return val=X.Y
-EOF
- end
-
- def test_bash_status
- bash(name: :nonzero, status: 128, stdin: <<-'EOF')
- exit 128
- EOF
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 status=128 measure=ferret-test.ferret.nonzero.success
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 val=100 measure=ferret-test.ferret.nonzero.uptime
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 at=return val=X.Y measure=ferret-test.ferret.nonzero.time
-EOF
- end
-
- def test_bash_status_nil
- bash(name: :nonzero, status: nil, stdin: <<-'EOF')
- exit 128
- EOF
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 status=128 measure=ferret-test.ferret.nonzero.success
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 val=100 measure=ferret-test.ferret.nonzero.uptime
-app=ferret-test.ferret xid=deadbeef fn=nonzero i=0 at=return val=X.Y measure=ferret-test.ferret.nonzero.time
-EOF
- end
-
- def test_bash_pattern_true
- bash(name: :grep, pattern: /hi/, stdin: <<-'EOF')
- echo hi
- EOF
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 status=0 measure=ferret-test.ferret.grep.success
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 val=100 measure=ferret-test.ferret.grep.uptime
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 at=return val=X.Y measure=ferret-test.ferret.grep.time
-EOF
- end
-
- def test_bash_pattern_false
- assert_raises(SystemExit) do
- bash(name: :grep, pattern: /hi/, stdin: <<-'EOF')
- echo hello
- EOF
- end
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 at=failure out='hello'
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 status=0 measure=ferret-test.ferret.grep.failure
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 val=0 measure=ferret-test.ferret.grep.uptime
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 at=return val=X.Y
-EOF
- end
-
- def test_bash_pattern_status
- bash(name: :grep, pattern: /hi/, status: nil, stdin: <<-'EOF')
- echo hi
- exit 1
- EOF
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 status=1 measure=ferret-test.ferret.grep.success
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 val=100 measure=ferret-test.ferret.grep.uptime
-app=ferret-test.ferret xid=deadbeef fn=grep i=0 at=return val=X.Y measure=ferret-test.ferret.grep.time
-EOF
- end
-
- def test_timeout
- assert_raises(SystemExit) do
- bash(name: :timeout, timeout: 0.01, stdin: <<-'EOF')
- sleep 2
- EOF
- end
-
- assert_equal logs, <<EOF
-app=ferret-test.ferret xid=deadbeef fn=timeout i=0 at=enter
-app=ferret-test.ferret xid=deadbeef fn=timeout at=timeout val=X.Y
-EOF
- end
-end
View
@@ -0,0 +1,129 @@
+ENV["FILENAME"] = "unit/test" # rake sets $0 to rake-test-loader
+
+require_relative "./test_helper"
+
+class TestBash < TestBase
+ def test_true
+ test(name: :true, bash: "true")
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 status=0 measure=success
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 val=100 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 at=return val=X.Y measure=time
+EOF
+ end
+
+ def test_false
+ assert_raises(SystemExit) do
+ test(name: :false, bash: "false")
+ end
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 status=1 measure=failure
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 val=0 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 at=return val=X.Y
+EOF
+ end
+
+ def test_retry
+ assert_raises(SystemExit) do
+ test(retry: 2, name: :false, bash: <<-'EOF')
+ false
+ EOF
+ end
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 status=1
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 at=return val=X.Y
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=1 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=1 status=1 measure=failure
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=1 val=0 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=1 at=return val=X.Y
+EOF
+ end
+
+ def test_status
+ test(name: :nonzero, status: 128, bash: <<-'EOF')
+ exit 128
+ EOF
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 status=128 measure=success
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 val=100 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 at=return val=X.Y measure=time
+EOF
+ end
+
+ def test_status_nil
+ test(name: :nonzero, status: nil, bash: <<-'EOF')
+ exit 128
+ EOF
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 status=128 measure=success
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 val=100 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.nonzero i=0 at=return val=X.Y measure=time
+EOF
+ end
+
+ def test_pattern_true
+ test(name: :grep, pattern: /hi/, bash: <<-'EOF')
+ echo hi
+ EOF
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 status=0 measure=success
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 val=100 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 at=return val=X.Y measure=time
+EOF
+ end
+
+ def test_pattern_false
+ assert_raises(SystemExit) do
+ test(name: :grep, pattern: /hi/, bash: <<-'EOF')
+ echo hello
+ EOF
+ end
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 at=failure out='hello'
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 status=0 measure=failure
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 val=0 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 at=return val=X.Y
+EOF
+ end
+
+ def test_pattern_status
+ test(name: :grep, pattern: /hi/, status: nil, bash: <<-'EOF')
+ echo hi
+ exit 1
+ EOF
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 status=1 measure=success
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 val=100 measure=uptime
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.grep i=0 at=return val=X.Y measure=time
+EOF
+ end
+
+ def test_timeout
+ assert_raises(SystemExit) do
+ test(name: :timeout, timeout: 0.01, bash: <<-'EOF')
+ sleep 2
+ EOF
+ end
+
+ assert_equal logs, <<EOF
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.timeout i=0 at=enter
+app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.timeout at=timeout val=X.Y
+EOF
+ end
+end
View
@@ -31,30 +31,4 @@ def test_false
app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 at=return val=X.Y
EOF
end
-end
-
-class TestFerretBash < TestBase
- def test_bash_true
- test(name: :true, bash: "true")
-
- assert_equal logs, <<EOF
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 at=enter
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 status=0 measure=success
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 val=100 measure=uptime
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.true i=0 at=return val=X.Y measure=time
-EOF
- end
-
- def test_bash_false
- assert_raises(SystemExit) do
- test(name: :false, bash: "false")
- end
-
- assert_equal logs, <<EOF
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 at=enter
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 status=1 measure=failure
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 val=0 measure=uptime
-app=ferret-dev.ferret-minitest xid=deadbeef source=unit.test-ferret.false i=0 at=return val=X.Y
-EOF
- end
-end
+end

0 comments on commit 105018a

Please sign in to comment.