Skip to content

Commit

Permalink
[Rust]簡単なテストコードとtestingライブラリの導入 (#134)
Browse files Browse the repository at this point in the history
* 簡単なテストコードとtestingライブラリの導入

参考になりそうな簡単なテストコードと独断ですがtestingライブラリを導入しました

* pull_request時にtestが実行されるようにした
  • Loading branch information
qwerty2501 authored May 15, 2022
1 parent ffd69d3 commit 57e4c27
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test workflow
on: [push]
on: [push, pull_request]
jobs:
rust-lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions crates/voicevox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ derive-new = "0.5.9"
once_cell = "1.10.0"
thiserror = "1.0.31"

[dev-dependencies]
rstest = "0.12.0"
pretty_assertions = "1.2.1"

[build-dependencies]
cbindgen = "0.23.0"
18 changes: 18 additions & 0 deletions crates/voicevox_core/src/c_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::Mutex;
*/

#[repr(C)]
#[derive(Debug, PartialEq)]
#[allow(non_camel_case_types)]
pub enum VoicevoxResultCode {
// C でのenum定義に合わせて大文字で定義している
Expand Down Expand Up @@ -214,3 +215,20 @@ pub extern "C" fn voicevox_error_result_to_message(
) -> *const c_char {
internal::voicevox_error_result_to_message(result_code).as_ptr() as *const c_char
}

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;

#[rstest]
#[case(Ok(()), VoicevoxResultCode::VOICEVOX_RESULT_SUCCEED)]
#[case(
Err(Error::NotLoadedOpenjtalkDict),
VoicevoxResultCode::VOICEVOX_RESULT_NOT_LOADED_OPENJTALK_DICT
)]
fn convert_result_works(#[case] result: Result<()>, #[case] expected: VoicevoxResultCode) {
let (_, actual) = convert_result(result);
assert_eq!(expected, actual);
}
}
3 changes: 3 additions & 0 deletions crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ mod result;

use error::*;
use result::*;

#[cfg(test)]
use rstest::*;

0 comments on commit 57e4c27

Please sign in to comment.