#[allow(unused_imports)]
use crate::error::ErrorCode;

use singe_cuda_sys::driver;

use crate::{error::Result, try_cuda};

/// Returns the version of CUDA supported by the driver.
/// The version is returned as (1000 \* major + 10 \* minor).
/// For example, CUDA 9.2 would be represented by 9020.
///
/// Note:
///
/// Note that this function may also return error codes from previous, asynchronous launches.
pub fn version() -> Result<i32> {
    let mut version: i32 = 0;
    unsafe {
        try_cuda!(driver::cuDriverGetVersion(&raw mut version))?;
    }
    Ok(version)
}

#[cfg(all(test, feature = "testing"))]
mod tests {
    use super::*;
    use crate::testing;

    #[test]
    fn it_works() {
        match version() {
            Ok(version) => assert_ne!(version, 0),
            Err(error) if testing::is_stub_library(&error) => {}
            Err(error) => panic!("{error:?}"),
        }
    }
}
