Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Oct 27, 2014
1 parent 64a1cca commit 6418d60
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 113 deletions.
52 changes: 0 additions & 52 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,52 +0,0 @@
*.pyc
*.pyo
*.class
*~
*#
/doc/generated/*
/runpy
/build
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml
htmlcov

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Complexity
output/*.html
output/*/index.html

# Sphinx
docs/_build

/venv
29 changes: 18 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
language: python

python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "pypy"
language: bash

before_install:
- git config --global user.email "[email protected]"
- git config --global user.name "Your Name"
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
- git config --global user.email "[email protected]"
- git config --global user.name "Your Name"

script:
- make test

script: make test
deploy:
provider: releases
api_key:
secure: IFO/IqsxE2ZF1oLIWQkr7VE6yTQtbG6vea/4+zgMrknWxjkfVproj25rSgsxL3Wxln03ubOqaG50d01hDmgWoaRz3sG3wV9mMn7EjXz9+M6MBCzv940VDYzBhZUaW225Sw7SDdZIA7bsgMrvkmlhK8tZg7Ow7pcYoeRmyDrehCE=
file: chag
on:
repo: mtdowling/chag
tags: true
all_branches: true
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
## 1.0.0 - 2014-10-26

* Using the format from http://keepachangelog.com
* Trimming down the feature set and switching back to bash. This makes chag
much simpler to install and does not require any dependencies.
* Trimming down the feature set and switching back to bash instead of Python.
This makes chag much simpler to install and does not require any
dependencies.
* Simplified by removing `chag new`, `chag append`, and `chag get`.

## 0.5.0 - 2014-08-16

Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
tag:
./chag tag --sign --debug CHANGELOG.rst latest

test:
bats test/

deploy: tag
git push origin master
git push origin --tags

.PHONY: test
36 changes: 19 additions & 17 deletions chag
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ unset COMMAND FILENAME TAG SIGN FORCE ADDV NOTRIM
HEADING_START='## .+'

version() {
echo "chag 0.6.0"
echo "chag 1.0.0"
}

