From 0a3c29c346178cb497fc92d0afc9f7dffb9aed34 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 26 May 2016 06:49:09 -0500 Subject: [PATCH] Fix for removal of limit_output This does something useful only for multiple versions of julia-0.5, since `limit_output(io)` was introduced (+1936) and then removed (+4305). Prior to that, you couldn't call `limit_output` on an `io` object. For earlier julia versions, this just evaluates as `false`. For, e.g., BenchmarkTools, it seems important to be able to support a range of julia-0.5 versions. --- src/Compat.jl | 23 +++++++++++++++++++++++ test/runtests.jl | 3 +++ 2 files changed, 26 insertions(+) diff --git a/src/Compat.jl b/src/Compat.jl index d22d3613f..1956a2683 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -357,6 +357,26 @@ function rewrite_pairs_to_tuples!(expr::Expr) return expr end +# rewrites accesses to IOContext dicts +function rewrite_iocontext!(expr::Expr) + if expr.head == :call && expr.args[1] == :get + key = expr.args[3] + if (((isa(key, QuoteNode) && key.value == :limit) || + (isa(key, Expr) && key.head == :quote && key.args[1] == :limit)) + && expr.args[4] == false) + if VERSION >= v"0.5.0-dev+1936" && VERSION < v"0.5.0-dev+4305" + expr.args[1] = :(Base.limit_output) + deleteat!(expr.args, 3:4) + elseif VERSION < v"0.5.0-dev+1936" + expr.head = :quote + expr.args[1] = false + deleteat!(expr.args, 3:4) + end + end + end + expr +end + if VERSION < v"0.4.0-dev+707" macro inline(ex) esc(ex) @@ -515,6 +535,9 @@ function _compat(ex::Expr) elseif VERSION < v"0.4.0-dev+1246" && f == :String ex = Expr(:call, :bytestring, ex.args[2:end]...) end + if VERSION < v"0.5.0-dev+4305" + rewrite_iocontext!(ex) + end elseif ex.head === :curly f = ex.args[1] if VERSION < v"0.4.0-dev+4319" && f === :Tuple diff --git a/test/runtests.jl b/test/runtests.jl index 437a1cda4..d2960c858 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1183,3 +1183,6 @@ if VERSION < v"0.5.0-dev+4267" else @test Compat.KERNEL == Sys.KERNEL end + +io = IOBuffer() +@test @compat(get(io, :limit, false)) == false