Skip to content

Instantly share code, notes, and snippets.

@KMACREATOR
Created June 17, 2024 23:15
Show Gist options
  • Save KMACREATOR/6ddc70f6f6305736164547ae1877958a to your computer and use it in GitHub Desktop.
Save KMACREATOR/6ddc70f6f6305736164547ae1877958a to your computer and use it in GitHub Desktop.
lab05

#lab05

Выполнил студент группы ИУ8-24 Конов Михаил

computer@MLK:~/KMACREATOR/workspace/projects/lab04$ cd ${GITHUB_USERNAME}/workspace
bash: cd: KMACREATOR/workspace: Нет такого файла или каталога
computer@MLK:~/KMACREATOR/workspace/projects/lab04$ cd ..
computer@MLK:~/KMACREATOR/workspace/projects$ cd ..
computer@MLK:~/KMACREATOR/workspace$ cd ${GITHUB_USERNAME}/workspace
bash: cd: KMACREATOR/workspace: Нет такого файла или каталога
computer@MLK:~/KMACREATOR/workspace$ pushd .
~/KMACREATOR/workspace ~/KMACREATOR/workspace ~/KMACREATOR/workspace
computer@MLK:~/KMACREATOR/workspace$ source scripts/activate
computer@MLK:~/KMACREATOR/workspace$ git clone git@github.com:KMACREATOR/lab04 projects/lab05
Клонирование в «projects/lab05»...
remote: Enumerating objects: 39, done.
remote: Counting objects: 100% (39/39), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 39 (delta 7), reused 39 (delta 7), pack-reused 0
Получение объектов: 100% (39/39), 7.24 КиБ | 7.24 МиБ/с, готово.
Определение изменений: 100% (7/7), готово.
computer@MLK:~/KMACREATOR/workspace$ cd projects/lab05
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git remote remove origin
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git remote add origin git@github.com:KMACREATOR/lab05
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ mkdir third-party
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git submodule add git@github.com/google/googletest third-party/gtest
URL репозитория: «git@github.com/google/googletest» должен быть абсолютным или начинаться с ./|../
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git submodule add git@github.com:google/googletest third-party/gtest
Клонирование в «/home/computer/KMACREATOR/workspace/projects/lab05/third-party/gtest»...
remote: Enumerating objects: 27535, done.
remote: Counting objects: 100% (73/73), done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 27535 (delta 29), reused 38 (delta 23), pack-reused 27462
Получение объектов: 100% (27535/27535), 12.84 МиБ | 2.42 МиБ/с, готово.
Определение изменений: 100% (20442/20442), готово.
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cd third-party/gtest && git checkout release-1.8.1 && cd ../..
Примечание: переключение на «release-1.8.1».

Вы сейчас в состоянии «отсоединённого указателя HEAD». Можете осмотреться,
внести экспериментальные изменения и зафиксировать их, также можете
отменить любые коммиты, созданные в этом состоянии, не затрагивая другие
ветки, переключившись обратно на любую ветку.

Если хотите создать новую ветку для сохранения созданных коммитов, можете
сделать это (сейчас или позже), используя команду switch с параметром -c.
Например:

  git switch -c <новая-ветка>

Или отмените эту операцию с помощью:

  git switch -

Отключите этот совет, установив переменную конфигурации
advice.detachedHead в значение false

