Permalink
Browse files

terrorize README and remove invalid tests.

I'll rewrite these in a better format with examples.
  • Loading branch information...
falconindy committed Dec 30, 2012
1 parent 0d698d4 commit 65a8cf47b7370a2e7502b2a5b0ee5edd81965649
Showing with 3 additions and 170 deletions.
  1. +3 −47 README.md
  2. +0 −53 expect-test
  3. +0 −70 mock-test
View
@@ -1,61 +1,17 @@
# Apron
-Apron is a mocking framework for Bash. Why Apron? Because Smock seemed
-way too obvious.
+Apron is a testing and mocking framework for Bash. Why Apron? Because Smock
+seemed way too obvious.
## Installation
You should not try to use Apron from a shared location. Simply include
it with your project and source it from a controlled location.
-## How to Use
-
-### Mocks
-
-Source apron as early as possible, and call `APRON_enable`. This initializes a
-small amount of bookkeeping needed to intercept calls and keep track of any
-mocks which you might register. At this point, any call which cannot be
-resolved by the shell will be caught by Apron as an uninteresting call. You can
-enable Apron with the `-v` flag to get verbose output as to what Apron is
-doing.
-
-Next, define your mocks! Let's call one `badcommand`. Of course, at this point,
-since shell functions take priority over external commands, the function will
-always be called. However, you'll also want to register your mock with Apron,
-by calling `APRON_register badcommand`. This allows Apron to keep track of
-the function in case you want to selectively unregister it, or temporarily
-pause mocking.
-
-Define as many mocks as you want! As mentioned, Apron can temporarily pause
-its mocking behavior with `APRON_pause`. This will cause all further calls
-to previously mocked commands to be executed normally. You can go back to
-your mocked environment with `APRON_unpause`.
-
-Finally, you can tear down your mocks selectively, or all at once. Use
-`APRON_unregister` to destroy a single mock or `APRON_unregister_all` to
-destroy all known mocks. Unregistering mocks will not cause APRON to be
-disabled. To completely uninitialize Apron, call `APRON_disable`. Note that
-calling `APRON_disable` will implicitly unregister all mocks for you.
-
-An example of Apron's mocking in use can be found in `mock-test`.
-
-### Expectations
-
-Apron can set and validate expectations on external calls, too. Again, start by
-calling `APRON_enable`. Set expectations by calling `APRON_expect_call` with
-the expected external call, and optionally a count. Once you're satisfied, call
-the function you want to watch with `APRON_replay`. Once `APRON_replay` returns,
-all expected calls are reset.
-
-And of course, you can combine expectations with your mocks to do even closer
-validation of behavior.
-
-An example of Apron's expectations in use can be found in `expect-test`.
-
## TODO/Known limitations
* Add ordering and argument validation to expectations
-* Figure out how to mock redirections
+* mock redirections?
## License
View
@@ -1,53 +0,0 @@
-#!/bin/bash
-
-. ./apron -v
-
-somefunc() {
- ls
- df
- du -sh .
- if false; then
- rm
- fi
- uncaught
-}
-
-APRON_enable
-
-#
-# set expectations
-#
-APRON_expect_call ls
-APRON_expect_call df
-APRON_expect_call du 2
-APRON_expect_call rm
-
-#
-# call the function, validate the expectations
-#
-APRON_replay somefunc
-
-#
-# Now add some mocks for the guts of the sample function
-#
-mock_called() {
- printf '==> MOCKED CALL: %s with %s args: %s\n' "$1" "$2" "${*:3}"
-}
-ls() { mock_called "$FUNCNAME" "$#" "$@"; }
-df() { mock_called "$FUNCNAME" "$#" "$@"; }
-du() { mock_called "$FUNCNAME" "$#" "$@"; }
-APRON_register 'ls'
-APRON_register 'df'
-APRON_register 'du'
-
-#
-# re-add expectations, correct this time
-#
-APRON_expect_call ls
-APRON_expect_call df
-APRON_expect_call du
-APRON_expect_call uncaught
-APRON_replay somefunc
-
-APRON_disable
-
View
@@ -1,70 +0,0 @@
-#!/bin/bash
-
-#
-# A short demo of how to use apron.
-#
-
-. './apron'
-
-# Enables mocking, with verbosity
-APRON_enable -v
-
-#
-# define some mocks for external commands and register them
-#
-mock_called() {
- printf '==> MOCKED CALL: %s with %s args: %s\n' "$1" "$2" "${*:3}"
-}
-ls() { mock_called "$FUNCNAME" "$#" "$@"; }
-df() { mock_called "$FUNCNAME" "$#" "$@"; }
-cp() { mock_called "$FUNCNAME" "$#" "$@"; }
-APRON_register 'cp'
-APRON_register 'ls'
-APRON_register 'df'
-
-# we can even be sneaky and define a mock for a full path to a command
-/bin/ls() { mock_called "$FUNCNAME" "$#" "$@"; }
-APRON_register '/bin/ls'
-
-#
-# call some external commands now, notice what happens to
-# the various calls.
-#
-ls /
-cp moe larry
-mv dont overwriteme
-df | sed 3q
-
-#
-# pause mocking temporarily, try to run ls again
-#
-APRON_pause
-ls /
-df | sed 2q
-
-#
-# resume mocking
-#
-APRON_unpause
-/bin/ls /
-
-#
-# Unregister a single mock, others remain
-#
-APRON_unregister 'ls'
-ls /
-df
-
-#
-# Unregister all mocks, but leave mocking enabled
-#
-APRON_unregister_all
-df
-badcommand
-
-#
-# Disable mocking, return to normal life
-#
-APRON_disable
-df | awk 'NR == 3 { exit; } 1'
-ls /

0 comments on commit 65a8cf4

Please sign in to comment.