GitHub Action
- This week, I set up GitHub Action for my Static Site Generator (SSG). There are several options with C++ language and I picked C/C++ with Make to implement.
- It auto generates a yml file with default contents. I had to change a few things. The structure of yml looks like this:
name: C/C++ CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: compile
run: g++ pgprogram.cpp HTMLFile.h HTMLFile.cpp MainPage.h MainPage.cpp -o pgprogram --std=c++17
- name: Program Test
run: g++ test/test.cpp test/catch.hpp HTMLFile.h HTMLFile.cpp -o programtest --std=c++17
- First, I set push and pull_request to run the test whenever it is pushed or pulled to the main branch:
push:
branches: [ main ]
pull_request:
branches: [ main ]
- Second, I set the run command of compile option to the command to compile my program:
g++ pgprogram.cpp HTMLFile.h HTMLFile.cpp MainPage.h MainPage.cpp -o pgprogram --std=c++17
- Third, I added option to test my program with testing command:
g++ test/test.cpp test/catch.hpp HTMLFile.h HTMLFile.cpp -o programtest --std=c++17
- Finally, the GitHub Action Workflow runs successfully on the project:
- Take a look at how it runs: GitHub Actions Run
Add Test to partner Repo
- I picked Gus's SSG to work on. I had work on his project before because we use the same C++ language. We use same testing framework, which is Catch2. So I generally understand how his SSG and Testing Tool work.
- I tested his project with his existing 10 test cases and it showed:
- I'm kind of ignoring failed tests for now and add my tests.
- On his existing test cases, I saw he had 4 functions to check for correct file/folder input. He only had the test cases to test if these functions are returning true values.
TEST_CASE("isText() Testing", "[istext]") {
REQUIRE(isText("The Adventure of the Speckled Band.txt") == true);
}
TEST_CASE("isMarkDown() Testing", "[ismarkdown]") {
REQUIRE(isMarkDown("readme.md") == true);
}
TEST_CASE("isFolder() Testing", "[isfolder]") {
REQUIRE(isFolder("./dist") == true);
}
TEST_CASE("isJson() Testing", "[isjson]") {
REQUIRE(isJson("ssg-config.json") == true);
}
- I added test cases to test if these functions are returning false values correctly.
TEST_CASE("isText() Testing (not .txt file)", "[istext]") {
REQUIRE(isText("The Adventure of the Speckled Band.md") == false);
REQUIRE(isText("The Adventure of the Speckled Band") == false);
}
TEST_CASE("isMarkDown() Testing (not .md file)", "[ismarkdown]") {
REQUIRE(isMarkDown("The Adventure of the Speckled Band.txt") == false);
REQUIRE(isMarkDown("The Adventure of the Speckled Band") == false);
}
TEST_CASE("isFolder() Testing (not folder)", "[isfolder]") {
REQUIRE(isFolder("The Adventure of the Speckled Band.txt") == false);
REQUIRE(isFolder("The Adventure of the Speckled Band.json") == false);
}
TEST_CASE("isJson() Testing (not .json file)", "[isjson]") {
REQUIRE(isJson("The Adventure of the Speckled Band.txt") == false);
REQUIRE(isJson("The Adventure of the Speckled Band") == false);
}
- After adding 4 tests, all tests worked perfectly.
- Take a look at my Pull Request.
Conclusion
Overall, it is really useful to add GitHub Action Workflow to my project. The future pull requests, commits, etc will needed to be checked through my compiling command and my test. It is absolutely a safeguard for the project.
Furthermore, it is interesting this week that I can contribute adding tests to my partner's repo. Hopefully, my test cases will be useful for your project.
Top comments (0)