Skip to content

azz #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 45 additions & 17 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,53 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Checks:
runs-on: self-hosted
# This workflow contains a single job called "build"
checks:
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 25

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: setup environment
run:
sudo ./scripts/setup-all.sh
- name: Codestyle
run:
scripts/codestyle.sh
- name: AddressSanitizer
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: prepare environment
run: sudo apt install git &&
git submodule update --init

- name: checks
run:
scripts/asan.sh
- name: ThreadSanitizer
docker run -v `pwd`:`pwd` -w `pwd` --cap-add=SYS_PTRACE -t rusdevops/bootstrap-cpp scripts/checks.sh


tests:
runs-on: ubuntu-latest
timeout-minutes: 25

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: prepare environment
run: sudo apt install git &&
git submodule update --init

- name: tests
run:
scripts/tsan.sh
- name: Coverage
docker run -v `pwd`:`pwd` -w `pwd` -t rusdevops/bootstrap-cpp scripts/tests.sh


quality:
runs-on: ubuntu-latest
timeout-minutes: 25
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: prepare environment
run: sudo apt install git &&
git submodule update --init

- name: quality
run:
scripts/coverage.sh
docker run -v `pwd`:`pwd` -w `pwd` -t rusdevops/bootstrap-cpp scripts/coverage.sh
4 changes: 2 additions & 2 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Build packages
id: build_packages
run: |
docker run -v `pwd`:`pwd` -w `pwd` --cap-add=SYS_PTRACE -t rusdevops/toolbox-cpp scripts/package.sh
docker run -v `pwd`:`pwd` -w `pwd` --cap-add=SYS_PTRACE -t rusdevops/bootstrap-cpp scripts/package.sh
cd _artifacts
DEB_PACKAGE_NAME=$(ls *.deb | tail -n 1)
RPM_PACKAGE_NAME=$(ls *.rpm | tail -n 1)
Expand Down Expand Up @@ -56,4 +56,4 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: _artifacts/${{ steps.build_packages.outputs.rpm_package_filename }}
asset_name: ${{ steps.build_packages.outputs.rpm_package_filename }}
asset_content_type: application/zip
asset_content_type: application/zip
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "tools/polly"]
path = tools/polly
url = https://github.com/bmstu-iu8-cpp-sem-3/polly
[submodule "tools/coverage"]
path = tools/coverage
url = https://github.com/bmstu-iu8-cpp-sem-3/infra-code-coverage
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
os: linux
language: minimal
services:
- docker

jobs:
include:
- name: "checks"
script:
- docker run -v `pwd`:`pwd` -w `pwd` --cap-add=SYS_PTRACE -t rusdevops/bootstrap-cpp scripts/checks.sh
- name: "tests"
script:
- docker run -v `pwd`:`pwd` -w `pwd` -t rusdevops/bootstrap-cpp scripts/tests.sh
- name: "quality"
script:
- docker run -v `pwd`:`pwd` -w `pwd` -t rusdevops/bootstrap-cpp scripts/coverage.sh
# The bot has gone...
# - docker run --env-file .env -v `pwd`:`pwd` -w `pwd` -t rusdevops/bootstrap-cpp scripts/duplication.sh

notifications:
email: false

branches:
- only:
- master
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.18)
cmake_minimum_required(VERSION 3.12)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -26,20 +26,22 @@ string(APPEND CMAKE_CXX_FLAGS " -pedantic -Werror -Wall -Wextra")
string(APPEND CMAKE_CXX_FLAGS " -Wno-unused-command-line-argument")
string(APPEND CMAKE_CXX_FLAGS " -Wshadow -Wnon-virtual-dtor")

# new versions of cmake contain gtest search files
# commented out to increase the build speed.
# hunter_add_package(GTest)
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
hunter_add_package(nlohmann_json)
find_package(nlohmann_json CONFIG REQUIRED)

