init coding and test thing

This commit is contained in:
kevinnls
2021-03-29 20:19:50 +05:30
parent e7ee3ed6a2
commit 774b2a39b2
3 changed files with 137 additions and 0 deletions

1
dev/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
tests.d

112
dev/test Executable file
View File

@@ -0,0 +1,112 @@
#!/bin/bash
set -e
# set -x for debugging if DEBUG is set
function debug() { set -xv; }
${DEBUG+debug}
# declare project info variables
declare -l project_lang project_name project_version;
project_name='stdouterr'
project_version='v0.1.0-beta'
project_lang='C'
project_root="$( cd .. ; pwd )"
test_dir="${project_root}/dev/tests.d"
[[ ! -d "${test_dir}" ]] && mkdir -p "${test_dir}"
src_dir="${project_root}/src"
c_compilers=('gcc')
cpp_compilers=('g++')
_oname="${project_name:0:5}-${project_version}~test"
oname="$test_dir/${output:-${_oname}}"
_iname="${src_dir}/main.c"
iname="${input:-${_iname}}"
_compileargs=( )
# add args from env or set args based on env
# script version of -o retained unless overridden by env
if [[ -n "${compile_args}" ]]; then
if [[ ! "${compile_args}" =~ /*-o/ ]]; then
compile_args+=( -o "${oname}" )
fi
else
compile_args=( "${_compileargs[@]}" -o "${oname}" )
fi
compile_args+=( "${compile_aargs[@]}" )
case "${project_lang}" in
'c')
compilers=( "${c_compilers[@]}" )
;;
'cpp')
compilers=( "${cpp_compilers[@]}" )
;;
*)
err_unknown_lang
;;
esac
list_compilers(){
for compiler in "${compilers[@]}"; do
echo -e " - ${compiler}\\n"
done
}
err_no_compilers(){
1>&2 echo "ERR: no supported compiler found for ${project_lang}"
1>&2 echo "install one of:"
1>&2 list_compilers
exit 127
}
check_compilers(){
for compiler in "${compilers[@]}"; do
compiler_path=$(command -v "${compiler}" 2>/dev/null)
if [[ -n "${compiler_path}" ]]; then
echo "found compiler: ${compiler}"
compile(){
echo "=== compiling ==="
echo
"${compiler_path}" "${compile_args[@]}" "${iname}"
if [[ $? -eq 0 ]]; then
echo
echo "=== compiled! ==="
return 0
else
echo
echo "=== compile failed! ==="
return 1
fi
}
else
continue
fi
done
{ command -v compile ; } &>/dev/null \
|| err_no_compilers
}
test(){
echo "=== start of test ==="
echo
"${oname}"
echo
echo
echo "=== end of test ==="
}
check_compilers \
&& compile \
&& echo $? \
&& test "$@" \
|| exit 1