Skip to content

Commit

Permalink
feat: Upgrading the project to be compatible with C++23 import std wi…
Browse files Browse the repository at this point in the history
…th latest Clang changes on Zork++
  • Loading branch information
TheRustifyer committed Aug 21, 2024
1 parent 186e77a commit 5c9f965
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 71 deletions.
43 changes: 16 additions & 27 deletions .github/workflows/project_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests for the project on Linux
name: Tests for the project

on:
push:
Expand All @@ -8,42 +8,31 @@ on:

jobs:
tests:
name: Running the project tests on Linux
runs-on: ubuntu-latest
name: Running the tests for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-latest }
# - { os: macos-latest }
# - { os: windows-latest }

steps:
- uses: actions/checkout@v3

- name: Clone Zork++
uses: GuillaumeFalourd/clone-github-repo-action@v2
uses: GuillaumeFalourd/clone-github-repo-action@v2.3
with:
owner: 'ZeroDayCode'
repository: 'Zork'
branch: 'feature/GH-127-clang-upgrades'

- name: Download the latest working version of Clang
- name: Download the latest possible version of Clang
run: |
# Exit on error
set -e
# Download and execute the LLVM installation script for the specified Clang version
echo "-----> Downloading and executing the LLVM installation script for Clang 16"
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 16
echo "-----> Installing libc++"
sudo apt-get install -y libc++-16-dev libc++abi-16-dev libunwind-16 libunwind-16-dev libc6 libzstd1
# Update the symbolic link to point to the newly installed Clang version
echo "-----> Updating the symbolic link to point to Clang 16"
sudo rm -f /usr/bin/clang++
sudo ln -s /usr/bin/clang++-16 /usr/bin/clang++
# Display the installation directory and version of the installed Clang
echo "-----> Clang-16 was installed on:"
which clang-16
echo "-----> Clang++ was installed on:"
which clang++-16
sudo apt update
sudo apt install clang-19 --install-suggests
sudo apt install libc++-19-dev libc++abi-19-dev
- name: Generate a Zork++ release build
run: |
Expand All @@ -54,4 +43,4 @@ jobs:
cp ./Zork/zork++/target/release/zork++ .
- name: Running the tests for ${{ matrix.os }} with Zork++
run: ./zork++ --match-files gh_linux -vv test
run: ./zork++ --match-files gh_linux -vv -c test
86 changes: 43 additions & 43 deletions zero/ifc/test-suite/suite.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import stylizer;
import formatter;
import print_utils;

using namespace zero::fmt;
using namespace zero;

/**
* @struct TestResults
Expand Down Expand Up @@ -164,7 +164,7 @@ void checkForTestErrors(const bool freeTestsErrors);
/*
* Litte helper for a visual separator tab
*/
void print_separator(const Color color = Color::EXT_SKY_BLUE);
void print_separator(const fmt::Color color = fmt::Color::EXT_SKY_BLUE);