usage() {
Expand Down Expand Up @@ -196,17 +196,17 @@ parse_options() {
# Gets the contents of a changelog entry
contents() {
if [ -z "$NOTRIM" ]; then
get_trimmed_entry "$TAG"
get_trimmed_entry "$TAG" || exit $?
else
get_changelog_entry "$TAG"
get_changelog_entry "$TAG" || exit $?
fi
}

tag() {
`git diff --quiet HEAD` || die 'Working directory not clean'
TAG=$(latest)
contents_cmd="get_trimmed_entry"
(entries | grep -q $TAG) || die "[FAILURE] $TAG not found in $FILENAME"
(entries | grep -q $TAG) || die "[FAILURE] $TAG not found"

if [ "$TAG" == "Unreleased" ]; then
die 'Not tagging an Unreleased tag. Please check your changelog file.'
Expand All @@ -229,7 +229,7 @@ tag() {
debug "Running git command: $cmd"
fi

(contents_cmd | $cmd) || die "[FAILURE] Failed tagging $real_tag"
($contents_cmd | $cmd) || die "[FAILURE] Failed tagging $real_tag"
echo "[SUCCESS] Tagged $real_tag"
}

Expand All @@ -238,14 +238,24 @@ update() {
start=$(find_first_entry)
local replacement="## $TAG - $(date +%Y-%m-%d)"
perl -i -pe "s/.*/$replacement/ if \$.==${start}" $FILENAME
echo "[SUCCESS] Updated ${FILENAME} with $replacement"
echo "[SUCCESS] Updated ${FILENAME} with ${TAG}"
}

# Get a list of entry versions separated by newlines
entries() {
entries_and_lines | cut -d ':' -f 2
}

# Prints each heading "line_number:line" from the changelog separated w/ "\n"
entries_and_lines() {
local pattern="^($HEADING_START)"
# Find each entry line number and version, separated by colons.
grep -n -E -e "$pattern" $FILENAME \
| sed -E 's/## //' \
| cut -d '-' -f 1 \
| sed -e 's/^ *//' -e 's/ *$//'
}

# Gets the latest version number from the changelog
latest() {
entries | head -n1 | cut -d ':' -f 1
Expand All @@ -270,7 +280,7 @@ get_changelog_entry() {
fi

# Ensure that the heading was found
[ "$found_line" == "" ] && die "Tag not found in $FILENAME"
[ "$found_line" == "" ] && die "[FAILURE] Tag not found"
# First line in the file of the changelog header.
local start_line=$(($found_line + 1))
# Find the length of the section
Expand All @@ -294,16 +304,8 @@ get_changelog_entry() {
# Gets a trimmed changelog entry
get_trimmed_entry() {
get_changelog_entry "$1" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba'
}

# Prints each heading "line_number:line" from the changelog separated w/ "\n"
entries_and_lines() {
local pattern="^($HEADING_START)"
# Find each entry line number and version, separated by colons.
grep -n -E -e "$pattern" $FILENAME \
| sed -E 's/## //' \
| cut -d '-' -f 1 \
| sed -e 's/^ *//' -e 's/ *$//'
# PIPESTATUS tells us the exit status of each command in the previous pipe.
[ ${PIPESTATUS[0]} -eq 0 ] || exit 1
}

main "$@"
2 changes: 1 addition & 1 deletion test/contents.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ load test_helper
run ./chag contents --file $CHNGFILE --tag 9.9.9
delete_changelog
[ $status -eq 1 ]
[ $(expr "${lines[0]}" : "Tag 9.9.9 not found") -ne 0 ]
[ "${lines[0]}" == "[FAILURE] Tag not found" ]
}

@test "contents can contents a tag" {
Expand Down
6 changes: 0 additions & 6 deletions test/latest.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ load test_helper
[ $(expr "${lines[0]}" : "Unknown option") -ne 0 ]
}

@test "latest requires a FILENAME" {
run ./chag latest
[ $status -eq 1 ]
[ $(expr "${lines[0]}" : ".* latest requires a FILENAME") -ne 0 ]
}

@test "latest shows latest tag" {
setup_changelog
run ./chag latest --file $CHNGFILE
Expand Down
20 changes: 4 additions & 16 deletions test/tag.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,15 @@ chagcmd="$BATS_TEST_DIRNAME/../chag"
[ $(expr "${lines[0]}" : "File not found: /path/to/does/not/exist") -ne 0 ]
}

@test "Tags with annotation and specific tag" {
setup_repo
run $chagcmd tag --addv --file CHANGELOG.rst
[ $status -eq 0 ]
[ "${lines[0]}" == '[SUCCESS] Tagged v0.0.1' ]
run git tag -l -n1 v0.0.1
cd -
[ $status -eq 0 ]
[ "${lines[0]}" == 'v0.0.1 * Initial release.' ]
delete_repo
}

@test "Tags debug output" {
setup_repo
run $chagcmd tag --debug --file CHANGELOG.rst
run $chagcmd tag --debug --file CHANGELOG.md
[ $status -eq 0 ]
[ "${lines[0]}" == 'Tagging 0.0.2 with the following annotation:' ]
[ "${lines[1]}" == '===[ BEGIN ]===' ]
[ "${lines[2]}" == '* Correcting ``--debug`` description.' ]
[ "${lines[3]}" == '===[ END ]===' ]
[ "${lines[4]}" == 'Running git command: git tag -a -F - 0.0.2' ]
[ "${lines[4]}" == 'Running git command: git tag -a -F - 0.0.2' ]
[ "${lines[5]}" == '[SUCCESS] Tagged 0.0.2' ]
run git tag -l -n1 0.0.2
cd -
Expand All @@ -53,9 +41,9 @@ chagcmd="$BATS_TEST_DIRNAME/../chag"

@test "Can force a tag" {
setup_repo
run $chagcmd tag CHANGELOG.rst 0.0.2
run $chagcmd tag CHANGELOG.md 0.0.2
[ $status -eq 0 ]
run $chagcmd tag --force --file CHANGELOG.rst --tag 0.0.2
run $chagcmd tag --force --file CHANGELOG.md --tag 0.0.2
[ $status -eq 0 ]
[ "${lines[0]}" == '[SUCCESS] Tagged 0.0.2' ]
cd -
Expand Down
6 changes: 3 additions & 3 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHAGREPO="$BATS_TMPDIR/chag-test"

# Creates a test fixure changelog
setup_changelog() {
tail -9 CHANGELOG.rst > $CHNGFILE
tail -9 CHANGELOG.md > $CHNGFILE
}

# Creates a test fixure changelog that has a TBD entry
Expand All @@ -14,7 +14,7 @@ setup_changelog_tbd() {
printf "Next Release (TBD)\n" >> $CHNGFILE
echo "------------------" >> $CHNGFILE
printf "\nHello!\n\n" >> $CHNGFILE
tail -9 CHANGELOG.rst >> $CHNGFILE
tail -9 CHANGELOG.md >> $CHNGFILE
}

# Deletes the test fixture changelog
Expand All @@ -32,7 +32,7 @@ setup_repo() {
delete_repo
# Create new git repo
mkdir -p $CHAGREPO
tail -9 CHANGELOG.rst > $CHAGREPO/CHANGELOG.rst
tail -9 CHANGELOG.md > $CHAGREPO/CHANGELOG.md
cd $CHAGREPO
git init && git add -A && git commit -m 'Initial commit'
}
4 changes: 2 additions & 2 deletions test/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ load test_helper

@test "updates inline" {
setup_changelog_tbd
run ./chag update --file $CHNGFILE --tag 9.9.9
run ./chag update --file $CHNGFILE 9.9.9
delete_changelog
[ $status -eq 0 ]
date=$(date +%Y-%m-%d)
[ "${lines[0]}" == "[SUCCESS] Updated ${CHNGFILE} with ## 9.9.9 - $date" ]
[ "${lines[0]}" == "[SUCCESS] Updated ${CHNGFILE} with 9.9.9" ]
}

0 comments on commit 6418d60

Please sign in to comment.