Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bunch of test cases #183

Merged
merged 5 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cesium.Compiler/stdlib/math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

#include <stdlib.h>
3 changes: 3 additions & 0 deletions Cesium.Compiler/stdlib/stdio.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
__cli_import("Cesium.Runtime.StdIoFunctions::PutS")
void puts(char *s); // TODO[#156]: Change to int

__cli_import("Cesium.Runtime.StdIoFunctions::PutS")
void printf(char* s);
6 changes: 6 additions & 0 deletions Cesium.IntegrationTests/arithmetics_overflow.ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main(void)
{
double f = 1000000042;
char z = f;
return z;
}
7 changes: 7 additions & 0 deletions Cesium.IntegrationTests/array_pointer.ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main(int argc, char *argv[])
{
int a[10];
int* b = &a[1];
*b = 42;
return a[1];
}
21 changes: 21 additions & 0 deletions Cesium.IntegrationTests/atexit.ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdlib.h>
#include <stdio.h>

void f1(void)
{
puts("f1");
}

void f2(void)
{
puts("f2");
}

int main(void)
{
if (!atexit(f1) && !atexit(f2) && !atexit(f2))
return 42;

// atexit registration failed
return -1;
} // <- if registration was successful calls f2, f2, f1
5 changes: 5 additions & 0 deletions Cesium.IntegrationTests/const_variables.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int main(void)
{
const int exit_code = 42;
return exit_code;
}
12 changes: 12 additions & 0 deletions Cesium.IntegrationTests/function_ptr.ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
int foo(int t)
{
return t + 2;
}

typedef int (*foo_t)(int x);

int main(void)
{
foo_t x = &foo;
return x(40);
}
11 changes: 11 additions & 0 deletions Cesium.IntegrationTests/if_condition.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>

int main(void)
{
int x = 10;
if (x > 30) {
return 0;
}

if (x > 44) return -1; else return 42;
}
6 changes: 6 additions & 0 deletions Cesium.IntegrationTests/stack_access.ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main(int argc, char *argv[])
{
int x = 42;
int a[10];
return a[-1];
}
10 changes: 10 additions & 0 deletions Cesium.IntegrationTests/stdlib/abs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <math.h>

int main(int argc, char *argv[])
{
if (abs(-42) != 42) return -1;
if (abs(142) != 142) return -2;
if (abs(-2147483648) != -2147483648) return -2;
if (abs(2147483647) != 2147483647) return 3;
return 42;
}
18 changes: 18 additions & 0 deletions Cesium.IntegrationTests/stdlib/printf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
printf("test");
// Create variables
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
char myLetter = 'D'; // Character

// Print variables
//printf("%d\n", myNum);
//printf("%f\n", myFloatNum);
//printf("%c\n", myLetter);

return 42;
}
11 changes: 11 additions & 0 deletions Cesium.IntegrationTests/struct_subscription.ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
typedef struct
{
int fixedArr[4];
} foo;

int main()
{
foo x;
x.fixedArr[3] = 42;
return x.fixedArr[3];
}
8 changes: 8 additions & 0 deletions Cesium.IntegrationTests/tertiary_operator.ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

int main(void)
{
int time = 20;
(time < 18) ? printf("Good day.") : printf("Good evening.");
return 42;
}
14 changes: 14 additions & 0 deletions Cesium.IntegrationTests/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
puts("test");
int exitCode = abs(-42);
exit(exitCode);
char x = 'c';
char y = '\t';
char z = '\x32';
char w = '\22';
return 0;
}
1 change: 1 addition & 0 deletions Cesium.Runtime/StdLibFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public unsafe static class StdLibFunctions
{
public static int Abs(int value)
{
if (value == int.MinValue) return int.MinValue;
return Math.Abs(value);
}
Comment on lines 8 to 12
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that's a gimmick. Let's write a unit test for the standard library, then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can, but I mostly think that should do that as part of "acceptance testing", but in retrospection after I think a bit on this I do agree with you. That's subsystem should be tested.


Expand Down