ExpectationStubs.all_expectations_used
— Methodall_expectations_used(stub::Stub)
Checks that every expectation setup for the stub was actually used. It is good to have this as a sanity check at the end of your test script using the stub.
ExpectationStubs.@expect
— Macro@expect(defn)
Prepares a stub, lets it know to expect a function call matching the defn
, and to return the result.
Has several forms, which align to julia function declations. Examples:
@expect(foo(1, 1.5)=10)
this prepares the stubfoo
, to return 10, if it gets given the input(1, 1.5)
@expect(foo(3, ::Int)=20)
this prepares the stubfoo
, to return 20, if it gets given the input with first arguement 3, and second argument anyInt
@expect(foo(5, ::Any)=30)
this prepares the stubfoo
, to return 30, if it gets given the input with first arguement 5, and second argument any type@expect(foo(Any, ::Any)=40)
this prepares the stubfoo
, to return 40, if it is given 2 arguements
Notes that you can not for the same stub both the declare that it is bound by type (i.e. that it can take anything of a given type), and declare that it is bound by value, for the same parameter.
Note that the result can not depend on the arguments of the function. This is intentional, as it is there to keep your Stubs simple and to the point. So you don't end up needing to test your tests.
Currently does not support KWArgs.
ExpectationStubs.@stub
— Macro@stub(name)
Declares that you will be making a stub function called name
. The key difference between a stub and a julia function, is that stubs can have values for arguements declared, which must match, as well as having types which must match. Also they are simpler, in that they can not varying their return result based on argument.
Once you have declared a stub, you should use @expect
to declare what it should respond to.
Calling methods that do not exist (with values provided), will result in Errors. This is intentional, as the stub exists to check that your function is only called with the arguements that you say are valid.
ExpectationStubs.@usecount
— Macro@usecount(defn)
Like @used
but returns the count of how many times the particular expectation was called.
Syntax is the same.
ExpectationStubs.@used
— Macro@used(defn)
Returns true if a particular expectionation was used. Syntax is similar to @expect
Like @expect
the key can be a value or a type. It does not have to match to the one that was used in @expect
Normally one would used this inside a test:
@test @used(foo(1, 1.5))
test thatfoo
was called with(1, 1.5)
@test @used(foo(3, ::Int))
test thefoo
was called with 3 and some Int@test !@used(foo(5, ::Any))
test thatfoo
was never called with the first arg 5 (and exactly 2 args)@test !@used(foo(Any, ::Any))
test tjatfoo
was never alled with 2 args
ExpectationStubs.DoNotCare
— TypeDoNotCare{T}
A type that is equal to all things that are of type <:T. For internal use. Will interact weirdly with hash based dicts
ExpectationStubs.ExpectationValueMismatchError
— TypeExpectationValueMismatchError
Similar to a julia MethodError This is thrown if a call was made on a stub, but the values/types did not match those that were expected.
ExpectationStubs.get_all_matches
— Methodget_all_matches(vd::VectorDict, key)
Returns all values matching the key
ExpectationStubs.name_argvals_and_sig
— Methodname_argvals_and_sig(defn)
Does the extraction of these as is needed for @used
and @usedcounts
ExpectationStubs.onlyesc
— Methodonlyesc(v)
Like esc
, except it ignores things that can not be escaped. Eg literals.
Internal use
ExpectationStubs.split_vals_and_sig
— Methodsplit_vals_and_sig(argsexpr)
Takes an expression from a function definition's args eg :([a::Int, ::Integer])
and breaks it down into the values, and the types. When value is not given it subsitutes DoNotCare()
, when type is not given it subsitutes typeof(val)
Returns a tuple of each, with all things in expression/symbol form.
Internal use
ExpectationStubs.usecount
— Methodusecount(stub:Stub, arg)
Returns how many times the stub
has been called with a matching argument