Skip to content

Commit

Permalink
Merge branch 'tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Nov 16, 2023
2 parents 526ea37 + 709e48e commit be9d46f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 42 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- name: Checkout prepare script
uses: actions/checkout@v4
with:
fetch-depth: 1
sparse-checkout: prepare.sh
sparse-checkout-cone-mode: false

Expand All @@ -34,3 +35,31 @@ jobs:

- name: Check README.md
run: tools/is-clean --make --root=doc README.md

test:
needs: build
strategy:
matrix:
kind: [ "system", "user" ]
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Prepare build environment
run: ./prepare.sh -us | tee -a "$GITHUB_ENV"

- name: Install (${{ matrix.kind }})
run: |
if [ "${{ matrix.kind }}" = "user" ]; then
./install.sh -u
elif [ "${{ matrix.kind }}" = "system" ]; then
SUDO=sudo ./install.sh -s
else
exit 1
fi
- name: Run tests
run: ./tests.sh
56 changes: 33 additions & 23 deletions data/displayswitcheroo/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,48 @@ for n, o in pairs(setup.outputs) do

local c = o.crtc
local geom = c and string.format(" %dx%d+%d+%d", c.width, c.height, c.x, c.y) or ""
print(string.format("output %s:%s%s (%dmm x %dmm) (fpr 0x%x)", n, pri, geom, o.mmwidth, o.mmheight, o.fingerprint))

local str = string.format("output %s:%s%s", n, pri, geom)
if o.mmwidth and o.mmheight then
str = str .. string.format(" (%dmm x %dmm)", o.mmwidth, o.mmheight)
end
if o.fingerprint then
str = str .. string.format(" (fpr 0x%x)", o.fingerprint)
end
print(str)

local s, w, h
for _, m in ipairs(o.modes) do
local flags = ""
if m.interlace then
flags = flags .. "i"
end
if m.refresh_rate then
local flags = ""
if m.interlace then
flags = flags .. "i"
end

if m.double_scan then
flags = flags .. "d"
end
if m.double_scan then
flags = flags .. "d"
end

if o.modes:is_preferred(m) then
flags = flags .. "+"
end
if o.modes:is_preferred(m) then
flags = flags .. "+"
end

if c and m == c.mode then
flags = flags .. "*"
end
if c and m == c.mode then
flags = flags .. "*"
end

local t = string.format(" %.2f%s", m.refresh_rate, flags)
local t = string.format(" %.2f%s", m.refresh_rate, flags)

if w == m.width and h == m.height then
s = s .. t
else
if s then
print(s)
if w == m.width and h == m.height then
s = s .. t
else
if s then
print(s)
end
w = m.width
h = m.height
s = string.format(" %dx%d%s", w, h, t)
end
w = m.width
h = m.height
s = string.format(" %dx%d%s", w, h, t)
end
end
if s then
Expand Down
17 changes: 10 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ EOF
exit "${1-0}"
}

SUDO=${SUDO-}
DESTDIR=${DESTDIR-$HOME/.local}
DIR_MODE=0700
APP=${APP-displayswitcheroo}
while getopts "dusah-" OPT; do
case $OPT in
d) DESTDIR=$OPTARG ;;
u) DESTDIR=$HOME/.local ;;
s) DESTDIR=/usr ;;
u) DESTDIR=$HOME/.local; DIR_MODE=0700;;
s) DESTDIR=/usr; DIR_MODE=0755 ;;
a) APP=$OPTARG ;;
h) usage ;;
-) break ;;
Expand All @@ -34,9 +36,10 @@ shift $((OPTIND-1))

make -C "$SCRIPT_DIR" clean build EXTRA_CFLAGS="-DXDG_APP='\"$APP\"'"

mkdir -pm 0700 "$DESTDIR/bin"
install -v "$SCRIPT_DIR/src/cli.exe" "$DESTDIR/bin/$APP"

mkdir -pm 0700 "$DESTDIR/share/$APP"
install -v -D "$SCRIPT_DIR/data/displayswitcheroo/list.lua" "$DESTDIR/share/$APP/list.lua"
install -v -D "$SCRIPT_DIR/data/displayswitcheroo/displayswitcheroo.lua" "$DESTDIR/share/$APP/$APP.lua"
$SUDO mkdir -pm "$DIR_MODE" "$DESTDIR/bin"
$SUDO install -v "$SCRIPT_DIR/src/cli.exe" "$DESTDIR/bin/$APP"

$SUDO mkdir -pm "$DIR_MODE" "$DESTDIR/share/$APP"
$SUDO install -v -D "$SCRIPT_DIR/data/displayswitcheroo/list.lua" "$DESTDIR/share/$APP/list.lua"
$SUDO install -v -D "$SCRIPT_DIR/data/displayswitcheroo/displayswitcheroo.lua" "$DESTDIR/share/$APP/$APP.lua"
33 changes: 21 additions & 12 deletions prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ set -o nounset -o pipefail -o errexit
SUDO=${SUDO-}
DISTRO=${DISTRO-}
UPDATE=${UPDATE-}
while getopts "ud:sS:-" OPT; do
TESTS=${TESTS-}
while getopts "ud:sS:t-" OPT; do
case $OPT in
d) DISTRO=$OPTARG ;;
u) UPDATE=1 ;;
s) SUDO=sudo ;;
S) SUDO=$OPTARG ;;
t) TESTS=1 ;;
-) break ;;
?) usage 2 ;;
esac
done
shift $((OPTIND-1))

if [ -z "$DISTRO" ]; then
if command -v lsb_release; then
if command -v lsb_release >/dev/null; then
DISTRO=$(lsb_release -is)
elif command -v pacman >/dev/null; then
DISTRO="Arch"
Expand All @@ -36,21 +38,28 @@ if [ "$DISTRO" = "Arch" ] || command -v pacman >/dev/null; then
if [ -n "$UPDATE" ]; then
$SUDO pacman -Sy 1>&2
fi
$SUDO pacman -S --noconfirm 1>&2 \
git \
make gcc pkgconf \
python gawk \
lua libxrandr
PKGs=(git)
PKGs+=(make gcc pkgconf)
PKGs+=(python gawk)
PKGs+=(lua libxrandr)
if [ -n "$TESTS" ]; then
PKGs+=(xorg-server-xvfb)
fi
$SUDO pacman -S --noconfirm "${PKGs[@]}" 1>&2
elif [ "$DISTRO" = "Ubuntu" ] || command -v apt-get >/dev/null; then
if [ -n "$UPDATE" ]; then
$SUDO apt-get update 1>&2
fi
$SUDO apt-get install --yes 1>&2 \
PKGs=(git ca-certificates)
PKGs+=(make gcc pkg-config)
PKGs+=(python3 gawk)
PKGs+=(liblua5.4-dev libxrandr-dev)
if [ -n "$TESTS" ]; then
PKGs+=(xvfb)
fi
$SUDO apt-get install --yes \
--no-install-recommends --no-install-suggests \
git ca-certificates \
make gcc pkg-config \
python3 gawk \
liblua5.4-dev libxrandr-dev
1>&2 "${PKGs[@]}"
echo "LUA_PKG=lua54"
else
echo "unconfigured distribution: $DISTRO" 1>&2
Expand Down
5 changes: 5 additions & 0 deletions src/.k
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ cli() {
make LOG_LEVEL=DEBUG cli.exe && ./cli.exe "${1-list}"
}

xvfb() {
make LOG_LEVEL=DEBUG cli.exe && xvfb-run ./cli.exe "$K_DIR/../data/displayswitcheroo/list.lua"
}


watch() {
make LOG_LEVEL=DEBUG cli.exe && ./cli.exe -w go.lua
}
Expand Down
9 changes: 9 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -o nounset -o pipefail -o errexit

APP=${APP-displayswitcheroo}

which "$APP"

xvfb-run "$APP" list

0 comments on commit be9d46f

Please sign in to comment.