Skip to content

Commit 65f70f2

Browse files
authored
fix tag filtering bug (#47)
* fix tag filtering bug * fix/add tests
1 parent 46b1d5a commit 65f70f2

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/groups.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,40 @@ end
171171

172172
# normal union doesn't have the behavior we want
173173
# (e.g. union(["1"], "2") === ["1", '2'])
174-
vcatunion(args...) = unique(vcat(args...))
174+
keyunion(args...) = unique(vcat(args...))
175+
176+
function tagunion(args...)
177+
unflattened = keyunion(args...)
178+
result = Any[]
179+
for i in unflattened
180+
if isa(i, Tuple)
181+
for j in i
182+
push!(result, j)
183+
end
184+
else
185+
push!(result, i)
186+
end
187+
end
188+
return result
189+
end
175190

176191
function loadtagged!(f::TagFilter, dest::BenchmarkGroup, src::BenchmarkGroup,
177192
group::BenchmarkGroup, keys::Vector, tags::Vector)
178-
ismatch = f.predicate(tags)
179-
if ismatch
193+
if f.predicate(tags)
180194
child_dest = createchild!(dest, src, keys)
181195
for (k, v) in group
182196
if isa(v, BenchmarkGroup)
183-
loadtagged!(f, dest, src, v, vcatunion(keys, k), vcatunion(tags, k, v.tags))
184-
else
197+
loadtagged!(f, dest, src, v, keyunion(keys, k), tagunion(tags, k, v.tags))
198+
elseif isa(child_dest, BenchmarkGroup)
185199
child_dest[k] = v
186200
end
187201
end
188202
else
189203
for (k, v) in group
190204
if isa(v, BenchmarkGroup)
191-
loadtagged!(f, dest, src, v, vcatunion(keys, k), vcatunion(tags, k, v.tags))
205+
loadtagged!(f, dest, src, v, keyunion(keys, k), tagunion(tags, k, v.tags))
206+
elseif f.predicate(tagunion(tags, k))
207+
createchild!(dest, src, keyunion(keys, k))
192208
end
193209
end
194210
end
@@ -202,8 +218,10 @@ function createchild!(dest, src, keys)
202218
k = first(keys)
203219
src_child = src[k]
204220
if !(haskey(dest, k))
205-
dest_child = similar(src_child)
221+
isgroup = isa(src_child, BenchmarkGroup)
222+
dest_child = isgroup ? similar(src_child) : src_child
206223
dest[k] = dest_child
224+
!(isgroup) && return
207225
else
208226
dest_child = dest[k]
209227
end

test/GroupsTests.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,17 @@ gnest = BenchmarkGroup(["1"],
181181
"2" => BenchmarkGroup(["3"], 1 => 1),
182182
4 => BenchmarkGroup(["3"], 5 => 6),
183183
7 => 8,
184-
"a" => BenchmarkGroup(["3"], "a" => :a),
184+
"a" => BenchmarkGroup(["3"], "a" => :a, (11, "b") => :b),
185185
9 => BenchmarkGroup(["2"],
186186
10 => BenchmarkGroup(["3"]),
187187
11 => BenchmarkGroup()))
188188

189-
@test leaves(gnest) == [([7],8), ([4,5],6), (["2",1],1), (["a","a"], :a)]
189+
@test leaves(gnest) == [([7],8), ([4,5],6), (["2",1],1), (["a", (11, "b")], :b), (["a","a"], :a)]
190+
191+
@test gnest[@tagged 11 || 10] == BenchmarkGroup(["1"],
192+
"a" => BenchmarkGroup(["3"],
193+
(11, "b") => :b),
194+
9 => gnest[9])
190195

191196
@test gnest[@tagged "3"] == BenchmarkGroup(["1"], "2" => gnest["2"], 4 => gnest[4], "a" => gnest["a"],
192197
9 => BenchmarkGroup(["2"], 10 => BenchmarkGroup(["3"])))

0 commit comments

Comments
 (0)