Skip to content

Commit

Permalink
chore: add extra integrity tests (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored May 26, 2023
1 parent 3fd6dab commit bdeba2e
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 8 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Integration tests
- name: Prepare lefthook
run: |
mkdir _icoverdir_
go install -cover
- run: go test integrity_test.go -tags=integrity
- name: Format coverage
- name: Run integrity tests
run: go test integrity_test.go -tags=integrity
- name: Collect coverage
run: |
go tool covdata textfmt -i _icoverdir_ -o coverage.out
- name: Report coverage
Expand Down
29 changes: 25 additions & 4 deletions testdata/dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ cmp stdout lefthook-dumped.toml
! stderr .

-- lefthook.yml --
colors: false
colors:
cyan: 14
gray: 244
green: '#32CD32'
red: '#FF1493'
yellow: '#F0E68C'
pre-commit:
follow: true
commands:
Expand All @@ -28,7 +33,12 @@ pre-commit:
glob: "*.js"
run: yarn test
-- lefthook-dumped.yml --
colors: false
colors:
cyan: 14
gray: 244
green: '#32CD32'
red: '#FF1493'
yellow: '#F0E68C'
pre-commit:
commands:
lint:
Expand All @@ -45,7 +55,13 @@ pre-commit:
follow: true
-- lefthook-dumped.json --
{
"colors": false,
"colors": {
"cyan": 14,
"gray": 244,
"green": "#32CD32",
"red": "#FF1493",
"yellow": "#F0E68C"
},
"pre-commit": {
"commands": {
"lint": {
Expand All @@ -69,7 +85,12 @@ pre-commit:
}
}
-- lefthook-dumped.toml --
colors = false
[colors]
cyan = 14
gray = 244
green = '#32CD32'
red = '#FF1493'
yellow = '#F0E68C'

[pre-commit]
follow = true
Expand Down
30 changes: 30 additions & 0 deletions testdata/hide_unstaged.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exec git init
exec lefthook install
exec git config user.email "you@example.com"
exec git config user.name "Your Name"

exec lefthook run edit_file
exec git add -A
exec lefthook run edit_file
exec git status --short
stdout 'AM newfile.txt'

exec git commit -m 'test hide unstaged changes'
exec git status --short
stdout 'M newfile.txt'

-- lefthook.yml --
min_version: 1.1.1
pre-commit:
commands:
edit_file:
run: echo newline >> file.txt
stage_fixed: true

edit_file:
commands:
echo:
run: echo newline >> newfile.txt

-- file.txt --
firstline
10 changes: 10 additions & 0 deletions testdata/min_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
exec git init
! exec lefthook run pre-commit
stdout 'required Lefthook version is higher than current'

-- lefthook.yml --
min_version: 13.1.1
pre-commit:
commands:
echo:
run: echo
21 changes: 21 additions & 0 deletions testdata/remote.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
exec git init
exec lefthook install

exec lefthook dump
cmp stdout lefthook-dump.yml

-- lefthook.yml --
remote:
git_url: https://github.com/evilmartians/lefthook
config: examples/with_scripts/lefthook.yml
ref: v1.4.0

-- lefthook-dump.yml --
pre-commit:
scripts:
good_job.js:
runner: node
remote:
config: examples/with_scripts/lefthook.yml
git_url: https://github.com/evilmartians/lefthook
ref: v1.4.0
22 changes: 22 additions & 0 deletions testdata/run_script.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exec git init
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec lefthook install
exec git commit -m 'test'
stderr '\s*Hi there from script\s*'

-- lefthook.yml --
skip_output:
- meta
- summary
- execution_info
pre-commit:
scripts:
"file.sh":
runner: sh

-- .lefthook/pre-commit/file.sh --
#!/usr/bin/env sh

echo Hi there from scripts
1 change: 0 additions & 1 deletion testdata/run_toml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ skip_output = [

[pre-commit.commands.echo]
run = "echo Hi there from Lefthook"

20 changes: 20 additions & 0 deletions testdata/stage_fixed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
exec git init
exec lefthook install
exec git config user.email "you@example.com"
exec git config user.name "Your Name"
exec git add -A
exec git status --short
exec git commit -m 'test stage_fixed'
exec git status --short
! stdout .

-- lefthook.yml --
min_version: 1.1.1
pre-commit:
commands:
edit_file:
run: echo newline >> file.txt
stage_fixed: true

-- file.txt --
firstline

0 comments on commit bdeba2e

Please sign in to comment.