Skip to content

Commit

Permalink
test: adding end to end tests (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperC286 committed Feb 7, 2024
1 parent b336542 commit 9326ef1
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ jobs:
uses: actions/checkout@v3
- name: Check YAML formatting.
run: earthly --ci +check-yaml-formatting
e2e-test:
name: End to End Test
runs-on: ubuntu-latest
steps:
- name: Download Earthly v0.8.1.
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.1/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Checkout code.
uses: actions/checkout@v3
- name: End to end test.
run: earthly --ci +e2e-test
37 changes: 37 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,40 @@ check-github-actions-workflows-linting:
RUN go install github.com/rhysd/actionlint/cmd/actionlint@v1.6.26
DO +COPY_CI_DATA
RUN ./ci/check-github-actions-workflows-linting.sh


COPY_SOURCECODE:
COMMAND
COPY "./zsh-simple-abbreviations.zsh" "./zsh-simple-abbreviations.zsh"
COPY "./src" "./src"
COPY "./end-to-end-tests" "./end-to-end-tests"


e2e-test:
BUILD +setting-abbreviation-e2e-test
BUILD +unsetting-abbreviation-e2e-test
BUILD +no-space-does-not-expand-abbreviation-e2e-test


e2e-test-base:
FROM python:3.9.18
DO +COPY_SOURCECODE
# https://askubuntu.com/questions/462690/what-does-apt-get-fix-missing-do-and-when-is-it-useful
RUN apt-get update --fix-missing
RUN apt-get install zsh -y
RUN pip3 install -r end-to-end-tests/requirements.txt


setting-abbreviation-e2e-test:
FROM +e2e-test-base
RUN python3 end-to-end-tests/setting-abbreviation.py


unsetting-abbreviation-e2e-test:
FROM +e2e-test-base
RUN python3 end-to-end-tests/unsetting-abbreviation.py


no-space-does-not-expand-abbreviation-e2e-test:
FROM +e2e-test-base
RUN python3 end-to-end-tests/no-space-does-not-expand-abbreviation.py
31 changes: 31 additions & 0 deletions end-to-end-tests/no-space-does-not-expand-abbreviation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pexpect
import os


full_path = os.path.realpath(__file__)
test_directory = os.path.dirname(full_path)

zsh = pexpect.spawnu('/usr/bin/env zsh --no-rcs',
env=os.environ | {'PROMPT': '>'})

# Ready to take a command.
zsh.expect('>')
# Source the plugin and add an abbreviation.
zsh.sendline(
f"source \"{test_directory}/../zsh-simple-abbreviations.zsh\" && zsh-simple-abbreviations --set H 'hello'")

# Ready to take a command.
zsh.expect('>')
before = zsh.after
# Use the abbreviation.
zsh.sendline("echo H")

# Ready to take a command.
zsh.expect('>')
output = (before + zsh.before)

# Assert the abbreviation was expanded to 'hello'.
assert "hello" not in output

# Done with test close Zsh.
zsh.close()
2 changes: 2 additions & 0 deletions end-to-end-tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pexpect==4.9.0
ptyprocess==0.7.0
31 changes: 31 additions & 0 deletions end-to-end-tests/setting-abbreviation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pexpect
import os


full_path = os.path.realpath(__file__)
test_directory = os.path.dirname(full_path)

zsh = pexpect.spawnu('/usr/bin/env zsh --no-rcs',
env=os.environ | {'PROMPT': '>'})

# Ready to take a command.
zsh.expect('>')
# Source the plugin and add an abbreviation.
zsh.sendline(
f"source \"{test_directory}/../zsh-simple-abbreviations.zsh\" && zsh-simple-abbreviations --set H 'hello'")

# Ready to take a command.
zsh.expect('>')
before = zsh.after
# Use the abbreviation.
zsh.sendline("echo H ")

# Ready to take a command.
zsh.expect('>')
output = (before + zsh.before)

# Assert the abbreviation was expanded to 'hello'.
assert "hello" in output

# Done with test close Zsh.
zsh.close()
44 changes: 44 additions & 0 deletions end-to-end-tests/unsetting-abbreviation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pexpect
import os


full_path = os.path.realpath(__file__)
test_directory = os.path.dirname(full_path)

zsh = pexpect.spawnu('/usr/bin/env zsh --no-rcs',
env=os.environ | {'PROMPT': '>'})

# Ready to take a command.
zsh.expect('>')
# Source the plugin and set an abbreviation.
zsh.sendline(
f"source \"{test_directory}/../zsh-simple-abbreviations.zsh\" && zsh-simple-abbreviations --set H 'hello'")

# Ready to take a command.
zsh.expect('>')
before = zsh.after
# Use the abbreviation.
zsh.sendline("echo H ")

# Ready to take a command.
zsh.expect('>')
output = (before + zsh.before)
# Assert the abbreviation was expanded to 'hello'.
assert "hello" in output
# Unset the abbreviation.
zsh.sendline("zsh-simple-abbreviations --unset H")

# Ready to take a command.
zsh.expect('>')
before = zsh.after
# Use the abbreviation.
zsh.sendline("echo H ")

# Ready to take a command.
zsh.expect('>')
output = (before + zsh.before)
# Assert abbreviation was unset.
assert "hello" not in output

# Done with test close Zsh.
zsh.close()

0 comments on commit 9326ef1

Please sign in to comment.