fixed async tests

This commit is contained in:
Max
2022-10-27 18:34:20 +02:00
parent ce4b7fcfff
commit 2a046a3df0
6 changed files with 104 additions and 26 deletions
+3
View File
@@ -87,10 +87,13 @@
//! taiko::TaikoScoreState,
//! };
//!
//! # /*
//! let map = match Beatmap::from_path("/path/to/file.osu") {
//! Ok(map) => map,
//! Err(why) => panic!("Error while parsing map: {}", why),
//! };
//! # */
//! # let map = Beatmap::default();
//!
//! let mods = 8 + 64; // HDDT
//!
+1 -1
View File
@@ -641,7 +641,7 @@ impl ManiaAttributeProvider for PerformanceAttributes {
}
}
#[cfg(not(any(feature = "async_tokio", feature = "async_str")))]
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))]
#[cfg(test)]
mod tests {
use super::*;
+1 -1
View File
@@ -739,7 +739,7 @@ impl OsuAttributeProvider for PerformanceAttributes {
}
}
#[cfg(not(any(feature = "async_tokio", feature = "async_str")))]
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))]
#[cfg(test)]
mod test {
use super::*;
+1 -1
View File
@@ -464,7 +464,7 @@ impl TaikoAttributeProvider for PerformanceAttributes {
}
}
#[cfg(not(any(feature = "async_tokio", feature = "async_str")))]
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))]
#[cfg(test)]
mod test {
use super::*;
+5 -5
View File
@@ -8,22 +8,22 @@ pub use self::mode::{Catch, Mania, Mode, Osu, Taiko};
#[rustfmt::skip]
macro_rules! test_map {
($mode:ident) => {{
#[cfg(not(any(feature = "async_tokio", feature = "async_str")))]
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))]
{ common::test_map::<$mode>() }
#[cfg(any(feature = "async_tokio", feature = "async_str"))]
#[cfg(any(feature = "async_tokio", feature = "async_std"))]
{ common::test_map::<$mode>().await }
}};
}
#[cfg(not(any(feature = "async_tokio", feature = "async_str")))]
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))]
pub fn test_map<M: Mode>() -> Beatmap {
let path = format!("./maps/{}.osu", M::TEST_MAP_ID);
Beatmap::from_path(path).unwrap()
}
#[cfg(any(feature = "async_tokio", feature = "async_str"))]
pub async fn test_map() -> Beatmap {
#[cfg(any(feature = "async_tokio", feature = "async_std"))]
pub async fn test_map<M: Mode>() -> Beatmap {
let path = format!("./maps/{}.osu", M::TEST_MAP_ID);
Beatmap::from_path(path).await.unwrap()
+93 -18
View File
@@ -1,15 +1,99 @@
#![cfg(not(any(feature = "async_tokio", feature = "async_std")))]
use rosu_pp::GameMode;
use rosu_pp::{Beatmap, GameMode};
use crate::common::{Catch, Mania, Osu, Taiko};
mod common;
#[test]
fn parse_osu() {
let map = test_map!(Osu);
#[cfg(not(any(feature = "async_tokio", feature = "async_std")))]
mod sync {
use super::*;
#[test]
fn parse_osu() {
assert_osu(test_map!(Osu));
}
#[test]
fn parse_taiko() {
assert_taiko(test_map!(Taiko));
}
#[test]
fn parse_catch() {
assert_catch(test_map!(Catch));
}
#[test]
fn parse_mania() {
assert_mania(test_map!(Mania));
}
}
#[cfg(feature = "async_tokio")]
mod async_tokio {
use tokio::runtime::Builder as RuntimeBuilder;
use super::*;
#[test]
fn parse_osu() {
RuntimeBuilder::new_current_thread()
.build()
.unwrap()
.block_on(async { assert_osu(test_map!(Osu)) });
}
#[test]
fn parse_taiko() {
RuntimeBuilder::new_current_thread()
.build()
.unwrap()
.block_on(async { assert_taiko(test_map!(Taiko)) });
}
#[test]
fn parse_catch() {
RuntimeBuilder::new_current_thread()
.build()
.unwrap()
.block_on(async { assert_catch(test_map!(Catch)) });
}
#[test]
fn parse_mania() {
RuntimeBuilder::new_current_thread()
.build()
.unwrap()
.block_on(async { assert_mania(test_map!(Mania)) });
}
}
#[cfg(feature = "async_std")]
mod async_tokio {
use super::*;
#[test]
fn parse_osu() {
async_std::task::block_on(async { assert_osu(test_map!(Osu)) });
}
#[test]
fn parse_taiko() {
async_std::task::block_on(async { assert_taiko(test_map!(Taiko)) });
}
#[test]
fn parse_catch() {
async_std::task::block_on(async { assert_catch(test_map!(Catch)) });
}
#[test]
fn parse_mania() {
async_std::task::block_on(async { assert_mania(test_map!(Mania)) });
}
}
fn assert_osu(map: Beatmap) {
assert_eq!(map.mode, GameMode::Osu);
assert_eq!(map.version, 14);
assert_eq!(map.n_circles, 307);
@@ -30,10 +114,7 @@ fn parse_osu() {
assert_eq!(map.breaks.len(), 1)
}
#[test]
fn parse_taiko() {
let map = test_map!(Taiko);
fn assert_taiko(map: Beatmap) {
assert_eq!(map.mode, GameMode::Taiko);
assert_eq!(map.version, 14);
assert_eq!(map.n_circles, 289);
@@ -54,10 +135,7 @@ fn parse_taiko() {
assert_eq!(map.breaks.len(), 0)
}
#[test]
fn parse_catch() {
let map = test_map!(Catch);
fn assert_catch(map: Beatmap) {
assert_eq!(map.mode, GameMode::Catch);
assert_eq!(map.version, 14);
assert_eq!(map.n_circles, 249);
@@ -78,10 +156,7 @@ fn parse_catch() {
assert_eq!(map.breaks.len(), 0)
}
#[test]
fn parse_mania() {
let map = test_map!(Mania);
fn assert_mania(map: Beatmap) {
assert_eq!(map.mode, GameMode::Mania);
assert_eq!(map.version, 14);
assert_eq!(map.n_circles, 2815);