Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit d42926d

Browse files
authored
Add macro hygiene test (#10)
* hide the forbidden symbol before Alex Arslan sees it * add macro hygeine test
1 parent 8c39812 commit d42926d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/BenchmarkHistograms.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ function Base.show(io::IO, ::MIME"text/plain", bp::BenchmarkHistogram; nbins=NBI
5757
println(io)
5858
end
5959
print(io, "min: ", minstr, "; mean: ", meanstr, "; median: ", medstr, "; max: ", maxstr, ".")
60+
return nothing
6061
end
6162

6263
macro benchmark(exprs...)
63-
quote
64+
return esc(quote
6465
$BenchmarkHistogram($BenchmarkTools.@benchmark($(exprs...)))
65-
end |> esc
66+
end)
6667
end
6768

6869
# We vendor some pretty-printing methods from BenchmarkTools

test/runtests.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import BenchmarkTools
44

55

66
function counting_tests(nbins=nothing)
7-
bp = @benchmark 1+1
8-
output = sprint(show, MIME"text/plain"(), bp)
7+
bh = @benchmark 1+1
8+
output = sprint(show, MIME"text/plain"(), bh)
99

1010
# Don't want to test the exact string since the stats will
1111
# fluctuate. So let's just test that it contains the right
@@ -30,9 +30,9 @@ end
3030

3131

3232
function empty_test()
33-
bp = @benchmark 1+1
34-
empty!(bp.trial.times)
35-
output = sprint(show, MIME"text/plain"(), bp)
33+
bh = @benchmark 1+1
34+
empty!(bh.trial.times)
35+
output = sprint(show, MIME"text/plain"(), bh)
3636

3737
# Don't want to test the exact string since the stats will
3838
# fluctuate. So let's just test that it contains the right
@@ -63,7 +63,6 @@ function with_bins(f, nbins)
6363
end
6464

6565
@testset "BenchmarkHistograms.jl" begin
66-
6766
@testset "Exports" begin
6867
@test symdiff(names(BenchmarkTools), names(BenchmarkHistograms)) == [:BenchmarkHistograms]
6968
end
@@ -76,4 +75,10 @@ end
7675
end
7776
end
7877

78+
# Macro hygiene test; done in global scope intentionally
79+
f(x) = x+1
80+
y=10
81+
bh = @benchmark f($y)
82+
@test bh isa BenchmarkHistograms.BenchmarkHistogram
83+
7984
include("vendor.jl")

0 commit comments

Comments
 (0)