// Top-level containers. They hold pointers to the types to avoid:
// `arithmetic on a pointer to an incomplete type`
Expand Down Expand Up @@ -248,11 +248,11 @@ export {
tsuite.cases.emplace_back(new TestCase(tname, tfunc));
else
tsuite.results.warnings.emplace_back(
stylize("[Warning in suite: ", Color::YELLOW) +
stylize(tsuite.uuid, Color::EXT_PURPLE) +
stylize("] Already exists a test case with the name: ", Color::YELLOW) +
stylize(tname, Color::EXT_SKY_BLUE) +
stylize(". Skipping test case.", Color::YELLOW)
fmt::stylize("[Warning in suite: ", fmt::Color::YELLOW) +
fmt::stylize(tsuite.uuid, fmt::Color::EXT_PURPLE) +
fmt::stylize("] Already exists a test case with the name: ", fmt::Color::YELLOW) +
fmt::stylize(tname, fmt::Color::EXT_SKY_BLUE) +
fmt::stylize(". Skipping test case.", fmt::Color::YELLOW)
);

/// If this is the first time that the suite is being registered
Expand All @@ -277,58 +277,58 @@ export {
}

void runSuiteTestCases(const TestRunBehavior behavior) {
println(
stylize("\n============================= ZERO TEST SUITE =============================", Color::GREEN, Modifier::BOLD)
fmt::println(
fmt::stylize("\n============================= ZERO TEST SUITE =============================", fmt::Color::GREEN, fmt::Modifier::BOLD)
);
println("- Running test suites. Total suites found: {}", testSuites.size());
print_separator(Color::GREEN);
newln();
fmt::println("- Running test suites. Total suites found: {}", testSuites.size());
print_separator(fmt::Color::GREEN);
fmt::newln();

for (const auto &test_suite : testSuites) {
print_separator();
println("- Running test suite:" + stylize(" {}", Color::EXT_PURPLE), test_suite->uuid);
fmt::println("- Running test suite:" + fmt::stylize(" {}", fmt::Color::EXT_PURPLE), test_suite->uuid);

for (const auto &warning : test_suite->results.warnings)
println(" {}", warning);
fmt::println(" {}", warning);
for (const auto &test_case : test_suite->cases) {
if (!runTest(test_case, test_suite->results)) {

if (behavior == HALT_SUITE_ON_FAIL) {
println(
stylize("\n========================================"
fmt::println(
fmt::stylize("\n========================================"
"\n[Halt Suite Tests] Stopping further tests "
"of the suite ",
Color::EXT_LIGHT_ORANGE, {Modifier::BOLD}) +
stylize("{} ", Color::EXT_PURPLE) +
stylize(
fmt::Color::EXT_LIGHT_ORANGE, {fmt::Modifier::BOLD}) +
fmt::stylize("{} ", fmt::Color::EXT_PURPLE) +
fmt::stylize(
"due to a failure."
"\n========================================",
Color::EXT_LIGHT_ORANGE, {Modifier::BOLD}),
fmt::Color::EXT_LIGHT_ORANGE, {fmt::Modifier::BOLD}),
test_suite->uuid);
break;
}

if (behavior == ABORT_ALL_ON_FAIL) {
println("Test suite [{}] summary:", test_suite->uuid);
println(stylize(" Passed: {}", Color::GREEN),
fmt::println("Test suite [{}] summary:", test_suite->uuid);
fmt::println(fmt::stylize(" Passed: {}", fmt::Color::GREEN),
test_suite->results.passed);
println(stylize(" Failed: {}", Color::RED),
fmt::println(fmt::stylize(" Failed: {}", fmt::Color::RED),
test_suite->results.failed);

println(
stylize("\n========================================"
fmt::println(
fmt::stylize("\n========================================"
"\n[Abort] All further tests are aborted due "
"to a failure in a test in this suite."
"\n========================================",
Color::RED, Modifier::BOLD));
fmt::Color::RED, fmt::Modifier::BOLD));
return;
}
}
}

println("- Test suite [{}] summary:", test_suite->uuid);
println(stylize("\tPassed: {}", Color::GREEN), test_suite->results.passed);
println(stylize("\tFailed: {}", Color::RED), test_suite->results.failed); // TODO:
fmt::println("- Test suite [{}] summary:", test_suite->uuid);
fmt::println(fmt::stylize("\tPassed: {}", fmt::Color::GREEN), test_suite->results.passed);
fmt::println(fmt::stylize("\tFailed: {}", fmt::Color::RED), test_suite->results.failed); // TODO:
// Add the names of the FAILED test cases?
print_separator();
}
Expand All @@ -337,7 +337,7 @@ void runSuiteTestCases(const TestRunBehavior behavior) {
bool runFreeTestCases(const TestRunBehavior behavior) {
bool anyFailed = false;
TestResults freeTestsResults;
println("Running free tests:");
fmt::println("Running free tests:");

for (const auto &testCase : freeTestCases) {
if (!runTest(testCase, freeTestsResults)) {
Expand All @@ -349,24 +349,24 @@ bool runFreeTestCases(const TestRunBehavior behavior) {
}
}

println("\nFree tests summary:");
println(stylize(" Passed: {}", Color::GREEN),
fmt::println("\nFree tests summary:");
fmt::println(fmt::stylize(" Passed: {}", fmt::Color::GREEN),
freeTestsResults.passed);
println(stylize(" Failed: {}", Color::RED), freeTestsResults.failed);
fmt::println(fmt::stylize(" Failed: {}", fmt::Color::RED), freeTestsResults.failed);

if (anyFailed) {
if (behavior == HALT_SUITE_ON_FAIL) {
println(stylize("\n========================================"
fmt::println(fmt::stylize("\n========================================"
"\n[Halt Free Tests] Stopping further free tests "
"due to a failure."
"\n========================================",
Color::EXT_LIGHT_ORANGE, {Modifier::BOLD}));
fmt::Color::EXT_LIGHT_ORANGE, {fmt::Modifier::BOLD}));
} else if (behavior == ABORT_ALL_ON_FAIL) {
println(stylize("\n========================================"
fmt::println(fmt::stylize("\n========================================"
"\n[Abort] All further tests are aborted due to a "
"failure in free tests."
"\n========================================",
Color::RED, {Modifier::BOLD}));
fmt::Color::RED, {fmt::Modifier::BOLD}));
std::exit(1);
}
}
Expand All @@ -375,15 +375,15 @@ bool runFreeTestCases(const TestRunBehavior behavior) {
}

bool runTest(const TestCase *const testCase, TestResults &results) {
print(" [[Test]]: {}", stylize(testCase->name, Color::EXT_SKY_BLUE));
fmt::print(" [[Test]]: {}", fmt::stylize(testCase->name, fmt::Color::EXT_SKY_BLUE));
try {
// Call the test function
testCase->fn();
println(" ... => {}", stylize("Passed!", Color::GREEN));
fmt::println(" ... => {}", fmt::stylize("Passed!", fmt::Color::GREEN));
results.passed++;
return true;
} catch (const std::exception &ex) {
println(" ... => {}:\n\t{}", stylize("Failed", Color::RED), ex.what());
fmt::println(" ... => {}:\n\t{}", fmt::stylize("Failed", fmt::Color::RED), ex.what());
results.failed++;
return false;
}
Expand All @@ -399,8 +399,8 @@ void checkForTestErrors(const bool freeTestsErrors) {
std::exit(1);
}

void print_separator(const Color color) {
println(
stylize("============================================================================", color, {Modifier::BOLD})
void print_separator(const fmt::Color color) {
fmt::println(
fmt::stylize("============================================================================", color, {fmt::Modifier::BOLD})
);
}
1 change: 1 addition & 0 deletions zero/ifc/text/stylizer.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export module stylizer;

import std;
import std.compat;

export namespace zero::fmt {

Expand Down
Binary file modified zork
Binary file not shown.
4 changes: 3 additions & 1 deletion zork_config/zork_local_linux.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ cpp_compiler = "clang"
driver_path = "clang++-16" # This binary is soft linked and included in our local path
cpp_standard = "2b"
std_lib = "LIBCPP"
std_lib_installed_dir = "/usr/local/share/libc++/v1"
extra_args = [
'-Werror', '-Wall', '-Wpedantic', '-pedantic', '-Wextra', '-Wconversion', '-Wfloat-conversion', '-Wsign-conversion',
'-Wshadow', '-Wnon-virtual-dtor', '-Wold-style-cast', '-Wcast-align', '-Wunused', '-Woverloaded-virtual',
'-Wmisleading-indentation', '-Wnull-dereference', '-Wdouble-promotion', '-Wformat=2', '-Wimplicit-fallthrough',
'-Weffc++'
'-Weffc++',
'-Wno-deprecated-declarations'
]

[build]
Expand Down

0 comments on commit 5c9f965

Please sign in to comment.