Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libc++-18-dev


- name: Install missing software on macos
if: contains(matrix.os, 'macos')
run: |
brew install python3

- name: Install missing Python packages
run: |
python3 -m pip config set global.break-system-packages true
python3 -m pip install pip --upgrade
python3 -m pip install pytest

- name: make simplecpp
run: make -j$(nproc)

Expand All @@ -41,6 +52,10 @@ jobs:
run: |
make -j$(nproc) selfcheck

- name: integration test
run: |
python3 -m pytest integration_test.py

- name: Run CMake
run: |
cmake -S . -B cmake.output
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ jobs:

- name: Setup msbuild.exe
uses: microsoft/setup-msbuild@v2


- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: '3.13'
check-latest: true

- name: Install missing Python packages
run: |
python -m pip install pip --upgrade || exit /b !errorlevel!
python -m pip install pytest || exit /b !errorlevel!

- name: Run cmake
if: matrix.os == 'windows-2019'
run: |
Expand All @@ -48,4 +59,9 @@ jobs:
- name: Selfcheck
run: |
.\${{ matrix.config }}\simplecpp.exe simplecpp.cpp -e || exit /b !errorlevel!

- name: integration test
run: |
set SIMPLECPP_EXE_PATH=.\${{ matrix.config }}\simplecpp.exe
python -m pytest integration_test.py || exit /b !errorlevel!

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ testrunner
# CLion
/.idea
/cmake-build-*

# python
__pycache__/
131 changes: 131 additions & 0 deletions integration_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
## test with python -m pytest integration_test.py

import os
from testutils import simplecpp, format_include_path_arg, format_include

def __test_relative_header_create_header(dir, with_pragma_once=True):
header_file = os.path.join(dir, 'test.h')
with open(header_file, 'wt') as f:
f.write(f"""
{"#pragma once" if with_pragma_once else ""}
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
#else
#error header_was_already_included
#endif
""")
return header_file, "error: #error header_was_already_included"

def __test_relative_header_create_source(dir, include1, include2, is_include1_sys=False, is_include2_sys=False):
src_file = os.path.join(dir, 'test.c')
with open(src_file, 'wt') as f:
f.write(f"""
#undef TEST_H_INCLUDED
#include {format_include(include1, is_include1_sys)}
#include {format_include(include2, is_include2_sys)}
""")
return src_file


def test_relative_header_0_rel(tmpdir):
_, double_include_error = __test_relative_header_create_header(tmpdir, with_pragma_once=False)

test_file = __test_relative_header_create_source(tmpdir, "test.h", "test.h")

args = [test_file]

_, _, stderr = simplecpp(args, cwd=tmpdir)
assert double_include_error in stderr

def test_relative_header_0_sys(tmpdir):
_, double_include_error = __test_relative_header_create_header(tmpdir, with_pragma_once=False)

test_file = __test_relative_header_create_source(tmpdir, "test.h", "test.h", is_include1_sys=True, is_include2_sys=True)

args = [format_include_path_arg(tmpdir), test_file]

_, _, stderr = simplecpp(args)
assert double_include_error in stderr

def test_relative_header_1_rel(tmpdir):
__test_relative_header_create_header(tmpdir)

test_file = __test_relative_header_create_source(tmpdir, "test.h", "test.h")

args = [test_file]

_, _, stderr = simplecpp(args, cwd=tmpdir)
assert stderr == ''

def test_relative_header_1_sys(tmpdir):
__test_relative_header_create_header(tmpdir)

test_file = __test_relative_header_create_source(tmpdir, "test.h", "test.h", is_include1_sys=True, is_include2_sys=True)

args = [format_include_path_arg(tmpdir), test_file]

_, _, stderr = simplecpp(args)
assert stderr == ''

## TODO: the following tests should pass after applying simplecpp#362

def test_relative_header_2(tmpdir):
header_file, _ = __test_relative_header_create_header(tmpdir)

test_file = __test_relative_header_create_source(tmpdir, "test.h", header_file)

args = [test_file]

_, _, stderr = simplecpp(args, cwd=tmpdir)
assert stderr == ''

def test_relative_header_3(tmpdir):
test_subdir = os.path.join(tmpdir, "test_subdir")
os.mkdir(test_subdir)
header_file, _ = __test_relative_header_create_header(test_subdir)

test_file = __test_relative_header_create_source(tmpdir, "test_subdir/test.h", header_file)

args = [test_file]

_, _, stderr = simplecpp(args, cwd=tmpdir)
assert stderr == ''

def test_relative_header_3_inv(tmpdir):
test_subdir = os.path.join(tmpdir, "test_subdir")
os.mkdir(test_subdir)
header_file, _ = __test_relative_header_create_header(test_subdir)

test_file = __test_relative_header_create_source(tmpdir, header_file, "test_subdir/test.h")

args = [test_file]

_, _, stderr = simplecpp(args, cwd=tmpdir)
assert stderr == ''


def test_relative_header_4(tmpdir):
test_subdir = os.path.join(tmpdir, "test_subdir")
os.mkdir(test_subdir)
header_file, _ = __test_relative_header_create_header(test_subdir)

test_file = __test_relative_header_create_source(tmpdir, header_file, "test.h", is_include2_sys=True)

args = [format_include_path_arg(test_subdir), test_file]

_, _, stderr = simplecpp(args, cwd=tmpdir)
assert stderr == ''



def test_relative_header_5(tmpdir):
test_subdir = os.path.join(tmpdir, "test_subdir")
os.mkdir(test_subdir)
__test_relative_header_create_header(test_subdir)

test_file = __test_relative_header_create_source(tmpdir, "test.h", "test_subdir/test.h", is_include1_sys=True)

args = [format_include_path_arg(test_subdir), test_file]

_, _, stderr = simplecpp(args, cwd=tmpdir)
assert stderr == ''
Loading