Skip to content

Commit

Permalink
Update from 17
Browse files Browse the repository at this point in the history
  • Loading branch information
Administrator committed Dec 4, 2021
1 parent 5100272 commit 42e65ad
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 0 deletions.
25 changes: 25 additions & 0 deletions materials/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM quay.io/school21/alpine:3.13

RUN apk --no-cache --upgrade add \
git \
git-lfs \
curl \
jq \
bash \
build-base \
python3 \
valgrind \
cppcheck \
alpine-sdk \
pcre-dev

RUN mkdir /test

COPY . /project
COPY materials/build/scripts /project/ci-scripts
COPY materials/build/scripts /project/tests
COPY materials/linters /project/tests/linters

WORKDIR "/project"

ENTRYPOINT ["/bin/bash","ci-scripts/test.sh"]
3 changes: 3 additions & 0 deletions materials/build/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
cd ../..
docker rmi -f school21/miniverter:1.0 && docker build . -t school21/miniverter:1.0 -f materials/build/Dockerfile && docker run school21/miniverter:1.0
Empty file.
9 changes: 9 additions & 0 deletions materials/build/scripts/CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
headers=h
linelength=110
filter=-runtime/int
filter=-legal/copyright
filter=-build/include_subdir
filter=-build/include
filter=-readability/casting
filter=-runtime/threadsafe_fn
filter=-runtime/printf
40 changes: 40 additions & 0 deletions materials/build/scripts/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import subprocess
import sys

PATH_TO_PROJECT = '/'.join(os.path.abspath(os.path.dirname(sys.argv[0])).split('/')[:-1])
build_stderr = sys.stdout
build_stdout = sys.stdout

test_name = sys.argv[1]


def get_all_about_make():
file = open(PATH_TO_PROJECT + '/tests/' + test_name + '/compile_file')
all_about_make = file.read().split()
file.close()
return all_about_make


def build(makefile_dir, makefile_name, makefile_stage):
try:
build_result = subprocess.run(['make', makefile_stage],
stderr=build_stderr, stdout=build_stdout, text=True,
cwd=PATH_TO_PROJECT + '/' + makefile_dir)
except Exception as e:
return -1

return build_result.returncode


def run():
makefile_dir, makefile_name, makefile_stage = get_all_about_make()
result_build_code = build(makefile_dir, makefile_name, makefile_stage)

if result_build_code != 0:
print('\nProject build: FAIL\n 0')
else:
print('\nProject build: OK\n 1')


run()
10 changes: 10 additions & 0 deletions materials/build/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Input parameters
test_name=$1

# Path to folders
script_dir="$(dirname ${BASH_SOURCE[0]})"
project_dir="${script_dir}/.."

python3 ${project_dir}/tests/build.py ${test_name}
1 change: 1 addition & 0 deletions materials/build/scripts/s21_cat/compile_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/cat Makefile s21_cat
1 change: 1 addition & 0 deletions materials/build/scripts/s21_grep/compile_file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/grep Makefile s21_grep
49 changes: 49 additions & 0 deletions materials/build/scripts/style_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import subprocess
import os
import sys

PATH_TO_PROJECT = '/'.join(os.path.abspath(os.path.dirname(sys.argv[0])).split('/')[:-1])
PATH_TO_CPPLINT = PATH_TO_PROJECT + '/tests/linters/cpplint.py'

devnull_stderr = sys.stdout
devnull_stdout = sys.stdout


def get_source_filenames():
files = os.listdir(PATH_TO_PROJECT + '/src')
arr_of_files = []
for file in files:
if file[file.find('.') + 1] == 'c':
arr_of_files.append(file)
return arr_of_files


def copy_cpplint_config():
subprocess.run(['cp', PATH_TO_PROJECT + '/tests/CPPLINT.cfg', PATH_TO_PROJECT], stdout=devnull_stdout,
stderr=devnull_stderr)


def delete_cpplint_config():
subprocess.run(['rm', PATH_TO_PROJECT + '/CPPLINT.cfg'], stdout=devnull_stdout, stderr=devnull_stderr)


def style_test_result(arr_of_files):
copy_cpplint_config()

for i in range(len(arr_of_files)):
result_style_test = subprocess.run(
['python3', PATH_TO_CPPLINT, '--extensions=c', '--quiet', PATH_TO_PROJECT + '/src/' + arr_of_files[i]],
stderr=devnull_stderr, stdout=subprocess.PIPE, text=True)
if len(result_style_test.stdout) != 0:
delete_cpplint_config()
return False

delete_cpplint_config()
return True


arr_of_files = get_source_filenames()
if style_test_result(arr_of_files):
print('Style test: OK\n1')
else:
print('Style test: FAIL\n0')
7 changes: 7 additions & 0 deletions materials/build/scripts/style_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Path to folders
script_dir="$(dirname ${BASH_SOURCE[0]})"
project_dir="${script_dir}/.."

python3 ${project_dir}/tests/style_tests.py
60 changes: 60 additions & 0 deletions materials/build/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
echo -e "\n"
echo "*********************_________*********
***********************_______*********
***********************_______*********
*****************************__**************
_____________________********________********
_____________________********________********
______***********************________********
______***************_*______________********
______***************_*______________********
______***************________________********
*********************________________********
********_____________________________********
********_____________________________********
*****************************________********
______***********************________********
______***********************________********
______***********************________********"

echo "__ ___/__ ____/___ / / /__ __ \__ __ \___ /
_____ \ _ / __ /_/ / _ / / /_ / / /__ /
____/ / / /___ _ __ / / /_/ / / /_/ / _ /___
/____/ \____/ /_/ /_/ \____/ \____/ /_____/"

echo -e "\nMiniVERTER is watching your code...¯\_(*_*)_/¯\n"
set -e

echo -e "-------------------------------------------------------------------------------\n"
echo -e "Style test\n"
STYLE_TEST_SCRIPT=tests/style_tests.sh
OUTPUT=$(bash ${STYLE_TEST_SCRIPT})
STYLE_TEST_RESULT=${OUTPUT: -1}
printf 'Style test output:\n %s\n' "$OUTPUT"
printf 'Style test result: %s\n' "$STYLE_TEST_RESULT"
echo -e "-------------------------------------------------------------------------------\n"

TEST_JSON=tests/tests.json

for TEST_NUMBER in $(jq ".tests[].number" ${TEST_JSON}); do
NAME_CATEGORY=$(jq -r ".tests[$TEST_NUMBER].name" ${TEST_JSON})
IFS='.' read -ra ARR_NAME_CATEGORY <<< "$NAME_CATEGORY"
NAME=${ARR_NAME_CATEGORY[0]}
CATEGORY=${ARR_NAME_CATEGORY[1]}
PART=${CATEGORY: -1}

if [ "$LAST_PART" != "$PART" ]
then
echo -e "Part:" ${NAME}"\n"
LAST_PART=$PART
BUILD_SCRIPT=ci-scripts/build.sh
OUTPUT=$(bash ${BUILD_SCRIPT} ${NAME})
BUILD_RESULT=${OUTPUT: -1}
printf 'Build output:\n %s\n' "$OUTPUT"
printf 'Build result: %s\n' "$BUILD_RESULT"
echo -e "-------------------------------------------------------------------------------\n"
fi
done


12 changes: 12 additions & 0 deletions materials/build/scripts/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tests": [
{
"number": 0,
"name": "s21_cat.part1"
},
{
"number": 1,
"name": "s21_grep.part2"
}
]
}

0 comments on commit 42e65ad

Please sign in to comment.