vscode 运行Rust cargo test时显示log输出

发布时间 2023-08-05 15:43:36作者: jing砸鸭

使用以下tasks.json

对于log库的输出(info,debug,warn...) 需要 在test方法上一行加 #[test_log::test] (来自 test-log https://crates.io/crates/test-log)


{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "problemMatcher": [
                "$rustc"
            ],
            "command": "cargo",
            "args": [
                "test",
                "'--'",
                "--nocapture",
            ],
            "group": "test",
            "label": "rust: cargo test nocapture"
        }
    ],
    "options": {
        "env": {
            "RUST_LOG": "DEBUG"
        }
    }
}