Skip to content

Commit

Permalink
Add a basic test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Sep 28, 2024
1 parent 51bd21d commit 3ba2de9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.bundle
test-repo
1 change: 1 addition & 0 deletions .tito/tito.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ builder = tito.builder.Builder
tagger = tito.tagger.VersionTagger
changelog_do_not_remove_cherrypick = 0
changelog_format = %s
fetch_sources = True
28 changes: 28 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/bash -ex

srcdir=$(dirname "$(readlink -f "$0")")
cd "$srcdir"
filename=$(basename "$(spectool -S vcs-diff-lint.spec | sed -n 's/Source1: \(.*\)/\1/p')")
echo "$filename"
rm -rf test-repo
git clone "$filename" test-repo
export PATH=$srcdir:$PATH
cd test-repo

for test_dir in "$srcdir"/test_data/*; do
test -d "$test_dir" || continue
test_name=$(basename "$test_dir")

echo "=== Test $test_name ==="
new=$(echo "$test_name" | cut -d_ -f2)
old=$(echo "$test_name" | cut -d_ -f3)
testdir=$srcdir/test_data/$test_name
git checkout "$new"
vcs-diff-lint --compare-against "$old" > errors || :

found_match=false
for added in "$testdir"/added-*.err; do
diff -ruN errors "$added" && found_match=: && break
done
$found_match
done
5 changes: 5 additions & 0 deletions test_data/001_51806b39_1059de39_basic/added-01.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error: PYLINT_WARNING:
python/hello-world-python:1: C0114[missing-module-docstring]: Missing module docstring

Error: PYLINT_WARNING:
python/hello-world-python:4: C0116[missing-function-docstring]: api_method: Missing function or method docstring
20 changes: 20 additions & 0 deletions vcs-diff-lint.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@ Release: 1%{?dist}
Summary: VCS Differential Code Analysis Tool
BuildArch: noarch

%bcond_without check

License: GPL-2.0-or-later
URL: https://github.com/fedora-copr/vcs-diff-lint
# Source is created by:
# git clone %%url && cd vcs-diff-lint
# tito build --tgz --tag %%name-%%version-%%release
Source0: %name-%version.tar.gz

Source1: https://github.com/praiskup/vcs-diff-lint-testdata/releases/download/v1.0.0/vcs-diff-lint-testdata-1.0.0.bundle

Requires: csdiff
Requires: git
Recommends: pylint
Recommends: python3-mypy
Recommends: python3-types-requests
Recommends: ruff

%if %{with check}
BuildRequires: csdiff
BuildRequires: git
BuildRequires: pylint
BuildRequires: rpmdevtools
%endif


%description
Analyze code, and print only reports related to a particular change.

Expand All @@ -31,6 +43,9 @@ added (or even fixed, as opt-in) analyzers' warnings.

%prep
%autosetup
%if %{with check}
cp %{SOURCE1} ./
%endif


%build
Expand All @@ -44,6 +59,11 @@ install -p vcs-diff-lint-csdiff-pylint %buildroot%_bindir
install -p vcs-diff-lint-csdiff-mypy %buildroot%_bindir
install -p vcs-diff-lint-csdiff-ruff %buildroot%_bindir

%if %{with check}
%check
./run-tests.sh
%endif


%files
%license LICENSE
Expand Down

0 comments on commit 3ba2de9

Please sign in to comment.