mirror of
https://github.com/ivuorinen/tree-sitter-shellspec.git
synced 2026-03-04 10:59:08 +00:00
fix: apply CodeRabbit nitpick suggestions and improve code quality
- Fix grammar.js TypeScript errors by correcting optional field usage - Update .yamlignore to use more robust glob pattern (**/node_modules/**) - Remove hard-coded test count from README.md for maintainability - Fix shellcheck directive format (add space after #) in all test specs - Fix typos throughout test specifications: - 'can not' → 'cannot' - 'expantion' → 'expansion' - 'singnal' → 'signal' - 'It mean' → 'It means' - Update CODE_OF_CONDUCT.md HTTP links to HTTPS - Update tree-sitter parse command to use --scope instead of --language - Add comments to .mega-linter.yml explaining disabled linters All grammar tests still pass (61/61) and the parser functions correctly with the updated tree-sitter CLI v0.25.0.
This commit is contained in:
2
.github/CODE_OF_CONDUCT.md
vendored
2
.github/CODE_OF_CONDUCT.md
vendored
@@ -142,4 +142,4 @@ the [Geek Feminism Anti-Harassment Policy][geek-feminism].
|
|||||||
[stumptown]: https://github.com/stumpsyn
|
[stumptown]: https://github.com/stumpsyn
|
||||||
[cc-by-sa]: https://creativecommons.org/licenses/by-sa/3.0/
|
[cc-by-sa]: https://creativecommons.org/licenses/by-sa/3.0/
|
||||||
[django]: https://www.djangoproject.com/conduct/
|
[django]: https://www.djangoproject.com/conduct/
|
||||||
[geek-feminism]: http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy
|
[geek-feminism]: https://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy
|
||||||
|
|||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -124,7 +124,7 @@ jobs:
|
|||||||
End
|
End
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
npx tree-sitter parse --language=shellspec test_sample.shellspec --quiet || {
|
npx tree-sitter parse --scope=source.shellspec test_sample.shellspec --quiet || {
|
||||||
echo "❌ Parser failed on sample ShellSpec code"
|
echo "❌ Parser failed on sample ShellSpec code"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ SHOW_SKIPPED_LINTERS: false # Show skipped linters in MegaLinter log
|
|||||||
|
|
||||||
DISABLE_LINTERS:
|
DISABLE_LINTERS:
|
||||||
- REPOSITORY_DEVSKIM
|
- REPOSITORY_DEVSKIM
|
||||||
- JSON_PRETTIER
|
- JSON_PRETTIER # Disabled for causing probelms
|
||||||
- SPELL_LYCHEE
|
- SPELL_LYCHEE # Disabled due to too many false positives
|
||||||
|
|
||||||
YAML_YAMLLINT_CONFIG_FILE: .yamllint.yml
|
YAML_YAMLLINT_CONFIG_FILE: .yamllint.yml
|
||||||
MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .markdownlint.json
|
MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .markdownlint.json
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
node_modules/**
|
**/node_modules/**
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ npm run rebuild # Clean + generate + build
|
|||||||
|
|
||||||
The grammar includes comprehensive test coverage:
|
The grammar includes comprehensive test coverage:
|
||||||
|
|
||||||
- **59 test cases** covering all ShellSpec constructs
|
- **Comprehensive test cases** covering all ShellSpec constructs
|
||||||
- **Real-world patterns** from official ShellSpec repository
|
- **Real-world patterns** from official ShellSpec repository
|
||||||
- **Edge cases** and complex nesting scenarios
|
- **Edge cases** and complex nesting scenarios
|
||||||
- **Mixed content** (ShellSpec + bash code)
|
- **Mixed content** (ShellSpec + bash code)
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ module.exports = grammar(bashGrammar, {
|
|||||||
"BeforeRun",
|
"BeforeRun",
|
||||||
"AfterRun",
|
"AfterRun",
|
||||||
),
|
),
|
||||||
field("label", optional(choice($.string, $.raw_string, $.word))),
|
optional(field("label", choice($.string, $.raw_string, $.word))),
|
||||||
repeat($._terminated_statement),
|
repeat($._terminated_statement),
|
||||||
"End",
|
"End",
|
||||||
),
|
),
|
||||||
@@ -115,7 +115,7 @@ module.exports = grammar(bashGrammar, {
|
|||||||
1,
|
1,
|
||||||
seq(
|
seq(
|
||||||
choice("Parameters", "Skip", "Pending", "Todo"),
|
choice("Parameters", "Skip", "Pending", "Todo"),
|
||||||
field("label", optional(choice($.string, $.raw_string, $.word))),
|
optional(field("label", choice($.string, $.raw_string, $.word))),
|
||||||
repeat($._terminated_statement),
|
repeat($._terminated_statement),
|
||||||
"End",
|
"End",
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7236,12 +7236,12 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "CHOICE",
|
||||||
"name": "label",
|
"members": [
|
||||||
"content": {
|
{
|
||||||
"type": "CHOICE",
|
"type": "FIELD",
|
||||||
"members": [
|
"name": "label",
|
||||||
{
|
"content": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
@@ -7257,12 +7257,12 @@
|
|||||||
"name": "word"
|
"name": "word"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "BLANK"
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT",
|
"type": "REPEAT",
|
||||||
@@ -7306,12 +7306,12 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "CHOICE",
|
||||||
"name": "label",
|
"members": [
|
||||||
"content": {
|
{
|
||||||
"type": "CHOICE",
|
"type": "FIELD",
|
||||||
"members": [
|
"name": "label",
|
||||||
{
|
"content": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
@@ -7327,12 +7327,12 @@
|
|||||||
"name": "word"
|
"name": "word"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "BLANK"
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT",
|
"type": "REPEAT",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
It 'is simple'
|
It 'is simple'
|
||||||
When call echo 'ok'
|
When call echo 'ok'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'this is "example group"'
|
Describe 'this is "example group"'
|
||||||
Context 'this is also "example group"'
|
Context 'this is also "example group"'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'example example'
|
Describe 'example example'
|
||||||
It 'is "example"'
|
It 'is "example"'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh disable=SC2016
|
# shellcheck shell=sh disable=SC2016
|
||||||
|
|
||||||
Describe 'evaluation example'
|
Describe 'evaluation example'
|
||||||
Describe 'call evaluation'
|
Describe 'call evaluation'
|
||||||
@@ -21,7 +21,7 @@ Describe 'evaluation example'
|
|||||||
|
|
||||||
It 'must be one call each example'
|
It 'must be one call each example'
|
||||||
When call echo 1
|
When call echo 1
|
||||||
When call echo 2 # can not be called more than once.
|
When call echo 2 # cannot be called more than once.
|
||||||
The output should eq 1
|
The output should eq 1
|
||||||
End
|
End
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ Describe 'evaluation example'
|
|||||||
The value 123 should eq 123
|
The value 123 should eq 123
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'can not be called after expectation'
|
It 'cannot be called after expectation'
|
||||||
The value 123 should eq 123
|
The value 123 should eq 123
|
||||||
When call echo 1 # can not be called after expectation.
|
When call echo 1 # cannot be called after expectation.
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'calls external command'
|
It 'calls external command'
|
||||||
@@ -48,7 +48,7 @@ Describe 'evaluation example'
|
|||||||
The status should be failure
|
The status should be failure
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'can not modify variable because it run with in subshell'
|
It 'cannot modify variable because it run with in subshell'
|
||||||
set_value() { SHELLSPEC_VERSION=$1; }
|
set_value() { SHELLSPEC_VERSION=$1; }
|
||||||
When run set_value 'no-version'
|
When run set_value 'no-version'
|
||||||
The value "$SHELLSPEC_VERSION" should not eq 'no-version'
|
The value "$SHELLSPEC_VERSION" should not eq 'no-version'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'expectation example'
|
Describe 'expectation example'
|
||||||
It 'is succeeds because expectation is successful'
|
It 'is succeeds because expectation is successful'
|
||||||
|
|||||||
@@ -1,49 +1,49 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# Each block (example group / example) runs within subshell.
|
# Each block (example group / example) runs within subshell.
|
||||||
# It mean that it works like lexical scope.
|
# It means that it works like lexical scope.
|
||||||
|
|
||||||
Describe 'scope example'
|
Describe 'scope example'
|
||||||
foo() { echo "foo"; } # It can call from anywhere within this example group
|
foo() { echo "foo"; } # It can call from anywhere within this example group
|
||||||
|
|
||||||
# By the way, you can only use shellspec DSL or define function here.
|
# By the way, you can only use shellspec DSL or define function here.
|
||||||
# Of course it is possible to write freely within the defined function
|
# Of course it is possible to write freely within the defined function
|
||||||
# but other code may breaks isolation of tests.
|
# but other code may breaks isolation of tests.
|
||||||
|
|
||||||
It 'calls "foo"'
|
It 'calls "foo"'
|
||||||
When call foo
|
When call foo
|
||||||
The output should eq 'foo'
|
The output should eq 'foo'
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'defines "bar" function'
|
It 'defines "bar" function'
|
||||||
bar() { echo "bar"; }
|
bar() { echo "bar"; }
|
||||||
When call bar
|
When call bar
|
||||||
The output should eq 'bar'
|
The output should eq 'bar'
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'can not call "bar" function, because different scope'
|
It 'cannot call "bar" function, because different scope'
|
||||||
When call bar
|
When call bar
|
||||||
The status should be failure # probably status is 127
|
The status should be failure # probably status is 127
|
||||||
The stderr should be present # probably stderr is "bar: not found"
|
The stderr should be present # probably stderr is "bar: not found"
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'redefines "foo" function'
|
It 'redefines "foo" function'
|
||||||
foo() { echo "FOO"; }
|
foo() { echo "FOO"; }
|
||||||
When call foo
|
When call foo
|
||||||
The output should eq 'FOO'
|
The output should eq 'FOO'
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'calls "foo" function of outer scope (not previous example)'
|
It 'calls "foo" function of outer scope (not previous example)'
|
||||||
When call foo
|
When call foo
|
||||||
The output should eq 'foo'
|
The output should eq 'foo'
|
||||||
End
|
End
|
||||||
|
|
||||||
Describe 'sub block'
|
Describe 'sub block'
|
||||||
foo() { echo "Foo"; }
|
foo() { echo "Foo"; }
|
||||||
|
|
||||||
It 'calls "foo" function of upper scope'
|
It 'calls "foo" function of upper scope'
|
||||||
When call foo
|
When call foo
|
||||||
The output should eq 'Foo'
|
The output should eq 'Foo'
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# shellspec has Before and After hook.
|
# shellspec has Before and After hook.
|
||||||
# Those hooks are execute for each example (It/Example/Specify).
|
# Those hooks are execute for each example (It/Example/Specify).
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
hook() { %logger "$1 $2 ${SHELLSPEC_EXAMPLE_ID}"; }
|
hook() { %logger "$1 $2 ${SHELLSPEC_EXAMPLE_ID}"; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'subject example'
|
Describe 'subject example'
|
||||||
Describe 'stdout'
|
Describe 'stdout'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'modifier example'
|
Describe 'modifier example'
|
||||||
data() {
|
data() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'matcher example'
|
Describe 'matcher example'
|
||||||
Describe 'status matchers'
|
Describe 'status matchers'
|
||||||
|
|||||||
@@ -1,100 +1,100 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'skip example'
|
Describe 'skip example'
|
||||||
Describe 'calc()'
|
Describe 'calc()'
|
||||||
calc() { echo "$(($*))"; }
|
calc() { echo "$(($*))"; }
|
||||||
|
|
||||||
It 'can add'
|
It 'can add'
|
||||||
When call calc 1 + 1
|
When call calc 1 + 1
|
||||||
The output should eq 2
|
The output should eq 2
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'can minus'
|
It 'can minus'
|
||||||
When call calc 1 - 1
|
When call calc 1 - 1
|
||||||
The output should eq 0
|
The output should eq 0
|
||||||
End
|
End
|
||||||
|
|
||||||
# Skip examples of after this line in current example group
|
# Skip examples of after this line in current example group
|
||||||
Skip "decimal point can not be calculated"
|
Skip "decimal point cannot be calculated"
|
||||||
|
|
||||||
It 'can add decimal point'
|
It 'can add decimal point'
|
||||||
When call calc 1.1 + 1.1
|
When call calc 1.1 + 1.1
|
||||||
The output should eq 2.2
|
The output should eq 2.2
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'can minus decimal point'
|
It 'can minus decimal point'
|
||||||
When call calc 1.1 - 1.1
|
When call calc 1.1 - 1.1
|
||||||
The output should eq 0
|
The output should eq 0
|
||||||
End
|
End
|
||||||
|
|
||||||
Describe 'Multiplication' # example group is also skipped
|
Describe 'Multiplication' # example group is also skipped
|
||||||
It 'can multiply decimal point'
|
It 'can multiply decimal point'
|
||||||
When call calc 1.1 '*' 1.1
|
When call calc 1.1 '*' 1.1
|
||||||
The output should eq 1.21
|
The output should eq 1.21
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|
||||||
Describe 'status_to_singnal()'
|
Describe 'status_to_signal()'
|
||||||
status_to_singnal() {
|
status_to_signal() {
|
||||||
if [ 128 -le "$1" ] && [ "$1" -le 192 ]; then
|
if [ 128 -le "$1" ] && [ "$1" -le 192 ]; then
|
||||||
echo "$(($1 - 128))"
|
echo "$(($1 - 128))"
|
||||||
else
|
else
|
||||||
# Not implemented: echo "status is out of range" >&2
|
# Not implemented: echo "status is out of range" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
It 'can not convert status to singnal'
|
It 'cannot convert status to signal'
|
||||||
When call status_to_singnal 0
|
When call status_to_signal 0
|
||||||
The status should be failure
|
The status should be failure
|
||||||
|
|
||||||
# Skip expection of after this line in current example
|
# Skip expection of after this line in current example
|
||||||
Skip 'outputs error message is not implemented'
|
Skip 'outputs error message is not implemented'
|
||||||
The error should be present
|
The error should be present
|
||||||
End
|
End
|
||||||
|
|
||||||
# This example is going to execute
|
# This example is going to execute
|
||||||
It 'converts status to singnal'
|
It 'converts status to signal'
|
||||||
When call status_to_singnal 137
|
When call status_to_signal 137
|
||||||
The output should eq 9
|
The output should eq 9
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|
||||||
# "temporary skip" can not hidden with "--skip-message quiet" option
|
# "temporary skip" cannot hidden with "--skip-message quiet" option
|
||||||
Describe 'temporary skip'
|
Describe 'temporary skip'
|
||||||
Example 'with Skip helper'
|
Example 'with Skip helper'
|
||||||
Skip # without reason
|
Skip # without reason
|
||||||
When call foo
|
When call foo
|
||||||
The status should be success
|
The status should be success
|
||||||
End
|
End
|
||||||
|
|
||||||
xExample 'with xExample (prepend "x")'
|
xExample 'with xExample (prepend "x")'
|
||||||
When call foo
|
When call foo
|
||||||
The status should be success
|
The status should be success
|
||||||
End
|
End
|
||||||
|
|
||||||
xDescribe 'with xDescribe (prepend "x")'
|
xDescribe 'with xDescribe (prepend "x")'
|
||||||
Example 'this is also skipped'
|
Example 'this is also skipped'
|
||||||
When call foo
|
When call foo
|
||||||
The status should be success
|
The status should be success
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|
||||||
Describe 'conditional skip'
|
Describe 'conditional skip'
|
||||||
Example 'skip1'
|
Example 'skip1'
|
||||||
conditions() { return 0; }
|
conditions() { return 0; }
|
||||||
Skip if "function returns success" conditions
|
Skip if "function returns success" conditions
|
||||||
When call echo ok
|
When call echo ok
|
||||||
The stdout should eq ok
|
The stdout should eq ok
|
||||||
End
|
End
|
||||||
|
|
||||||
Example 'skip2'
|
Example 'skip2'
|
||||||
conditions() { echo "skip"; }
|
conditions() { echo "skip"; }
|
||||||
Skip if 'function returns "skip"' [ "$(conditions)" = "skip" ]
|
Skip if 'function returns "skip"' [ "$(conditions)" = "skip" ]
|
||||||
When call echo ok
|
When call echo ok
|
||||||
The stdout should eq ok
|
The stdout should eq ok
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# Pending is better than skip in some case. Skip is just only skips,
|
# Pending is better than skip in some case. Skip is just only skips,
|
||||||
# but Pending is runs example and decide the success or failure.
|
# but Pending is runs example and decide the success or failure.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'include helper example'
|
Describe 'include helper example'
|
||||||
Describe 'include helper'
|
Describe 'include helper'
|
||||||
|
|||||||
@@ -1,85 +1,85 @@
|
|||||||
#shellcheck shell=sh disable=SC2016
|
# shellcheck shell=sh disable=SC2016
|
||||||
|
|
||||||
# Data helper is easy way to input data from stdin for evaluation.
|
# Data helper is easy way to input data from stdin for evaluation.
|
||||||
# Removes `#|` from the beginning of the each line in the Data helper,
|
# Removes `#|` from the beginning of the each line in the Data helper,
|
||||||
# the rest is the input data.
|
# the rest is the input data.
|
||||||
|
|
||||||
Describe 'Data helper'
|
Describe 'Data helper'
|
||||||
Example 'provide with Data helper block style'
|
Example 'provide with Data helper block style'
|
||||||
Data
|
Data
|
||||||
#|item1 123
|
#|item1 123
|
||||||
#|item2 456
|
#|item2 456
|
||||||
#|item3 789
|
#|item3 789
|
||||||
End
|
End
|
||||||
When call awk '{total+=$2} END{print total}'
|
When call awk '{total+=$2} END{print total}'
|
||||||
The output should eq 1368
|
The output should eq 1368
|
||||||
End
|
End
|
||||||
|
|
||||||
Example 'provide string with Data helper'
|
Example 'provide string with Data helper'
|
||||||
Data '123 + 456 + 789'
|
Data '123 + 456 + 789'
|
||||||
When call bc
|
When call bc
|
||||||
The output should eq 1368
|
The output should eq 1368
|
||||||
End
|
End
|
||||||
|
|
||||||
Example 'provide from function with Data helper'
|
Example 'provide from function with Data helper'
|
||||||
data() {
|
data() {
|
||||||
echo item1 123
|
echo item1 123
|
||||||
echo item2 456
|
echo item2 456
|
||||||
echo item3 789
|
echo item3 789
|
||||||
}
|
}
|
||||||
Data data
|
Data data
|
||||||
When call awk '{total+=$2} END{print total}'
|
When call awk '{total+=$2} END{print total}'
|
||||||
The output should eq 1368
|
The output should eq 1368
|
||||||
End
|
End
|
||||||
|
|
||||||
Describe 'Data helper with filter'
|
Describe 'Data helper with filter'
|
||||||
Example 'from block'
|
Example 'from block'
|
||||||
Data | tr 'abc' 'ABC'
|
Data | tr 'abc' 'ABC'
|
||||||
#|aaa
|
#|aaa
|
||||||
#|bbb
|
#|bbb
|
||||||
End
|
End
|
||||||
|
|
||||||
When call cat -
|
When call cat -
|
||||||
The first line of output should eq 'AAA'
|
The first line of output should eq 'AAA'
|
||||||
The second line of output should eq 'BBB'
|
The second line of output should eq 'BBB'
|
||||||
End
|
End
|
||||||
|
|
||||||
Example 'from function'
|
Example 'from function'
|
||||||
foo() { printf '%s\n' "$@"; }
|
foo() { printf '%s\n' "$@"; }
|
||||||
Data foo a b c | tr 'abc' 'ABC' # comment
|
Data foo a b c | tr 'abc' 'ABC' # comment
|
||||||
When call cat -
|
When call cat -
|
||||||
The first line of output should eq 'A'
|
The first line of output should eq 'A'
|
||||||
The second line of output should eq 'B'
|
The second line of output should eq 'B'
|
||||||
The third line of output should eq "C"
|
The third line of output should eq "C"
|
||||||
The lines of entire output should eq 3
|
The lines of entire output should eq 3
|
||||||
End
|
End
|
||||||
|
|
||||||
Example 'from string'
|
Example 'from string'
|
||||||
Data 'abc'| tr 'abc' 'ABC' # comment
|
Data 'abc' | tr 'abc' 'ABC' # comment
|
||||||
When call cat -
|
When call cat -
|
||||||
The output should eq ABC
|
The output should eq ABC
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|
||||||
Describe 'variable expansion'
|
Describe 'variable expansion'
|
||||||
Before 'item=123'
|
Before 'item=123'
|
||||||
|
|
||||||
Example 'not expand variable (default)'
|
Example 'not expand variable (default)'
|
||||||
Data:raw
|
Data:raw
|
||||||
#|item $item
|
#|item $item
|
||||||
End
|
End
|
||||||
When call cat -
|
When call cat -
|
||||||
The output should eq 'item $item'
|
The output should eq 'item $item'
|
||||||
End
|
End
|
||||||
|
|
||||||
Example 'expand variable'
|
Example 'expand variable'
|
||||||
Data:expand
|
Data:expand
|
||||||
#|item $item
|
#|item $item
|
||||||
End
|
End
|
||||||
When call cat -
|
When call cat -
|
||||||
The output should eq 'item 123'
|
The output should eq 'item 123'
|
||||||
End
|
End
|
||||||
|
|
||||||
# variable expansion is supported by block style only.
|
# variable expansion is supported by block style only.
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|||||||
@@ -1,93 +1,93 @@
|
|||||||
#shellcheck shell=sh disable=SC2016
|
# shellcheck shell=sh disable=SC2016
|
||||||
|
|
||||||
# %text directive is easy way to output text like here document.
|
# %text directive is easy way to output text like here document.
|
||||||
# Removes `#|` from the beginning of the each line in the %text directive,
|
# Removes `#|` from the beginning of the each line in the %text directive,
|
||||||
# the rest is the output text.
|
# the rest is the output text.
|
||||||
|
|
||||||
Describe '%text directive'
|
Describe '%text directive'
|
||||||
It 'outputs texts'
|
It 'outputs texts'
|
||||||
output() {
|
output() {
|
||||||
echo "start" # you can write code here
|
echo "start" # you can write code here
|
||||||
%text
|
%text
|
||||||
#|aaa
|
#|aaa
|
||||||
#|bbb
|
#|bbb
|
||||||
#|ccc
|
#|ccc
|
||||||
echo "end" # you can write code here
|
echo "end" # you can write code here
|
||||||
}
|
}
|
||||||
When call output
|
When call output
|
||||||
The line 1 of output should eq 'start'
|
The line 1 of output should eq 'start'
|
||||||
The line 2 of output should eq 'aaa'
|
The line 2 of output should eq 'aaa'
|
||||||
The line 3 of output should eq 'bbb'
|
The line 3 of output should eq 'bbb'
|
||||||
The line 4 of output should eq "ccc"
|
The line 4 of output should eq "ccc"
|
||||||
The line 5 of output should eq 'end'
|
The line 5 of output should eq 'end'
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'sets to variable'
|
It 'sets to variable'
|
||||||
output() {
|
output() {
|
||||||
texts=$(
|
texts=$(
|
||||||
%text
|
%text
|
||||||
#|aaa
|
#|aaa
|
||||||
#|bbb
|
#|bbb
|
||||||
#|ccc
|
#|ccc
|
||||||
)
|
)
|
||||||
echo "$texts"
|
echo "$texts"
|
||||||
}
|
}
|
||||||
When call output
|
When call output
|
||||||
The line 1 of output should eq 'aaa'
|
The line 1 of output should eq 'aaa'
|
||||||
The line 2 of output should eq 'bbb'
|
The line 2 of output should eq 'bbb'
|
||||||
The line 3 of output should eq "ccc"
|
The line 3 of output should eq "ccc"
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'outputs texts with filter'
|
It 'outputs texts with filter'
|
||||||
output() {
|
output() {
|
||||||
%text | tr 'a-z_' 'A-Z_'
|
%text | tr 'a-z_' 'A-Z_'
|
||||||
#|abc
|
#|abc
|
||||||
}
|
}
|
||||||
When call output
|
When call output
|
||||||
The output should eq 'ABC'
|
The output should eq 'ABC'
|
||||||
End
|
End
|
||||||
|
|
||||||
Describe 'variable expantion'
|
Describe 'variable expansion'
|
||||||
Before 'text=abc'
|
Before 'text=abc'
|
||||||
|
|
||||||
Example 'not expand variable (default)'
|
Example 'not expand variable (default)'
|
||||||
output() {
|
output() {
|
||||||
%text:raw
|
%text:raw
|
||||||
#|$text
|
#|$text
|
||||||
}
|
}
|
||||||
When call output
|
When call output
|
||||||
The output should eq '$text'
|
The output should eq '$text'
|
||||||
End
|
End
|
||||||
|
|
||||||
Example 'expand variable'
|
Example 'expand variable'
|
||||||
output() {
|
output() {
|
||||||
%text:expand
|
%text:expand
|
||||||
#|$text
|
#|$text
|
||||||
}
|
}
|
||||||
When call output
|
When call output
|
||||||
The output should eq 'abc'
|
The output should eq 'abc'
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|
||||||
It 'outputs texts with more complex code'
|
It 'outputs texts with more complex code'
|
||||||
output() {
|
output() {
|
||||||
if true; then
|
if true; then
|
||||||
set -- 1 2 3 4 5
|
set -- 1 2 3 4 5
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
%text:expand | tr 'a-z_' 'A-Z_'
|
%text:expand | tr 'a-z_' 'A-Z_'
|
||||||
#|value $(($1 * 10))
|
#|value $(($1 * 10))
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
%text
|
%text
|
||||||
#|text
|
#|text
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
When call output
|
When call output
|
||||||
The line 1 of output should eq 'VALUE 10'
|
The line 1 of output should eq 'VALUE 10'
|
||||||
The line 2 of output should eq 'VALUE 20'
|
The line 2 of output should eq 'VALUE 20'
|
||||||
The line 3 of output should eq 'VALUE 30'
|
The line 3 of output should eq 'VALUE 30'
|
||||||
The line 4 of output should eq "VALUE 40"
|
The line 4 of output should eq "VALUE 40"
|
||||||
The line 5 of output should eq 'VALUE 50'
|
The line 5 of output should eq 'VALUE 50'
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe '%putsn directive'
|
Describe '%putsn directive'
|
||||||
Example 'outputs arguments'
|
Example 'outputs arguments'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
%const NAME: value
|
%const NAME: value
|
||||||
# shellcheck disable=SC2288
|
# shellcheck disable=SC2288
|
||||||
@@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
# %const (% is short hand) directive is define constant value.
|
# %const (% is short hand) directive is define constant value.
|
||||||
# The characters that can be used for variable name is upper capital, number
|
# The characters that can be used for variable name is upper capital, number
|
||||||
# and underscore only. It can not be define inside of the example group or
|
# and underscore only. It cannot be define inside of the example group or
|
||||||
# the example.
|
# the example.
|
||||||
#
|
#
|
||||||
# The timing of evaluation of the value is the specfile translation process.
|
# The timing of evaluation of the value is the specfile translation process.
|
||||||
# So you can access shellspec variables, but you can not access variable or
|
# So you can access shellspec variables, but you cannot access variable or
|
||||||
# function in the specfile.
|
# function in the specfile.
|
||||||
#
|
#
|
||||||
# This feature assumed use with conditional skip. The conditional skip may runs
|
# This feature assumed use with conditional skip. The conditional skip may runs
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'Logger helper'
|
Describe 'Logger helper'
|
||||||
%logger 'this is log'
|
%logger 'this is log'
|
||||||
Example 'outputs log'
|
Example 'outputs log'
|
||||||
%logger 'this is log'
|
%logger 'this is log'
|
||||||
End
|
End
|
||||||
End
|
End
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'mock stub example'
|
Describe 'mock stub example'
|
||||||
unixtime() { date +%s; }
|
unixtime() { date +%s; }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
Describe 'intercept example'
|
Describe 'intercept example'
|
||||||
Intercept begin
|
Intercept begin
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# Sometime, functions are defined in a single shell script.
|
# Sometime, functions are defined in a single shell script.
|
||||||
# You will want to test it. but you do not want to run the script.
|
# You will want to test it. but you do not want to run the script.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# regexp custom matcher is defined in "support/custom_matcher.sh" and
|
# regexp custom matcher is defined in "support/custom_matcher.sh" and
|
||||||
# imported by "spec_helper.sh"
|
# imported by "spec_helper.sh"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# set -eu
|
# set -eu
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# imported by "spec_helper.sh"
|
# imported by "spec_helper.sh"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user