Skip to content

Commit

Permalink
Added perl unit test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
guiquanz committed Mar 17, 2016
1 parent a2e4a89 commit 016d55f
Show file tree
Hide file tree
Showing 57 changed files with 4,048 additions and 0 deletions.
39 changes: 39 additions & 0 deletions t/00_assignment.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test assignment
--- src
#include <stdio.h>
int main()
{
int a;
a = 42;
printf("%d\n", a);
int b = 64;
printf("%d\n", b);
int c = 12, d = 34;
printf("%d, %d\n", c, d);
return 0;
}
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
--- args
--- out
42
64
12, 34
--- err
35 changes: 35 additions & 0 deletions t/01_comment.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test comment
--- src
#include <stdio.h>
int main()
{
printf("Hello\n");
printf("Hello\n"); /* this is a comment */ printf("Hello\n");
printf("Hello\n");
// this is also a comment sayhello();
printf("Hello\n");
return 0;
}
--- args
--- out
Hello
Hello
Hello
Hello
Hello
--- err
51 changes: 51 additions & 0 deletions t/02_printf.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test printf
--- src
#include <stdio.h>
int main()
{
printf("Hello world\n");
int Count;
for (Count = -5; Count <= 5; Count++)
printf("Count = %d\n", Count);
printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there");
printf("Character 'A' is '%c'\n", 65);
printf("Character 'a' is '%c'\n", 'a');
return 0;
}
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
--- args
--- out
Hello world
Count = -5
Count = -4
Count = -3
Count = -2
Count = -1
Count = 0
Count = 1
Count = 2
Count = 3
Count = 4
Count = 5
String 'hello', 'there' is 'hello', 'there'
Character 'A' is 'A'
Character 'a' is 'a'
--- err
56 changes: 56 additions & 0 deletions t/03_struct.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test struct
--- src
#include <stdio.h>
struct fred
{
int boris;
int natasha;
};
void main()
{
struct fred bloggs;
bloggs.boris = 12;
bloggs.natasha = 34;
printf("%d\n", bloggs.boris);
printf("%d\n", bloggs.natasha);
struct fred jones[2];
jones[0].boris = 12;
jones[0].natasha = 34;
jones[1].boris = 56;
jones[1].natasha = 78;
printf("%d\n", jones[0].boris);
printf("%d\n", jones[0].natasha);
printf("%d\n", jones[1].boris);
printf("%d\n", jones[1].natasha);
return 0;
}
--- args
--- out
12
34
12
34
56
78
--- err
44 changes: 44 additions & 0 deletions t/04_for.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test for
--- src
#include <stdio.h>
int main()
{
int Count;
for (Count = 1; Count <= 10; Count++)
{
printf("%d\n", Count);
}
return 0;
}
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
--- args
--- out
1
2
3
4
5
6
7
8
9
10
--- err
50 changes: 50 additions & 0 deletions t/05_array.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test array
--- src
#include <stdio.h>
int main()
{
int Count;
int Array[10];
for (Count = 1; Count <= 10; Count++)
{
Array[Count-1] = Count * Count;
}
for (Count = 0; Count < 10; Count++)
{
printf("%d\n", Array[Count]);
}
return 0;
}
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
--- args
--- out
1
4
9
16
25
36
49
64
81
100
--- err
56 changes: 56 additions & 0 deletions t/06_case.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test case
--- src
#include <stdio.h>
int main()
{
int Count;
for (Count = 0; Count < 4; Count++)
{
printf("%d\n", Count);
switch (Count)
{
case 1:
printf("%d\n", 1);
break;
case 2:
printf("%d\n", 2);
break;
default:
printf("%d\n", 0);
break;
}
}
return 0;
}
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
--- args
--- out
0
0
1
1
2
2
3
0
--- err
53 changes: 53 additions & 0 deletions t/07_function.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

# vi: ft= et tw=4 sw=4

use lib 't/lib';
use Test::sakura 'no_plan';

run_tests();

__DATA__
=== TEST 1: test function
--- src
#include <stdio.h>
int myfunc(int x)
{
return x * x;
}
void vfunc(int a)
{
printf("a=%d\n", a);
}
void qfunc()
{
printf("qfunc()\n");
}
int main()
{
printf("%d\n", myfunc(3));
printf("%d\n", myfunc(4));
vfunc(1234);
qfunc();
return 0;
}
// vim: set expandtab ts=4 sw=3 sts=3 tw=80 :
--- args
--- out
9
16
a=1234
qfunc()
--- err
Loading

0 comments on commit 016d55f

Please sign in to comment.