diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index cd73f2a..57233c5 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -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 tests + 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: Check YAML formatting. + run: earthly --ci +e2e-test diff --git a/Earthfile b/Earthfile index 8bb7d95..1733a77 100644 --- a/Earthfile +++ b/Earthfile @@ -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 diff --git a/end-to-end-tests/no-space-does-not-expand-abbreviation.py b/end-to-end-tests/no-space-does-not-expand-abbreviation.py new file mode 100644 index 0000000..ea587ac --- /dev/null +++ b/end-to-end-tests/no-space-does-not-expand-abbreviation.py @@ -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() diff --git a/end-to-end-tests/requirements.txt b/end-to-end-tests/requirements.txt new file mode 100644 index 0000000..0cb0017 --- /dev/null +++ b/end-to-end-tests/requirements.txt @@ -0,0 +1,2 @@ +pexpect==4.9.0 +ptyprocess==0.7.0 diff --git a/end-to-end-tests/setting-abbreviation.py b/end-to-end-tests/setting-abbreviation.py new file mode 100644 index 0000000..99ededb --- /dev/null +++ b/end-to-end-tests/setting-abbreviation.py @@ -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() diff --git a/end-to-end-tests/unsetting-abbreviation.py b/end-to-end-tests/unsetting-abbreviation.py new file mode 100644 index 0000000..67a462d --- /dev/null +++ b/end-to-end-tests/unsetting-abbreviation.py @@ -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()