Skip to content

Commit

Permalink
Fix Vararg handling on v1.7+ (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG authored Jan 23, 2022
1 parent 4ee3c0d commit 00d6e5c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 22 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI
on:
push:
branches:
- master
pull_request:
jobs:
test:
name: Julia ${{ matrix.version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version:
- 1.6
- 1
- nightly
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
continue-on-error: ${{ matrix.version == 'nightly' }}
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: 1
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SimpleMock"
uuid = "a896ed2c-15a5-4479-b61d-a0e88e2a1d25"
authors = ["Chris de Graaf <[email protected]>"]
version = "1.2.0"
version = "1.2.1"

[deps]
Cassette = "7057c7e9-c182-5462-911a-8362d720325c"
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# SimpleMock [![Docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliatesting.github.io/SimpleMock.jl) [![Build Status](https://travis-ci.com/JuliaTesting/SimpleMock.jl.svg?branch=master)](https://travis-ci.com/JuliaTesting/SimpleMock.jl)
# SimpleMock [![Docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliatesting.github.io/SimpleMock.jl) [![CI](https://github.com/JuliaTesting/SimpleMock.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaTesting/SimpleMock.jl/actions/workflows/CI.yml)

### Notice: kind of broken

This package is [broken in some cases on Julia 1.6 and newer](https://github.com/JuliaTesting/SimpleMock.jl/issues/13), for unknown reasons.
Use at your own risk!

---

A basic mocking module, inspired by Python's [`unittest.mock`](https://docs.python.org/3/library/unittest.mock.html) and implemented with [Cassette](https://github.com/jrevels/Cassette.jl).

Expand Down
4 changes: 4 additions & 0 deletions src/SimpleMock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ using Base: Callable, invokelatest, unwrap_unionall
using Base.Iterators: Pairs
using Core: Builtin, kwftype

if VERSION >= v"1.7"
using Core: TypeofVararg
end

using Cassette: Cassette, Context, overdub, posthook, prehook, recurse, @context

export
Expand Down
15 changes: 14 additions & 1 deletion src/mock_fun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,20 @@ function make_overdub(::Type{Ctx}, f::F, sig::Tuple) where {Ctx <: Context, F}
T_uw = unwrap_unionall(T)
name = gensym()

if T_uw.name.name === :Vararg
if VERSION >= v"1.7" && T_uw isa TypeofVararg
# T === T_uw.
if isdefined(T, :T) && isdefined(T, :N) # Vararg{T, N}.
foreach(1:T.N) do _i
push!(sig_exs, :($name::$(T.T)))
push!(sig_names, name)
name = gensym()
end
else # Vararg{T, N} where {T, N} or Vararg{T, N} where N.
T = Vararg{Any}
push!(sig_exs, :($name::$(T.T)...))
push!(sig_names, :($name...))
end
elseif T_uw.name.name === :Vararg
if T isa UnionAll && T.body isa UnionAll # Vararg{T, N} where {T, N}.
T = Vararg{Any}
end
Expand Down

2 comments on commit 00d6e5c

@christopher-dG
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Fix for some internal Julia 1.7 changes (#17).

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/53011

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.1 -m "<description of version>" 00d6e5c42637003c17e4bcfbab91bb78746d5de5
git push origin v1.2.1

Please sign in to comment.