Skip to content

Commit 13aac76

Browse files
committed
refactor(test): Format long strings in expect_exact calls for better readability
1 parent 834e85c commit 13aac76

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

tests/validation/nvs/nvs.ino

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <Arduino.h>
22
#include <Preferences.h>
33

4-
54
struct TestData {
65
uint8_t id;
76
uint16_t value;
@@ -78,16 +77,15 @@ void setup() {
7877
}
7978

8079
Serial.printf("Values from Preferences: ");
81-
Serial.printf("char: %c | uchar: %u | short: %d | ushort: %u | int: %ld | uint: %lu | ",
82-
val_char, val_uchar, val_short, val_ushort, val_int, val_uint);
83-
Serial.printf("long: %lld | ulong: %lu | long64: %lld | ulong64: %llu | ",
84-
val_long, val_ulong, val_long64, val_ulong64);
85-
Serial.printf("float: %.2f | double: %.2f | bool: %s | str: %s | strLen: %s | struct: {id:%u,val:%u}\n",
86-
val_float, val_double, val_bool ? "true" : "false", val_string.c_str(), val_string_buf, test_data.id, test_data.value);
87-
80+
Serial.printf("char: %c | uchar: %u | short: %d | ushort: %u | int: %ld | uint: %lu | ", val_char, val_uchar, val_short, val_ushort, val_int, val_uint);
81+
Serial.printf("long: %lld | ulong: %lu | long64: %lld | ulong64: %llu | ", val_long, val_ulong, val_long64, val_ulong64);
82+
Serial.printf(
83+
"float: %.2f | double: %.2f | bool: %s | str: %s | strLen: %s | struct: {id:%u,val:%u}\n", val_float, val_double, val_bool ? "true" : "false",
84+
val_string.c_str(), val_string_buf, test_data.id, test_data.value
85+
);
8886

8987
// Increment the values
90-
val_char += 1; // Increment char A -> B
88+
val_char += 1; // Increment char A -> B
9189
val_uchar += 1;
9290
val_short += 1;
9391
val_ushort += 1;
@@ -99,7 +97,7 @@ void setup() {
9997
val_ulong64 += 1;
10098
val_float += 1.1f;
10199
val_double += 1.1;
102-
val_bool = !val_bool; // Toggle boolean value
100+
val_bool = !val_bool; // Toggle boolean value
103101

104102
// Increment string values using function
105103
incrementStringValues(val_string, val_string_buf, sizeof(val_string_buf));

tests/validation/nvs/test_nvs.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@ def test_nvs(dut):
55
LOGGER = logging.getLogger(__name__)
66

77
LOGGER.info("Expecting default values from Preferences")
8-
dut.expect_exact("Values from Preferences: char: A | uchar: 0 | short: 0 | ushort: 0 | int: 0 | uint: 0 | long: 0 | ulong: 0 | long64: 0 | ulong64: 0 | float: 0.00 | double: 0.00 | bool: false | str: str0 | strLen: strLen0 | struct: {id:1,val:100}")
8+
dut.expect_exact(
9+
"Values from Preferences: char: A | uchar: 0 | short: 0 | ushort: 0 | int: 0 | uint: 0 | long: 0 | ulong: 0 | "
10+
"long64: 0 | ulong64: 0 | float: 0.00 | double: 0.00 | bool: false | str: str0 | strLen: strLen0 | "
11+
"struct: {id:1,val:100}"
12+
)
913

1014
LOGGER.info("Expecting updated preferences for the first time")
11-
dut.expect_exact("Values from Preferences: char: B | uchar: 1 | short: 1 | ushort: 1 | int: 1 | uint: 1 | long: 1 | ulong: 1 | long64: 1 | ulong64: 1 | float: 1.10 | double: 1.10 | bool: true | str: str1 | strLen: strLen1 | struct: {id:2,val:110}")
15+
dut.expect_exact(
16+
"Values from Preferences: char: B | uchar: 1 | short: 1 | ushort: 1 | int: 1 | uint: 1 | long: 1 | ulong: 1 | "
17+
"long64: 1 | ulong64: 1 | float: 1.10 | double: 1.10 | bool: true | str: str1 | strLen: strLen1 | "
18+
"struct: {id:2,val:110}"
19+
)
1220

1321
LOGGER.info("Expecting updated preferences for the second time")
14-
dut.expect_exact("Values from Preferences: char: C | uchar: 2 | short: 2 | ushort: 2 | int: 2 | uint: 2 | long: 2 | ulong: 2 | long64: 2 | ulong64: 2 | float: 2.20 | double: 2.20 | bool: false | str: str2 | strLen: strLen2 | struct: {id:3,val:120}")
22+
dut.expect_exact(
23+
"Values from Preferences: char: C | uchar: 2 | short: 2 | ushort: 2 | int: 2 | uint: 2 | long: 2 | ulong: 2 | "
24+
"long64: 2 | ulong64: 2 | float: 2.20 | double: 2.20 | bool: false | str: str2 | strLen: strLen2 | "
25+
"struct: {id:3,val:120}"
26+
)

0 commit comments

Comments
 (0)