Skip to content

Commit

Permalink
Making sure unit tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
Fur0rem committed Jan 24, 2024
1 parent 165b267 commit 1a61e37
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Unit Tests

on:
push:
branches:
- main

jobs:
format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind
- name: Compile Tests
run: |
make test
- name: Run Tests
run: |
for test in test/bin/*; do
valgrind --leak-check=full --error-exitcode=1 --show-leak-kinds=all --errors-for-leak-kinds=all $test
if [ $? -ne 0 ]; then
exit 1
fi
done
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode/
.bin/
bin/
test/bin/
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
TARGET := ../edgerunner
DEBUG := ../edgerunner_dbg

TEST := ../test
TEST_DBG := ../test_dbg

CC := gcc

DEBUG_FLAGS := -g -fsanitize=address -fsanitize=object-size -fno-optimize-sibling-calls -fsanitize=undefined -fsanitize=leak -fsanitize=alignment
CFLAGS := -Og -std=gnu17 -Wall -Wextra -Wpedantic -Wno-unused-parameter

SRCS := $(wildcard src/*.c)

all: $(TARGET)

$(TARGET): $(SRCS) main.c
$(CC) $(CFLAGS) $^ -o $(TARGET)
$(DEBUG) : $(SRCS) main.c
$(CC) $(CFLAGS) $(DEBUG_FLAGS) $^ -o $(DEBUG)


test: $(TEST)
$(TEST): $(SRCS) $(wildcard test/*.c)
$(CC) $(SRCS) $(CFLAGS) $^ -o test/bin/$(basename $(notdir $^))

File renamed without changes.
9 changes: 9 additions & 0 deletions test/john.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>

int main() {
int* thing = (int*)malloc(sizeof(int));
*thing = 5;
printf("thing = %d\n", *thing);
return 0;
}

0 comments on commit 1a61e37

Please sign in to comment.