slightish 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +37 -8
- data/Rakefile +3 -1
- data/lib/slightish/test_case.rb +26 -33
- data/lib/slightish/version.rb +1 -1
- data/lib/string_mixins.rb +9 -13
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 51b6f31fd54515ff6b59a63f80ddfce65eeb5703
|
|
4
|
+
data.tar.gz: 16efeba26b6cb63d64557a01ac35ea0718e30be4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c59d7efd070ec46a902d998c7c01c5f276ceb097e69b1259df9dc7eedb48a61593865fef9df5c37b47926a16618e7280f1b90a5df31efe1aa68f3bf7dd89dae5
|
|
7
|
+
data.tar.gz: 007865b79838119a79e91853dd11f129fc25526061ddde39a024b22e4a78a353da904507369ec5f4397dbef4ec0a427e77c54dc9e889927615b8ea30246541e6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
*Literate testing of shell scripts*
|
|
4
4
|
|
|
5
|
-
[](https://travis-ci.org/misterfifths/slightish) [](https://coveralls.io/github/misterfifths/slightish?branch=master) [](https://rubygems.org/gems/slightish)
|
|
5
|
+
[](https://travis-ci.org/misterfifths/slightish) [](https://coveralls.io/github/misterfifths/slightish?branch=master) [](https://codeclimate.com/github/misterfifths/slightish) [](https://rubygems.org/gems/slightish)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
### What's this then?
|
|
@@ -38,9 +38,9 @@ $ echo stdout; echo stderr >&2; echo "more stdout"; exit 2
|
|
|
38
38
|
|
|
39
39
|
That example covers 90% of the functionality. The syntax in detail works like this:
|
|
40
40
|
|
|
41
|
-
- Lines that start with `$
|
|
42
|
-
- Lines starting with `|
|
|
43
|
-
- Lines starting with `@
|
|
41
|
+
- Lines that start with `$ ` are interpreted as commands to run in the shell. The `$` must be in the first column of the file and must be followed by a space.
|
|
42
|
+
- Lines starting with `| ` specify the stdout of the most recent command. As with `$ `, the `|` must be in the first column and must be followed by a space. You may specify more than one `| ` line to test for multiline output.
|
|
43
|
+
- Lines starting with `@ ` specify the stderr of the most recent command. You may also specify more than one `@ ` line per command to test for multiline output on stderr.
|
|
44
44
|
- A line of the form `? <positive integer>` specifies the expected exit code of the most recent command. You may omit a `? ` line for an expected exit code of zero.
|
|
45
45
|
|
|
46
46
|
Specifying any of the above magic lines out of order is a syntax error; you must specify a command (`$ `), and then optionally stdout (`| `), stderr (`@ `), and the exit code (`? `). If a command is expected to produce no output and have an exit code of zero, you may omit everything but the `$ ` line:
|
|
@@ -60,7 +60,7 @@ slightish my-first-test.md my-second-test
|
|
|
60
60
|
|
|
61
61
|
This will run all the tests in all the specified files, and output details about any failures. The command will exit with status code 1 if any tests fail.
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
As a demonstration, let's add a failing test:
|
|
64
64
|
|
|
65
65
|
```sh
|
|
66
66
|
$ exit 2
|
|
@@ -79,15 +79,44 @@ Expected exit code: 0
|
|
|
79
79
|
Actual exit code: 2
|
|
80
80
|
|
|
81
81
|
----------
|
|
82
|
-
README.md
|
|
82
|
+
README.md 11 passed 1 failed
|
|
83
83
|
|
|
84
|
-
Total tests:
|
|
85
|
-
Passed:
|
|
84
|
+
Total tests: 12
|
|
85
|
+
Passed: 11
|
|
86
86
|
Failed: 1
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
### More features
|
|
90
90
|
|
|
91
|
+
#### Command and variable expansion
|
|
92
|
+
|
|
93
|
+
Environmental variables in your command, stdout, and stderr are all expanded. The syntax is `$VARIABLE` or `${VARIABLE}`. Note that escaping and quoting of such strings is *not* supported; they will be expanded regardless.
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
$ echo $USER
|
|
97
|
+
| $USER
|
|
98
|
+
|
|
99
|
+
$ echo "${HOME}/dir"
|
|
100
|
+
| ${HOME}/dir
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Nonexistent environmental variables will not be expanded, and the original string will be passed through unaltered:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
$ echo '$_TOTAL_NONSENSE_'
|
|
107
|
+
| $_TOTAL_NONSENSE_
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Subcommands are also expanded, using the syntax `$(cmd)` or `` `cmd` ``. Only the stdout of subcommands is captured. If a subcommand produces output on stderr, or has a nonzero exit status, a warning is printed.
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
$ echo "$(pwd)"
|
|
114
|
+
| `pwd`
|
|
115
|
+
|
|
116
|
+
$ echo `whoami`
|
|
117
|
+
| $USER
|
|
118
|
+
```
|
|
119
|
+
|
|
91
120
|
#### Sandboxes
|
|
92
121
|
|
|
93
122
|
Each test file is run in its own sandbox directory, so you can safely write to files if your tests require it:
|
data/Rakefile
CHANGED
data/lib/slightish/test_case.rb
CHANGED
|
@@ -42,42 +42,15 @@ class Slightish::TestCase
|
|
|
42
42
|
|
|
43
43
|
def failure_description
|
|
44
44
|
res = ''
|
|
45
|
+
res += output_failure_description('stdout', @expected_output, @actual_output) unless @expected_output == @actual_output
|
|
45
46
|
|
|
46
|
-
if @
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
else
|
|
50
|
-
res += "Expected stdout:\n".red.bold
|
|
51
|
-
res += @expected_output.gray + "\n"
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
if @actual_output.empty?
|
|
55
|
-
res += 'Actual stdout: empty'.green.bold
|
|
56
|
-
else
|
|
57
|
-
res += "Actual stdout:\n".green.bold
|
|
58
|
-
res += @actual_output.gray
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
if @actual_error_output != (@expected_error_output || '')
|
|
63
|
-
res += "\n\n" unless res == ''
|
|
64
|
-
if @expected_error_output.empty?
|
|
65
|
-
res += "Expected stderr: empty\n".red.bold
|
|
66
|
-
else
|
|
67
|
-
res += "Expected stderr:\n".red.bold
|
|
68
|
-
res += (@expected_error_output || '').gray + "\n"
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
if @actual_error_output.empty?
|
|
72
|
-
res += 'Actual stderr: empty'.green.bold
|
|
73
|
-
else
|
|
74
|
-
res += "Actual stderr:\n".green.bold
|
|
75
|
-
res += @actual_error_output.gray
|
|
76
|
-
end
|
|
47
|
+
if @expected_error_output != @actual_error_output
|
|
48
|
+
res += "\n\n" unless res.empty?
|
|
49
|
+
res += output_failure_description('stderr', @expected_error_output, @actual_error_output)
|
|
77
50
|
end
|
|
78
51
|
|
|
79
52
|
if @actual_exit_code != @expected_exit_code
|
|
80
|
-
res += "\n\n" unless res
|
|
53
|
+
res += "\n\n" unless res.empty?
|
|
81
54
|
res += 'Expected exit code: '.red.bold + @expected_exit_code.to_s.gray + "\n"
|
|
82
55
|
res += 'Actual exit code: '.green.bold + @actual_exit_code.to_s.gray
|
|
83
56
|
end
|
|
@@ -87,7 +60,7 @@ class Slightish::TestCase
|
|
|
87
60
|
|
|
88
61
|
def source_description
|
|
89
62
|
if @start_line == @end_line
|
|
90
|
-
"#{@source_file}
|
|
63
|
+
"#{@source_file}:#{@start_line}"
|
|
91
64
|
else
|
|
92
65
|
"#{@source_file}:#{@start_line}-#{@end_line}"
|
|
93
66
|
end
|
|
@@ -124,6 +97,26 @@ class Slightish::TestCase
|
|
|
124
97
|
|
|
125
98
|
private
|
|
126
99
|
|
|
100
|
+
def output_failure_description(name, expected, actual)
|
|
101
|
+
res = ''
|
|
102
|
+
|
|
103
|
+
if expected.empty?
|
|
104
|
+
res += "Expected #{name}: empty\n".red.bold
|
|
105
|
+
else
|
|
106
|
+
res += "Expected #{name}:\n".red.bold
|
|
107
|
+
res += expected.gray + "\n"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if actual.empty?
|
|
111
|
+
res += "Actual #{name}: empty".green.bold
|
|
112
|
+
else
|
|
113
|
+
res += "Actual #{name}:\n".green.bold
|
|
114
|
+
res += actual.gray
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
res
|
|
118
|
+
end
|
|
119
|
+
|
|
127
120
|
def expand(sandbox)
|
|
128
121
|
@command = @raw_command.expand(chdir: sandbox.path, source: source_description)
|
|
129
122
|
@expected_output = (@raw_expected_output || '').expand(chdir: sandbox.path, source: source_description)
|
data/lib/slightish/version.rb
CHANGED
data/lib/string_mixins.rb
CHANGED
|
@@ -52,6 +52,13 @@ class String
|
|
|
52
52
|
|
|
53
53
|
private
|
|
54
54
|
|
|
55
|
+
def puts_warning(message, cmd, source)
|
|
56
|
+
s = "warning: #{message} ("
|
|
57
|
+
s += source + '; ' unless source.nil? || source.empty?
|
|
58
|
+
s += "'#{cmd}')"
|
|
59
|
+
$stderr.puts(s.yellow) unless ENV['SLIGHTISH_NO_WARNINGS']
|
|
60
|
+
end
|
|
61
|
+
|
|
55
62
|
def capture_stdout_with_logging(cmd, chdir, source)
|
|
56
63
|
if chdir.nil?
|
|
57
64
|
stdout, stderr, status = Open3.capture3(cmd)
|
|
@@ -59,19 +66,8 @@ class String
|
|
|
59
66
|
stdout, stderr, status = Open3.capture3(cmd, { chdir: chdir })
|
|
60
67
|
end
|
|
61
68
|
|
|
62
|
-
unless stderr.empty?
|
|
63
|
-
|
|
64
|
-
message += source + '; ' unless source.nil? || source.empty?
|
|
65
|
-
message += "'#{cmd}') will be ignored"
|
|
66
|
-
$stderr.puts(message.yellow) unless ENV['SLIGHTISH_NO_WARNINGS']
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
unless status.exitstatus.zero?
|
|
70
|
-
message = "warning: nonzero exit code (#{status.exitstatus}) from command substitution ("
|
|
71
|
-
message += source + '; ' unless source.nil? || source.empty?
|
|
72
|
-
message += "'#{cmd}')"
|
|
73
|
-
$stderr.puts(message.yellow) unless ENV['SLIGHTISH_NO_WARNINGS']
|
|
74
|
-
end
|
|
69
|
+
puts_warning('stderr from command substitution will be ignored', cmd, source) unless stderr.empty?
|
|
70
|
+
puts_warning("nonzero exit code (#{status.exitstatus}) from command substitution", cmd, source) unless status.exitstatus.zero?
|
|
75
71
|
|
|
76
72
|
stdout.chomp
|
|
77
73
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slightish
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Clem
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-07-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: slightish lets you write and run tests for shell tools in a simple, flexible
|
|
14
14
|
syntax, intermingled with any other file format (Markdown, plain text, HTML). Your
|