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; [
rustup
gcc
clang_16
];
shellHook = ''
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin

View file

@ -12,8 +12,18 @@ clean() {
for test in tests/c/*; do
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
echo "error: failed to compile test $test"
@ -21,16 +31,15 @@ for test in tests/c/*; do
exit 1
fi
printf "test $name "
OUTPUT=$("$test_dir/$name")
code="$?"
if [ "$code" -ne "0" ]; then
echo -e "\e[31mFAIL\e[0m"
echo "error: test failed with code $code: $test, running $test_dir/$name"
echo "------ output:"
echo "$OUTPUT"
echo "-----"
echo "error: test failed with code $code: $test, compiled with $flags"
echo "------output"
echo -n "$OUTPUT"
echo "------"
else
echo -e "\e[32mPASS\e[0m"
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[@]}"