mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Build vttest, improve runner
This commit is contained in:
@ -1,3 +1,20 @@
|
|||||||
|
#--------------------------------------------------------------------
|
||||||
|
# vttest
|
||||||
|
#--------------------------------------------------------------------
|
||||||
|
FROM alpine:3.16 AS vttest
|
||||||
|
|
||||||
|
RUN apk add --no-cache build-base curl
|
||||||
|
|
||||||
|
RUN curl -o vttest.tar.gz https://invisible-island.net/archives/vttest/vttest-20220215.tgz && \
|
||||||
|
tar xvzf vttest.tar.gz && \
|
||||||
|
cd vttest-20220215 && \
|
||||||
|
./configure && \
|
||||||
|
make && \
|
||||||
|
cp ./vttest /
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------
|
||||||
|
# main runner
|
||||||
|
#--------------------------------------------------------------------
|
||||||
FROM alpine:3.16
|
FROM alpine:3.16
|
||||||
|
|
||||||
# Base packages. A good set of this is just to get X (xvfb) and OpenGL
|
# Base packages. A good set of this is just to get X (xvfb) and OpenGL
|
||||||
@ -6,6 +23,8 @@ RUN apk add --no-cache \
|
|||||||
bash \
|
bash \
|
||||||
grep \
|
grep \
|
||||||
procps \
|
procps \
|
||||||
|
font-inconsolata-nerd \
|
||||||
|
i3wm \
|
||||||
imagemagick \
|
imagemagick \
|
||||||
libxrandr \
|
libxrandr \
|
||||||
mesa-dev \
|
mesa-dev \
|
||||||
@ -19,7 +38,8 @@ RUN apk add --no-cache \
|
|||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
alacritty
|
alacritty
|
||||||
|
|
||||||
COPY ./run.sh /run.sh
|
COPY --from=vttest /vttest /usr/bin/vttest
|
||||||
COPY ./colors.sh /colors.sh
|
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/bash"]
|
COPY ./run.sh /entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
6
test/cases/vttest/1_1.sh
Executable file
6
test/cases/vttest/1_1.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function test_do {
|
||||||
|
xdotool type "vttest"
|
||||||
|
xdotool key Return
|
||||||
|
}
|
@ -1,96 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Tom Hale, 2016. MIT Licence.
|
|
||||||
# Print out 256 colours, with each number printed in its corresponding colour
|
|
||||||
# See http://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal/821163#821163
|
|
||||||
|
|
||||||
set -eu # Fail on errors or undeclared variables
|
|
||||||
|
|
||||||
printable_colours=256
|
|
||||||
|
|
||||||
# Return a colour that contrasts with the given colour
|
|
||||||
# Bash only does integer division, so keep it integral
|
|
||||||
function contrast_colour {
|
|
||||||
local r g b luminance
|
|
||||||
colour="$1"
|
|
||||||
|
|
||||||
if (( colour < 16 )); then # Initial 16 ANSI colours
|
|
||||||
(( colour == 0 )) && printf "15" || printf "0"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Greyscale # rgb_R = rgb_G = rgb_B = (number - 232) * 10 + 8
|
|
||||||
if (( colour > 231 )); then # Greyscale ramp
|
|
||||||
(( colour < 244 )) && printf "15" || printf "0"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# All other colours:
|
|
||||||
# 6x6x6 colour cube = 16 + 36*R + 6*G + B # Where RGB are [0..5]
|
|
||||||
# See http://stackoverflow.com/a/27165165/5353461
|
|
||||||
|
|
||||||
# r=$(( (colour-16) / 36 ))
|
|
||||||
g=$(( ((colour-16) % 36) / 6 ))
|
|
||||||
# b=$(( (colour-16) % 6 ))
|
|
||||||
|
|
||||||
# If luminance is bright, print number in black, white otherwise.
|
|
||||||
# Green contributes 587/1000 to human perceived luminance - ITU R-REC-BT.601
|
|
||||||
(( g > 2)) && printf "0" || printf "15"
|
|
||||||
return
|
|
||||||
|
|
||||||
# Uncomment the below for more precise luminance calculations
|
|
||||||
|
|
||||||
# # Calculate percieved brightness
|
|
||||||
# # See https://www.w3.org/TR/AERT#color-contrast
|
|
||||||
# # and http://www.itu.int/rec/R-REC-BT.601
|
|
||||||
# # Luminance is in range 0..5000 as each value is 0..5
|
|
||||||
# luminance=$(( (r * 299) + (g * 587) + (b * 114) ))
|
|
||||||
# (( $luminance > 2500 )) && printf "0" || printf "15"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Print a coloured block with the number of that colour
|
|
||||||
function print_colour {
|
|
||||||
local colour="$1" contrast
|
|
||||||
contrast=$(contrast_colour "$1")
|
|
||||||
printf "\e[48;5;%sm" "$colour" # Start block of colour
|
|
||||||
printf "\e[38;5;%sm%3d" "$contrast" "$colour" # In contrast, print number
|
|
||||||
printf "\e[0m " # Reset colour
|
|
||||||
}
|
|
||||||
|
|
||||||
# Starting at $1, print a run of $2 colours
|
|
||||||
function print_run {
|
|
||||||
local i
|
|
||||||
for (( i = "$1"; i < "$1" + "$2" && i < printable_colours; i++ )) do
|
|
||||||
print_colour "$i"
|
|
||||||
done
|
|
||||||
printf " "
|
|
||||||
}
|
|
||||||
|
|
||||||
# Print blocks of colours
|
|
||||||
function print_blocks {
|
|
||||||
local start="$1" i
|
|
||||||
local end="$2" # inclusive
|
|
||||||
local block_cols="$3"
|
|
||||||
local block_rows="$4"
|
|
||||||
local blocks_per_line="$5"
|
|
||||||
local block_length=$((block_cols * block_rows))
|
|
||||||
|
|
||||||
# Print sets of blocks
|
|
||||||
for (( i = start; i <= end; i += (blocks_per_line-1) * block_length )) do
|
|
||||||
printf "\n" # Space before each set of blocks
|
|
||||||
# For each block row
|
|
||||||
for (( row = 0; row < block_rows; row++ )) do
|
|
||||||
# Print block columns for all blocks on the line
|
|
||||||
for (( block = 0; block < blocks_per_line; block++ )) do
|
|
||||||
print_run $(( i + (block * block_length) )) "$block_cols"
|
|
||||||
done
|
|
||||||
(( i += block_cols )) # Prepare to print the next row
|
|
||||||
printf "\n"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
print_run 0 16 # The first 16 colours are spread over the whole spectrum
|
|
||||||
printf "\n"
|
|
||||||
print_blocks 16 231 6 6 3 # 6x6x6 colour cube between 16 and 231 inclusive
|
|
||||||
print_blocks 232 255 12 2 1 # Not 50, but 24 Shades of Grey
|
|
81
test/run.sh
81
test/run.sh
@ -1,7 +1,52 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# This script runs a given test case and captures a screenshot. This script
|
||||||
|
# expects to run in the Docker image so it just captures the full screen rather
|
||||||
|
# than a specific window.
|
||||||
|
#
|
||||||
|
# This outputs the captured image to the `--output` value. This will not
|
||||||
|
# compare the captured output. This is only used to capture the output of
|
||||||
|
# a test case.
|
||||||
|
|
||||||
# The child program to execute
|
#--------------------------------------------------------------------
|
||||||
CHILD="alacritty"
|
# Helpers
|
||||||
|
|
||||||
|
function has_func() {
|
||||||
|
declare -f -F $1 > /dev/null
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
#--------------------------------------------------------------------
|
||||||
|
# Flag parsing
|
||||||
|
|
||||||
|
while [[ "$#" -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-e|--exec) ARG_EXEC="$2"; shift ;;
|
||||||
|
-c|--case) ARG_CASE="$2"; shift ;;
|
||||||
|
-o|--output) ARG_OUT="$2"; shift ;;
|
||||||
|
*) echo "Unknown parameter passed: $1"; exit 1 ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
bad=0
|
||||||
|
if [ -z "$ARG_EXEC" ]; then bad=1; fi
|
||||||
|
if [ -z "$ARG_CASE" ]; then bad=1; fi
|
||||||
|
if [ -z "$ARG_OUT" ]; then bad=1; fi
|
||||||
|
if [ $bad -ne 0 ]; then
|
||||||
|
echo "Usage: run.sh --exec <terminal> --case <path to case> --output <path to png>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Load our test case
|
||||||
|
source ${ARG_CASE}
|
||||||
|
if ! has_func "test_do"; then
|
||||||
|
echo "Test case is invalid."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Term: ${ARG_EXEC}"
|
||||||
|
echo "Case: ${ARG_CASE}"
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
# Some terminals require XDG be properly setup. We create a new
|
# Some terminals require XDG be properly setup. We create a new
|
||||||
@ -11,20 +56,34 @@ export XDG_RUNTIME_DIR="${XDG_BASE_DIR}/runtime"
|
|||||||
mkdir -p ${XDG_BASE_DIR} ${XDG_RUNTIME_DIR}
|
mkdir -p ${XDG_BASE_DIR} ${XDG_RUNTIME_DIR}
|
||||||
chmod 0700 $XDG_RUNTIME_DIR
|
chmod 0700 $XDG_RUNTIME_DIR
|
||||||
|
|
||||||
|
# Configure i3
|
||||||
|
cat <<EOF >${XDG_BASE_DIR}/i3.cfg
|
||||||
|
exec ${ARG_EXEC}
|
||||||
|
EOF
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
|
|
||||||
# Start up the program under test
|
# Start up the program under test by launching i3. We use i3 so we can
|
||||||
CHILD_LOG="${XDG_BASE_DIR}/child.log"
|
# more carefully control the window settings, test resizing, etc.
|
||||||
${CHILD} -o "window.start_maximized=true" >${CHILD_LOG} 2>&1 &
|
WM_LOG="${XDG_BASE_DIR}/wm.log"
|
||||||
CHILD_PID=$!
|
i3 -c ${XDG_BASE_DIR}/i3.cfg >${WM_LOG} 2>&1 &
|
||||||
echo "Child pid: ${CHILD_PID}"
|
|
||||||
echo "Child log: ${CHILD_LOG}"
|
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Started window manager..."
|
||||||
|
|
||||||
|
# Wait for startup
|
||||||
|
# TODO: we can probably use xdotool or wmctrl or something to detect if any
|
||||||
|
# windows actually launched and make error handling here better.
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
xdotool type "/colors.sh"
|
# Run our test case (should be defined in test case file)
|
||||||
xdotool key Return
|
echo "Executing test case..."
|
||||||
|
test_do
|
||||||
|
|
||||||
|
# Sleep a second to let it render
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
import -window root /src/screen.jpeg
|
echo "Capturing screen shot..."
|
||||||
|
import -window root ${ARG_OUT}
|
||||||
|
|
||||||
|
echo "Done"
|
||||||
|
Reference in New Issue
Block a user