Skip to content

Commit

Permalink
Add missing tests, fixing a broken error condition along the way
Browse files Browse the repository at this point in the history
  • Loading branch information
jmert committed Nov 10, 2022
1 parent 13ed2bd commit 74d13e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BitFlags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function _bitflag(__module__::Module, T::Union{Symbol, Expr}, x::Vector{Any})
end
basetype = baseexpr::Type{<:Unsigned}
else
_throw_error(typename, T)
_throw_error(T, "bad expression head")
end
if isempty(x)
throw(ArgumentError("no arguments given for BitFlag $typename"))
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ end

@test_throws ArgumentError("no arguments given for BitFlag Foo"
) @macrocall(@bitflag Foo)
@test_throws ArgumentError("invalid argument for BitFlag Foo isa UInt32: bad expression head"
) @macrocall(@bitflag Foo isa UInt32)
@test_throws ArgumentError("invalid argument for BitFlag Foo: Foo::Float64; "
* "base type must be a bitstype unsigned integer"
) @macrocall(@bitflag Foo::Float64 x=1.)
Expand All @@ -103,6 +105,8 @@ end
) @macrocall(@bitflag Foo x=1 y=1)
@test_throws ArgumentError("invalid argument for BitFlag Foo: y = 0; value is not unique"
) @macrocall(@bitflag Foo x=0 y=0)
@test_throws ArgumentError("invalid argument for BitFlag Foo: x; name is not unique"
) @macrocall(@bitflag Foo x=0 x)

# Explicit values must be powers of two
@test_throws ArgumentError("invalid argument for BitFlag Foo: _three = 3; "
Expand All @@ -129,6 +133,9 @@ end
) @macrocall(@bitflag Foo x ? 1 : 2)
@test_throws ArgumentError("invalid argument for BitFlag Foo: 1 = 2"
) @macrocall(@bitflag Foo 1=2)
@test_throws ArgumentError("invalid argument for BitFlag Foo: #1; "
* "not a valid identifier"
) @eval @macrocall(@bitflag Foo $(Symbol("#1")))

# Disallow value overflow
@test_throws ArgumentError("overflow in value \"y\" of BitFlag Foo"
Expand Down

0 comments on commit 74d13e3

Please sign in to comment.