Skip to content

Commit 5bdb746

Browse files
authored
Merge pull request #11 from lkdvos/testinferred
add `@testinferred`
2 parents 44a7256 + 23ce71b commit 5bdb746

File tree

6 files changed

+511
-208
lines changed

6 files changed

+511
-208
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TestExtras"
22
uuid = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
33
authors = ["Jutho Haegeman <[email protected]> and contributors"]
4-
version = "0.3.1"
4+
version = "0.3.3"
55

66
[deps]
77
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@
66
This package adds useful additions to the functionality provided by `Test`, the Julia
77
standard library for writing tests.
88

9-
# What's new in version 0.2
9+
# What's new in version 0.3.3
1010

11-
* The way in which `@constinferred` defines a new function has been changed so as to avoid
12-
"method overwrite" warnings in Julia v1.10 and higher.
13-
* Since Julia v1.8, the default `Test.@testset` prints elapsed timings of tests, thereby
14-
replicating the behaviour of `@timedtestset` and making the latter superfluous. However,
15-
`@timedtestset` and its associated test set type `TimedTestSet` remains available in
16-
TestExtras.jl in order to support older Julia versions. It is now a literal copy of the
17-
`DefaultTestSet` implementation as in the `Test` standard library of Julia 1.8 and thus
18-
also supports the `verbose` keyword.
11+
* Introduction of a `@testinferred` macro, that unlike `@constinferred` can be used inside
12+
functions, but does not apply constant propagation. However, unlike `Test.@inferred`, it
13+
does contribute to the test results.
1914

2015
# Short description of the package
2116

22-
The first feature of TestExtras.jl is a macro `@constinferred`, which is a replacement of
23-
`Test.@inferred` but with two major differences.
17+
The first feature of TestExtras.jl are the macros `@testinferred` and `@constinferred`,
18+
which are a replacement of `Test.@inferred` but with two major differences.
2419

2520
1. Unlike `Test.@inferred`, the comparison between the actual and inferred runtype is a
2621
proper test which contributes to the total number of passed or failed tests.
@@ -39,6 +34,12 @@ The first feature of TestExtras.jl is a macro `@constinferred`, which is a repl
3934
in the test, for example because you want to loop over possible values. In that case,
4035
you can interpolate the value into the `@constinferred` expression.
4136

37+
However, because this macro works by defining a new function, it cannot be used inside
38+
other functions. Therefore, `@testinferred` is provided as a variant that works inside
39+
functions, but without constant propagation. In fact, `@constinferred f(args...)` is
40+
equivalent to `@testinferred f(args...) constprop=true`, where the optional keyword argument
41+
`constprop` (default `false`) controls whether constant propagation is applied.
42+
4243
Some example is probably more insightful. We define a new function `mysqrt` that is
4344
type-unstable with respect to real values of the argument `x`, at least if the keyword
4445
argument `complex = true`.

src/TestExtras.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module TestExtras
22

3+
export @testinferred, @testinferred_broken
34
export @constinferred, @constinferred_broken
45
export @timedtestset
56
export @include
67
export ConstInferred
78

8-
include("constinferred.jl")
9+
include("testinferred.jl")
910
include("includemacro.jl")
1011

1112
if VERSION >= v"1.8"
@@ -14,7 +15,7 @@ else
1415
include("timedtest.jl")
1516
end
1617

17-
using .ConstInferred: @constinferred, @constinferred_broken
18+
using .TestInferred: @constinferred, @constinferred_broken, @testinferred, @testinferred_broken
1819
using .TimedTests: @timedtestset
1920

2021
end

src/constinferred.jl

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)