diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 77a86021..24e78d64 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -9,7 +9,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 env: RM_TS_DIR: "/tmp/rmlint-unit-testdir" steps: @@ -17,75 +17,27 @@ jobs: with: fetch-depth: 0 - - name: "Prepare build environment" - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - scons python3-sphinx gettext python3-setuptools \ - libblkid-dev libelf-dev libglib2.0-dev libjson-glib-dev \ - clang python3-pip python3-cffi python3-dev libffi-dev - pip3 install -r tests/requirements.txt - - - name: "Build" - # Todo: eventually run tests with valgrind (RM_TS_USE_VALGRIND) - # Todo enable slow tests in pytest - run: | - scons config - scons VERBOSE=1 DEBUG=1 O=release - - - name: "Check need for testing" - # TODO also include skipping build but allow docs to be processed + + - name: "Check changes" + # TODO also include skippin + shell: bash run: | - if git diff --exit-code --name-only origin/$GITHUB_BASE_REF HEAD ':!.gitignore' ':!docs' ':!*.md' ':!*.txt'; then - echo "RUN_TEST=false" >> "$GITHUB_ENV" + echo "BASE: $GITHUB_BASE_REF" + echo "REF: $GITHUB_REF" + echo "MERGECOMMIT: $GITHUB_SHA" + echo "HEAD_REF: ${{ GITHUB.HEAD_REF }}" + if git diff --exit-code --name-only origin/$GITHUB_BASE_REF...$GITHUB_SHA ':!.gitignore' ':!docs' ':!*.md' ':!*.txt' ':!*.yml'; then + echo "RUN_TEST=false" >> $GITHUB_ENV echo "RUN_TEST = false" else - echo "RUN_TEST=true" >> "$GITHUB_ENV" + echo "RUN_TEST=true" >> $GITHUB_ENV echo "RUN_TEST = true" fi - - - name: "Prepare test environment" - # TODO Ignore linter warning. See https://github.com/github/vscode-github-actions/issues/222 - if: ${{ env.RUN_TEST == 'true' }} - # The test suite is seriously disk-intensive. Given that linux - # instances hosted in GitHub have 16G of RAM available we will - # use it to speed up the run. - run: | - sudo mkdir "${RM_TS_DIR}" - sudo mount -o size=12G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" + - name: "Should we test" + run: + echo "the answer is $RUN_TEST" - name: "Test it" - if: ${{ env.RUN_TEST == 'true' }} - run: | - RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest -s -v - - - name: CoW tests - if: ${{ env.RUN_TEST == 'true' }} - shell: bash - run: | - sudo umount "${RM_TS_DIR}" - sudo modprobe brd rd_nr=1 rd_size=12582912 - sudo mkfs.btrfs -f /dev/ram0 - sudo mount /dev/ram0 "${RM_TS_DIR}" - sudo chmod 0777 "${RM_TS_DIR}" - cat <<'EOF' >> tests/conftest.py - - def pytest_collection_modifyitems(items, config): - selected_items = [] - deselected_items = [] - - for item in items: - if "needs_reflink_fs" in getattr(item, "fixturenames", ()): - selected_items.append(item) - else: - deselected_items.append(item) - config.hook.pytest_deselected(items=deselected_items) - items[:] = selected_items - EOF - RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest -s -v - - - name: "Cleanup" - if: ${{ env.RUN_TEST == 'true' }} + if: ! ${{ env.RUN_TEST == 'true' }} run: | - sudo umount "${RM_TS_DIR}" - sudo rmdir "${RM_TS_DIR}" + echo "RUNNING IT... " diff --git a/tests/.python-version b/tests/.python-version new file mode 100644 index 00000000..251b3507 --- /dev/null +++ b/tests/.python-version @@ -0,0 +1 @@ +3.10.16 diff --git a/tests/test_formatters/test_csv.py b/tests/test_formatters/test_csv.py index 8d19cb64..4659525a 100644 --- a/tests/test_formatters/test_csv.py +++ b/tests/test_formatters/test_csv.py @@ -8,8 +8,8 @@ def csv_string_to_data(csv_dump): data = list(csv.reader(csv_dump.splitlines())) return data[1:] - -def test_simple(usual_setup_usual_teardown): +@pytest.mark.usefixtures('usual_setup_usual_teardown') +def test_simple(): create_file('1234', 'a') create_file('1234', 'b') create_file('1234', 'stupid\'file,name') diff --git a/tests/test_formatters/test_json.py b/tests/test_formatters/test_json.py index 2e72e2ee..d04a1396 100644 --- a/tests/test_formatters/test_json.py +++ b/tests/test_formatters/test_json.py @@ -2,7 +2,8 @@ from tests.utils import * -def test_simple(usual_setup_usual_teardown): +@pytest.mark.usefixtures('usual_setup_usual_teardown') +def test_simple(): full_path_a = create_file('x', '\t\r\"\b\f\\') full_path_b = create_file('x', '\"\t\n2134124') head, *data, footer = run_rmlint('-S a') diff --git a/tests/test_formatters/test_others.py b/tests/test_formatters/test_others.py index 3f16a637..746166cf 100644 --- a/tests/test_formatters/test_others.py +++ b/tests/test_formatters/test_others.py @@ -2,7 +2,8 @@ from tests.utils import * -def test_just_call_it(usual_setup_usual_teardown): +@pytest.mark.usefixtures('usual_setup_usual_teardown') +def test_just_call_it(): create_file('1234', 'a') create_file('1234', 'b') diff --git a/tests/test_formatters/test_sh.py b/tests/test_formatters/test_sh.py index 3b332c89..6ead303f 100644 --- a/tests/test_formatters/test_sh.py +++ b/tests/test_formatters/test_sh.py @@ -19,7 +19,8 @@ def filter_part_of_directory(data): return [e for e in data if e['type'] != 'part_of_directory'] -def test_basic(usual_setup_usual_teardown, shell): +@pytest.mark.usefixtures('usual_setup_usual_teardown') +def test_basic(shell): create_file('xxx', 'a') create_file('xxx', 'b')