| 1 |
writeInfoLine: "Testing runSubprocess..." |
| 2 |
@test: empty$# (0) |
| 3 |
@test: { "hello" } |
| 4 |
@test: { “hello” } |
| 5 |
@test: { """hello""" } |
| 6 |
@test: { "a""hello""b" } |
| 7 |
@test: { "a""""hello""""b" } |
| 8 |
@test: { “he"llo"a” } |
| 9 |
@test: { “he " llo"a” } |
| 10 |
@test: { “he " llo” } |
| 11 |
@test: { "" } |
| 12 |
@test: { "", "" } |
| 13 |
@test: { "hello", "" } |
| 14 |
@test: { "", "hello" } |
| 15 |
@test: { "hello world", "" } |
| 16 |
@test: { "", "hello world" } |
| 17 |
@test: { "hello world" } |
| 18 |
@test: { "hello, world" } |
| 19 |
@test: { "hello", "world" } |
| 20 |
@test: { "hello goodbye", "world" } |
| 21 |
@test: { "hello/goodbye", "world" } |
| 22 |
@test: { "hello@goodbye", "world" } |
| 23 |
@test: { "hello", "goodbye world" } |
| 24 |
@test: { "hello all", "goodbye world" } |
| 25 |
@test: { “hello goodbye”, "world" } |
| 26 |
@test: { “hello" goodbye”, "world" } |
| 27 |
@test: { “hello " goodbye”, "world" } |
| 28 |
@test: { “hello "goodbye”, "world" } |
| 29 |
@test: { “hello "goodbye"”, "world" } |
| 30 |
@test: { “hello "goodbye" all”, "world 1a" } |
| 31 |
@test: { “hello "goodbye"all”, "world 1b" } |
| 32 |
@test: { “hello"goodbye" all”, "world 1c" } |
| 33 |
@test: { “hello"goodbye"all”, "world 1c" } |
| 34 |
@test: { “hello ""goodbye""”, "world 2" } |
| 35 |
@test: { “hello ""goodbye"" all”, "world 3" } |
| 36 |
@test: { “hello ""goodbye""all”, "world 4" } |
| 37 |
@test: { “hello """goodbye""" all”, "world" } |
| 38 |
@test: { “hello ""goodbye""allp”, "world" } |
| 39 |
@test: { “hello ""a""""goodbye""""b""”, "world 5" } |
| 40 |
@test: { “hello "a"""goodbye"""b"”, "world 6" } |
| 41 |
@test: { “hello "a"""goodbye""b"”, "world 7" } |
| 42 |
@test: { "hello goodbye", "wor ld&world" } |
| 43 |
@test: { "hello goodbye", "&world" } |
| 44 |
@test: { "hello&", "goodbye world" } |
| 45 |
@test: { "hello, goodbye, world!" } |
| 46 |
if not windows |
| 47 |
@test: { "*.exe" } ; there are executables in this folder, so the asterisk will expand on Windows |
| 48 |
@test: { "*.praat" } ; there is a Praat script in this folder, so the asterisk will expand on Windows |
| 49 |
endif |
| 50 |
@test: { "*.praathello" } |
| 51 |
@test: { "*.praat ; ls -al"} ; to show that this is safe |
| 52 |
@test: { "*.praat ; ls -al", "hello" } ; to show that this is safe |
| 53 |
@test: { "*.praathello" + newline$ + "ls -al"} ; to show that this is safe |
| 54 |
@test: { "*.praathello" + newline$ + "ls -al", "hello"} ; to show that this is safe |
| 55 |
@test: { "\""" } |
| 56 |
|
| 57 |
# |
| 58 |
# From https://learn.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments?view=msvc-170 |
| 59 |
# |
| 60 |
@test: { “a b c”, “d”, “e” } |
| 61 |
@test: { “ab"c”, “\”, “d” } |
| 62 |
@test: { “a\\\b”, “de fg”, “h” } |
| 63 |
@test: { “a\"b”, “c”, “d” } |
| 64 |
@test: { “a\\b c”, “d”, “e” } |
| 65 |
@test: { “a b" c d” } |
| 66 |
|
| 67 |
@test: { “back\slash\” } |
| 68 |
@test: { "\" } |
| 69 |
@test: { "\\" } |
| 70 |
@test: { "\\\" } |
| 71 |
@test: { "\\\\" } |
| 72 |
@test: { "\\\\\" } |
| 73 |
@test: { "\\\\\\" } |
| 74 |
|
| 75 |
procedure test: .args$# |
| 76 |
executable$ = |
| 77 |
... if macintosh then |
| 78 |
... if praat_arm64 then "spit_mac_arm64" else "spit_mac_intel64" fi |
| 79 |
... else if windows then |
| 80 |
... if praat_arm64 then "spit_win_arm64.exe" else "spit_win_intel64.exe" fi |
| 81 |
... else if unix then |
| 82 |
... if praat_arm64 then "spit_linux_arm64" |
| 83 |
... else if praat_s390x then "spit_linux_s390x" |
| 84 |
... else if praat_armv7 then "spit_linux_armv7" |
| 85 |
... else "spit_linux_intel64" |
| 86 |
... fi fi fi |
| 87 |
... else "spit_unknown" fi fi fi |
| 88 |
;executable$ = "a.exe" |
| 89 |
folderPath$ = if macintosh then "./" else "" fi |
| 90 |
appendInfoLine () |
| 91 |
@testje: folderPath$ + executable$, .args$# |
| 92 |
executable$ = replace$ (executable$, "_", " ", 0) |
| 93 |
@testje: folderPath$ + executable$, .args$# |
| 94 |
endproc |
| 95 |
procedure testje: .spittingApp$, .args$# |
| 96 |
appendInfoLine: .spittingApp$ |
| 97 |
.narg = size (.args$#) |
| 98 |
for .iarg to .narg |
| 99 |
appendInfoLine: "in[", .iarg, "] = <<", .args$# [.iarg], ">>" |
| 100 |
endfor |
| 101 |
if .narg = 0 |
| 102 |
.output$ = runSubprocess$: .spittingApp$ |
| 103 |
elif .narg = 1 |
| 104 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1] |
| 105 |
elif .narg = 2 |
| 106 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2] |
| 107 |
elif .narg = 3 |
| 108 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2], .args$# [3] |
| 109 |
elif .narg = 4 |
| 110 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2], .args$# [3], .args$# [4] |
| 111 |
elif .narg = 5 |
| 112 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2], .args$# [3], .args$# [4], |
| 113 |
... .args$# [5] |
| 114 |
elif .narg = 6 |
| 115 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2], .args$# [3], .args$# [4] |
| 116 |
... .args$# [5], .args$# [6] |
| 117 |
elif .narg = 7 |
| 118 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2], .args$# [3], .args$# [4] |
| 119 |
... .args$# [5], .args$# [6], .args$# [7] |
| 120 |
elif .narg = 8 |
| 121 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2], .args$# [3], .args$# [4] |
| 122 |
... .args$# [5], .args$# [6], .args$# [7], .args$# [8] |
| 123 |
elif .narg = 9 |
| 124 |
.output$ = runSubprocess$: .spittingApp$, .args$# [1], .args$# [2], .args$# [3], .args$# [4] |
| 125 |
... .args$# [5], .args$# [6], .args$# [7], .args$# [8], .args$# [9] |
| 126 |
endif |
| 127 |
assert index (.output$, "arg [0] = <<" + .spittingApp$ + ">>") ; <<'.output$'>> |
| 128 |
for .iarg to .narg |
| 129 |
if not index (.output$, "arg [" + string$ (.iarg) + "] = <<" + .args$# [.iarg] + ">>") |
| 130 |
for i to length (.output$) |
| 131 |
kar$ = mid$ (.output$, i) |
| 132 |
appendInfoLine: i, " ", kar$, " ", unicode (kar$) |
| 133 |
endfor |
| 134 |
for i to length (.args$# [.iarg]) |
| 135 |
kar$ = mid$ (.args$# [.iarg], i) |
| 136 |
appendInfoLine: i, " ", kar$, " ", unicode (kar$) |
| 137 |
endfor |
| 138 |
endif |
| 139 |
assert index (.output$, "arg [" + string$ (.iarg) + "] = <<" + .args$# [.iarg] + ">>") ; <<'.output$'>> |
| 140 |
endfor |
| 141 |
assert not index (.output$, "arg [" + string$ (.narg + 1) + "]") ; <<'.output$'>> |
| 142 |
endproc |
| 143 |
appendInfoLine: newline$, "OK" |