All Projects → JuliaIO → Suppressor.jl

JuliaIO / Suppressor.jl

Licence: other
Julia macros for suppressing and/or capturing output (STDOUT), warnings (STDERR) or both streams at the same time.

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to Suppressor.jl

QSimulator.jl
Unitary and Lindbladian evolution in Julia
Stars: ✭ 19 (-79.79%)
Mutual labels:  julia-language
ProximalOperators.jl
Proximal operators for nonsmooth optimization in Julia
Stars: ✭ 119 (+26.6%)
Mutual labels:  julia-language
Julia-data-science
Data science and numerical computing with Julia
Stars: ✭ 54 (-42.55%)
Mutual labels:  julia-language
BenchmarksPythonJuliaAndCo
Benchmark(s) of numerical programs with Python (and Scipy, Pythran, Numba), Julia and C++.
Stars: ✭ 19 (-79.79%)
Mutual labels:  julia-language
LinearOperators.jl
Linear Operators for Julia
Stars: ✭ 126 (+34.04%)
Mutual labels:  julia-language
DataScienceTutorials.jl
A set of tutorials to show how to use Julia for data science (DataFrames, MLJ, ...)
Stars: ✭ 94 (+0%)
Mutual labels:  julia-language
ComputationalMathematics
Lecture slides and homework assignments for MA5233 Computational Mathematics at the National University of Singapore.
Stars: ✭ 35 (-62.77%)
Mutual labels:  julia-language
YOLO.jl
YOLO Object Detection in Julia
Stars: ✭ 41 (-56.38%)
Mutual labels:  julia-language
juliaimages.github.io
Documentation For JuliaImages
Stars: ✭ 25 (-73.4%)
Mutual labels:  julia-language
Acorn.jl
A pure julia text editor
Stars: ✭ 41 (-56.38%)
Mutual labels:  julia-language
SpineOpt.jl
A highly adaptable modelling framework for multi-energy systems
Stars: ✭ 25 (-73.4%)
Mutual labels:  julia-language
ECharts.jl
Julia package for the Apache ECharts v4 visualization library
Stars: ✭ 80 (-14.89%)
Mutual labels:  julia-language
Expronicon.jl
Collective tools for metaprogramming on Julia Expr
Stars: ✭ 36 (-61.7%)
Mutual labels:  julia-language
DataFrames
Welcome to DataFrames.jl with Bogumił Kamiński
Stars: ✭ 106 (+12.77%)
Mutual labels:  julia-language
IterTools.jl
Common functional iterator patterns
Stars: ✭ 124 (+31.91%)
Mutual labels:  julia-language
NotebookToLaTeX.jl
A Julia package for converting your Pluto and Jupyter Notebooks into beautiful Latex.
Stars: ✭ 70 (-25.53%)
Mutual labels:  julia-language
static-export-template
A template to automatically convert Pluto notebooks to an HTML website with GitHub Pages. Demo page:
Stars: ✭ 70 (-25.53%)
Mutual labels:  julia-language
Scientific-Programming-in-Julia
Repository for B0M36SPJ
Stars: ✭ 32 (-65.96%)
Mutual labels:  julia-language
jill.py
A cross-platform installer for the Julia programming language
Stars: ✭ 202 (+114.89%)
Mutual labels:  julia-language
Oracle.jl
Oracle Database driver for the Julia language.
Stars: ✭ 32 (-65.96%)
Mutual labels:  julia-language

Suppressor

Travis Build status CoverAlls CodeCov

Julia macros for suppressing and/or capturing output (stdout), warnings (stderr) or both streams at the same time.

Installation

julia> Pkg.add("Suppressor")

Usage

julia> using Suppressor

julia> using Compat: @warn  # on 0.6

julia> @suppress begin
           println("This string doesn't get printed!")
           @warn("This warning is ignored.")
       end

julia> @suppress_out begin
           println("This string doesn't get printed!")
           @warn("This warning is important")
       end
┌ Warning: This warning is important
└ @ Main REPL[4]:3

julia> @suppress_err begin
           println("This string gets printed!")
           @warn("This warning is unimportant")
       end
This string gets printed!

julia> @suppress begin
           println("This string doesn't get printed!")
           @warn("This warning is ignored.")
           error("Remember that errors are still printed!")
       end
ERROR: Remember that errors are still printed!

The suppress macros return whatever the given expression returns, but Suppressor also provides @capture_out and @capture_err macros that work similiarly to their @suppress_ cousins except they return any output as a string:

julia> output = @capture_out begin
    println("should get captured, not printed")
end;

julia> output == "should get captured, not printed\n"
true

julia> output = @capture_err begin
    @warn("should get captured, not printed")
end;

julia> output[1:56] == "┌ Warning: should get captured, not printed\n└ @ Main"
true

NOTE: the following example only works on Julia 0.6; on later versions of Julia the color codes are never captured

Often when capturing output for test purposes it's useful to control whether color is enabled or not, so that you can compare with or without the color escape characters regardless of whether the julia process has colors enabled or disabled globally. You can use the @color_output macro for this:

@color_output false begin
    output = @capture_err begin
        warn("should get captured, not printed")
    end
end
@test output == "WARNING: should get captured, not printed\n"

@color_output true begin
    output = @capture_err begin
        warn("should get captured, not printed")
    end
end
@test output == "\e[1m\e[33mWARNING: \e[39m\e[22m\e[33mshould get captured, not printed\e[39m\n"

Variable Scope

The macros in Suppressor.jl need to wrap the given expression in a try...finally block to make sure that everything is cleaned up correctly. This means that any variables introduced within the macro expression aren't in-scope afterwards. To work around this you can use local to introduce the variable before the block, for example:

local x
output = @capture_out x = loudfunction()
println(x) # x is available here
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].