Skip to content

Commit

Permalink
Add more configurations to build matrix, update cpp_sample
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong authored Nov 21, 2021
1 parent 4acafe7 commit 9849511
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
24 changes: 10 additions & 14 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ on:
pull_request:
branches: [ master ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
build_type: [Release, Debug]
os: [macos-latest, ubuntu-latest]
CC: [clang, gcc]
gcc_version: [latest, 11]
exclude:
- os: macos-latest
CC: clang
- os: ubuntu-latest
CC: gcc
- CC: clang
gcc_version: 11
- os: ubuntu-latest
CC: gcc
gcc_version: latest

steps:
- uses: actions/checkout@v2
Expand All @@ -38,8 +34,8 @@ jobs:
env:
CC: ${{ matrix.CC }}
run: |
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} tests
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON tests
cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}}
- name: Test
working-directory: ${{github.workspace}}/build
Expand All @@ -50,5 +46,5 @@ jobs:
CC: ${{ matrix.CC }}
run: |
rm -rf ${{github.workspace}}/build
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} samples
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON samples
cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}}
3 changes: 1 addition & 2 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
cmake_policy(VERSION 2.6)
cmake_minimum_required(VERSION 3.0)

project(tinydir)

Expand Down
27 changes: 24 additions & 3 deletions samples/cpp_sample.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <list>
#include <stdexcept>
#include <string>

Expand All @@ -8,7 +9,9 @@ class TinyDir {
public:
TinyDir(const std::string& path);
~TinyDir();
std::string BaseName() const;
std::string baseName() const;
std::list<std::string> listDir();

private:
tinydir_dir* dir;
};
Expand All @@ -22,10 +25,11 @@ TinyDir::TinyDir(const std::string& path) : dir(new tinydir_dir) {
}

TinyDir::~TinyDir() {
tinydir_close(dir);
delete dir;
}

std::string TinyDir::BaseName() const {
std::string TinyDir::baseName() const {
const std::string path{dir->path};
auto lastSlash = path.find_last_of("/\\");
if (lastSlash == std::string::npos) {
Expand All @@ -34,13 +38,30 @@ std::string TinyDir::BaseName() const {
return path.substr(lastSlash + 1);
}

std::list<std::string> TinyDir::listDir()
{
std::list<std::string> files;

while (dir->has_next)
{
tinydir_file file;
tinydir_readfile(dir, &file);

files.push_back(std::string{dir->path} + "/" + file.name);

tinydir_next(dir);
}

return files;
}

int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: cpp_sample filename\n";
return 1;
}
TinyDir td{argv[1]};
std::cout << "Basename is " << td.BaseName() << "\n";
std::cout << "Basename is " << td.baseName() << "\n";
return 0;
}

2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)

project(tinydir_tests C)

Expand Down

0 comments on commit 9849511

Please sign in to comment.