Skip to content

Latest commit

 

History

History
289 lines (207 loc) · 8.05 KB

11_exercises.md

File metadata and controls

289 lines (207 loc) · 8.05 KB

< Back

11. Introduction

Exercise 110

Set up development environment

Quick install

Windows: Chocolatey

PowerShell run as Admin

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/mod-cpp/pacman/main/dev/windows.ps1'))
Windows: WinGet

PowerShell run as Admin

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/mod-cpp/pacman/main/dev/windows_winget.ps1'))
Ubuntu: apt
bash <(curl -s https://raw.githubusercontent.com/mod-cpp/pacman/main/dev/ubuntu.sh)

Manual install

Windows
MacOS
  • Install clang by typing xcode-select --install in a terminal and following the instructions
  • Install brew if you haven't already
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Install the build tools
brew install cmake ninja
Ubuntu 20.04 or newer
sudo apt install build-essential clang-12 cmake curl g++-10 git libgl1-mesa-dev libudev-dev libx11-dev libxi-dev libxrandr-dev ninja-build pkg-config tar unzip zip

Install Visual Studio Code

You can either download the package for VS Code from the official website or by adding the vscode repository to your distribution's package manager.

Fedora 33 or newer
sudo dnf install ninja-build SFML-devel libXi-devel libX11-devel libXrandr-devel mesa-libGL-devel systemd-devel

Install Visual Studio Code

You can either download the package for VS Code from the official website or by adding the vscode repository to your distribution's package manager.

FreeBSD 12 or newer
sudo pkg install catch cmake libfmt ninja sfml

Install VS Code

sudo pkg install vscode

Build

VS Code
git clone https://github.com/mod-cpp/pacman.git
cd pacman
code .
  • A dialog will appear saying "Do you trust the authors of the files in this folder?", select "Yes, I trust the authors".
  • You will get a popup in the lower right hand corner asking "Do you want to install the recommended extensions for C++?" - click Install.
  • Click on "No Configure Preset Selected" on the bottom status bar
  • In the dropdown that appears select
    • either x64-windows (64 bit) or x86-windows (32 bit).
    • linux-gcc on Linux
    • macos on MacOS
  • Build by clicking on "Build" button on the bottom status bar.
  • Wait until build is finished, it might take a while the first time because it is downloading and building the dependencies as well.
  • Click on flask icon on the left vertical bar to open the test panel
  • Run the tests by clicking on the run button on top of the test panel
  • Run the game by clicking on the play button on the bottom status bar
  • Select pacman in the dropdown
  • To debug, click on the play button with a bug on it on the left vertical bar to open the debug panel
  • Then click the play button on the top of the panel to run in the debugger.
Commandline

Example for Ubuntu using the preset linux-gcc, for other platforms use the appropriate preset, see CMakePresets.json.

git clone https://github.com/mod-cpp/pacman.git
cd pacman
cmake --preset linux-gcc -DCMAKE_BUILD_TYPE=Debug # configure
cmake --build --preset linux-gcc-build --config Debug # build
ctest --preset linux-gcc-test -C Debug # run tests
CLion
  • Clone project through "Get from VCS": https://github.com/mod-cpp/pacman.git
  • In the "Open Project Wizard" unselect "Enable profile" for the "Debug" profile
  • Select the profile(s) appropriate for your platform, example x64-windows-build for Windows 64 bit
  • Enable the profile by checking the checkbox "Enable profile"
  • Check the checkbox at the top of the dialog "Reload CMake project on editing CMakeLists.txt or other CMake configuration files"
  • Click "OK"
  • (If CLion created a cmake-build-debug folder you can safely delete it, we will be using the build directory)
  • If you need to get back to this dialog, open Settings and go to: Build, Execution, Deployment > CMake
  • On the bottom of the CLion window you will see a tab called CMake
  • To reload CMake fully, click on it and click on the cog wheel and select "Reset Cache and Reload Project"
  • To run pacman press the green play button at the top right of the window
  • To run in debug press the bug button to its right
  • To run the tests click on the dropdown to its left and select "All CTest" and then either the run or the debug button.

Troubleshoot

All

After installing the build tools, you may have to reboot your IDE and/or your Linux session if you encounter any errors such as Ninja not being found by VSCode.

Arch Linux

If there are opengl driver errors, try running in software mode

Windows
  • If you have issues with using VSCode, start it from the "Developer Command Prompt for VS 2022"
  • (Windows Defender dialog for VSCode: "Allow access")

Enable a test and make it green

Make sure you can run tests, so enable the test in the cpp file, and make sure it fails before you make it pass. Hint is in the comment over the test.

// HINT: To enable a test remove [.] from the tags on the test
TEST_CASE("Exercise 111 : Enable the test and make it green", "[.][11]") {
REQUIRE(true == false);
}
Solution
TEST_CASE("Exercise 111 : Enable a test and make it green", "[11]") {
  REQUIRE(true == true);
}

Make both asserts run (distinguish between REQUIRE and CHECK in Catch2)

Enable the test and see you will only get one error. Look up REQUIRE and CHECK in Catch2 and change the code in the test, so you get an error on both lines.

Then fix both errors by making both sides of the == the same.

// HINT: https://github.com/catchorg/Catch2/blob/v2.x/docs/assertions.md
TEST_CASE("Exercise 112 : Make both asserts run (distinguish between REQUIRE and CHECK in Catch2)", "[.][11]") {
  REQUIRE(true == false);
  CHECK(false == true);
}
Solution
TEST_CASE("Exercise 112 : Make both asserts run (distinguish between REQUIRE and CHECK in Catch2)", "[11]") {
  CHECK(true == true);
  CHECK(true == true);
}