Skip to content

Commit f5df160

Browse files
committed
Add test cases for function parsing validation
Since the previous commit enhanced function parsing so that the parser reports an error if a later function declaration differs from a previous one, this commit adds some test cases to the test suite to validate this functionality.
1 parent d0702f8 commit f5df160

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

tests/driver.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5560,6 +5560,123 @@ int main() {
55605560
}
55615561
EOF
55625562

5563+
begin_category "Function parsing" "Forward declaration and implementation"
5564+
5565+
# Normal case
5566+
try_output 0 "Hello" << EOF
5567+
void func(char *ptr);
5568+
5569+
void func(char *ptr)
5570+
{
5571+
while (*ptr) {
5572+
printf("%c", *ptr);
5573+
ptr++;
5574+
}
5575+
}
5576+
5577+
int main()
5578+
{
5579+
func("Hello");
5580+
return 0;
5581+
}
5582+
EOF
5583+
5584+
# Incorrect function returning type
5585+
try_compile_error << EOF
5586+
void func(void);
5587+
5588+
int **func(void)
5589+
{
5590+
return 3;
5591+
}
5592+
5593+
int main()
5594+
{
5595+
func();
5596+
return 0;
5597+
}
5598+
EOF
5599+
5600+
# Incorrect number of parameters
5601+
try_compile_error << EOF
5602+
void func(void *a);
5603+
5604+
void func(void *a, int x)
5605+
{
5606+
return 3;
5607+
}
5608+
5609+
int main()
5610+
{
5611+
func();
5612+
return 0;
5613+
}
5614+
EOF
5615+
5616+
# Conflicting parameter types
5617+
try_compile_error << EOF
5618+
void func(void *a, char x);
5619+
5620+
void func(void *a, int x)
5621+
{
5622+
return 3;
5623+
}
5624+
5625+
int main()
5626+
{
5627+
func();
5628+
return 0;
5629+
}
5630+
EOF
5631+
5632+
# Conflicting parameter types (variadic parameters)
5633+
try_compile_error << EOF
5634+
void func(void *a);
5635+
5636+
void func(void *a, ...)
5637+
{
5638+
return 3;
5639+
}
5640+
5641+
int main()
5642+
{
5643+
func();
5644+
return 0;
5645+
}
5646+
EOF
5647+
5648+
# Incorrect function returning type (const)
5649+
try_compile_error << EOF
5650+
void *func(int *a, char x);
5651+
5652+
const void *func(int *a, char x)
5653+
{
5654+
return 3;
5655+
}
5656+
5657+
int main()
5658+
{
5659+
func();
5660+
return 0;
5661+
}
5662+
EOF
5663+
5664+
# Conflicting parameter types (const)
5665+
try_compile_error << EOF
5666+
void func(int *a, char x);
5667+
5668+
void func(const int *a, char x)
5669+
{
5670+
return 3;
5671+
}
5672+
5673+
int main()
5674+
{
5675+
func();
5676+
return 0;
5677+
}
5678+
EOF
5679+
55635680
# Test Results Summary
55645681

55655682
echo ""

0 commit comments

Comments
 (0)