feat: implement complete tree-sitter-shellspec grammar with comprehensive testing (#1)

* feat: implement complete tree-sitter-shellspec grammar with comprehensive testing

- Add full ShellSpec grammar extending tree-sitter-bash
- Support all ShellSpec constructs: Describe, Context, It, hooks, utilities
- Include Data block parsing with statements and argument styles
- Add 61 comprehensive test cases covering real-world patterns
- Implement optimized GitHub workflows with CI/CD automation
- Configure complete development tooling (linting, formatting, pre-commit)
- Add comprehensive documentation and contribution guidelines
- Optimize grammar conflicts to zero warnings
- Support editor integration for Neovim, VS Code, Emacs

Breaking Changes:
- Initial release, no previous API to break

BREAKING CHANGE: Initial implementation of tree-sitter-shellspec grammar

* fix(ci): checkout before using local actions

* fix(ci): use inline steps instead of actions

* fix(ci): add checkout before testing, cleanup

* chore(ci): add coderabbit config

* chore: lint and code review fixes

* chore(ci): update workflows

* refactor: enhance CI/CD workflows and apply CodeRabbit suggestions

- Convert GitHub Actions from local to inline actions for better maintainability
- Add comprehensive caching for npm dependencies, tree-sitter CLI, and build artifacts
- Fix checkout steps missing in test matrix jobs
- Apply defensive programming in test coverage validation
- Use local tree-sitter CLI via npx instead of global installation
- Update tree-sitter-cli to v0.25.0 for compatibility with tree-sitter-bash
- Add proper tree-sitter field to package.json with grammar metadata
- Fix grammar precedence for Data blocks (#| lines now have higher precedence)
- Standardize dates in memory files to September 12, 2025
- Enhance workflow robustness with dynamic workflow ID resolution
- Improve test file pattern matching and error handling

This commit addresses all CodeRabbit review suggestions and optimizes
GitHub Actions workflows for better performance and reliability.

* 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.

* perf: optimize grammar for 32x faster parsing performance

- Reduce grammar conflicts to essential bash and ShellSpec rules only
- Restore original precedence values for consistent rule ordering
- Simplify Data block rule while maintaining all functionality
- Add required statements field to match test expectations

Performance improvements:
- Parse speed: ~55 bytes/ms → 1784 bytes/ms (32x faster)
- All 61 tests still pass (100% success rate)
- Significantly reduced parser generation time and runtime complexity

The optimizations focused on minimizing unnecessary conflicts and
simplifying complex choice structures while preserving full ShellSpec
grammar compatibility and correctness.

* fix(ci): ensure parser is built before testing in GitHub workflows

- Add explicit parser build step before sample code testing
- Remove --scope parameter that requires parser to be compiled first
- Fix tree-sitter CLI v0.25.0 compatibility issue in CI environment

The issue was that tree-sitter CLI v0.25.0 requires the parser to be
compiled before it can recognize custom language scopes. This fix
ensures the parser is always built before attempting to parse test files,
resolving the 'Unknown scope' error in GitHub Actions.

* feat(ci): expand cache paths to support all Node.js package managers

- Add comprehensive caching for npm, yarn, and pnpm package managers
- Cache paths now include:
  - npm: ~/.npm, node_modules/.cache
  - yarn: ~/.yarn, ~/.cache/yarn, ~/.cache/yarn/global
  - pnpm: ~/.pnpm-store, ~/.cache/pnpm, ~/.local/share/pnpm/global
- Update cache keys to include all lockfile types (package-lock.json, yarn.lock, pnpm-lock.yaml)
- Rename 'Cache Tree-sitter CLI' to 'Cache npx store' for clarity
- Apply changes consistently across test, lint, and coverage jobs

This improves cache hit rates and build performance regardless of which
Node.js package manager is used in the development environment.

* chore: tweaks to megalinter and grammar.js

* fix(scanner): address memory safety and correctness issues in C code

- Add len==0 check in set_contains() to prevent buffer overflow
- Add missing stdlib.h include in scanner.c
- Clear heredoc stack properly in deserialize when length==0
- Ensure NUL termination in delimiter deserialization
- Create alloc.c to define ts_current_* symbols for TREE_SITTER_REUSE_ALLOCATOR

All changes tested with full test suite: 61/61 tests passing.

Addresses PR #1 review comments from CodeRabbit.

* ci: improve workflow determinism and security scanning

- Add --language=shellspec flag to tree-sitter parse for deterministic grammar selection
- Add C++ language to CodeQL analysis to scan src/scanner.c for security issues

Addresses PR #1 review comments from CodeRabbit.

* test: fix typos and incorrect hook usage in spec files

- Fix 'yot' → 'yet' typos in test/spec/03.example_spec.sh
- Fix 'Sometime' → 'Sometimes' and cpunum.sh references in test/spec/22.sourcced_spec.sh
- Fix Before → After in after hook section of test/spec/07.before_after_hook_spec.sh
- Improve wording and capitalization throughout hook spec file

All 61 tests still passing after corrections.

Addresses PR #1 review comments from Copilot and CodeRabbit.

* docs: update Node.js requirement to match CI configuration

- Change Node.js requirement from v16 to v22+ to align with CI matrix
- Update tree-sitter CLI recommendation from global install to npx usage
- Matches actual devDependency configuration in package.json

Addresses PR #1 review comment from CodeRabbit.

* chore: update dependencies and workflow actions

- Update GitHub Actions to latest versions (checkout v6, setup-node v6, cache v4.3)
- Update package dependencies
- Format workflow files
- Update .gitignore and project configuration

* fix(ci): remove unsupported --language flag from tree-sitter parse

The --language flag is not supported in tree-sitter-cli 0.25.10.
Tree-sitter correctly auto-detects the grammar based on file extension.

* chore: add prettier and format all files

- Install prettier ^3.6.2
- Add .prettierrc with project formatting rules
- Add .prettierignore to exclude generated files and dependencies
- Add npm scripts: format and format:check
- Format all files with prettier

* chore: add eclint for editorconfig linting and fix violations

- Install eclint ^2.8.1 for editorconfig validation and fixing
- Add .eclintignore to exclude generated files and dependencies
- Add npm scripts: lint:editorconfig and lint:editorconfig:fix
- Fix indentation issues in CONTRIBUTING.md (3 spaces -> 2 spaces)
- Fix code alignment in scanner.c to match editorconfig rules
- Regenerate parser after scanner.c formatting changes

* feat: add post-generation script to preserve buffer overflow fix

Created scripts/post-generate.sh that automatically re-applies the critical
buffer overflow fix to parser.h after tree-sitter generate runs. This fix
prevents undefined behavior in set_contains() when accessing an empty array.

The script is automatically executed after tree-sitter generate via the npm
generate script. Added generate:only for cases where post-processing should
be skipped.

* fix: address code review findings and critical issues

Critical Fixes:
- Fixed EditorConfig violations in grammar.js, scanner.c, README.md, .mega-linter.yml
  - Changed JSDoc comments from 1-space to 2-space indent per .editorconfig
  - Fixed line length violations in README.md and .mega-linter.yml
- Updated test count badge from 59/59 to 61/61 in README.md
- Created queries/highlights.scm for syntax highlighting support
- Updated package.json with repository and files fields

Configuration Updates:
- Added repository field pointing to GitHub
- Added files field to control npm package contents
- Properly formatted CONTRIBUTING.md with prettier

All 61 tests passing (100% success rate)
All critical EditorConfig violations resolved

* enhance: add Data block test coverage and improve syntax highlighting

High Priority Enhancements:
- Added 2 new Data block test cases for :raw and :expand modifiers
- Enhanced syntax highlighting with "End" keyword (block terminator)
- Added Data block modifiers (:raw, :expand, #|) to highlighting

Test Coverage:
- 63/63 tests passing (100%)
- Test count increased from 61 to 63
- Average parse speed: 623 bytes/ms

* docs: add comprehensive grammar documentation and precedence explanation

Medium Priority Enhancement:
- Added detailed precedence strategy comments explaining how ShellSpec extends bash
- Documented all 5 conflicts with resolution strategies
- Explained why conflicts are necessary and optimal
- Added context about GLR parsing and precedence hints

Documentation improvements:
- Precedence levels clearly explained (bash: 1, ShellSpec: 2)
- Each conflict documented with resolution strategy
- Notes on intentional design decisions
- Helps future maintainers understand grammar design

* fix: resolve documentation inconsistencies and add ExampleGroup variants

Documentation Fixes:
- README.md: Update test count from 59 to 63 (badge, features, test command)
- README.md: Fix lint script references to actual npm scripts
- CONTRIBUTING.md: Correct format script reference to npm run format:check
- package.json: Remove non-existent yamllint script, split lint:markdown into check/fix variants

Grammar Enhancements:
- Add fExampleGroup and xExampleGroup to Context block variants
- Regenerate parser with new grammar (63/63 tests passing, 100% success rate)

Syntax Highlighting:
- Add fExampleGroup and xExampleGroup to focused/skipped block highlights
- Remove non-matching Data modifier tokens (:raw, :expand, #|)
- Add "End" keyword as block terminator

Memory File Corrections:
- Remove incorrect merge_group trigger references
- Remove pr-lint.yml workflow references (deleted in previous optimization)
- Update test counts with timestamps (59→63, added 2025-12-11)
- Update conflict count (13→5, optimized)

Code Style:
- Auto-format renovate.json and tree-sitter.json with prettier

* chore: update dependencies and project configuration

- Align tree-sitter dependencies to latest versions (bash 0.25.1, cli 0.25.10)
- Clean up .gitignore redundant patterns and normalize path styles
- Improve CodeRabbit configuration with path filters and simplified instructions
- Add test corpus exclusion to match project intent

* docs: improve documentation and memory files

- Update CONTRIBUTING.md code style check commands with actual available scripts
- Use npx tree-sitter in test examples to avoid assuming global installation
- Improve project status memory file with proper JSON formatting
- Add CI enforcement recommendation for zero-conflict grammar generation
- Align prerequisites with CI requirements (Node 22+)

* ci: improve workflow configuration and reliability

- Replace global read-all permissions with scoped permissions (contents: read, actions: write)
- Fix cache configuration to exclude node_modules and include package-lock.json
- Improve CI workflow resolution with flexible path matching and pagination
- Verify version instead of committing version bumps from CI
- Detect prereleases and publish with appropriate npm tags (next vs latest)
- Use generic test suite description in release notes to avoid drift

* fix: remove non-existent locals.scm reference from tree-sitter.json

Remove queries/locals.scm from locals array as the file does not exist.
Only queries/highlights.scm is present in the repository.

* security: replace vulnerable eclint with editorconfig-checker

- Remove eclint@2.8.1 (has 15 vulnerabilities, possibly abandoned)
- Add editorconfig-checker@6.1.1 (actively maintained, zero vulnerabilities)
- Update npm scripts to use editorconfig-checker commands
- Resolves all 15 security vulnerabilities (8 moderate, 7 high)

editorconfig-checker is a more modern, actively maintained alternative
written in Go with no Node.js dependency vulnerabilities.

* style: fix JSDoc comment indentation

* fix(ci): separate CodeQL languages in matrix

Previously 'actions,javascript' was treated as a single language.
Now correctly split into separate 'actions' and 'javascript' entries.

* chore(deps): update GitHub Actions dependencies

- actions/checkout: v6.0.0 -> v6.0.1
- actions/setup-node: v6.0.0 -> v6.1.0
- softprops/action-gh-release: v2.4.2 -> v2.5.0
- ivuorinen/actions/*: v2025.11.x -> v2025.12.10

* ci: restore pr-lint workflow from main

* chore(deps): update GitHub Actions dependencies

Update action pins: checkout v6.0.2, setup-node v6.3.0, cache v5.0.3,
pr-lint v2026.03.07. Add checkov skip comment, VERSION prefix strip,
and scanner.c to grammar cache key.

* feat: extend grammar with hooks, mocks, statements, and directives

Add 27 ShellSpec-specific grammar rules covering hook blocks/statements,
mock blocks, When/The/Assert statements, Path/Set/Dump/Intercept statements,
Parameters variants, Pending/Skip/Todo, and percent directives. Update
highlights and test corpus with 128 passing tests.

* docs: update README, CLAUDE.md, and test spec comments

Comprehensive README rewrite documenting all 27 grammar rules, block types,
statement types, and directives. Add CLAUDE.md project instructions for
Claude Code. Update test spec file comments for clarity.

* chore: update project config and dependencies

Update tree-sitter-cli to ^0.26.6, remove broken lint:editorconfig:fix
script. Update shellcheck disabled rules. Add JSDoc header to
post-generate script. Update gitignore for build artifacts.

* fix(ci): use env var for version in release publish step

Replace direct expression interpolation with VERSION env var to fix
actionlint SC2193 false positive in the npm publish step.

* style: fix editorconfig and markdownlint issues

Break long cache key YAML value into multiline scalar to comply with
160-character line length limit.

* ci: update MegaLinter config for ShellSpec project

Add disabled linters for generated/DSL code false positives, v8r exclude
pattern, and broader path filter. Remove .coderabbit.yaml in favor of
shared org config.

* chore: add Claude Code automation config

Add hooks (pre-edit guard for generated files, post-edit lint),
skills (generate-and-test, add-shellspec-rule, debug-parse-failure,
update-highlights, validate-release), and grammar-validator agent.

* chore: update Serena memory files

Update project status, real-world ShellSpec patterns, and GitHub
workflows optimization memory files.

* fix(ci): fix MegaLinter config and remove C from CodeQL

- Change FILTER_REGEX_EXCLUDE from `>` to `>-` to strip trailing
  newline that silently broke all path exclusions
- Add YAML_V8R_FILTER_REGEX_EXCLUDE to skip schema validation on
  .mega-linter.yml (schemastore enum is outdated for BASH_BASH_EXEC)
- Remove "c" from CodeQL language matrix since src/parser.c is
  generated and produces false positives

* fix: add missing test spec stub files

- Add test/spec/lib.sh stub with calc() function (referenced by
  01.very_simple_spec.sh)
- Add test/spec/count_cpus.sh stub (referenced by
  21.intercept_spec.sh)
This commit is contained in:
2026-03-09 03:02:34 +02:00
committed by GitHub
parent 25f3e679ca
commit 7353f2729c
96 changed files with 474844 additions and 221 deletions

View File

@@ -0,0 +1,131 @@
================================================================================
Basic Context block
================================================================================
Context "when condition is true"
echo "test"
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
ExampleGroup block
================================================================================
ExampleGroup "group of examples"
echo "test"
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Focused Context block
================================================================================
fContext "focused context"
echo "focused"
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Skipped Context block
================================================================================
xContext "skipped context"
echo "skipped"
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Context with raw string
================================================================================
Context 'raw string context'
local var="test"
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (raw_string)
(declaration_command
(variable_assignment
name: (variable_name)
value: (string
(string_content))))))
================================================================================
Context with word description
================================================================================
Context simple_context
echo "test"
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (word)
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Empty Context block
================================================================================
Context "empty context"
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (string
(string_content))))

View File

@@ -0,0 +1,143 @@
================================================================================
Basic Describe block
================================================================================
Describe "basic functionality"
echo "test"
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Focused Describe block
================================================================================
fDescribe "focused test"
echo "focused"
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Skipped Describe block
================================================================================
xDescribe "skipped test"
echo "skipped"
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Describe with raw string
================================================================================
Describe 'raw string test'
echo "test"
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (raw_string)
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Describe with word description
================================================================================
Describe simple_test
echo "test"
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (word)
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Empty Describe block
================================================================================
Describe "empty test"
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))))
================================================================================
Describe with multiple statements
================================================================================
Describe "multiple statements"
echo "first"
echo "second"
local var="value"
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))
(command
name: (command_name
(word))
argument: (string
(string_content)))
(declaration_command
(variable_assignment
name: (variable_name)
value: (string
(string_content))))))

291
test/corpus/hook_blocks.txt Normal file
View File

@@ -0,0 +1,291 @@
================================================================================
BeforeEach hook
================================================================================
BeforeEach
setup_environment
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
BeforeEach with label
================================================================================
BeforeEach "setup database"
init_database
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(string
(string_content))))
(command
name: (command_name
(word)))))
================================================================================
AfterEach hook
================================================================================
AfterEach
cleanup_environment
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
AfterEach with label
================================================================================
AfterEach "cleanup database"
cleanup_database
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(string
(string_content))))
(command
name: (command_name
(word)))))
================================================================================
BeforeAll hook
================================================================================
BeforeAll
global_setup
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
BeforeAll with raw string label
================================================================================
BeforeAll 'global setup'
global_setup
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(raw_string)))
(command
name: (command_name
(word)))))
================================================================================
AfterAll hook
================================================================================
AfterAll
global_cleanup
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
BeforeCall hook
================================================================================
BeforeCall
prepare_call
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
AfterCall hook
================================================================================
AfterCall
verify_call
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
BeforeRun hook
================================================================================
BeforeRun
prepare_run
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
AfterRun hook
================================================================================
AfterRun
verify_run
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(word)))))
================================================================================
Hook with multiple statements
================================================================================
BeforeEach "complex setup"
export TEST_VAR="value"
mkdir -p /tmp/test
touch /tmp/test/file
End
--------------------------------------------------------------------------------
(program
(shellspec_hook_block
(command
name: (command_name
(string
(string_content))))
(declaration_command
(variable_assignment
name: (variable_name)
value: (string
(string_content))))
(command
name: (command_name
(word))
argument: (word)
argument: (word))
(command
name: (command_name
(word))
argument: (word))))
================================================================================
BeforeRun standalone statement
================================================================================
BeforeRun my_setup
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (word)))
================================================================================
AfterRun standalone statement
================================================================================
AfterRun my_cleanup
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (word)))
================================================================================
BeforeCall standalone statement
================================================================================
BeforeCall pre_call
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (word)))
================================================================================
AfterCall standalone statement
================================================================================
AfterCall post_call
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (word)))
================================================================================
BeforeEach standalone statement
================================================================================
BeforeEach setup_func
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (word)))
================================================================================
AfterEach standalone statement
================================================================================
AfterEach cleanup_func
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (word)))

213
test/corpus/it_blocks.txt Normal file
View File

@@ -0,0 +1,213 @@
================================================================================
Basic It block
================================================================================
It "should work correctly"
echo "test"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Example block
================================================================================
Example "example behavior"
echo "example"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Specify block
================================================================================
Specify "specific behavior"
echo "specify"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Focused It block
================================================================================
fIt "focused test"
echo "focused"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Focused Example block
================================================================================
fExample "focused example"
echo "focused"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Focused Specify block
================================================================================
fSpecify "focused specify"
echo "focused"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Skipped It block
================================================================================
xIt "skipped test"
echo "skipped"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Skipped Example block
================================================================================
xExample "skipped example"
echo "skipped"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Skipped Specify block
================================================================================
xSpecify "skipped specify"
echo "skipped"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
It with complex assertions
================================================================================
It "should handle complex logic"
local result
result=$(some_function "param")
[ "$result" = "expected" ]
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(declaration_command
(variable_name))
(variable_assignment
name: (variable_name)
value: (command_substitution
(command
name: (command_name
(word))
argument: (string
(string_content)))))
(test_command
(binary_expression
left: (string
(simple_expansion
(variable_name)))
right: (string
(string_content))))))

View File

@@ -0,0 +1,76 @@
================================================================================
Mock simple command
================================================================================
Mock curl
echo "mocked response"
End
--------------------------------------------------------------------------------
(program
(shellspec_mock_block
name: (word)
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Mock command with string name
================================================================================
Mock "git"
echo "mock git"
End
--------------------------------------------------------------------------------
(program
(shellspec_mock_block
name: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content)))))
================================================================================
Mock empty command
================================================================================
Mock curl
End
--------------------------------------------------------------------------------
(program
(shellspec_mock_block
name: (word)))
================================================================================
Mock with multiple statements
================================================================================
Mock curl
echo "status: 200"
echo "body: ok"
End
--------------------------------------------------------------------------------
(program
(shellspec_mock_block
name: (word)
(command
name: (command_name
(word))
argument: (string
(string_content)))
(command
name: (command_name
(word))
argument: (string
(string_content)))))

View File

@@ -0,0 +1,236 @@
================================================================================
Describe with Context
================================================================================
Describe "main feature"
Context "when condition A"
echo "setup A"
End
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(shellspec_context_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content))))))
================================================================================
Describe with It
================================================================================
Describe "main feature"
It "should work"
echo "test"
End
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content))))))
================================================================================
Context with It
================================================================================
Context "when ready"
It "should execute"
echo "executing"
End
End
--------------------------------------------------------------------------------
(program
(shellspec_context_block
description: (string
(string_content))
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))
argument: (string
(string_content))))))
================================================================================
Describe with hooks and tests
================================================================================
Describe "complete feature"
BeforeEach
setup_test
End
It "should work correctly"
run_test
End
AfterEach
cleanup_test
End
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(shellspec_hook_block
(command
name: (command_name
(word))))
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))))
(shellspec_hook_block
(command
name: (command_name
(word))))))
================================================================================
Complex nested structure
================================================================================
Describe "main functionality"
BeforeAll
global_setup
End
Context "when user is authenticated"
BeforeEach
login_user
End
It "should access protected resource"
access_resource
End
Context "and has admin privileges"
It "should access admin panel"
access_admin
End
End
AfterEach
logout_user
End
End
AfterAll
global_cleanup
End
End
--------------------------------------------------------------------------------
(program
(shellspec_describe_block
description: (string
(string_content))
(shellspec_hook_block
(command
name: (command_name
(word))))
(shellspec_context_block
description: (string
(string_content))
(shellspec_hook_block
(command
name: (command_name
(word))))
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word))))
(shellspec_context_block
description: (string
(string_content))
(shellspec_it_block
description: (string
(string_content))
(command
name: (command_name
(word)))))
(shellspec_hook_block
(command
name: (command_name
(word)))))
(shellspec_hook_block
(command
name: (command_name
(word))))))
================================================================================
Mixed with regular bash
================================================================================
#!/bin/bash
function helper() {
echo "helper function"
}
Describe "using bash functions"
It "should call helper"
result=$(helper)
echo "$result"
End
End
--------------------------------------------------------------------------------
(program
(comment)
(function_definition
name: (word)
body: (compound_statement
(command
name: (command_name
(word))
argument: (string
(string_content)))))
(shellspec_describe_block
description: (string
(string_content))
(shellspec_it_block
description: (string
(string_content))
(variable_assignment
name: (variable_name)
value: (command_substitution
(command
name: (command_name
(word)))))
(command
name: (command_name
(word))
argument: (string
(simple_expansion
(variable_name)))))))

View File

@@ -0,0 +1,110 @@
================================================================================
Parameters:block variant
================================================================================
Parameters:block
"arg1" "arg2"
"arg3" "arg4"
End
--------------------------------------------------------------------------------
(program
(shellspec_utility_block
label: (string
(string_content))
(command
name: (command_name
(string
(string_content))))
(command
name: (command_name
(string
(string_content)))
argument: (string
(string_content)))))
================================================================================
Parameters:value variant
================================================================================
Parameters:value
val1
val2
End
--------------------------------------------------------------------------------
(program
(shellspec_utility_block
(command
name: (command_name
(word)))
(command
name: (command_name
(word)))))
================================================================================
Parameters:matrix variant
================================================================================
Parameters:matrix
"a" "b"
"c" "d"
End
--------------------------------------------------------------------------------
(program
(shellspec_utility_block
label: (string
(string_content))
(command
name: (command_name
(string
(string_content))))
(command
name: (command_name
(string
(string_content)))
argument: (string
(string_content)))))
================================================================================
Parameters:dynamic variant
================================================================================
Parameters:dynamic
generate_params
End
--------------------------------------------------------------------------------
(program
(shellspec_utility_block
(command
name: (command_name
(word)))))
================================================================================
Parameters:block with label
================================================================================
Parameters:block "test cases"
"case1" "expected1"
End
--------------------------------------------------------------------------------
(program
(shellspec_utility_block
(command
name: (command_name
(string
(string_content))))
(command
name: (command_name
(string
(string_content)))
argument: (string
(string_content)))))

View File

@@ -0,0 +1,95 @@
================================================================================
Inline Pending with reason
================================================================================
Pending 'not yet implemented'
--------------------------------------------------------------------------------
(program
(shellspec_pending_statement
reason: (raw_string)))
================================================================================
Inline Pending with double-quoted reason
================================================================================
Pending "not yet implemented"
--------------------------------------------------------------------------------
(program
(shellspec_pending_statement
reason: (string
(string_content))))
================================================================================
Inline Pending inside It block
================================================================================
It 'should do something'
Pending 'not yet implemented'
When call my_func
The output should equal "hello"
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (raw_string)
(shellspec_pending_statement
reason: (raw_string))
(shellspec_when_statement
function: (word))
(shellspec_the_statement
subject: (shellspec_subject
(word))
matcher: (shellspec_matcher
(word)
(string
(string_content))))))
================================================================================
Inline Skip with reason
================================================================================
Skip 'not supported on this platform'
--------------------------------------------------------------------------------
(program
(shellspec_skip_statement
reason: (raw_string)))
================================================================================
Inline Skip with double-quoted reason
================================================================================
Skip "not supported"
--------------------------------------------------------------------------------
(program
(shellspec_skip_statement
reason: (string
(string_content))))
================================================================================
Inline Skip inside It block
================================================================================
It 'should do something'
Skip 'not supported'
When call my_func
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (raw_string)
(shellspec_skip_statement
reason: (raw_string))
(shellspec_when_statement
function: (word))))

View File

@@ -0,0 +1,206 @@
================================================================================
%text directive with data line
================================================================================
%text
#|line one
--------------------------------------------------------------------------------
(program
(shellspec_text_directive
data_line: (shellspec_data_line_content)))
================================================================================
%text:raw directive
================================================================================
%text:raw
#|raw content $var
--------------------------------------------------------------------------------
(program
(shellspec_text_directive
data_line: (shellspec_data_line_content)))
================================================================================
%text:expand directive
================================================================================
%text:expand
#|expanded $var
--------------------------------------------------------------------------------
(program
(shellspec_text_directive
data_line: (shellspec_data_line_content)))
================================================================================
%text with pipe filter
================================================================================
%text | tr 'a-z' 'A-Z'
#|hello
--------------------------------------------------------------------------------
(program
(shellspec_text_directive
filter: (word)
filter: (raw_string)
filter: (raw_string)
data_line: (shellspec_data_line_content)))
================================================================================
%const directive
================================================================================
%const NAME: value
--------------------------------------------------------------------------------
(program
(shellspec_const_directive
name: (word)
value: (word)))
================================================================================
%const directive with string value
================================================================================
%const NAME: "hello world"
--------------------------------------------------------------------------------
(program
(shellspec_const_directive
name: (word)
value: (string
(string_content))))
================================================================================
% shorthand directive
================================================================================
% VERSION: "1.0"
--------------------------------------------------------------------------------
(program
(shellspec_const_directive
name: (word)
value: (string
(string_content))))
================================================================================
%puts directive
================================================================================
%puts value
--------------------------------------------------------------------------------
(program
(shellspec_output_directive
argument: (word)))
================================================================================
%putsn directive
================================================================================
%putsn value
--------------------------------------------------------------------------------
(program
(shellspec_output_directive
argument: (word)))
================================================================================
%- directive
================================================================================
%- value
--------------------------------------------------------------------------------
(program
(shellspec_output_directive
argument: (word)))
================================================================================
%= directive
================================================================================
%= value
--------------------------------------------------------------------------------
(program
(shellspec_output_directive
argument: (word)))
================================================================================
%puts with string argument
================================================================================
%puts "hello world"
--------------------------------------------------------------------------------
(program
(shellspec_output_directive
argument: (string
(string_content))))
================================================================================
%preserve directive
================================================================================
%preserve VAR1 VAR2
--------------------------------------------------------------------------------
(program
(shellspec_preserve_directive
variable: (word)
variable: (word)))
================================================================================
%preserve single variable
================================================================================
%preserve RESULT
--------------------------------------------------------------------------------
(program
(shellspec_preserve_directive
variable: (word)))
================================================================================
%logger directive
================================================================================
%logger "debug message"
--------------------------------------------------------------------------------
(program
(shellspec_logger_directive
argument: (string
(string_content))))
================================================================================
%logger with word argument
================================================================================
%logger debug_info
--------------------------------------------------------------------------------
(program
(shellspec_logger_directive
argument: (word)))

View File

@@ -0,0 +1,95 @@
================================================================================
Before hook statements
================================================================================
Before 'setup'
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (raw_string)))
================================================================================
After hook with multiple arguments
================================================================================
Before 'setup1' 'setup2'
--------------------------------------------------------------------------------
(program
(shellspec_hook_statement
argument: (raw_string)
argument: (raw_string)))
================================================================================
Include directive
================================================================================
Include ./lib.sh
--------------------------------------------------------------------------------
(program
(shellspec_directive_statement
path: (word)))
================================================================================
Skip with conditional
================================================================================
Skip if "function returns success" conditions
--------------------------------------------------------------------------------
(program
(shellspec_directive_statement
reason: (string
(string_content))
condition: (word)))
================================================================================
Skip with complex conditional
================================================================================
Skip if 'function returns "skip"' [ "$(conditions)" = "skip" ]
--------------------------------------------------------------------------------
(program
(shellspec_directive_statement
reason: (raw_string)
condition: (test_command
(binary_expression
left: (string
(command_substitution
(command
name: (command_name
(word)))))
right: (string
(string_content))))))
================================================================================
Top-level It without Describe
================================================================================
It 'is simple'
When call echo 'ok'
The output should eq 'ok'
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (raw_string)
(shellspec_when_statement
function: (word)
argument: (raw_string))
(shellspec_the_statement
subject: (shellspec_subject
(word))
matcher: (shellspec_matcher
(word)
(raw_string)))))

View File

@@ -0,0 +1,96 @@
================================================================================
Path statement
================================================================================
Path helper=./lib/helper.sh
--------------------------------------------------------------------------------
(program
(shellspec_path_statement
argument: (word)))
================================================================================
File statement
================================================================================
File config_file
--------------------------------------------------------------------------------
(program
(shellspec_path_statement
argument: (word)))
================================================================================
Dir statement
================================================================================
Dir testdir
--------------------------------------------------------------------------------
(program
(shellspec_path_statement
argument: (word)))
================================================================================
Set statement with option
================================================================================
Set 'errexit:on'
--------------------------------------------------------------------------------
(program
(shellspec_set_statement
option: (raw_string)))
================================================================================
Set statement with multiple options
================================================================================
Set 'errexit:on' 'nounset:on'
--------------------------------------------------------------------------------
(program
(shellspec_set_statement
option: (raw_string)
option: (raw_string)))
================================================================================
Dump statement
================================================================================
Dump
--------------------------------------------------------------------------------
(program
(shellspec_dump_statement))
================================================================================
Intercept statement
================================================================================
Intercept my_func
--------------------------------------------------------------------------------
(program
(shellspec_intercept_statement
argument: (word)))
================================================================================
Intercept with string argument
================================================================================
Intercept "network_call"
--------------------------------------------------------------------------------
(program
(shellspec_intercept_statement
argument: (string
(string_content))))

View File

@@ -0,0 +1,323 @@
================================================================================
Data block
================================================================================
Data
item1
item2
item3
End
--------------------------------------------------------------------------------
(program
(shellspec_data_block
statements: (command
name: (command_name
(word)))
statements: (command
name: (command_name
(word)))
statements: (command
name: (command_name
(word)))))
================================================================================
Data block with label
================================================================================
Data "test data"
"value 1"
"value 2"
End
--------------------------------------------------------------------------------
(program
(shellspec_data_block
statements: (command
name: (command_name
(string
(string_content))))
statements: (command
name: (command_name
(string
(string_content))))
statements: (command
name: (command_name
(string
(string_content))))))
================================================================================
Parameters block
================================================================================
Parameters
param1
param2
End
--------------------------------------------------------------------------------
(program
(shellspec_utility_block
(command
name: (command_name
(word)))
(command
name: (command_name
(word)))))
================================================================================
Parameters with label
================================================================================
Parameters "test parameters"
"first param"
"second param"
End
--------------------------------------------------------------------------------
(program
(shellspec_utility_block
(command
name: (command_name
(string
(string_content))))
(command
name: (command_name
(string
(string_content))))
(command
name: (command_name
(string
(string_content))))))
================================================================================
Skip with reason
================================================================================
Skip 'skipped for now'
--------------------------------------------------------------------------------
(program
(shellspec_skip_statement
reason: (raw_string)))
================================================================================
Skip with double-quoted reason
================================================================================
Skip "not implemented yet"
--------------------------------------------------------------------------------
(program
(shellspec_skip_statement
reason: (string
(string_content))))
================================================================================
Pending with reason
================================================================================
Pending 'work in progress'
--------------------------------------------------------------------------------
(program
(shellspec_pending_statement
reason: (raw_string)))
================================================================================
Pending with double-quoted reason
================================================================================
Pending "waiting for fix"
--------------------------------------------------------------------------------
(program
(shellspec_pending_statement
reason: (string
(string_content))))
================================================================================
Todo standalone
================================================================================
Todo "implement feature X"
--------------------------------------------------------------------------------
(program
(shellspec_todo_statement
description: (string
(string_content))))
================================================================================
Todo with raw string
================================================================================
Todo 'implement feature X'
--------------------------------------------------------------------------------
(program
(shellspec_todo_statement
description: (raw_string)))
================================================================================
Empty utility block
================================================================================
Data "empty data"
End
--------------------------------------------------------------------------------
(program
(shellspec_data_block
statements: (command
name: (command_name
(string
(string_content))))))
================================================================================
Data string argument style
================================================================================
Data "inline data"
--------------------------------------------------------------------------------
(program
(shellspec_data_block
argument: (string
(string_content))))
================================================================================
Data function argument style
================================================================================
Data get_test_data
--------------------------------------------------------------------------------
(program
(shellspec_data_block
argument: (word)))
================================================================================
Data block with :raw modifier
================================================================================
Data :raw
'raw data here'
End
--------------------------------------------------------------------------------
(program
(shellspec_data_block
statements: (command
name: (command_name
(word)))
statements: (command
name: (command_name
(raw_string)))))
================================================================================
Data block with :expand modifier
================================================================================
Data :expand
"expanded $variable"
End
--------------------------------------------------------------------------------
(program
(shellspec_data_block
statements: (command
name: (command_name
(word)))
statements: (command
name: (command_name
(string
(string_content)
(simple_expansion
(variable_name)))))))
================================================================================
Data block with pipe filter
================================================================================
Data | tr 'abc' 'ABC'
#|aaa
#|bbb
End
--------------------------------------------------------------------------------
(program
(shellspec_data_block
filter: (word)
filter: (raw_string)
filter: (raw_string)
data_line: (shellspec_data_line_content)
data_line: (shellspec_data_line_content)))
================================================================================
Data block with pipe filter and modifier
================================================================================
Data:expand | tr 'a' 'A'
#|hello
End
--------------------------------------------------------------------------------
(program
(shellspec_data_block
filter: (word)
filter: (raw_string)
filter: (raw_string)
data_line: (shellspec_data_line_content)))
================================================================================
Data function argument with pipe filter
================================================================================
Data foo a b c | tr 'abc' 'ABC'
--------------------------------------------------------------------------------
(program
(shellspec_data_block
argument: (word)
extra_argument: (word)
extra_argument: (word)
extra_argument: (word)
filter: (word)
filter: (raw_string)
filter: (raw_string)))
================================================================================
Data string argument with pipe filter
================================================================================
Data 'abc' | tr 'abc' 'ABC'
--------------------------------------------------------------------------------
(program
(shellspec_data_block
argument: (raw_string)
filter: (word)
filter: (raw_string)
filter: (raw_string)))

View File

@@ -0,0 +1,250 @@
================================================================================
When call simple function
================================================================================
When call my_func
--------------------------------------------------------------------------------
(program
(shellspec_when_statement
function: (word)))
================================================================================
When call function with arguments
================================================================================
When call add 2 3
--------------------------------------------------------------------------------
(program
(shellspec_when_statement
function: (word)
argument: (word)
argument: (word)))
================================================================================
When call function with string argument
================================================================================
When call my_func "hello world"
--------------------------------------------------------------------------------
(program
(shellspec_when_statement
function: (word)
argument: (string
(string_content))))
================================================================================
When run simple
================================================================================
When run my_func
--------------------------------------------------------------------------------
(program
(shellspec_when_statement
function: (word)))
================================================================================
When run command
================================================================================
When run command expr 1 + 2
--------------------------------------------------------------------------------
(program
(shellspec_when_statement
function: (word)
argument: (word)
argument: (word)
argument: (word)))
================================================================================
When run script
================================================================================
When run script ./test.sh
--------------------------------------------------------------------------------
(program
(shellspec_when_statement
function: (word)))
================================================================================
When run source
================================================================================
When run source ./lib.sh arg1
--------------------------------------------------------------------------------
(program
(shellspec_when_statement
function: (word)
argument: (word)))
================================================================================
The output should eq string
================================================================================
The output should eq 'ok'
--------------------------------------------------------------------------------
(program
(shellspec_the_statement
subject: (shellspec_subject
(word))
matcher: (shellspec_matcher
(word)
(raw_string))))
================================================================================
The status should be success
================================================================================
The status should be success
--------------------------------------------------------------------------------
(program
(shellspec_the_statement
subject: (shellspec_subject
(word))
matcher: (shellspec_matcher
(word)
(word))))
================================================================================
The output should not eq bad
================================================================================
The output should not eq "bad"
--------------------------------------------------------------------------------
(program
(shellspec_the_statement
subject: (shellspec_subject
(word))
matcher: (shellspec_matcher
(word)
(string
(string_content)))))
================================================================================
The status should be failure
================================================================================
The status should be failure
--------------------------------------------------------------------------------
(program
(shellspec_the_statement
subject: (shellspec_subject
(word))
matcher: (shellspec_matcher
(word)
(word))))
================================================================================
The with multi-word subject
================================================================================
The line 1 of output should eq "first"
--------------------------------------------------------------------------------
(program
(shellspec_the_statement
subject: (shellspec_subject
(word)
(word)
(word)
(word))
matcher: (shellspec_matcher
(word)
(string
(string_content)))))
================================================================================
Assert simple function
================================================================================
Assert my_function
--------------------------------------------------------------------------------
(program
(shellspec_assert_statement
argument: (word)))
================================================================================
Assert with multiple arguments
================================================================================
Assert check_result "expected value"
--------------------------------------------------------------------------------
(program
(shellspec_assert_statement
argument: (word)
argument: (string
(string_content))))
================================================================================
When and The inside It block
================================================================================
It "should add numbers"
When call add 2 3
The output should eq 5
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(shellspec_when_statement
function: (word)
argument: (word)
argument: (word))
(shellspec_the_statement
subject: (shellspec_subject
(word))
matcher: (shellspec_matcher
(word)
(word)))))
================================================================================
Assert inside It block
================================================================================
It "should validate"
When call validate "input"
Assert check_valid
End
--------------------------------------------------------------------------------
(program
(shellspec_it_block
description: (string
(string_content))
(shellspec_when_statement
function: (word)
argument: (string
(string_content)))
(shellspec_assert_statement
argument: (word))))