Skip to content

Commit 71e8008

Browse files
committed
Add tests
Signed-off-by: Darshan Sen <[email protected]>
1 parent 90a8f03 commit 71e8008

File tree

13 files changed

+121
-104
lines changed

13 files changed

+121
-104
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ commands:
110110
- attach_workspace:
111111
at: .
112112

113-
- run: make check
113+
- run: make test
114114

115115
## JOBS ##
116116

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include vendor/vendorpull/targets.mk
33
include build/system.mk
44
include build/deps.mk
55

6-
all: vendor compile patch check
6+
all: vendor compile patch test
77

88
.PHONY: lief
99
lief: dist/lief
@@ -15,6 +15,6 @@ dist/lief:
1515
cd vendor/lief && python3 ./setup.py $(BUILD_OPTS) build_ext -b ../../$@ -j $(JOBS)
1616

1717

18-
.PHONY: check
19-
check:
20-
$(MAKE) -C examples/
18+
.PHONY: test
19+
test:
20+
./test.sh

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $ ./postject.py --macho-segment-name __ELECTRON /Users/dsanders/electron/src/out
2929
### Testing
3030

3131
```sh
32-
$ make check
32+
$ make test
3333
```
3434

3535
## Design

examples/Makefile

Lines changed: 0 additions & 22 deletions
This file was deleted.

examples/test.S

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/test.c

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/test.cpp

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/test.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

test.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
for test_directory in tests/*
7+
do
8+
if [ -d "$test_directory" ]
9+
then
10+
echo "---- Running $test_directory" 1>&2
11+
TEMPORARY_DIRECTORY="$(mktemp -d)"
12+
pwd="$PWD"
13+
cd "$test_directory"
14+
TEMPORARY_DIRECTORY="$TEMPORARY_DIRECTORY" ./test.sh \
15+
&& EXIT_CODE="$?" || EXIT_CODE="$?"
16+
cd "$pwd"
17+
rm -rf "$TEMPORARY_DIRECTORY"
18+
19+
if [ "$EXIT_CODE" = "0" ]
20+
then
21+
echo "\033[33;32m✓ PASS\x1b[0m $test_directory" 1>&2
22+
else
23+
echo "\033[33;31m× FAIL\x1b[0m $test_directory" 1>&2
24+
exit "$EXIT_CODE"
25+
fi
26+
fi
27+
done
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
#include "../../postject-api.h"
5+
6+
int main()
7+
{
8+
size_t size;
9+
const void *ptr = postject_find_resource("foobar", &size, NULL);
10+
11+
if (ptr && size > 0) {
12+
char *str = (char *)malloc(size + 1);
13+
memset(str, 0, size + 1);
14+
strncpy(str, ptr, size);
15+
printf("%s\n", str);
16+
} else {
17+
printf("Hello world\n");
18+
}
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)