-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathintegration_tests.rs
98 lines (84 loc) · 2.41 KB
/
integration_tests.rs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use anyhow::Result;
use autokernel::{
bridge::{Bridge, SymbolValue, Tristate},
script::{KConfig, LuaScript, Script},
};
mod setup_teardown;
use serial_test::serial;
use setup_teardown::{setup, teardown, teardown_full};
#[test]
#[serial(K)]
fn integration_setup() {
teardown_full();
setup();
}
#[test]
#[serial(K)]
fn integration_test_symbols() {
let bridge = setup();
println!("Testing tristate");
test_symbol_tristate(&bridge);
//TODO more tests
teardown();
}
fn test_symbol_tristate(bridge: &Bridge) {
const SYMBOL: &str = "CMDLINE_BOOL";
let mut sym = bridge.symbol(SYMBOL).unwrap();
// Getting
assert_eq!(sym.name().unwrap(), SYMBOL);
assert_eq!(sym.get_tristate_value(), Tristate::No);
// Setting
sym.set_value_tracked(SymbolValue::Tristate(Tristate::Yes), file!().to_string(), line!(), None)
.unwrap();
assert_eq!(sym.get_tristate_value(), Tristate::Yes);
}
#[test]
#[serial(K)]
fn integration_test_kconfig() {
let bridge = setup();
println!("testing kconfig");
let config = KConfig::from_content("good.kconfig".into(), include_str!("good.kconfig").into()).unwrap();
test_script(&bridge, &config).unwrap();
teardown();
}
#[test]
#[serial(K)]
fn integration_test_luaconfig() {
let bridge = setup();
println!("testing LuaScript");
macro_rules! lua_test {
($name:literal, $code:expr) => {
test_script(&bridge, &LuaScript::from_raw($name.into(), $code.into())).unwrap()
};
}
macro_rules! lua_bad_test {
($name:literal, $code:expr) => {
assert!(
test_script(&bridge, &LuaScript::from_raw($name.into(), $code.into())).is_err(),
$name
)
};
}
bridge
.symbol("MODULES")
.expect("this should have worked for test")
.set_value_tracked(SymbolValue::Tristate(Tristate::Yes), file!().to_string(), line!(), None)
.expect("this was for setting up the test");
lua_test!(
"assign syntax",
r#"
CONFIG_CRYPTO "y"
CONFIG_CRYPTO "m"
CONFIG_CRYPTO "n"
CONFIG_CRYPTO(y)
CONFIG_CRYPTO(m)
CONFIG_CRYPTO(n)
"#
);
lua_test!("test_full_config", include_str!("good.lua"));
lua_bad_test!("bad_literal", "CONFIG_CRYPTO y");
teardown();
}
fn test_script(bridge: &Bridge, script: &impl Script) -> Result<()> {
script.apply(bridge)
}