Ultimate tester
This commit is contained in:
parent
7e887018c1
commit
66506ce53c
100
.bashrc
100
.bashrc
|
@ -2,8 +2,8 @@ alias v='vim'
|
||||||
alias ..='cd ..'
|
alias ..='cd ..'
|
||||||
alias ...='cd ../..'
|
alias ...='cd ../..'
|
||||||
alias tmux='tmux -2'
|
alias tmux='tmux -2'
|
||||||
alias ft='cc -Wall -Wextra -Werror -o main -xc <(grep -v "////" *.c) && ./main; rm ./main 2>/dev/null; :'
|
alias ft='cc -Wall -Wextra -Werror -o main -xc -- <(grep -v "////" *.c) && ./main; rm -f -- ./main; :'
|
||||||
alias ft2='cc -Wall -Wextra -Werror -o main -xc <(grep -v "////" *.c) && ./main'
|
alias ft2='cc -Wall -Wextra -Werror -o main -xc -- <(grep -v "////" *.c) && ./main'
|
||||||
alias git='EDITOR=vim git'
|
alias git='EDITOR=vim git'
|
||||||
alias cmatrix='cmatrix -cu3 -Cred'
|
alias cmatrix='cmatrix -cu3 -Cred'
|
||||||
alias gca='git add * && git commit -m *'
|
alias gca='git add * && git commit -m *'
|
||||||
|
@ -65,16 +65,24 @@ if [ -f /nfs/homes/tischmid/.config/synth-shell/better-history.sh ] && [ -n "$(
|
||||||
fi
|
fi
|
||||||
|
|
||||||
check () {
|
check () {
|
||||||
|
# Set params
|
||||||
URL="${1}"
|
URL="${1}"
|
||||||
DIR="/tmp/tmp_repo_$(date +%s)"
|
DIR="/tmp/tmp_repo_$(date +%s)"
|
||||||
|
|
||||||
|
# If no URL, get it from current repo
|
||||||
if [ -z "${URL}" ]; then
|
if [ -z "${URL}" ]; then
|
||||||
URL="$(git remote get-url origin)"
|
URL="$(git remote get-url origin)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Clone in temp folder
|
||||||
git clone --quiet "${URL}" "${DIR}"
|
git clone --quiet "${URL}" "${DIR}"
|
||||||
|
|
||||||
|
# Only proceed if clone success
|
||||||
if [ -d "${DIR}" ]; then
|
if [ -d "${DIR}" ]; then
|
||||||
|
# Check the norm and print beautiful message
|
||||||
norminette "${DIR}" && printf '\033[30;102m%s\033[m\n' "Norminette success" || printf '\033[30;101m%s\033[m\n' "Norminette fail!!!"
|
norminette "${DIR}" && printf '\033[30;102m%s\033[m\n' "Norminette success" || printf '\033[30;101m%s\033[m\n' "Norminette fail!!!"
|
||||||
|
|
||||||
|
# Remove temp folder
|
||||||
rm -rf "${DIR}"
|
rm -rf "${DIR}"
|
||||||
else
|
else
|
||||||
printf '\033[30;101m%s\033[m\n' "Could not clone the repo"
|
printf '\033[30;101m%s\033[m\n' "Could not clone the repo"
|
||||||
|
@ -82,30 +90,89 @@ check () {
|
||||||
}
|
}
|
||||||
|
|
||||||
timo_moulinette () {
|
timo_moulinette () {
|
||||||
|
# Set params
|
||||||
subject="${1}"
|
subject="${1}"
|
||||||
ex="${2}"
|
ex="${2}"
|
||||||
|
|
||||||
|
# Arghandle
|
||||||
if [ -z "${subject}" ]; then
|
if [ -z "${subject}" ]; then
|
||||||
echo "Must provide at least one argument. Exiting"
|
printf '%s\n' "Must provide at least one argument. Exiting"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If exercise was not provided, get it from current folder name
|
||||||
if [ -z "${ex}" ]; then
|
if [ -z "${ex}" ]; then
|
||||||
ex="$(basename "${PWD}")"
|
ex="$(basename -- "${PWD}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Search for a compiler
|
||||||
|
if command -v cc >/dev/null 2>&1; then
|
||||||
|
CC="$(command -v cc)"
|
||||||
|
elif command -v gcc >/dev/null 2>&1; then
|
||||||
|
CC="$(command -v gcc)"
|
||||||
|
elif command -v clang >/dev/null 2>&1; then
|
||||||
|
CC="$(command -v clang)"
|
||||||
|
else
|
||||||
|
printf '%s\n' "Could not find a compiler. Exiting"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
git_base="https://git.timo.one/42berlin/piscine-timo-moulinette/raw/branch/master"
|
git_base="https://git.timo.one/42berlin/piscine-timo-moulinette/raw/branch/master"
|
||||||
|
|
||||||
test_file_name="$(find . -mindepth 1 -maxdepth 1 -name '*.c' -type f -exec basename {} \; | sed 's/\.c$/_test.c/g')"
|
# Find the first C file
|
||||||
if [ -z "${test_file_name}" ]; then
|
file_name="$(find . -mindepth 1 -maxdepth 1 -name '*.c' ! -name '*moulinette*' -type f -exec basename {} \; -quit)"
|
||||||
echo "Could not find any C files in the current directory. Exiting"
|
|
||||||
|
# If no C files found, exit
|
||||||
|
if [ -z "${file_name}" ]; then
|
||||||
|
printf '%s\n' "Could not find any C files in the current directory. Exiting"
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Testfiles have the "_test.c" suffix
|
||||||
|
test_file_name="$(printf '%s' "${file_name}" | sed 's/\.c$/_test.c/g')"
|
||||||
|
|
||||||
|
# Full git url to raw file
|
||||||
git_full="${git_base}/${subject}/${ex}/${test_file_name}"
|
git_full="${git_base}/${subject}/${ex}/${test_file_name}"
|
||||||
echo "${git_full}"
|
|
||||||
|
# Name of the C testfile
|
||||||
|
download_file_name="./timo_moulinette_${subject}_${ex}_${test_file_name}"
|
||||||
|
|
||||||
|
# Download tesfile
|
||||||
|
curl -sL "${git_full}" -o "${download_file_name}"
|
||||||
|
|
||||||
|
# Preprocess source file (remove comments)
|
||||||
|
${CC} -dD -E -o "${file_name}.nocomments" -- "${file_name}"
|
||||||
|
|
||||||
|
# Extract function definitions from preprocessed file and append semicolon
|
||||||
|
prototypes="$(cat -- "${file_name}.nocomments" | grep -v '#' | grep ')$' | grep '[a-zA-Z0-9](' | sed 's/$/;/')"
|
||||||
|
|
||||||
|
# Remove preprocessed file
|
||||||
|
rm -f -- "${file_name}.nocomments"
|
||||||
|
|
||||||
|
# Write prototypes to beginning of testfile
|
||||||
|
IFS="$(printf '\n')"
|
||||||
|
for proto in "${prototypes}"; do
|
||||||
|
printf '%s\n' "${proto}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
|
||||||
|
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
|
||||||
|
done
|
||||||
|
IFS="$(printf ' \n\t')"
|
||||||
|
|
||||||
|
# Compile
|
||||||
|
out_binary="timo_moulinette_${subject}_${ex}_$(basename -- "${test_file_name}" .c).out"
|
||||||
|
${CC} -Wall -Wextra -Werror -o "${out_binary}" -xc -- *.c
|
||||||
|
|
||||||
|
# Delete testfile
|
||||||
|
rm -f -- "${download_file_name}"
|
||||||
|
|
||||||
|
# Run binary
|
||||||
|
./${out_binary}
|
||||||
|
rm -f -- "./${out_binary}"
|
||||||
}
|
}
|
||||||
|
|
||||||
prev () {
|
prev () {
|
||||||
ex="$(basename "${PWD}")"
|
|
||||||
ex_num="$(echo "${ex}" | cut -c3-)"
|
|
||||||
if [ -z "${1}" ]; then
|
if [ -z "${1}" ]; then
|
||||||
|
ex="$(basename "${PWD}")"
|
||||||
|
ex_num="$(printf '%s' "${ex}" | cut -c3-)"
|
||||||
next_ex_num="$(( ${ex_num} - 1 ))"
|
next_ex_num="$(( ${ex_num} - 1 ))"
|
||||||
else
|
else
|
||||||
next_ex_num="${1}"
|
next_ex_num="${1}"
|
||||||
|
@ -116,14 +183,23 @@ prev () {
|
||||||
}
|
}
|
||||||
|
|
||||||
next () {
|
next () {
|
||||||
ex="$(basename "${PWD}")"
|
# If no arg, calculate next num
|
||||||
ex_num="$(echo "${ex}" | cut -c3-)"
|
|
||||||
if [ -z "${1}" ]; then
|
if [ -z "${1}" ]; then
|
||||||
|
# Exercise name
|
||||||
|
ex="$(basename "${PWD}")"
|
||||||
|
|
||||||
|
# Exercise num
|
||||||
|
ex_num="$(printf '%s' "${ex}" | cut -c3-)"
|
||||||
|
|
||||||
|
# + 1 for next
|
||||||
next_ex_num="$(( ${ex_num} + 1 ))"
|
next_ex_num="$(( ${ex_num} + 1 ))"
|
||||||
else
|
else
|
||||||
next_ex_num="${1}"
|
next_ex_num="${1}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Pad to two 0's and save in variable "padded"
|
||||||
builtin printf -v padded '%02d' "${next_ex_num}"
|
builtin printf -v padded '%02d' "${next_ex_num}"
|
||||||
|
|
||||||
next_dir="ex${padded}"
|
next_dir="ex${padded}"
|
||||||
builtin cd "../${next_dir}"
|
builtin cd "../${next_dir}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue