cmake_parser/doc/command/project/
create_test_sourcelist.rs

1use ::cmake_parser_derive::CMake;
2
3use crate::{CommandScope, ToCommandScope, Token};
4
5/// Create a test driver and source list for building test programs.
6///
7/// Reference: <https://cmake.org/cmake/help/v3.26/command/create_test_sourcelist.html>
8#[derive(CMake, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[cmake(pkg = "crate", default = "tests")]
10pub struct CreateTestSourceList<'t> {
11    #[cmake(positional)]
12    pub source_list_name: Token<'t>,
13    #[cmake(positional)]
14    pub driver_name: Token<'t>,
15    #[cmake(rename = "")]
16    pub tests: Vec<Token<'t>>,
17    pub extra_include: Option<Token<'t>>,
18    pub function: Option<Token<'t>>,
19}
20
21impl<'t> ToCommandScope for CreateTestSourceList<'t> {
22    fn to_command_scope(&self) -> CommandScope {
23        CommandScope::Project
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use crate::doc::cmake_parse::tests::tokens;
31    use crate::*;
32
33    #[test]
34    fn create_test_sourcelist() {
35        let src = include_bytes!("../../../../../fixture/commands/project/create_test_sourcelist");
36        let cmakelists = parse_cmakelists(src).unwrap();
37        let doc = Doc::from(cmakelists);
38
39        assert_eq!(
40            doc.commands(),
41            Ok(vec![
42                Command::CreateTestSourceList(Box::new(CreateTestSourceList {
43                    source_list_name: b"srclist".into(),
44                    driver_name: b"test_runner.cpp".into(),
45                    tests: tokens([b"${cpptestsrc}"]).to_vec(),
46                    extra_include: None,
47                    function: None,
48                })),
49                Command::CreateTestSourceList(Box::new(CreateTestSourceList {
50                    source_list_name: b"Tests".into(),
51                    driver_name: b"CommonCxxTests.cxx".into(),
52                    tests: tokens([
53                        b"ObjectFactory.cxx",
54                        b"otherArrays.cxx",
55                        b"otherEmptyCell.cxx",
56                        b"TestSmartPointer.cxx",
57                        b"SystemInformation.cxx",
58                    ])
59                    .to_vec(),
60                    extra_include: Some(b"hello.h".into()),
61                    function: Some(b"hello_world".into()),
62                })),
63            ])
64        )
65    }
66}