OILS / stdlib / stream.ysh View on Github | oilshell.org

139 lines, 40 significant
1# stream.ysh
2#
3# Usage:
4# source --builtin stream.ysh
5#
6# For reading lines, decoding, extracting, splitting
7
8# make this file a test server
9source --builtin osh/byo-server-lib.sh
10
11source --builtin args.ysh
12
13proc slurp-by (; num_lines) {
14 # TODO: (stdin)
15 for line in <> {
16 echo TODO
17 }
18}
19
20# Note:
21# - these are all the same algorithm
22# - also word, block, etc. are all optional
23
24proc each-line (...words; template=null; ; block=null) {
25 # TODO:
26 # parse --j8 --max-jobs flag
27
28 # parse template_str as string
29 # TODO: this is dangerous though ... because you can execute code
30 # I think you need a SAFE version
31
32 # evaluate template string expression - I guess that allows $(echo hi) and so
33 # forth
34
35 # evaluate block with _line binding
36 # block: execute in parallel with --max-jobs
37
38 for line in <> {
39 echo TODO
40 }
41}
42
43proc test-each-line {
44 echo 'TODO: need basic test runner'
45
46 # ysh-tool test stream.ysh
47 #
48 # Col
49
50
51}
52
53proc each-row (; ; block) {
54 echo TODO
55}
56
57proc split-by (; ifs=null; block) {
58 echo TODO
59}
60
61proc if-split-by (; ifs=null; block) {
62 echo TODO
63}
64
65proc chop () {
66 ### alias for if-split-by
67 echo TODO
68}
69
70proc must-match (; pattern; block) {
71 echo TODO
72}
73
74proc if-match (; pattern; block) {
75 echo TODO
76}
77
78# Protocol:
79#
80# - The file lists its tests the "actions"
81# - Then the test harness runs them
82# - But should it be ENV vars
83#
84# - BYO_LIST_TESTS=1
85# - BYO_RUN_TEST=foo
86# - $PWD is a CLEAN temp dir, the process doesn't have to do anything
87
88# - silent on success, but prints file on output
89# - OK this makes sense
90#
91# The trivial test in Python:
92#
93# from test import byo
94# byo.maybe_main()
95#
96# bash library:
97# source --builtin byo-server.sh
98#
99# byo-maybe-main # reads env variables, and then exits
100#
101# source --builtin assertions.ysh
102#
103# assert-ok 'echo hi'
104# assert-stdout 'hi' 'echo -n hi'
105#
106# "$@"
107#
108# Run all tests
109# util/byo-client.sh run-tests $YSH stdlib/table.ysh
110# util/byo-client.sh run-tests -f x $YSH stdlib/table.ysh
111
112# Clean process
113# Clean working dir
114
115#
116# Stream Protocol:
117# #.byo - is this she-dot, that's for a file
118# Do we need metadata?
119#
120
121# The harness
122#
123# It's process based testing.
124#
125# Test runner process: bash or OSH (unlike sharness!)
126# Tested process: any language - bash,
127#
128# Key point: you don't have to quote shell code?
129
130list-byo-tests() {
131 echo TODO
132}
133
134run-byo-tests() {
135 # source it
136 echo TODO
137}
138
139byo-maybe-main