mirror of
https://github.com/rui314/chibicc
synced 2025-02-22 16:44:03 +03:00
89 lines
1.8 KiB
Bash
Executable File
89 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
chibicc=$1
|
|
|
|
tmp=`mktemp -d /tmp/chibicc-test-XXXXXX`
|
|
trap 'rm -rf $tmp' INT TERM HUP EXIT
|
|
echo > $tmp/empty.c
|
|
|
|
check() {
|
|
if [ $? -eq 0 ]; then
|
|
echo "testing $1 ... passed"
|
|
else
|
|
echo "testing $1 ... failed"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# -o
|
|
rm -f $tmp/out
|
|
./chibicc -c -o $tmp/out $tmp/empty.c
|
|
[ -f $tmp/out ]
|
|
check -o
|
|
|
|
# --help
|
|
$chibicc --help 2>&1 | grep -q chibicc
|
|
check --help
|
|
|
|
# -S
|
|
echo 'int main() {}' | $chibicc -S -o - - | grep -q 'main:'
|
|
check -S
|
|
|
|
# Default output file
|
|
rm -f $tmp/out.o $tmp/out.s
|
|
echo 'int main() {}' > $tmp/out.c
|
|
(cd $tmp; $OLDPWD/$chibicc -c out.c)
|
|
[ -f $tmp/out.o ]
|
|
check 'default output file'
|
|
|
|
(cd $tmp; $OLDPWD/$chibicc -c -S out.c)
|
|
[ -f $tmp/out.s ]
|
|
check 'default output file'
|
|
|
|
# Multiple input files
|
|
rm -f $tmp/foo.o $tmp/bar.o
|
|
echo 'int x;' > $tmp/foo.c
|
|
echo 'int y;' > $tmp/bar.c
|
|
(cd $tmp; $OLDPWD/$chibicc -c $tmp/foo.c $tmp/bar.c)
|
|
[ -f $tmp/foo.o ] && [ -f $tmp/bar.o ]
|
|
check 'multiple input files'
|
|
|
|
rm -f $tmp/foo.s $tmp/bar.s
|
|
echo 'int x;' > $tmp/foo.c
|
|
echo 'int y;' > $tmp/bar.c
|
|
(cd $tmp; $OLDPWD/$chibicc -c -S $tmp/foo.c $tmp/bar.c)
|
|
[ -f $tmp/foo.s ] && [ -f $tmp/bar.s ]
|
|
check 'multiple input files'
|
|
|
|
# Run linker
|
|
rm -f $tmp/foo
|
|
echo 'int main() { return 0; }' | $chibicc -o $tmp/foo -
|
|
$tmp/foo
|
|
check linker
|
|
|
|
rm -f $tmp/foo
|
|
echo 'int bar(); int main() { return bar(); }' > $tmp/foo.c
|
|
echo 'int bar() { return 42; }' > $tmp/bar.c
|
|
$chibicc -o $tmp/foo $tmp/foo.c $tmp/bar.c
|
|
$tmp/foo
|
|
[ "$?" = 42 ]
|
|
check linker
|
|
|
|
# a.out
|
|
rm -f $tmp/a.out
|
|
echo 'int main() {}' > $tmp/foo.c
|
|
(cd $tmp; $OLDPWD/$chibicc foo.c)
|
|
[ -f $tmp/a.out ]
|
|
check a.out
|
|
|
|
# -E
|
|
echo foo > $tmp/out
|
|
echo "#include \"$tmp/out\"" | $chibicc -E - | grep -q foo
|
|
check -E
|
|
|
|
echo foo > $tmp/out1
|
|
echo "#include \"$tmp/out1\"" | $chibicc -E -o $tmp/out2 -
|
|
cat $tmp/out2 | grep -q foo
|
|
check '-E and -o'
|
|
|
|
echo OK
|