From 60316e559333dbc3d1c28ed76202a207d55ff2fe Mon Sep 17 00:00:00 2001 From: ddidderr Date: Sun, 8 May 2022 19:09:38 +0200 Subject: [PATCH] (tests) data-driven tests with macros --- src/main.rs | 1 + src/proto.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/main.rs b/src/main.rs index abb751a..4d644ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![feature(concat_idents)] use std::net::UdpSocket; use std::sync::mpsc; use std::thread::{self, JoinHandle}; diff --git a/src/proto.rs b/src/proto.rs index ca6510a..00baa1d 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -228,9 +228,19 @@ pub enum DNSParseError { #[cfg(test)] mod tests { + macro_rules! data_driven_test { + ($name:expr, $func:expr, $input:literal, $output:literal) => { + #[test] + fn concat_idents!($name, _test) { + assert_eq!($input, $output); + } + } + } mod from_udp_datagram { + data_driven_test!("my_macro_test", somefunc, 5, 5); + mod header_length { use super::super::super::*;