add_library(${PROJECT_NAME} STATIC
# enum your files and delete this comment
${CMAKE_CURRENT_SOURCE_DIR}/sources/example.cpp
)
${CMAKE_CURRENT_SOURCE_DIR}/sources/source.cpp
include/Student.cpp include/Student.hpp)
target_link_libraries(${PROJECT_NAME} nlohmann_json::nlohmann_json)


add_executable(demo
${CMAKE_CURRENT_SOURCE_DIR}/demo/main.cpp
)

target_link_libraries(demo nlohmann_json::nlohmann_json)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>"
Expand All @@ -48,9 +50,11 @@ target_include_directories(${PROJECT_NAME} PUBLIC
target_link_libraries(demo ${PROJECT_NAME})

if(BUILD_TESTS)
include_directories(${CMAKE_SOURCE_DIR}/jsonExamples)
add_definitions(-D_JSON_DIR="${CMAKE_SOURCE_DIR}/jsonExamples")
add_executable(tests
# TODO: enum your files and delete this comment
${CMAKE_CURRENT_SOURCE_DIR}/tests/example.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/test.cpp
)
target_link_libraries(tests ${PROJECT_NAME} GTest::gtest_main)
enable_testing()
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export LAB_KEYWORD=yyyyyyy
export LAB_NAME=lab-${LAB_NUMBER}-${LAB_KEYWORD}
git clone https://github.com/bmstu-iu8-cpp-sem-3/${LAB_NAME}
cd ${LAB_NAME}
git remote rename origin template
git remote add template https://github.com/bmstu-iu8-cpp-sem-3/lab-xx-template.git
git fetch template master
git branch -f template template/master
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM ubuntu:21.04
LABEL version="0.1"
# rusdevops/bootstrap-cpp image
FROM ubuntu:20.04
LABEL maintainer="[email protected]"
ENV DEBIAN_FRONTEND noninteractive
RUN apt -y update && \
apt -y install clang g++ cmake libgtest-dev libgmock-dev git \
python3 python3-pip gcovr lcov doxygen && \
python3 -m pip install cpplint requests gitpython && \
apt -y install software-properties-common doxygen rpm g++-7 curl llvm g++ lcov gcovr cmake python3-pip clang git && \
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
pip3 install cpplint gitpython requests && \
apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016-2021 The ISC Authors.
Copyright (c) 2016-2020 The ISC Authors.

All rights reserved.

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ using nlohmann::json;

void from_json(const json& j, student_t& s) {

s.name = get_name(j.at("group"));
s.name = get_name(j.at("name"));
s.group = get_group(j.at("group"));
s.avg = get_avg(j.at("avg"));
s.debt = get_group(j.at("debt"));
s.debt = get_debt(j.at("debt"));
}

auto get_name(const json& j) -> std::string {
Expand Down Expand Up @@ -128,7 +128,7 @@ auto get_avg(const json& j) -> std::any {

auto get_group(const json& j) -> std::any {
if (j.is_string())
return = j.get<std::string>();
return j.get<std::string>();
else
return j.get<std::size_t>();
}
Expand Down
11 changes: 7 additions & 4 deletions demo/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <example.hpp>
#include "header.hpp"

int main() {
example();
}
int main(int argc, char** argv) {
auto data = getJSON(argc, argv);
auto students = parseJSON(data);
print(students, std::cout);
return 0;
}
125 changes: 125 additions & 0 deletions include/Student.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include "header.hpp"
#include <iomanip>
#include <utility>

Student::Student(std::string _name, std::any _group,
std::any _avg, std::any _debt) {
name = std::move(_name);
group = std::move(_group);
avg = std::move(_avg);
debt = std::move(_debt);
}
bool anyCompare(std::any a1, std::any a2)
{
if (a1.type() != a2.type())
return false;
if (a1.type() == typeid(std::string))
return std::any_cast<std::string>(a1)== std::any_cast<std::string>(a2);
if (a1.type() == typeid(nullptr))
return true;
if (a1.type() == typeid(double))
return std::any_cast<double>(a1) == std::any_cast<double>(a2);
if (a1.type() == typeid(size_t))
return std::any_cast<size_t>(a1) == std::any_cast<size_t>(a2);
if (a1.type() == typeid(std::vector<std::string>))
return
std::any_cast<std::vector<std::string>>(a1)
== std::any_cast<std::vector<std::string>>(a2);
return false;
}
bool Student::operator==(const Student& student) const
{
bool n = name == student.name;
bool g = anyCompare(group, student.group);
bool a = anyCompare(avg, student.avg);
bool d = anyCompare(debt, student.debt);
return n && g && a && d;
}

Student::Student() = default;

auto get_name(const json& j) -> std::string {
return j.get<std::string>();
}
auto get_debt(const json& j) -> std::any {
if (j.is_null())
return nullptr;
else if (j.is_string())
return j.get<std::string>();
else
return j.get<std::vector<std::string>>();
}

auto get_avg(const json& j) -> std::any {
if (j.is_null())
return nullptr;
else if (j.is_string())
return j.get<std::string>();
else if (j.is_number_float())
return j.get<double>();
else
return j.get<std::size_t>();
}

auto get_group(const json& j) -> std::any {
if (j.is_string())
return j.get<std::string>();
else
return j.get<std::size_t>();
}
void from_json(const json& j, Student& s) {
s.name = get_name(j.at("name"));
s.group = get_group(j.at("group"));
s.avg = get_avg(j.at("avg"));
s.debt = get_debt(j.at("debt"));
}
std::string toString(std::any& item)
{
std::stringstream ss;
if (item.type() == typeid(std::nullptr_t))
ss << "null";
else if (item.type() == typeid(std::string))
ss << std::any_cast<std::string>(item);
else if (item.type() == typeid(double))
ss << std::any_cast<double>(item);
else if (item.type() == typeid(std::vector<std::string>))
ss << std::any_cast<std::vector<std::string> >(item).size();
else if (item.type() == typeid(size_t))
ss << std::any_cast<size_t>(item);
else ss << "unknown";
return ss.str();
}
void print(std::string s1, std::string s2,
std::string s3, std::string s4, std::ostream& os)
{
os << "| " << std::setw(20) << std::left << s1 << "| "
<< std::setw(10) << std::left << s2 << "| "
<< std::setw(10) << std::left << s3 << "| "
<< std::setw(10) << std::left << s4 << "|\n"
<< "|---------------------|-----------|-----------|-----------|\n";
}
void print(Student& student, std::ostream& os)
{
print(student.name,
toString(student.group),
toString(student.avg),
toString(student.debt), os);
}
void print(std::vector<Student>& students, std::ostream& os)
{
print("name", "group", "avg", "debt", os);
for (Student& student : students) {
print(student, os);
}
}
std::vector<Student> parseJSON(json& data)
{
std::vector<Student> students;
for (auto const& item : data.at("items"))
{
Student student1;
from_json(item, student1);
students.push_back(student1);
}
return students;
}
38 changes: 38 additions & 0 deletions include/header.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef INCLUDE_HEADER_HPP_
#define INCLUDE_HEADER_HPP_

#include <string>
#include <any>
#include <nlohmann/json.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>

using nlohmann::json;

// Объявления, связанные с JSON
json getJSON(int argc, char** argv);

// Объявления, связанные со Student
struct Student {
public:
Student();
Student(std::string name, std::any group, std::any avg, std::any debt);
bool operator==(const Student& student) const;

std::string name;
std::any group;
std::any avg;
std::any debt;
};

void from_json(const json& j, Student& s);
void print(Student& student, std::ostream& os);
void print(std::string s1, std::string s2, std::string s3, std::string s4, std::ostream& os);
void print(std::vector<Student>& students, std::ostream& os);
std::vector<Student> parseJSON(json& data);


#endif // INCLUDE_HEADER_HPP_

Loading