Skip to content

Commit f28dc1e

Browse files
committed
add native tests runner
1 parent f7108f3 commit f28dc1e

File tree

17 files changed

+742
-0
lines changed

17 files changed

+742
-0
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,18 @@ jobs:
2222

2323
- name: Run the default task
2424
run: bundle exec rake
25+
26+
test-native:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
32+
- name: Set up Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: head
36+
bundler-cache: true
37+
38+
- name: Run native tests
39+
run: make test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010

1111
/lib/yarp/yarp.*
1212
test.rb
13+
test-native/run-one
14+
*.dSYM

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CFLAGS += -fsanitize=address -g
2+
CFLAGS += -Wall
3+
4+
LSAN_OPTIONS = suppressions=test-native/LSan.supp:print_suppressions=0
5+
6+
test: test-native/run-one
7+
LSAN_OPTIONS=$(LSAN_OPTIONS) ASAN_OPTIONS=detect_leaks=1 ./test-native/run-all.sh
8+
9+
test-native/run-one: test-native/run-one.c
10+
$(CC) $(CFLAGS) $< -o $@
11+
12+
clean:
13+
rm -f test-native/run-one
14+
15+
.PHONY: test clean

bin/templates/token_type.c.erb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "token_type.h"
2+
#include <string.h>
23

34
const char *
45
token_type_to_str(yp_token_type_t token_type)
@@ -12,3 +13,16 @@ token_type_to_str(yp_token_type_t token_type)
1213
return "MAXIMUM";
1314
}
1415
}
16+
17+
yp_token_type_t
18+
token_type_from_str(const char *s)
19+
{
20+
<%- tokens.each do |token| -%>
21+
if (strcmp(s, "<%= token.name %>") == 0) {
22+
return YP_TOKEN_<%= token.name %>;
23+
}
24+
<%- end -%>
25+
26+
// Fallback
27+
return YP_TOKEN_INVALID;
28+
}

bin/templates/token_type.h.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ typedef enum yp_token_type {
99
} yp_token_type_t;
1010

1111
const char *token_type_to_str(yp_token_type_t token_type);
12+
yp_token_type_t token_type_from_str(const char *s);
1213

1314
#endif // YARP_TOKEN_TYPE_H

0 commit comments

Comments
 (0)