Skip to content

Commit

Permalink
comma test runner (nushell#715)
Browse files Browse the repository at this point in the history
- Stabilized the format
- Test suit runner
- Support batch mode
- Watch supports postpone
- `settings.theme`
- docker.nu Simplify process-list logic

---------

Co-authored-by: nash <[email protected]>
  • Loading branch information
fj0r and nashvi committed Dec 29, 2023
1 parent b9cfa0d commit 9b7c177
Show file tree
Hide file tree
Showing 7 changed files with 1,299 additions and 423 deletions.
157 changes: 105 additions & 52 deletions modules/comma/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,129 @@ Working dir task runner, similar to `pwd-module`, but supports completion and de
- `,` or `*` need to be exported in order to use `,` directly
- Directly execute `,` to create a new template file or edit an existing file
- Custom tasks are written in `$env.comma` and can be nested
- no spaces allowed in name (except testing)
- Generate completions based on the structure of `$env.comma`
- You can use closure to customize completion
- In `$env.commax.act` of default closure, you can receive parameters after the current position
- In `$env.commax.cmp` , you can receive the parameter before the current position
- In `$_.act` of default closure, you can receive parameters after the current position
- In `$_.cmp` , you can receive the parameter before the current position
- Supports `computed`, the definition method refers to `$env.comma_scope.computed`, accepts two parameters, runtime parameters and `$env.comma_scope`
- Supports `filter`, similar to `computed`, but only runs when declared, specified through `$env.comm.flt`
- Supports `watch`, specified through `$env.comm.wth`. Support polling like 'poll:2sec'
- Supports `filter`, similar to `computed`, but only runs when declared, specified through `$_.flt`
- Supports `watch` (and polling), specified through `$_.wth`.
- `glob` defaults to `*`, `op` defaults to `['Write']`, `postpone` defaults to `false`
- In watch mode (not Polling) inject `$_.wth`(op, path, new_path) into parameter `$s`
- when the `interval` field is included, it is polling mode(`clear` defaults to 'false')
- Identity supports alias
- children sub s
- description desc dsc d
- action act a
- completion cmp c
- filter flt f
- computed cpu u
- watch wth w
- tag
- expect exp e x
- mock test_args m
- report rpt r


example:
```
$env.comma_scope = {
created: '2023-12-21{4}10:35:31'
computed: {$env.comm.cpu:{|a, s| $'($s.created)($a)' }}
say: {|s| print $'(ansi yellow_italic)($s)(ansi reset)' }
quick: {$env.comm.flt:{|a, s| do $s.say 'run a `quick` filter' }}
slow: {$env.comm.flt:{|a, s|
$env.comma_scope = {|_|{
created: '2023-12-24{0}01:46:27'
computed: {$_.computed:{|a, s| $'($s.created)($a)' }}
say: {|s| print $'(ansi $_.settings.theme.info)($s)(ansi reset)' }
quick: {$_.filter:{|a, s| do $s.say 'run a `quick` filter' }}
slow: {$_.filter:{|a, s|
do $s.say 'run a `slow` filter'
sleep 1sec
do $s.say 'filter need to be declared'
sleep 1sec
$'($s.computed)<($a)>'
}}
}
}}
$env.comma = {
$env.comma = {|_|{
created: {|a, s| $s.computed }
open: {
$env.comm.sub: {
any: {
$env.comm.act: {|a, s| open $a.0}
$env.comm.cmp: {ls | get name}
$env.comm.dsc: 'open a file'
}
json: {
$env.comm.act: {|a, s| open $a.0}
$env.comm.cmp: {ls *.json | get name}
$env.comm.dsc: 'open a json file'
$env.comm.wth: '*.json'
inspect: {|a, s| {index: $_, scope: $s, args: $a} | table -e }
test: {
$_.sub: {
batch: { 'created; inspect' | do $_.batch }
watch: {
$_.action: {|a, s| $s | get $_.watch }
$_.completion: {ls *.json | get name}
$_.desc: 'inspect watch context'
$_.watch: {
glob: '*'
op: ['Write', 'Create']
postpone: true
}
}
scope: {
$env.comm.act: {|a, s| print $'args: ($a)'; $s }
$env.comm.flt: ['slow']
$env.comm.dsc: 'open scope'
$env.comm.wth: 'poll:2sec'
open_file: {
$_.action: {|a, s| open $a.0 }
$_.completion: {ls | get name}
$_.desc: 'open a file'
$_.filter: ['slow']
}
}
$env.comm.dsc: 'open something'
$env.comm.flt: ['quick']
}
# Nest as you like
a: {
b: {
c: {
$env.commax.act: {|x| print $x }
$env.commax.dsc: 'description'
$env.commax.cmp: {|| ls | get name }
}
d: { pwd }
}
x: {
$env.commax.sub: {
y: {
$env.commax.act: {|x| print y}
$env.commax.cmp: {|| [y1 y2 y3]}
$env.commax.dsc: 'description'
ping: {
$_.action: {|a, s| ping -c 2 localhost }
$_.watch: {
interval: 2sec
clear: true
}
}
$env.commax.dsc: 'xxx'
}
$_.desc: 'run test'
$_.filter: ['quick']
}
}
}}
```

### todo
- [x] run
- [ ] dry
- [ ] dry wrap lines
- [ ] accept list<string>
- [x] formatter: outdent
- [x] complete
- [x] with args
- [x] scoped test
- [x] tree map
- [x] test
- [ ] tag
- [ ] watch mode
- [x] override sub node watch
- [x] args
- [x] allow running on leaf node
- [x] test action
- [x] scope
- [ ] filter
- [x] support many expect (list) for one spec
- [ ] curl integration
- [ ] report
- [x] `$x.report` in `test_message` should be `list<string>`
- [x] diff
- [ ] run with `nu -c` (dynamic source nu file)
- [ ] template
- [x] vscode-tasks
- [ ] should panic when identity not exists
- [ ] integration
- [x] gen vscode task json file
- [x] tree map
- [x] batch mode
- [x] run complete in batch mode
- [x] Input variables
- [ ] pickString
- [x] augustocdias.tasks-shell-input
- [x] allow rest args as `promptString`
- https://code.visualstudio.com/docs/editor/variables-reference
- [x] clean filter output
- [x] add gen vscode-tasks to template
- [ ] test and watch
- [x] modulize
- [x] refactor with `resolve node`
- [x] run
- [x] complete
- [x] fix redundant filter in description
- [x] theme
- [x] poll sep bar
- [x] tips
Loading

0 comments on commit 9b7c177

Please sign in to comment.