Created
June 17, 2019 14:38
-
-
Save hoegaarden/d6d28ba3c6f4a89464b602ebf22baf10 to your computer and use it in GitHub Desktop.
all them awks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
set -u | |
set -o pipefail | |
AWKS=( | |
/usr/bin/original-awk | |
/usr/bin/gawk | |
/usr/bin/mawk | |
) | |
EXPECTED_REMOTE=( | |
'/some/repo' | |
':some/repo' | |
'[:/]some/repo' | |
'notsome/repo' | |
) | |
DIR="$(mktemp -d)" | |
trap 'rm -r "$DIR"' EXIT | |
cd "$DIR" | |
setup() { | |
git init | |
git remote add git [email protected]:some/repo | |
git remote add http http://github.com/some/repo | |
} | |
setup | |
echo '#### Testing awks' | |
echo | |
for awk in "${AWKS[@]}" | |
do | |
for expectedRemote in "${EXPECTED_REMOTE[@]}" | |
do | |
for remotePattern in \ | |
"${expectedRemote}(.git)* \(fetch\)$" \ | |
"${expectedRemote//\//\\\/}(.git)* \(fetch\)$" | |
do | |
echo -e "# awk: ${awk} \t expectedRemote: ${expectedRemote} \t remotePattern: ${remotePattern}" | |
git remote -v | "$awk" "-vP=${remotePattern}" '$0 ~ P {print $1}' || echo " -- $awk failed" | |
echo | |
done | |
done | |
done | |
echo '#### Testing grep | cut' | |
echo | |
for expectedRemote in "${EXPECTED_REMOTE[@]}" | |
do | |
for remotePattern in \ | |
"${expectedRemote}(.git)* \(fetch\)$" \ | |
"${expectedRemote//\//\\\/}(.git)* \(fetch\)$" | |
do | |
echo -e "expectedRemote: ${expectedRemote} \t remotePattern: ${remotePattern}" | |
git remote -v | grep -E "$remotePattern" | cut -f1 | |
echo | |
done | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@ba15ba6d621b:/# ./awks.sh | |
Initialized empty Git repository in /tmp/tmp.j10N5MTZX6/.git/ | |
#### Testing awks | |
# awk: /usr/bin/original-awk expectedRemote: /some/repo remotePattern: /some/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/original-awk expectedRemote: /some/repo remotePattern: \/some\/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/original-awk expectedRemote: :some/repo remotePattern: :some/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/original-awk expectedRemote: :some/repo remotePattern: :some\/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/original-awk expectedRemote: [:/]some/repo remotePattern: [:/]some/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/original-awk expectedRemote: [:/]some/repo remotePattern: [:\/]some\/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/original-awk expectedRemote: notsome/repo remotePattern: notsome/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/original-awk expectedRemote: notsome/repo remotePattern: notsome\/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/gawk expectedRemote: /some/repo remotePattern: /some/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/gawk expectedRemote: /some/repo remotePattern: \/some\/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\/' treated as plain `/' | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/gawk expectedRemote: :some/repo remotePattern: :some/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/gawk expectedRemote: :some/repo remotePattern: :some\/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\/' treated as plain `/' | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/gawk expectedRemote: [:/]some/repo remotePattern: [:/]some/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/gawk expectedRemote: [:/]some/repo remotePattern: [:\/]some\/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\/' treated as plain `/' | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/gawk expectedRemote: notsome/repo remotePattern: notsome/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/gawk expectedRemote: notsome/repo remotePattern: notsome\/repo(.git)* \(fetch\)$ | |
gawk: warning: escape sequence `\/' treated as plain `/' | |
gawk: warning: escape sequence `\(' treated as plain `(' | |
gawk: warning: escape sequence `\)' treated as plain `)' | |
# awk: /usr/bin/mawk expectedRemote: /some/repo remotePattern: /some/repo(.git)* \(fetch\)$ | |
http | |
# awk: /usr/bin/mawk expectedRemote: /some/repo remotePattern: \/some\/repo(.git)* \(fetch\)$ | |
http | |
# awk: /usr/bin/mawk expectedRemote: :some/repo remotePattern: :some/repo(.git)* \(fetch\)$ | |
git | |
# awk: /usr/bin/mawk expectedRemote: :some/repo remotePattern: :some\/repo(.git)* \(fetch\)$ | |
git | |
# awk: /usr/bin/mawk expectedRemote: [:/]some/repo remotePattern: [:/]some/repo(.git)* \(fetch\)$ | |
git | |
http | |
# awk: /usr/bin/mawk expectedRemote: [:/]some/repo remotePattern: [:\/]some\/repo(.git)* \(fetch\)$ | |
git | |
http | |
# awk: /usr/bin/mawk expectedRemote: notsome/repo remotePattern: notsome/repo(.git)* \(fetch\)$ | |
# awk: /usr/bin/mawk expectedRemote: notsome/repo remotePattern: notsome\/repo(.git)* \(fetch\)$ | |
#### Testing grep | cut | |
expectedRemote: /some/repo remotePattern: /some/repo(.git)* \(fetch\)$ | |
http | |
expectedRemote: /some/repo remotePattern: \/some\/repo(.git)* \(fetch\)$ | |
http | |
expectedRemote: :some/repo remotePattern: :some/repo(.git)* \(fetch\)$ | |
git | |
expectedRemote: :some/repo remotePattern: :some\/repo(.git)* \(fetch\)$ | |
git | |
expectedRemote: [:/]some/repo remotePattern: [:/]some/repo(.git)* \(fetch\)$ | |
git | |
http | |
expectedRemote: [:/]some/repo remotePattern: [:\/]some\/repo(.git)* \(fetch\)$ | |
git | |
http | |
expectedRemote: notsome/repo remotePattern: notsome/repo(.git)* \(fetch\)$ | |
root@ba15ba6d621b:/# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment