Skip to content

Commit

Permalink
Restructure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Jun 12, 2018
1 parent 5a222d2 commit cc867e0
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 352 deletions.
338 changes: 1 addition & 337 deletions .travis.yml

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ SHELL = /bin/sh

MKDIR_P = mkdir -p

# If ./configure has been run, include configure.in
ifneq ("$(wildcard configure.in)","")
include configure.in
endif

# 'test' directory exists, therefore force make to run test
.PHONY: test


###
### Help
###
help:
@echo Options
@echo " make test"
@echo " Test awesome-ci scripts"
@echo ""
@echo " make install"
@echo " Install everthing (requires sudo or root)"
@echo ""
Expand Down Expand Up @@ -61,3 +72,13 @@ clean:
###
docker:
docker build -t cytopia/awesome-ci .


###
###
###
test:
./test/test.sh



70 changes: 55 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@
[![Latest Stable Version](https://poser.pugx.org/cytopia/awesome-ci/v/stable)](https://packagist.org/packages/cytopia/awesome-ci)
[![Total Downloads](https://poser.pugx.org/cytopia/awesome-ci/downloads)](https://packagist.org/packages/cytopia/awesome-ci)
[![License](https://poser.pugx.org/cytopia/awesome-ci/license)](http://opensource.org/licenses/MIT)
[![Type](https://img.shields.io/badge/type-bash-red.svg)](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29)

---

**Runs on**
**Runs on every good OS**

[![Linux](https://raw.githubusercontent.com/cytopia/icons/master/64x64/linux.png)](https://www.kernel.org/)
[![FreeBSD](https://raw.githubusercontent.com/cytopia/icons/master/64x64/freebsd.png)](https://www.freebsd.org)
[![OSX](https://raw.githubusercontent.com/cytopia/icons/master/64x64/osx.png)](https://www.apple.com/osx)

Continuous Integration command line tools for git repositories, file characteristics, syntax errors
and static source code analysis.

Lot's of tools for git, file and static source code analysis.

**Documentation**
Awesome-CI is capable of finding various problems in your code repository as well as fixing them
automatically.

* [Dependencies](dependencies/)
* [Examples](EXAMPLES.md)
* [Regex Contributions](REGEX_CONTRIBUTIONS.md)

---

Expand All @@ -33,10 +28,12 @@ Lot's of tools for git, file and static source code analysis.
4. [Custom regex contributions](#custom-regex-contributions)
5. [General usage](#general-usage)
6. [Installation](i#installation)
1. [Install OSX](#install-osx)
2. [Install Linux/BSD](#install-linuxbsd)
1. [Requirements](#requirements)
2. [Install OSX](#install-osx)
3. [Install Linux/BSD](#install-linuxbsd)
7. [Awesome CI Docker image](#awesome-ci-docker-image)
8. [License](#license)
8. [Documentation](#documentation)
9. [License](#license)


## Tools
Expand Down Expand Up @@ -149,6 +146,23 @@ Please use pull requests to add useful checks.

## Installation

### Requirements

Awesome-ci requires the following tools to be installed:

* `dos2unix`
* `eslint`
* `file`
* `git`
* `jsonlint`
* `mdl`
* `perl`
* `php`
* `python`
* `ruby`
* `scss_lint`
* `shellcheck`

### Install OSX

```bash
Expand All @@ -174,13 +188,39 @@ make install

## Awesome CI Docker image

Instead of installing it, you can also use the bundled Docker image:
**[cytopia/awesome-ci](https://hub.docker.com/r/cytopia/awesome-ci/)**
Instead of installing awesome-ci and all its required dependencies locally on your computer,
you can also use the bundled Docker image
**[cytopia/awesome-ci](https://hub.docker.com/r/cytopia/awesome-ci/)** which has everything
pre-installed and is built nightly by travis-ci.

```bash
docker run -v ${PWD}:/ac cytopia/awesome-ci file-crlf --path=/ac
```

The above example is using `file-crlf` to scan the current directory for files containing
Windows newlines:

* `${PWD}` (the current host directory) is mounted into the container's `/ac` directoy
* `file-crlf` path then points (inside the container) to `/ac` (which is the current host directory)
* `/ac` can actually be named by whatever name you want

If you use an awesome-ci configuration which is not inside the directory you want to check, you
will also have to mount that into the container:
```bash
docker run \
-v /host/path/to/awesome-ci.conf:/etc/awesome-ci.conf \
-v ${PWD}:/ac cytopia/awesome-ci file-crlf --path=/ac --config=/etc/awesome-ci.conf
```

## Documentation

To find out more about awesome-ci, have a look at the following links.

* [Dependencies](dependencies/)
* [Examples](EXAMPLES.md)
* [Regex Contributions](REGEX_CONTRIBUTIONS.md)


## License

[MIT License](LICENSE.md)
Expand Down
3 changes: 3 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Awesome-CI test cases

This directory contains test cases for awesome-ci.
40 changes: 40 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail


###
### Define Paths
###
GIT_PATH="$( cd "$(dirname "$0")" ; pwd -P )/.."
RUN_PATH="${GIT_PATH}/test/test_single.sh"


${RUN_PATH} file-cr
${RUN_PATH} file-crlf
${RUN_PATH} file-empty
${RUN_PATH} file-nullbyte-char
${RUN_PATH} file-trailing-newline
${RUN_PATH} file-trailing-single-newline
${RUN_PATH} file-trailing-space
${RUN_PATH} file-utf8
${RUN_PATH} file-utf8-bom
${RUN_PATH} git-conflicts
${RUN_PATH} git-ignored
${RUN_PATH} inline-css
${RUN_PATH} inline-js
${RUN_PATH} regex-grep
${RUN_PATH} regex-perl
${RUN_PATH} syntax-bash
${RUN_PATH} syntax-css
${RUN_PATH} syntax-js
${RUN_PATH} syntax-json
${RUN_PATH} syntax-markdown
${RUN_PATH} syntax-perl
${RUN_PATH} syntax-php
${RUN_PATH} syntax-python
${RUN_PATH} syntax-ruby
${RUN_PATH} syntax-scss
${RUN_PATH} syntax-sh
141 changes: 141 additions & 0 deletions test/test_single.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail


###
### Define Paths
###
GIT_PATH="$( cd "$(dirname "$0")" ; pwd -P )/.."
ETC_PATH="${GIT_PATH}/etc/awesome-ci.conf"
BIN_PATH="${GIT_PATH}/bin"

TEST_SUCC_PATH="${GIT_PATH}/test/ok"
TEST_FAIL_PATH="${GIT_PATH}/test/err"

# Add dependencies to path
PATH=${GIT_PATH}/dependencies:${PATH}


###
### Check arguments
###
if [ "${#}" -ne "1" ]; then
>&2 echo "This script requires exactly one argument: ${#} are given."
exit 1
fi

# Path to binary
BINARY="${BIN_PATH}/${1}"


############################################################
# Functions
############################################################

run () {
local cmd="${1}"

>&2 echo "----------------------------------------------------------------------------------------------------"
>&2 echo "\$ ${cmd}"
>&2 echo "----------------------------------------------------------------------------------------------------"

${cmd}
}


############################################################
# Run tests
############################################################


###
### 1. Info
###
COMMAND="${BINARY} --info"
if ! OUT="$( run "${COMMAND}" )"; then
echo "${OUT}"
>&2 echo "[Error] 'Info test' failed"
exit 1
fi
echo "[TEST PASSED]"
echo


###
### 2. Dry
###
if [ "${1}" = "git-ignored" ]; then
COMMAND="${BINARY} --path=. --dry"
else
COMMAND="${BINARY} --path=. --config=${ETC_PATH} --dry"
fi
if ! OUT="$( run "${COMMAND}" )"; then
echo "${OUT}"
>&2 echo "[TEST FAILED] 'Dry test' failed"
exit 1
fi
echo "[TEST PASSED]"
echo


###
### 3. Test OK
###
if [ "${1}" != "git-ignored" ] && [ "${1}" != "regex-grep" ] && [ "${1}" != "regex-perl" ]; then

COMMAND="${BINARY} --path=${TEST_SUCC_PATH} --config=${ETC_PATH}"

if ! OUT="$( run "${COMMAND} --list" )"; then
echo "${OUT}"
>&2 echo "[TEST FAILED] 'Success test' failed"
exit 1
fi
echo "[TEST PASSED]"
echo

if ! OUT="$( run "${COMMAND} --verbose" )"; then
echo "${OUT}"
>&2 echo "[TEST FAILED] 'Success test' failed"
exit 1
fi
echo "[TEST PASSED]"
echo

if ! OUT="$( run "${COMMAND}" )"; then
echo "${OUT}"
>&2 echo "[TEST FAILED] 'Success test' failed"
exit 1
fi
echo "[TEST PASSED]"
echo
fi


###
### 3. Test Failure
###
if [ "${1}" != "git-ignored" ] && [ "${1}" != "regex-grep" ] && [ "${1}" != "regex-perl" ]; then

COMMAND="${BINARY} --path=${TEST_FAIL_PATH} --config=${ETC_PATH}"

if ! OUT="$( run "${COMMAND} --verbose" )"; then
echo "[TEST PASSED]"
echo
else
echo "${OUT}"
>&2 echo "[TEST FAILED] 'Failure test' failed"
exit 1
fi

if ! OUT="$( run "${COMMAND}" )"; then
echo "[TEST PASSED]"
echo
else
echo "${OUT}"
>&2 echo "[TEST FAILED] 'Failure test' failed"
exit 1
fi
fi

0 comments on commit cc867e0

Please sign in to comment.