Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Rust unit tests #51

Open
qryxip opened this issue Aug 21, 2020 · 1 comment
Open

Generate Rust unit tests #51

qryxip opened this issue Aug 21, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@qryxip
Copy link
Owner

qryxip commented Aug 21, 2020

このようなテンプレートにRustのユニットテストを生成するようにすればVSCodeとかのGUIデバッガで動かせて便利なのではという考え。やるとすればproc-macroも良いが完全にstdのみで動く簡潔なテストがベストか。

use proconio::source::once::OnceSource;
use std::io::Write;

fn main() {
    let mut input = ::std::string::String::new();
    ::std::io::Read::read_to_string(&mut std::io::stdin(), &mut input).unwrap();
    let stdout = ::std::io::stdout();
    let mut output = ::std::io::BufWriter::new(stdout.lock());
    crate::solve(&input, &mut output);
    ::std::io::Write::flush(&mut output).unwrap();
}

fn solve<S: AsRef<str>, W: Write>(input: S, mut output: W) {
    let input = input.as_ref();
    let mut input = OnceSource::from(input);
    macro_rules! input(($($tt:tt)*) => (proconio::input!(from &mut input, $($tt)*)));
    macro_rules! println(($($tt:tt)*) => (writeln!(output, $($tt)*).unwrap()));

    input! {
        n: usize,
    }

    println!("{}", 2 * n);
}
@qryxip qryxip added the enhancement New feature or request label Aug 21, 2020
@qryxip
Copy link
Owner Author

qryxip commented Aug 21, 2020

あるいはintegration-testで

#[allow(dead_code)
#[path = "../src/bin/a.rs"]
mod a;

ってやるか。せっかくRustに密なんだしいつかやりたい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant