From 2e40f65b2e016ac049a1948656191133eb4088c7 Mon Sep 17 00:00:00 2001 From: Mathew Odden Date: Tue, 13 May 2014 22:29:46 -0500 Subject: [PATCH] Add tests and samples for legacy bash8 This change introduces some basic tests for bash8 checks, including a sample file that is used to verify checked errors before/in the 0.1.0 release. Change-Id: Icc8f9889e5539949a6475769d1083cd619c2c79e --- bash8/bash8.py | 4 ++ bash8/tests/samples/E001_bad.sh | 4 ++ bash8/tests/samples/E002_bad.sh | 3 ++ bash8/tests/samples/legacy_sample.sh | 40 +++++++++++++++ bash8/tests/test_bash8.py | 76 ++++++++++++++++++++++++++++ test-requirements.txt | 1 + 6 files changed, 128 insertions(+) create mode 100644 bash8/tests/samples/E001_bad.sh create mode 100644 bash8/tests/samples/E002_bad.sh create mode 100644 bash8/tests/samples/legacy_sample.sh diff --git a/bash8/bash8.py b/bash8/bash8.py index 3ca97b8..99d348b 100644 --- a/bash8/bash8.py +++ b/bash8/bash8.py @@ -66,6 +66,10 @@ def print_error(error, line, filelineno = fileinput.filelineno() global ERRORS ERRORS = ERRORS + 1 + log_error(error, line, filename, filelineno) + + +def log_error(error, line, filename, filelineno): print("%s: '%s'" % (error, line.rstrip('\n'))) print(" - %s: L%s" % (filename, filelineno)) diff --git a/bash8/tests/samples/E001_bad.sh b/bash8/tests/samples/E001_bad.sh new file mode 100644 index 0000000..e0a2785 --- /dev/null +++ b/bash8/tests/samples/E001_bad.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# E001 +somefunction args diff --git a/bash8/tests/samples/E002_bad.sh b/bash8/tests/samples/E002_bad.sh new file mode 100644 index 0000000..561407b --- /dev/null +++ b/bash8/tests/samples/E002_bad.sh @@ -0,0 +1,3 @@ +#!/bin/bash + + echo "E002: Has a tab" diff --git a/bash8/tests/samples/legacy_sample.sh b/bash8/tests/samples/legacy_sample.sh new file mode 100644 index 0000000..d5059f7 --- /dev/null +++ b/bash8/tests/samples/legacy_sample.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# E020 +function somefunction () { + echo "E002: Has a tab" + + echo "E003: Not an indent with multiple of 4" +} + +# E001 +somefunction args + +# E010 +for thing in things +do + run_things thing +done + +while 0 +do + run_thing +done + +until 1 +do + run_thing +done + +# E011 +if [ 0 ] +then + run_morethings +else + run_otherthings +fi + +# E012 +cat <=0.5.6,<0.8 +mock>=1.0 coverage>=3.6 discover