# How to test whether evaluating an expression produces no output at all?

**URL:** https://discourse.julialang.org/t/how-to-test-whether-evaluating-an-expression-produces-no-output-at-all/86102
**Category:** General Usage
**Tags:** testing
**Created:** [August 21, 2022, 7:40pm UTC](https://discourse.julialang.org/t/how-to-test-whether-evaluating-an-expression-produces-no-output-at-all/86102 "2022-08-21T19:40:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [August 21, 2022, 7:40pm UTC](https://discourse.julialang.org/t/how-to-test-whether-evaluating-an-expression-produces-no-output-at-all/86102/1 "2022-08-21T19:40:06Z")

</div>

- [`@test_logs`](https://docs.julialang.org/en/v1/stdlib/Test/#Testing-Log-Statements) tests for log output
- [`@test_nowarn`](https://docs.julialang.org/en/v1/stdlib/Test/#Test.@test_nowarn) tests that `stdout` is empty (and, despite the name, isn’t meant strictly for the `@warn` macro)

How to test whether `stdout` is empty as well? How to test whether an expression didn’t output _anything_ (log messages or anything else) to `stderr` _and_ `stdout`?

I tried to redirect `stdout` and `stderr` to `IOBuffer`s, but it [didn’t work](https://discourse.julialang.org/t/capturing-available-data-written-to-redirected-stdout-and-or-stderr/6378/5).

---

<div class="post-metadata">

### Author: ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)
#### Post date: [August 22, 2022, 3:24am UTC](https://discourse.julialang.org/t/how-to-test-whether-evaluating-an-expression-produces-no-output-at-all/86102/2 "2022-08-22T03:24:06Z")

</div>

Could you post a simple code example showing what you have tried?

---

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [August 22, 2022, 12:20pm UTC](https://discourse.julialang.org/t/how-to-test-whether-evaluating-an-expression-produces-no-output-at-all/86102/3 "2022-08-22T12:20:04Z")

</div>

The last link in my post is a link to the example, but here it is again. I tried to `redirect_stdio` to some `IOBuffer`s:

```julia
buf_stdout, buf_stderr = IOBuffer(), IOBuffer()
redirect_stdio(stdout=buf_stdout, stderr=buf_stderr, stdin=devnull) do
    @info "Hello!"
end

```

I then planned to test whether `length(take!(buf_stdout)) == 0` (and similarly for `buf_stderr`).

However, it produced this error:

```
MethodError: no method matching (::Base.RedirectStdStream)(::IOBuffer)

```

---

<div class="post-metadata">

### Author: ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)
#### Post date: [August 22, 2022, 7:58pm UTC](https://discourse.julialang.org/t/how-to-test-whether-evaluating-an-expression-produces-no-output-at-all/86102/4 "2022-08-22T19:58:08Z")

</div>

Yes, it looks like you have hit an issue that has been around for a long time.

The only solution I can think of is to redirect to a temporary file or a socket, but of course that is not very elegant and I could imagine that you have seen that solution already. The other solution would be to make a pull request fixing this in the next release of Julia 😬
