This repository has been archived by the owner on Oct 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathecunit2.ps1
executable file
·171 lines (140 loc) · 4.72 KB
/
ecunit2.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# ecunit2.ps1: Editorconfig Vimscript unit-test runner
# Part of editorconfig-core-vimscript.
# Copyright (c) 2018 Chris White. CC-BY-SA 3.0.
# Thanks to https://cecs.wright.edu/~pmateti/Courses/233/Labs/Scripting/bashVsPowerShellTable.html
# by Gallagher and Mateti.
#Requires -Version 3
. "$PSScriptRoot\ecvimlib.ps1"
### Argument processing ================================================
$argv = @(de64_args($args))
# Defaults
$globpat = ''
$files=@()
$extra_info = ''
# Hand-parse - pretend we're sort of like getopt.
$idx = 0
while($idx -lt $argv.count) {
$a = $argv[$idx]
if($debug) {
echo "$idx - $a" | D
}
switch -CaseSensitive -Regex ($a) {
'^-g$' {
if($idx -eq ($argv.count-1)) {
throw '-g <glob pattern>: no pattern provided'
} else {
++$idx
$globpat = $argv[$idx]
}
} #-g
'^-x$' {
if($idx -eq ($argv.count-1)) {
throw '-x <extra info>: no info provided'
} else {
++$idx
$extra_info = $argv[$idx]
}
} #-g
'^--$' { # End of options, so capture the rest as filenames
++$idx;
while($idx -lt $argv.count) {
$files += $argv[$idx]
++$idx
}
}
default { $files += $a }
}
++$idx
} # end foreach argument
### Main ===============================================================
if($debug) {
if($extra_info -ne '') {
echo "--- $extra_info --- " | D
}
echo "Running in $DIR" | D
echo "Vim executable: $VIM" | D
echo "glob pattern: $globpat" | D
echo "Filenames: $files" | D
echo "Args: $args" | D
echo "Decoded args: $argv" | D
}
if($files.count -lt 2) {
exit
}
if($files[0] -eq '-') {
throw "Reading filenames from stdin not yet supported"
}
$fn=[System.IO.Path]::GetTempFileName(); # Vim will write the settings into here. ~stdout.
#$script_output_fn = ''
#if($debug) {
# $script_output_fn = [System.IO.Path]::GetTempFileName()
#}
if(!$globpat) {
throw "At the moment, I can only do -g"
}
# Permit throwing in setup commands
$cmd = ''
if($env:ECUNIT_EXTRA) {
$cmd += $env:ECUNIT_EXTRA + ' | '
}
#$cmd += "let g:editorconfig_core_vimscript_debug=1 | "
$cmd += 'if editorconfig_core#fnmatch#fnmatch('
$cmd += (vesc($files[0] + '/' + $files[1]))
$cmd += ', ' + (vesc($files[0] + '/'))
$cmd += ', ' + (vesc($globpat))
$cmd += ') | quit! | else | cquit! | endif'
if($debug) { echo "Running Vim command ${cmd}" | D }
$vim_args = @(
'-c', "set rtp+=$DIR",
'-c', $cmd
)
# Run editorconfig. Thanks for options to
# http://vim.wikia.com/wiki/Vim_as_a_system_interpreter_for_vimscript .
# Add -V1 to the below for debugging output.
# Do not output anything to stdout or stderr,
# since it messes up ctest's interpretation
# of the results if regex tests are used.
$basic_args = '-nNes','-i','NONE','-u','NONE','-U','NONE' # , '-V1'
#echo 'DEBUG message here yay' >> $script_output_fn #DEBUG
if($debug) { echo "Running vim ${VIM}" | D }
$vimstatus = run_process $VIM -stdout $debug -stderr $debug `
-argv ($basic_args+$vim_args)
if($debug) { echo "Done running vim" | D }
if($vimstatus -eq 0) {
cat $fn
}
# Debug output cannot be included on stdout or stderr, because
# ctest's regex check looks both of those places. Therefore, dump to a
# separate debugging file.
if($debug) {
echo "Current directory:" | D
(get-item -path '.').FullName | D
echo "Script directory: $DIR" | D
### echo Vim args: "${vim_args[@]}" >> "$debug"
### #od -c <<<"${vim_args[@]}" >> "$debug"
echo "Vim returned $vimstatus" | D
### echo "Vim messages were: " | D
### cat $script_output_fn | D
### echo "Output was:" | D
###
### # Modified from https://www.itprotoday.com/powershell/get-hex-dumps-files-powershell
### Get-Content $script_output_fn -Encoding Byte -ReadCount 16 | `
### ForEach-Object {
### $output = ""
### $chars = ''
### foreach ( $byte in $_ ) {
### $output += "{0:X2} " -f $byte
### if( ($byte -ge 32) -and ($byte -le 127) ) {
### $chars += [char]$byte
### } else {
### $chars += '.'
### }
### }
### $output + ' ' + $chars
### } | D
###
### del -Force $script_output_fn
} #endif $debug
del -Force $fn
exit $vimstatus
# vi: set ts=4 sts=4 sw=4 et ai: