This commit is contained in:
nora 2023-10-01 15:28:22 +02:00
parent 9d74d9120c
commit 2f0191768f
6 changed files with 44 additions and 6 deletions

View file

@ -2,6 +2,7 @@
buildInputs = with pkgs; [ buildInputs = with pkgs; [
rustup rustup
gcc gcc
clang_16
]; ];
shellHook = '' shellHook = ''
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin

View file

@ -12,8 +12,18 @@ clean() {
for test in tests/c/*; do for test in tests/c/*; do
name=$(basename $test .c) name=$(basename $test .c)
printf "test $name "
"$SCRIPT_DIR/uwuc-gcc" "$test" -o "$test_dir/$name" flags=$(grep "//@flags: " "$test" | sed 's#//@flags: ##')
grep "//@ignore" "$test" >/dev/null
ignore=$?
if [ "$ignore" -eq "0" ]; then
echo -e "\e[33mIGNORE\e[0m"
continue
fi
"$SCRIPT_DIR/uwuc-gcc" $flags "$test" -o "$test_dir/$name"
if [ "$?" -ne "0" ]; then if [ "$?" -ne "0" ]; then
echo "error: failed to compile test $test" echo "error: failed to compile test $test"
@ -21,16 +31,15 @@ for test in tests/c/*; do
exit 1 exit 1
fi fi
printf "test $name "
OUTPUT=$("$test_dir/$name") OUTPUT=$("$test_dir/$name")
code="$?" code="$?"
if [ "$code" -ne "0" ]; then if [ "$code" -ne "0" ]; then
echo -e "\e[31mFAIL\e[0m" echo -e "\e[31mFAIL\e[0m"
echo "error: test failed with code $code: $test, running $test_dir/$name" echo "error: test failed with code $code: $test, compiled with $flags"
echo "------ output:" echo "------output"
echo "$OUTPUT" echo -n "$OUTPUT"
echo "-----" echo "------"
else else
echo -e "\e[32mPASS\e[0m" echo -e "\e[32mPASS\e[0m"
fi fi

7
tests/c/errno.c Normal file
View file

@ -0,0 +1,7 @@
//@ignore doens't initialize fs yet
#include<errno.h>
int main(void) {
int err = errno;
return err;
}

5
tests/c/stack_prot.c Normal file
View file

@ -0,0 +1,5 @@
//@flags: -fstack-protector-all
//@ignore no support yet
int main(void) {}

9
tests/c/strtol.c Normal file
View file

@ -0,0 +1,9 @@
#include<stdlib.h>
int main(void) {
char *str = "12";
long value = strtol(str, NULL, 10);
if (value != 12) {
return 1;
}
}

7
uwuc-clang Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
args=("-nodefaultlibs" "-nostdlib" "-L${SCRIPT_DIR}/target/debug" "-lrawc")
exec clang "$@" "${args[@]}"