You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by rz...@apache.org on 2025/01/17 11:41:17 UTC
(opennlp) 01/01: x
This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch OPENNLP-1688
in repository https://gitbox.apache.org/repos/asf/opennlp.git
commit 8b5d7ec5a96b4f7084e13405bb3a99d6c98372c4
Author: Richard Zowalla <rz...@apache.org>
AuthorDate: Fri Jan 17 12:41:05 2025 +0100
x
---
.github/workflows/shell-tests.yml | 62 +++++++++++++++++++++++++++++
opennlp-distr/src/test/sh/test_opennlp.bats | 31 +++++++++++++++
2 files changed, 93 insertions(+)
diff --git a/.github/workflows/shell-tests.yml b/.github/workflows/shell-tests.yml
new file mode 100644
index 00000000..28662b31
--- /dev/null
+++ b/.github/workflows/shell-tests.yml
@@ -0,0 +1,62 @@
+name: Test Shell Script with Bats
+
+on:
+ push:
+# branches:
+# - main
+ pull_request:
+
+jobs:
+ test-unix-shell:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Install Bats (Testing Framework)
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y bats
+
+ - name: Set up JDK 17
+ uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: 17
+
+ - name: Build with Maven
+ run: mvn -V clean install --no-transfer-progress -Pci -DskipTests=true
+
+ - name: Find and Extract OpenNLP Distribution
+ run: |
+ # Find the first non-src .tar.gz file in the target directory
+ TAR_FILE=$(find opennlp-distr/target -maxdepth 1 -type f -name "*.tar.gz" ! -name "*-src*.tar.gz" | head -n 1)
+
+ # Ensure we found a file
+ if [ -z "$TAR_FILE" ]; then
+ echo "Error: No matching tar.gz file found in opennlp-distr/target"
+ exit 1
+ fi
+
+ # Extract the tar.gz file
+ tar -xzvf "$TAR_FILE" -C $HOME
+
+ # Get the directory name of the extracted content
+ EXTRACTED_DIR=$(tar -tf "$TAR_FILE" | head -n 1 | cut -f1 -d"/")
+
+ # Set OPENNLP_HOME dynamically
+ echo "OPENNLP_HOME=$HOME/$EXTRACTED_DIR" >> $GITHUB_ENV
+ echo "$HOME/$EXTRACTED_DIR/bin" >> $GITHUB_PATH
+
+ - name: Verify Extraction
+ run: |
+ echo "OPENNLP_HOME: $OPENNLP_HOME"
+ ls -l $OPENNLP_HOME/bin
+
+ - name: Run Bats Tests
+ run: |
+ bats ./opennlp-distr/src/test/sh
+ env:
+ JAVA_HOME: ${{ env.JAVA_HOME }}
+ OPENNLP_HOME: ${{ env.OPENNLP_HOME }}
diff --git a/opennlp-distr/src/test/sh/test_opennlp.bats b/opennlp-distr/src/test/sh/test_opennlp.bats
new file mode 100644
index 00000000..b181858d
--- /dev/null
+++ b/opennlp-distr/src/test/sh/test_opennlp.bats
@@ -0,0 +1,31 @@
+#!/usr/bin/env bats
+
+# Setup the environment before running the tests
+setup() {
+ PATH="$OPENNLP_HOME/bin:$PATH"
+}
+
+# Test to check if the binary is accessible
+@test "Binary 'opennlp' exists and is executable" {
+ run command -v opennlp
+ [ "$status" -eq 0 ]
+ [ -x "$output" ]
+}
+
+# Test to validate the output of the SimpleTokenizer
+@test "SimpleTokenizer produces correct output" {
+ input="Hello, friends"
+ expected_output="Hello , friends"
+
+ # Run the command and capture output
+ run echo "$input" | opennlp SimpleTokenizer
+
+ # Validate the output
+ [ "$status" -eq 0 ]
+ [ "${output}" = "$expected_output" ]
+}
+
+# Teardown the environment after running the tests
+teardown() {
+ unset OPENNLP_HOME
+}