HEAD сейчас на 2fe3bd99 Merge pull request #1433 from dsacre/fix-clang-warnings
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git add third-party/gtest
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git commit -m"added gtest framework"
[main 45a09cc] added gtest framework
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 third-party/gtest
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ alias gsed=sed
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ gsed -i '/option(BUILD_EXAMPLES "Build examples" OFF)/a\
> option(BUILD_TESTS "Build tests" OFF)
> ' CMakeLists.txt
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cat >> CMakeLists.txt <<EOF
> 
> if(BUILD_TESTS)
>   enable_testing()
>   add_subdirectory(third-party/gtest)
>   file(GLOB \${PROJECT_NAME}_TEST_SOURCES tests/*.cpp)
>   add_executable(check \${\${PROJECT_NAME}_TEST_SOURCES})
>   target_link_libraries(check \${PROJECT_NAME} gtest_main)
>   add_test(NAME check COMMAND check)
> endif()
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ mkdir tests
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cat > tests/test1.cpp <<EOF
> #include <print.hpp>
> 
> #include <gtest/gtest.h>
> 
> TEST(Print, InFileStream)
> {
>   std::string filepath = "file.txt";
>   std::string text = "hello";
>   std::ofstream out{filepath};
> 
>   print(text, out);
>   out.close();
> 
>   std::string result;
>   std::ifstream in{filepath};
>   in >> result;
> 
>   EXPECT_EQ(result, text);
> }
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cmake -H. -B_build -DBUILD_TESTS=ON
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/bin/python3.8 (found version "3.8.10") 
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/computer/KMACREATOR/workspace/projects/lab05/_build
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cmake --build _build
Scanning dependencies of target print
[  8%] Building CXX object CMakeFiles/print.dir/sources/print.cpp.o
In file included from /home/computer/KMACREATOR/workspace/projects/lab05/sources/print.cpp:1:
/home/computer/KMACREATOR/workspace/projects/lab05/include/print.hpp:3:10: fatal error: streing: Нет такого файла или каталога
    3 | #include <streing>
      |          ^~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/print.dir/build.make:63: CMakeFiles/print.dir/sources/print.cpp.o] Ошибка 1
make[1]: *** [CMakeFiles/Makefile2:169: CMakeFiles/print.dir/all] Ошибка 2
make: *** [Makefile:141: all] Ошибка 2
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cat > tests/test1.cpp <<EOF
#include <print.hpp>


#include <gtest/gtest.h>


TEST(Print, InFileStream)
{
  std::string filepath = "file.txt";
  std::string text = "hello";
  std::ofstream out{filepath};

  print(text, out);
  out.close();

  std::string result;
  std::ifstream in{filepath};
  in >> result;

  EXPECT_EQ(result, text);
}
EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cat > tests/test1.cpp <<EOF
#include <print.hpp>                                 make --build _build
computer@MLK:~/KMACREATOR/workspace/projects/lab05$  at > tests/test1.cpp <<EOF
#include <print.hpp>
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cmake --build _build
Scanning dependencies of target print
[  8%] Building CXX object CMakeFiles/print.dir/sources/print.cpp.o
/home/computer/KMACREATOR/workspace/projects/lab05/sources/print.cpp: In function ‘void print(const string&, std::ofstream&)’:
/home/computer/KMACREATOR/workspace/projects/lab05/sources/print.cpp:11:1: error: expected ‘}’ at end of input
   11 | {
      | ^
/home/computer/KMACREATOR/workspace/projects/lab05/sources/print.cpp:11:1: error: expected ‘}’ at end of input
/home/computer/KMACREATOR/workspace/projects/lab05/sources/print.cpp:9:1: note: to match this ‘{’
    9 | {
      | ^
make[2]: *** [CMakeFiles/print.dir/build.make:63: CMakeFiles/print.dir/sources/print.cpp.o] Ошибка 1
make[1]: *** [CMakeFiles/Makefile2:169: CMakeFiles/print.dir/all] Ошибка 2
make: *** [Makefile:141: all] Ошибка 2
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cmake --build _build
Scanning dependencies of target print
[  8%] Building CXX object CMakeFiles/print.dir/sources/print.cpp.o
[ 16%] Linking CXX static library libprint.a
[ 16%] Built target print
Scanning dependencies of target gtest
[ 25%] Building CXX object third-party/gtest/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 33%] Linking CXX static library libgtest.a
[ 33%] Built target gtest
Scanning dependencies of target gtest_main
[ 41%] Building CXX object third-party/gtest/googlemock/gtest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 50%] Linking CXX static library libgtest_main.a
[ 50%] Built target gtest_main
Scanning dependencies of target check
[ 58%] Building CXX object CMakeFiles/check.dir/tests/test1.cpp.o
[ 66%] Linking CXX executable check
[ 66%] Built target check
Scanning dependencies of target gmock
[ 75%] Building CXX object third-party/gtest/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
[ 83%] Linking CXX static library libgmock.a
[ 83%] Built target gmock
Scanning dependencies of target gmock_main
[ 91%] Building CXX object third-party/gtest/googlemock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
[100%] Linking CXX static library libgmock_main.a
[100%] Built target gmock_main
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cmake --build _build --target test
Running tests...
Test project /home/computer/KMACREATOR/workspace/projects/lab05/_build
    Start 1: check
1/1 Test #1: check ............................   Passed    0.01 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.04 sec
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ _build/check
Running main() from /home/computer/KMACREATOR/workspace/projects/lab05/third-party/gtest/googletest/src/gtest_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Print
[ RUN      ] Print.InFileStream
[       OK ] Print.InFileStream (0 ms)
[----------] 1 test from Print (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cmake --build _build --target test -- ARGS=--verbose
Running tests...
UpdateCTestConfiguration  from :/home/computer/KMACREATOR/workspace/projects/lab05/_build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/home/computer/KMACREATOR/workspace/projects/lab05/_build/DartConfiguration.tcl
Test project /home/computer/KMACREATOR/workspace/projects/lab05/_build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: check

1: Test command: /home/computer/KMACREATOR/workspace/projects/lab05/_build/check
1: Test timeout computed to be: 10000000
1: Running main() from /home/computer/KMACREATOR/workspace/projects/lab05/third-party/gtest/googletest/src/gtest_main.cc
1: [==========] Running 1 test from 1 test case.
1: [----------] Global test environment set-up.
1: [----------] 1 test from Print
1: [ RUN      ] Print.InFileStream
1: [       OK ] Print.InFileStream (1 ms)
1: [----------] 1 test from Print (1 ms total)
1: 
1: [----------] Global test environment tear-down
1: [==========] 1 test from 1 test case ran. (1 ms total)
1: [  PASSED  ] 1 test.
1/1 Test #1: check ............................   Passed    0.00 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.00 sec
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ cmake --build _build --target test -- ARGS=--verbose
Running tests...
UpdateCTestConfiguration  from :/home/computer/KMACREATOR/workspace/projects/lab05/_build/DartConfiguration.tcl
UpdateCTestConfiguration  from :/home/computer/KMACREATOR/workspace/projects/lab05/_build/DartConfiguration.tcl
Test project /home/computer/KMACREATOR/workspace/projects/lab05/_build
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: check

1: Test command: /home/computer/KMACREATOR/workspace/projects/lab05/_build/check
1: Test timeout computed to be: 10000000
1: Running main() from /home/computer/KMACREATOR/workspace/projects/lab05/third-party/gtest/googletest/src/gtest_main.cc
1: [==========] Running 1 test from 1 test case.
1: [----------] Global test environment set-up.
1: [----------] 1 test from Print
1: [ RUN      ] Print.InFileStream
1: [       OK ] Print.InFileStream (0 ms)
1: [----------] 1 test from Print (0 ms total)
1: 
1: [----------] Global test environment tear-down
1: [==========] 1 test from 1 test case ran. (0 ms total)
1: [  PASSED  ] 1 test.
1/1 Test #1: check ............................   Passed    0.01 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.01 sec
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ gsed -i 's/lab04/lab05/g' README.md
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ gsed -i 's/\(DCMAKE_INSTALL_PREFIX=_install\)/\1 -DBUILD_TESTS=ON/' .travis.yml
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ gsed -i '/cmake --build _build --target install/a\
> - cmake --build _build --target test -- ARGS=--verbose
> ' .travis.yml
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ travis lint

Команда «travis» не найдена, но может быть установлена с помощью:

sudo snap install travis  # version 1.8.9, or
sudo apt  install travis  # version 190101-1build1

See 'snap info travis' for additional versions.

computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git add .travis.yml
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git add tests
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git add -p
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96a361e..aa7a323 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 option(BUILD_EXAMPLES "Build examples" OFF)
+option(BUILD_TESTS "Build tests" OFF)
 
 project(print)
 
(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? ?
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
e - manually edit the current hunk
? - print help
@@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 option(BUILD_EXAMPLES "Build examples" OFF)
+option(BUILD_TESTS "Build tests" OFF)
 
 project(print)
 
(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y
@@ -34,3 +35,12 @@ install(TARGETS print
 
 install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include)
 install(EXPORT print-config DESTINATION cmake)
+
+if(BUILD_TESTS)
+  enable_testing()
+  add_subdirectory(third-party/gtest)
+  file(GLOB ${PROJECT_NAME}_TEST_SOURCES tests/*.cpp)
+  add_executable(check ${${PROJECT_NAME}_TEST_SOURCES})
+  target_link_libraries(check ${PROJECT_NAME} gtest_main)
+  add_test(NAME check COMMAND check)
+endif()
(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? y

diff --git a/include/print.hpp b/include/print.hpp
index 61372bd..32efd0c 100644
--- a/include/print.hpp
+++ b/include/print.hpp
@@ -1,5 +1,5 @@
 #include <fstream>
 #include <iostream> 
-#include <streing>
+#include <string>
 void print(const std::string& text, std::ofstream& out);
 void print(const std::string& text, std::ostream& out = std::cout);
(1/1) Stage this hunk [y,n,q,a,d,e,?]? y

diff --git a/sources/print.cpp b/sources/print.cpp
index a5e5231..6ff025c 100644
--- a/sources/print.cpp
+++ b/sources/print.cpp
@@ -8,4 +8,4 @@ void print(const std::string& text, std::ostream& out)
 void print(const std::string& text, std::ofstream& out)
 {
  out << text;
-{
+}
(1/1) Stage this hunk [y,n,q,a,d,e,?]? y

computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git push origin master
error: src refspec master ничему не соответствует
error: не удалось отправить некоторые ссылки в «git@github.com:KMACREATOR/lab05»
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ git push origin main
Перечисление объектов: 43, готово.
Подсчет объектов: 100% (43/43), готово.
При сжатии изменений используется до 4 потоков
Сжатие объектов: 100% (27/27), готово.
Запись объектов: 100% (43/43), 7.61 КиБ | 7.61 МиБ/с, готово.
Всего 43 (изменения 8), повторно использовано 38 (изменения 7)
remote: Resolving deltas: 100% (8/8), done.
To github.com:KMACREATOR/lab05
 * [new branch]      main -> main
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ travis login --auto

Команда «travis» не найдена, но может быть установлена с помощью:

sudo snap install travis  # version 1.8.9, or
sudo apt  install travis  # version 190101-1build1

See 'snap info travis' for additional versions.

computer@MLK:~/KMACREATOR/workspace/projects/lab05$ travis enable

Команда «travis» не найдена, но может быть установлена с помощью:

sudo snap install travis  # version 1.8.9, or
sudo apt  install travis  # version 190101-1build1

See 'snap info travis' for additional versions.

computer@MLK:~/KMACREATOR/workspace/projects/lab05$ mkdir artifacts
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ sleep 20s && gnome-screenshot --file artifacts/screenshot.png
computer@MLK:~/KMACREATOR/workspace/projects/lab05$ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment