Skip to content

Commit 7929ddc

Browse files
committed
Add comprehensive short type tests to driver.sh
- Add overflow behavior tests for char, short, and int types - Add sizeof tests for short type and struct containing short - Add union size test with short member - Ensure test coverage for short type functionality
1 parent acf4f9b commit 7929ddc

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/driver.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,37 @@ declare -a arithmetic_tests=(
400400
run_expr_tests arithmetic_tests
401401
expr 6 "111 % 7"
402402

403+
# Category: Overflow Behavior
404+
begin_category "Overflow Behavior" "Testing integer overflow handling"
405+
406+
try_output 0 "-2147483647" << EOF
407+
int main()
408+
{
409+
int a = 2147483647;
410+
a += 2;
411+
printf("%d\n", a);
412+
return 0;
413+
}
414+
EOF
415+
416+
try_output 0 "-32767" << EOF
417+
int main() {
418+
short a = 32767;
419+
a += 2;
420+
printf("%d\n", a);
421+
return 0;
422+
}
423+
EOF
424+
425+
try_output 0 "-127" << EOF
426+
int main() {
427+
char a = 127;
428+
a += 2;
429+
printf("%d\n", a);
430+
return 0;
431+
}
432+
EOF
433+
403434
# Category: Comparison Operations
404435
begin_category "Comparison Operations" "Testing relational and equality operators"
405436

@@ -2097,6 +2128,16 @@ typedef struct {
20972128
} struct_t;
20982129
int main() { return sizeof(struct_t*); }
20992130
EOF
2131+
2132+
try_ 6 << EOF
2133+
typedef struct {
2134+
int x;
2135+
short y;
2136+
} struct_t;
2137+
2138+
int main() { return sizeof(struct_t); }
2139+
EOF
2140+
21002141
# sizeof enum
21012142
try_ 4 << EOF
21022143
typedef enum {
@@ -2111,6 +2152,7 @@ items 4 "int x = 42; return sizeof(x);"
21112152
items 4 "int arr[5]; return sizeof(arr[0]);"
21122153
items 4 "int x = 10; int *ptr = &x; return sizeof(*ptr);"
21132154
items 1 "char c = 'A'; return sizeof(c);"
2155+
items 2 "short s = 100; return sizeof(s);"
21142156
items 4 "int a = 1, b = 2; return sizeof(a + b);"
21152157

21162158
# sizeof with complex expressions
@@ -4761,6 +4803,17 @@ int main() {
47614803
}
47624804
EOF
47634805

4806+
try_ 2 << EOF
4807+
typedef union {
4808+
short s; /* 2 bytes */
4809+
char c; /* 1 byte */
4810+
} size_union_t;
4811+
4812+
int main() {
4813+
return sizeof(size_union_t); /* Returns 2 (size of short) */
4814+
}
4815+
EOF
4816+
47644817
# Union with different data types
47654818
try_output 0 "Value as int: 1094795585, as char: 65" << EOF
47664819
typedef union {

0 commit comments

Comments
 (0)