Skip to content

Commit 9f6d0e6

Browse files
authored
Merge branch 'diamond' into diamond
2 parents 8868919 + c8a58f2 commit 9f6d0e6

File tree

14 files changed

+241
-30
lines changed

14 files changed

+241
-30
lines changed

.github/CODEOWNERS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Lines starting with '#' are comments.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in the repo.
5+
* @ziobron
6+
7+
# Order is important. The last matching pattern has the most precedence.
8+
# So if a pull request only touches cpp, hpp or md files, only these owners
9+
# will be requested to review.
10+
*.cpp @ziobron
11+
*.hpp @ziobron
12+
*.md @ziobron
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: cars-exception
2+
3+
on: [pull_request, push, workflow_dispatch]
4+
5+
jobs:
6+
cars-exception:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.path }}
15+
- name: Compile
16+
working-directory: ${{ env.path }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.path }}
22+
run: |
23+
chmod +x ../.github/workflows/check-exception.sh
24+
../.github/workflows/check-exception.sh ../*.cpp ../*.hpp

.github/workflows/cars-tests.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: cars-tests
2+
3+
on: [pull_request, push, workflow_dispatch]
4+
5+
jobs:
6+
cars-tests:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.path }}
15+
- name: Compile
16+
working-directory: ${{ env.path }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.path }}
22+
run: |
23+
chmod +x ../.github/workflows/check-tests.sh
24+
../.github/workflows/check-tests.sh ../CMakeLists.txt
25+
ctest -V
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
#RED="\e[41m"
4+
#GREEN="\e[42m"
5+
#BOLD="\e[1m"
6+
#DEFAULT="\e[0m"
7+
8+
FILES="${@:2}"
9+
failed=0
10+
11+
function check()
12+
{
13+
if [ "$1" != 0 ]; then
14+
echo -e ❌ $RED "FAILED ON" "$@" $DEFAULT
15+
((failed+=1))
16+
else
17+
echo -e ✅ $GREEN "FOUND" $DEFAULT
18+
fi
19+
}
20+
21+
function positive_lookup()
22+
{
23+
echo -e "---"
24+
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
25+
egrep -s "$2" $FILES
26+
check $? $1
27+
}
28+
29+
echo -e $BOLD "Performing checks" $DEFAULT
30+
31+
positive_lookup "should have InvalidGear that inherits from logic_error" "(class|struct)\s+InvalidGear\s*:\s*(public)?\s*(std::)?logic_error"
32+
positive_lookup "should throw InvalidGear" "throw\s+InvalidGear"
33+
# positive_lookup "should catch InvalidGear" "catch.*InvalidGear"
34+
35+
echo -e "==="
36+
37+
if [ $failed == 0 ]; then
38+
echo -e 💚💚💚 $GREEN "ALL CHECKS PASSED" 💚💚💚 $DEFAULT
39+
else
40+
echo -e ❗️❗️❗️ $RED $failed "CHECKS FAILED" ❗️❗️❗️ $DEFAULT
41+
fi
42+
43+
exit $failed

.github/workflows/check-tests.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
#RED="\e[41m"
4+
#GREEN="\e[42m"
5+
#BOLD="\e[1m"
6+
#DEFAULT="\e[0m"
7+
8+
FILE=$1
9+
failed=0
10+
11+
if [ ! -e "$FILE" ]; then
12+
echo -e "Given file does not exist - $FILE"
13+
exit 1
14+
fi
15+
16+
function check()
17+
{
18+
if [ "$1" != 0 ]; then
19+
echo -e ❌ $RED "FAILED ON" "$@" $DEFAULT
20+
((failed+=1))
21+
else
22+
echo -e ✅ $GREEN "FOUND" $DEFAULT
23+
fi
24+
}
25+
26+
function negative_check()
27+
{
28+
if [ "$1" == 0 ]; then
29+
echo -e ❌ $RED "FAILED ON" "$@" $DEFAULT
30+
((failed+=1))
31+
else
32+
echo -e ✅ $GREEN "NOT FOUND" $DEFAULT
33+
fi
34+
}
35+
36+
function min_2_allowed_check()
37+
{
38+
if [ "$1" -lt 2 ]; then
39+
echo -e ❌ $RED "FAILED ON" "$@" $DEFAULT
40+
((failed+=1))
41+
else
42+
echo -e ✅ $GREEN "OK" $DEFAULT
43+
fi
44+
}
45+
46+
function positive_lookup()
47+
{
48+
echo -e "---"
49+
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
50+
egrep "$2" "$FILE"
51+
check $? $1
52+
}
53+
54+
function negative_lookup()
55+
{
56+
echo -e "---"
57+
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
58+
egrep "$2" "$FILE"
59+
negative_check $? $1
60+
}
61+
62+
function min_2_allowed_lookup()
63+
{
64+
echo -e "---"
65+
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
66+
min_2_allowed_check `egrep "$2" "$FILE" -c` $1
67+
}
68+
69+
function does_file_exist()
70+
{
71+
echo -e "---"
72+
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
73+
if [[ -f "$1" ]]; then
74+
echo -e ✅ $GREEN "FILE EXISTS" $DEFAULT
75+
else
76+
echo -e ❌ $RED "FILE DOES NOT EXIST" $DEFAULT
77+
((failed+=1))
78+
fi
79+
}
80+
81+
echo -e $BOLD "Performing checks on $FILE" $DEFAULT
82+
83+
does_file_exist $FILE
84+
min_2_allowed_lookup "should have more than 1 add_executable" "add_executable"
85+
positive_lookup "should have enable_testing" "enable_testing"
86+
positive_lookup "should have add_test" "add_test"
87+
88+
echo -e "==="
89+
90+
if [ $failed == 0 ]; then
91+
echo -e 💚💚💚 $GREEN "ALL CHECKS PASSED" 💚💚💚 $DEFAULT
92+
else
93+
echo -e ❗️❗️❗️ $RED $failed "CHECKS FAILED" ❗️❗️❗️ $DEFAULT
94+
fi
95+
96+
exit $failed

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ set(SRC_LIST
1212
main.cpp
1313
PetrolCar.cpp
1414
PetrolEngine.cpp
15-
Cars.cpp
16-
15+
Car.cpp
1716
)
1817

1918
find_package(Catch2)
2019

2120
add_executable(${PROJECT_NAME} ${SRC_LIST})
22-
target_compile_options(${PROJECT_NAME} PUBLIC -Wall -Werror -Wpedantic -Wextra)
21+
target_compile_options(${PROJECT_NAME} PUBLIC -Wall -Wpedantic -Wextra)
2322
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR})
2423

2524
add_executable(${PROJECT_NAME}-ut test/Cars.ut.cpp )

Car.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "Car.hpp"
2+
#include <iostream>
3+
4+
void Car::turnLeft() { std::cout << __FUNCTION__ << std::endl; }
5+
void Car::turnRight() { std::cout << __FUNCTION__ << std::endl; }
6+
void Car::brake() { std::cout << __FUNCTION__ << std::endl; }
7+
void Car::accelerate(int) { std::cout << __FUNCTION__ << std::endl; }

Car.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
class Car
4+
{
5+
public:
6+
void turnLeft();
7+
void turnRight();
8+
void brake();
9+
void accelerate(int speed);
10+
virtual void refill() = 0;
11+
virtual ~Car(){}
12+
};

ElectricCar.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ class ElectricCar : virtual public Cars
1313
private:
1414
ElectricEngine* engine_;
1515
};
16-

ElectricEngine.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class ElectricEngine
77

88

99
private:
10-
int power_; // in HP
10+
int power_; // in HP
1111
int batteryCapacity_; // in Ah
1212
};
13-

0 commit comments

Comments
 (0)