File: smoke_test.rs

package info (click to toggle)
rust-cxx 1.0.192-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,808 kB
  • sloc: cpp: 1,625; javascript: 124; sh: 11; makefile: 8
file content (66 lines) | stat: -rw-r--r-- 1,573 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::cpp_compile;
use indoc::indoc;
use quote::quote;

#[test]
fn test_success() {
    let test = cpp_compile::Test::new(quote! {
        #[cxx::bridge]
        mod ffi {
            unsafe extern "C++" {
                include!("include.h");
                pub fn do_cpp_thing();
            }
        }
    });
    test.write_file(
        "include.h",
        indoc! {"
            void do_cpp_thing();
        "},
    );
    test.compile().assert_success();
}

#[test]
fn test_failure() {
    let test = cpp_compile::Test::new(quote! {
        #[cxx::bridge]
        mod ffi {
            unsafe extern "C++" {
                include!("include.h");
            }
        }
    });
    test.write_file(
        "include.h",
        indoc! {r#"
            static_assert(false, "This is a failure smoke test");
        "#},
    );
    let err_msg = test.compile().expect_single_error();
    assert!(err_msg.contains("This is a failure smoke test"));
}

#[test]
#[should_panic = "Unexpectedly more than 1 error line was present"]
fn test_unexpected_extra_error() {
    let test = cpp_compile::Test::new(quote! {
        #[cxx::bridge]
        mod ffi {
            unsafe extern "C++" {
                include!("include.h");
            }
        }
    });
    test.write_file(
        "include.h",
        indoc! {r#"
            static_assert(false, "First error line");
            static_assert(false, "Second error line");
        "#},
    );

    // We `should_panic` inside `expect_single_error` below:
    let _ = test.compile().expect_single_error();
}