Help us understand the problem. What is going on with this article?

cargo test で 標準出力をコンソールに流す

More than 5 years have passed since last update.

cargo test を行う際は、println!("{:?}", hoge}; などを行った際に、標準出力には流れません。

この場合の対処方法として

use std::io::Write;

#[test]
fn test_escape() {

    let a = "ab'cd
    e'rf";
    writeln!(&mut std::io::stderr(), "{}", a.escape()).unwrap();

}

このようにすることで、標準エラー出力を行う事ができます。
しかし、テストなのにこんなめんどくさいことしていられません。

その場合は下記のようにすることで標準出力をコンソールに流すことができます。

cargo test -- --nocapture

黒魔術感ありますが、一応これでできます!

参考:
stackoverflow: println! doesn't work in rust unit tests?

nacika_ins
お仕事募集してます
https://nacika.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした