Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
name: 'wgetpaste test runner'
on: [pull_request, push]
jobs:
run-test:
name: 'Run test/test.sh'
run-tests:
strategy:
matrix:
test: [test, test_ansi]
name: "Run test/${{ matrix.test }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: test/test.sh
shell: bash
run-test-ansi:
name: 'Run test/test_ansi.sh'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Install ansifilter'
- name: 'Checkout repository'
uses: actions/checkout@v4

- name: 'Install dependencies'
run: |
sudo apt-get update
sudo apt-get install ansifilter
- run: test/test_ansi.sh
sudo apt-get install meson ${{ matrix.test == 'test_ansi' && 'ansifilter' || '' }}
shell: bash

- name: 'Build wgetpaste'
run: |
mkdir build
meson setup build --prefix="/"
shell: bash

- run: meson test -C ./build ${{ matrix.test }}
45 changes: 45 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
project(
'wgetpaste',
license: 'MIT',
license_files: 'LICENSE',
version: '2.35.0',
meson_version: '>=1.1.0',
)

config_data = configuration_data()
config_data.set('WGETPASTE_SHEBANG', get_option('shebang'))
config_data.set('WGETPASTE_VERSION', meson.project_version())
configure_file(
output: 'wgetpaste',
input: 'wgetpaste',
configuration: config_data,
install: true,
install_dir: get_option('bindir'),
install_mode: 'rwxr-xr-x'
)

install_data(
'_wgetpaste',
install_dir: get_option('datadir') / get_option('zsh-completions-dir'),
install_mode: 'rw-r--r--'
)

test_runner = find_program('test/test.sh')
test(
'test',
test_runner,
timeout: 0,
env: [
'MESON_BUILD_ROOT=' + meson.project_build_root()
]
)

test_runner = find_program('test/test_ansi.sh')
test(
'test_ansi',
test_runner,
timeout: 0,
env: [
'MESON_BUILD_ROOT=' + meson.project_build_root()
]
)
11 changes: 11 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
option(
'shebang',
type: 'string',
value: '/usr/bin/env bash',
description: 'Specify shebang line for wgetpaste script'
)
option('zsh-completions-dir',
type: 'string',
value: 'zsh/site-functions',
description: 'Specify location of zsh-completions directory (relative to datadir)'
)
5 changes: 3 additions & 2 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Don't assume the test is being run from the same directory as the script
TEST_DIR="$(dirname "$0")"
WGETPASTE="${MESON_BUILD_ROOT}/wgetpaste"
TEST_FILE="$TEST_DIR/test.txt"
DL_DIR="$(mktemp -q --tmpdir -d wgetpaste_test.XXXXX)"
# Services to hard skip
Expand All @@ -30,7 +31,7 @@ echo "Using download directory: $DL_DIR"

# Post test file into each service (if possible)
# Download the resulting paste into /tmp/wgetpaste_test.XXXXX/<service>.txt
for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do
for serv in $("$WGETPASTE" -S --completions); do
# Hard skips
for hs in "${!HARD_SKIPS[@]}"; do
if [ "$serv" == "$hs" ]; then
Expand All @@ -45,7 +46,7 @@ for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do
# Log deleted at the end of each loop unless error other than 401
echo -n "Posting to $serv: "
ERROR_LOG="$DL_DIR/$serv-error.log"
URL="$("$TEST_DIR"/../wgetpaste -r -s "$serv" -v "$TEST_FILE" 2>"$ERROR_LOG")"
URL="$("$WGETPASTE" -r -s "$serv" -v "$TEST_FILE" 2>"$ERROR_LOG")"
STATUS="$?"

# Skip failed posts (eg, not authorized for GitHub/GitLab, service error)
Expand Down
17 changes: 9 additions & 8 deletions test/test_ansi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Don't assume the test is being run from the same directory as the script
TEST_DIR="$(dirname "$0")"
WGETPASTE="${MESON_BUILD_ROOT}/wgetpaste"
ANSI_FILE="$TEST_DIR/red.txt"
NOANSI_FILE="$TEST_DIR/red_no_ansi.txt"
DL_DIR="$(mktemp -q --tmpdir -d wgetpaste_test_ansi.XXXXX)"
Expand All @@ -30,7 +31,7 @@ fi
echo "Using download directory: $DL_DIR"

# Post test file into each service until one succeeds
for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do
for serv in $("$WGETPASTE" -S --completions); do
# Hard skips
for hs in "${!HARD_SKIPS[@]}"; do
if [ "$serv" == "$hs" ]; then
Expand All @@ -44,7 +45,7 @@ for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do
# Log deleted at the end of each loop unless error other than 401
echo -n "Posting to $serv: "
ERROR_LOG="$DL_DIR/$serv-error.log"
URL="$("$TEST_DIR"/../wgetpaste -r -s "$serv" -v "$ANSI_FILE" 2>"$ERROR_LOG")"
URL="$("$WGETPASTE" -r -s "$serv" -v "$ANSI_FILE" 2>"$ERROR_LOG")"
STATUS="$?"

# Skip failed posts (eg, not authorized for GitHub/GitLab, service error)
Expand Down Expand Up @@ -96,7 +97,7 @@ fi
sleep 1
echo -n "Pasting command output with ANSI stripping (cat): "
ERROR_LOG="$DL_DIR/command-noansi-error.log"
URL="$("$TEST_DIR"/../wgetpaste -N -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")"
URL="$("$WGETPASTE" -N -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")"
if [ $? -ne 0 ]; then
echo "FAILED!"
FAILED_PASTE=$((FAILED_PASTE + 1))
Expand All @@ -118,7 +119,7 @@ fi
sleep 1
echo -n "Pasting command output without ANSI stripping (cat): "
ERROR_LOG="$DL_DIR/command-ansi-error.log"
URL="$("$TEST_DIR"/../wgetpaste -A -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")"
URL="$("$WGETPASTE" -A -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")"
if [ $? -ne 0 ]; then
echo "FAILED!"
FAILED_PASTE=$((FAILED_PASTE + 1))
Expand All @@ -141,7 +142,7 @@ fi
sleep 1
echo -n "Pasting stdin with ANSI stripping (cat | wgetpaste): "
ERROR_LOG="$DL_DIR/stdin-noansi-error.log"
URL="$(cat "$ANSI_FILE" | "$TEST_DIR"/../wgetpaste -N -r -s "$WORKING" -v 2>"$ERROR_LOG")"
URL="$(cat "$ANSI_FILE" | "$WGETPASTE" -N -r -s "$WORKING" -v 2>"$ERROR_LOG")"
if [ $? -ne 0 ]; then
echo "FAILED!"
FAILED_PASTE=$((FAILED_PASTE + 1))
Expand All @@ -160,7 +161,7 @@ fi
sleep 1
echo -n "Pasting stdin without ANSI stripping (cat | wgetpaste): "
ERROR_LOG="$DL_DIR/stdin-ansi-error.log"
URL="$(cat "$ANSI_FILE" | "$TEST_DIR"/../wgetpaste -A -r -s "$WORKING" -v 2>"$ERROR_LOG")"
URL="$(cat "$ANSI_FILE" | "$WGETPASTE" -A -r -s "$WORKING" -v 2>"$ERROR_LOG")"
if [ $? -ne 0 ]; then
echo "FAILED!"
FAILED_PASTE=$((FAILED_PASTE + 1))
Expand All @@ -180,7 +181,7 @@ fi
sleep 1
echo -n "Pasting a file with ANSI stripping: "
ERROR_LOG="$DL_DIR/file-noansi-error.log"
URL="$("$TEST_DIR"/../wgetpaste -N -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")"
URL="$("$WGETPASTE" -N -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")"
if [ $? -ne 0 ]; then
echo "FAILED!"
FAILED_PASTE=$((FAILED_PASTE + 1))
Expand All @@ -199,7 +200,7 @@ fi
sleep 1
echo -n "Pasting a file without ANSI stripping: "
ERROR_LOG="$DL_DIR/file-ansi-error.log"
URL="$("$TEST_DIR"/../wgetpaste -A -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")"
URL="$("$WGETPASTE" -A -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")"
if [ $? -ne 0 ]; then
echo "FAILED!"
FAILED_PASTE=$((FAILED_PASTE + 1))
Expand Down
4 changes: 2 additions & 2 deletions wgetpaste
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#!@WGETPASTE_SHEBANG@
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably just ignorant, but do we really have to make the shebang configurable? Isn't /usr/bin/env supposed to be universal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably just ignorant, but do we really have to make the shebang configurable? Isn't /usr/bin/env supposed to be universal?

The configuration is optional. If the builder does not set WGETPASTE_SHEBANG it defaults to /usr/bin/env bash.

/usr/bin/env does depend on the environment variable PATH being correctly set to find bash. Generally this isn't a problem, but on the few occasions it is, this option allows a downstream builder to hard code the correct path for bash.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a bash script happens to use features of Bash 4.x then using /usr/bin/env bash is unreliable and will break on systems such as macOS where you must guarantee that the "correct, new enough* version of bash is utilized regardless of how the user configures $PATH.

# A Script that automates pasting to a number of pastebin services
# relying only on bash, sed, coreutils (mktemp/sort/tr/wc/whoami/tee) and wget
# Copyright (c) 2007-2016 Bo Ørsted Andresen <[email protected]>

VERSION="2.33"
VERSION="@WGETPASTE_VERSION@"

# don't inherit LANGUAGE from the env
unset LANGUAGE
Expand Down