From 643616575a20dfc03bc9a4890133d82fbfb65db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oona=20R=C3=A4is=C3=A4nen?= Date: Mon, 5 Aug 2024 21:48:28 +0300 Subject: [PATCH] wording, formatting, minor --- CONTRIBUTING.md | 32 +++++++++++++++++--------------- test/cli.pl | 2 +- test/unit.cc | 32 ++++++++++++++++---------------- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e40dd4f..03a7091 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,33 +41,35 @@ CI pipeline in place to ensure that the build works and no basic functionality breaks. So no worries. Our maintainer can help complete the PR as time allows. However, note that this is still a hobby project. +Let's face it, C++ is memory-unsafe and not the easiest language at that. But +there are things we can do to make it safer and more usable for us: + * Squashed commits with clear and concise [commit messages](https://www.gitkraken.com/learn/git/best-practices/git-commit-message) are preferred. Use force-push to update the PR branch if necessary. * Since 1.0, we wish to have tests in repo for all new features or bugfixes. The tests can be unit tests written in [Catch2](https://github.com/catchorg/Catch2/) (see `test/unit.cc`), or they can be end-to-end tests against the CLI executable itself (some Perl examples in `test/cli.pl`). Perl is only used for testing; all code should pass Perl::Critic level 3. -* C++ style is described in `.clang-format`, but this is not strict and serious for - every commit. -* But we are serious about C++14 compatibility, so unfortunately more modern -features can't be used. +* C++ style is described in `.clang-format`; format-on-save is recommended. +* We aim for C++14 compatibility, so unfortunately more modern features can't be used. * We have some static analysis rules described in `.clang-tidy`. * Keep in mind redsea has a real-time requirement and it might be run on some low-end 32-bit embedded platform. Unfortunately we don't have automated tests for this. * Try to avoid resorting to manual memory management. We have an address sanitizer in CI but currently no leak checks. -* Some design philosophy: - * Each JSON line should somehow correspond to a single RDS group. But this may - well change in the future, for any good reason. - * All JSON output should validate successfully against `schema.json`. - * Data spread over multiple groups should be withdrawn until fully received, unless - the user specifies the `--show-partial` option. - * The hex output should be compatible with RDS Spy, the (unaffiliated) Windows GUI software. (Yes, - it's difficult to automate this test) - * GUI features are outside of our scope - * Preferably redsea should not create any files in the file system; instead all - output should be via stdout if possible + +Some design philosophy: +* Each JSON line should somehow correspond to a single RDS group. But this may + well change in the future, for any good reason. +* All JSON output should validate successfully against `schema.json`. +* Data spread over multiple groups should be withdrawn until fully received, unless + the user specifies the `--show-partial` option. +* The hex output should be compatible with RDS Spy, the (unaffiliated) Windows GUI software. (Yes, + it's difficult to automate this test) +* GUI features are outside of our scope +* Preferably redsea should not create any files in the file system; instead all + output should be via stdout if possible The project uses [semantic versioning](https://semver.org/). diff --git a/test/cli.pl b/test/cli.pl index 1630f3c..40aa2a1 100644 --- a/test/cli.pl +++ b/test/cli.pl @@ -5,7 +5,7 @@ package cli; use warnings; use strict; -use IPC::Cmd qw(can_run); +use IPC::Cmd qw/can_run/; use Carp; use utf8; use open qw/:std :utf8/; diff --git a/test/unit.cc b/test/unit.cc index bb91540..6d7903a 100644 --- a/test/unit.cc +++ b/test/unit.cc @@ -12,33 +12,33 @@ #include "test_helpers.h" TEST_CASE("Bitfield extraction") { - const std::uint16_t block1{0x1234}; - const std::uint16_t block2{0x5678}; + constexpr std::uint16_t block1{0b0001'0010'0011'0100}; + constexpr std::uint16_t block2{0b0101'0110'0111'1000}; SECTION("Works with single block") { - CHECK(redsea::getBits<4>(block1, 0) == 4); + CHECK(redsea::getBits<4>(block1, 0) == 0b0100); - CHECK(redsea::getBits<5>(block1, 4) == 0x3); - CHECK(redsea::getBits<6>(block1, 4) == 0x23); - CHECK(redsea::getBits<8>(block1, 4) == 0x23); - CHECK(redsea::getBits<9>(block1, 4) == 0x123); + CHECK(redsea::getBits<5>(block1, 4) == 0b0'0011); + CHECK(redsea::getBits<6>(block1, 4) == 0b10'0011); + CHECK(redsea::getBits<8>(block1, 4) == 0b0010'0011); + CHECK(redsea::getBits<9>(block1, 4) == 0b1'0010'0011); - CHECK(redsea::getBits<5>(block1, 5) == 0x11); - CHECK(redsea::getBits<8>(block1, 5) == 0x91); + CHECK(redsea::getBits<5>(block1, 5) == 0b10'001); + CHECK(redsea::getBits<8>(block1, 5) == 0b1'0010'001); CHECK(redsea::getBool(block1, 12) == true); } SECTION("Works with concatenation of two blocks") { - CHECK(redsea::getBits<4>(block1, block2, 0) == 8); + CHECK(redsea::getBits<4>(block1, block2, 0) == 0b1000); - CHECK(redsea::getBits<5>(block1, block2, 4) == 0x7); - CHECK(redsea::getBits<6>(block1, block2, 4) == 0x27); - CHECK(redsea::getBits<8>(block1, block2, 4) == 0x67); - CHECK(redsea::getBits<9>(block1, block2, 4) == 0x167); + CHECK(redsea::getBits<5>(block1, block2, 4) == 0b0'0111); + CHECK(redsea::getBits<6>(block1, block2, 4) == 0b10'0111); + CHECK(redsea::getBits<8>(block1, block2, 4) == 0b0110'0111); + CHECK(redsea::getBits<9>(block1, block2, 4) == 0b1'0110'0111); - CHECK(redsea::getBits<12>(block1, block2, 8) == 0x456); - CHECK(redsea::getBits<12>(block1, block2, 9) == 0xA2B); + CHECK(redsea::getBits<12>(block1, block2, 8) == 0b0100'0101'0110); + CHECK(redsea::getBits<12>(block1, block2, 9) == 0b1'0100'0101'011); } }