Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden testing #982

Merged
merged 1 commit into from Nov 20, 2020
Merged

Harden testing #982

merged 1 commit into from Nov 20, 2020

Conversation

ferrarimarco
Copy link
Collaborator

@ferrarimarco ferrarimarco commented Nov 10, 2020

Fixes #949

(maybe we can add more tests/validation in this PR before actually closing #949)

Proposed Changes

  1. Fail if a TAP to compare against is not available.
  2. Remove WARNING_ARRAY_TEST declaration, export, and iteration over because we now fail on each error, instead of printing warnings.
  3. Set ERROR_ON_MISSING_EXEC_BIT to true in our builds.
  4. Enable executable bit for scripts that didn't have it set to 1.
  5. Fix file paths while generating the test report: now paths don't include the full path, which might change according to where volumes are mounted.
  6. Exclude .tap files from the list when validating Dockerfiles.
  7. Use fatal instead of an explicit exit 1 to terminate testing.
  8. Add tests for:
    1. arm-ttk
    2. bash-exec
    3. Clojure
    4. C#
    5. Editorconfig-checker
    6. Gherkin
    7. Groovy
    8. Java
    9. JSON
    10. Kubeval
    11. Latex
    12. Lua
  9. Fix tests for:
    1. bash
    2. cloudformation
    3. Coffeescript
    4. CSS
    5. Dart
    6. Dockerfilelint
    7. Docker hadolint
    8. dotenv-linter
    9. Go
    10. HTML
    11. javascript_es
    12. javascript_standard
    13. Kotlin
    14. Markdownlint
    15. Perl
    16. PHP (built-in)
    17. PHPCS
    18. PHP PSALM
    19. Powershell
    20. Protobuf
    21. Python
    22. Raku
    23. Ruby
    24. States
    25. Terraform
    26. Typescript Standard
    27. XML
    28. yamllint

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request

Reviewing Maintainer

  • Label as breaking if this is a large fundamental change
  • Label as either automation, bug, documentation, enhancement, infrastructure, or performance

@ferrarimarco
Copy link
Collaborator Author

@ferrarimarco ferrarimarco commented Nov 10, 2020

@admiralAwkbar basically what happens is:

  1. we have an "expected" TAP report in the test directory.
  2. Generate a TAP on the fly for each language.
  3. Diff the generated tap against the expected tap.

Example of an expected TAP:

TAP version 13
1..2
not ok 1 - shell_bad_1.sh
  ---
  message: \nIn /tmp/lint/.automation/test/bash/shell_bad_1.sh line 10 \nif [ $ERROR_CODE -ne 0]; then\n^-- SC1009  The mentioned syntax error was in this if expression.\n   ^-- SC1073  Couldn't parse this test expression. Fix to allow more checks.\n                       ^-- SC1020  You need a space before the ].\n                       ^-- SC1072  Missing space before ]. Fix any mentioned problems and try again.\n\nFor more information \n  https //www.shellcheck.net/wiki/SC1020 -- You need a space before the ].\n  https //www.shellcheck.net/wiki/SC1072 -- Missing space before ]. Fix any m...\n  https //www.shellcheck.net/wiki/SC1073 -- Couldn't parse this test expressi...\n
  ...
ok 2 - /tmp/lint/.automation/test/bash/shell_good_1.sh
  1. TAP version 13: tap version, mandated by the spec

  2. 1..2: test plan. Tells how many tests will be run, or how many tests have run. In this example we see two tests: one for the good file, and one for the bad file in the shell test directory.

  3. not ok 1 - shell_bad_1.sh and ok 2 - /tmp/lint/.automation/test/bash/shell_good_1.sh: test lines. Tell that the test 1 fails (the bad file), and the test 2 runs successfully (the good file).

  4. The YAML block. This is not standardized in the spec, so we have complete freedom. In super-linter, someone made the choice to use the format:

    ---
    message: ABCDEFG.....
    ...

    We then use this YAML to save the expected output message, or the actual output message.

There are issues in this approach when the output has dynamic parts. I suspect that's the reason why some languages (such as arm-ttk) have a TAP file, but with an ignored extension.

PS: found some info here #421

PPS: we can tweak the TransformTAPDetails function to handle this.

@ferrarimarco ferrarimarco marked this pull request as draft Nov 18, 2020
@ferrarimarco
Copy link
Collaborator Author

@ferrarimarco ferrarimarco commented Nov 18, 2020

@admiralAwkbar almost there. I'm missing a regex and fixing a weird formatting issue with the powershell test.

@ferrarimarco ferrarimarco marked this pull request as ready for review Nov 19, 2020
@ferrarimarco
Copy link
Collaborator Author

@ferrarimarco ferrarimarco commented Nov 19, 2020

@admiralAwkbar finally ready for review.

Copy link
Collaborator

@admiralAwkbar admiralAwkbar left a comment

Amazing work!@

@admiralAwkbar admiralAwkbar merged commit 241f9f2 into master Nov 20, 2020
1 check passed
@admiralAwkbar admiralAwkbar deleted the harden-testing branch Nov 20, 2020
@tunetheweb
Copy link
Contributor

@tunetheweb tunetheweb commented Nov 20, 2020

Great work @ferrarimarco ! Dunno what it all means to be honest (TAP?) but hopefully will help catch things in future and looks like a huge amount of work, so thanks!

@ferrarimarco
Copy link
Collaborator Author

@ferrarimarco ferrarimarco commented Nov 20, 2020

LOL. TAP = Test Anything Protocol. It's a semi-structured protocol for test reporting. We're using it in super-linter to check if the test results match our expectations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants