Skip to content

Commit 7ec4b48

Browse files
jupblbampcode-com
andcommitted
Fix test suite and CI workflow issues
- Fix shellcheck warnings (use single quotes in trap, remove unused code) - Format README.md with pandoc for consistency - Update CI workflow to exclude test fixtures from pre-commit formatting - Test fixtures must remain unformatted for test suite to work correctly - All 25 tests now pass successfully Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-a4b3b491-de29-4cf7-a459-f324a9c0c53b
1 parent b7b55ed commit 7ec4b48

File tree

5 files changed

+26
-31
lines changed

5 files changed

+26
-31
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ jobs:
2727
- name: Test with pre-commit
2828
run: |
2929
pip install pre-commit
30-
pre-commit run --all-files || true
30+
# Create a test configuration that excludes test fixtures
31+
cat > .pre-commit-test-config.yaml << 'EOF'
32+
repos:
33+
- repo: .
34+
rev: HEAD
35+
hooks:
36+
- id: pandoc
37+
exclude: ^tests/fixtures/
38+
EOF
39+
pre-commit run --config .pre-commit-test-config.yaml --all-files || true
3140
# Run again to ensure idempotency
32-
pre-commit run --all-files
41+
pre-commit run --config .pre-commit-test-config.yaml --all-files
3342
3443
lint:
3544
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ repos:
44
rev: HEAD
55
hooks:
66
- id: pandoc
7+
exclude: ^tests/fixtures/
78
# Optional: customize formatting options
89
# args: [--columns=100, --no-reference-links, --from=markdown, --to=markdown]

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pre-commit-pandoc
22

3-
[![Test](https://github.com/jupblb/pre-commit-pandoc/actions/workflows/test.yml/badge.svg)](https://github.com/jupblb/pre-commit-pandoc/actions/workflows/test.yml)
3+
[![Test]][1]
44

55
A [pre-commit] hook for formatting Markdown files using [pandoc].
66

@@ -16,7 +16,7 @@ This hook formats Markdown files with pandoc using the following settings:
1616
## Prerequisites
1717

1818
- [pre-commit] installed
19-
- [pandoc][1] installed
19+
- [pandoc][2] installed
2020

2121
## Installation
2222

@@ -82,8 +82,8 @@ repos:
8282
- `--to <format>` - Set output format (default: gfm)
8383

8484
Common format values include: `gfm` (GitHub Flavored Markdown), `markdown`,
85-
`markdown_strict`, `commonmark`. See [pandoc documentation][2] for all
86-
supported formats.
85+
`markdown_strict`, `commonmark`. See [pandoc documentation] for all supported
86+
formats.
8787

8888
## How it Works
8989

@@ -102,7 +102,9 @@ Contributions are welcome! Please feel free to submit a Pull Request.
102102

103103
MIT License - see LICENSE file for details.
104104

105+
[Test]: https://github.com/jupblb/pre-commit-pandoc/actions/workflows/test.yml/badge.svg
106+
[1]: https://github.com/jupblb/pre-commit-pandoc/actions/workflows/test.yml
105107
[pre-commit]: https://pre-commit.com
106108
[pandoc]: https://pandoc.org/
107-
[1]: https://pandoc.org/installing.html
108-
[2]: https://pandoc.org/MANUAL.html#general-options
109+
[2]: https://pandoc.org/installing.html
110+
[pandoc documentation]: https://pandoc.org/MANUAL.html#general-options

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
pkgs = (import nixpkgs) { inherit system; };
1111
in {
1212
devShell = pkgs.mkShell {
13-
buildInputs = with pkgs; [ pandoc pre-commit ];
13+
buildInputs = with pkgs; [ pandoc pre-commit shellcheck ];
1414
};
1515
}
1616
);

tests/test_pandoc_format.sh

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PANDOC_FORMAT="$PROJECT_ROOT/pandoc-format"
2222

2323
# Temporary directory for test files
2424
TEST_TEMP_DIR=$(mktemp -d)
25-
trap "rm -rf $TEST_TEMP_DIR" EXIT
25+
trap 'rm -rf "$TEST_TEMP_DIR"' EXIT
2626

2727
# Helper functions
2828
print_test_header() {
@@ -55,24 +55,6 @@ assert_exit_code() {
5555
fi
5656
}
5757

58-
assert_file_changed() {
59-
local file1=$1
60-
local file2=$2
61-
local test_name=$3
62-
63-
TESTS_RUN=$((TESTS_RUN + 1))
64-
65-
if ! cmp -s "$file1" "$file2"; then
66-
print_success "$test_name: file was changed as expected"
67-
TESTS_PASSED=$((TESTS_PASSED + 1))
68-
return 0
69-
else
70-
print_failure "$test_name: file was not changed"
71-
TESTS_FAILED=$((TESTS_FAILED + 1))
72-
return 1
73-
fi
74-
}
75-
7658
assert_file_unchanged() {
7759
local file1=$1
7860
local file2=$2
@@ -141,7 +123,6 @@ test_basic_formatting() {
141123
print_test_header "Basic formatting with defaults"
142124

143125
cp "$SCRIPT_DIR/fixtures/simple.md" "$TEST_TEMP_DIR/test1.md"
144-
local original="$TEST_TEMP_DIR/test1.md"
145126

146127
# Run pandoc-format
147128
set +e
@@ -156,7 +137,8 @@ test_basic_formatting() {
156137
assert_contains "$TEST_TEMP_DIR/test1.md" "\[inline link\]:" "Reference links"
157138

158139
# Check line wrapping (approximate check for 80 columns)
159-
local long_lines=$(awk 'length > 85' "$TEST_TEMP_DIR/test1.md" | wc -l)
140+
local long_lines
141+
long_lines=$(awk 'length > 85' "$TEST_TEMP_DIR/test1.md" | wc -l)
160142
TESTS_RUN=$((TESTS_RUN + 1))
161143
if [ "$long_lines" -eq 0 ]; then
162144
print_success "Lines wrapped at ~80 columns"
@@ -182,7 +164,8 @@ test_custom_columns() {
182164
assert_exit_code 1 $exit_code "Custom columns formatting"
183165

184166
# Check line wrapping (approximate check for 60 columns)
185-
local long_lines=$(awk 'length > 65' "$TEST_TEMP_DIR/test2.md" | wc -l)
167+
local long_lines
168+
long_lines=$(awk 'length > 65' "$TEST_TEMP_DIR/test2.md" | wc -l)
186169
TESTS_RUN=$((TESTS_RUN + 1))
187170
if [ "$long_lines" -eq 0 ]; then
188171
print_success "Lines wrapped at ~60 columns"

0 commit comments

Comments
 (0)