Skip to content

Commit

Permalink
separate and expand flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Jacobs committed Mar 17, 2018
1 parent aa4c416 commit aa1c066
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
19 changes: 10 additions & 9 deletions c
Expand Up @@ -182,24 +182,25 @@ for f in "${comp[@]}"; do
done

# final operations before compilation
final_comp=()
rest=()
flags=()
for f in "${comp[@]}"; do
# skip empty elements
[[ -z "$f" ]] && break

# remove shebangs
if [[ -f "$f" ]] && [[ "$(head -n1 "$f")" == \#\!* ]]; then
echo "$(tail -n +2 "$f")" > "$f"
fi

[[ -n "$f" ]] && final_comp+=("$f")
done

i=0
for c in "${final_comp[@]}"; do
let i++
echo $i "$c"
# separate the flags from other arguments
[[ "$f" =~ ^- ]] &&\
flags+=("$f") ||\
rest+=("$f")
done

# compile and run
if "$CC" -O2 -o "$binname" "${final_comp[@]}" "${includes[@]}"; then
if "$CC" -O2 -o "$binname" ${flags[@]} "${includes[@]}" "${rest[@]}"; then
run "$@"
else
cleanup
Expand Down
20 changes: 17 additions & 3 deletions tests/examples/test.sh
Expand Up @@ -7,11 +7,25 @@ header1 "Test #6: Ensure ./examples are running correctly."
files=("dns.c" "hello.c" "hello.cpp" "rand.c")
returns=(1 0 0 0 1)

for i in `seq 0 $((${#files[@]} - 1))`; do
for shebang in $c ""; do
eval $shebang ../examples/${files[$i]}
for shebang in "" "$c"; do
[ -z "$shebang" ] &&\
header2 "using shebang" ||\
header2 "calling directly"

for i in `seq 0 $((${#files[@]} - 1))`; do
cmd="$shebang ../examples/${files[$i]}"

# set CFLAGS for non-shebang
unset cf
[ -n "$shebang" ] && cf="-DRUN -std=c99"

# run cmd
echo $cmd
CFLAGS=$cf eval $cmd

assert "return" "$? -eq ${returns[$i]}"
done
echo
done

echo
10 changes: 5 additions & 5 deletions tests/test.sh
Expand Up @@ -4,11 +4,11 @@
source "./test_helpers.sh"

# Run tests
#source ./argument_and_link_test/test.sh
#source ./complex_arguments/test.sh
#source ./stdin/test.sh
#source ./C++/test.sh
#source ./shell/test.sh
source ./argument_and_link_test/test.sh
source ./complex_arguments/test.sh
source ./stdin/test.sh
source ./C++/test.sh
source ./shell/test.sh
source ./examples/test.sh

quit

0 comments on commit aa1c066

Please sign in to comment.