mirror of
https://github.com/kevinnlsamuel/stdouterr.git
synced 2025-12-06 09:55:58 +05:30
init coding and test thing
This commit is contained in:
1
dev/.gitignore
vendored
Normal file
1
dev/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
tests.d
|
||||||
112
dev/test
Executable file
112
dev/test
Executable 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
|
||||||
|
|
||||||
24
src/main.c
Normal file
24
src/main.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char *output = "This is output", *error = "This is an error message";
|
||||||
|
int printOut = 0, printErr = 0;
|
||||||
|
|
||||||
|
void write_stdout(){
|
||||||
|
fprintf(stdout, "%s\n", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_stderr(){
|
||||||
|
fprintf(stderr, "%s\n", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[]) {
|
||||||
|
|
||||||
|
if(argc > 1){
|
||||||
|
//parse the arguments
|
||||||
|
}
|
||||||
|
|
||||||
|
write_stdout();
|
||||||
|
write_stderr();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user