/ tests / test_emacs_mode_detection.sh
test_emacs_mode_detection.sh
 1  #!/usr/bin/env bash
 2  # -*- mode: sh; sh-shell: bash -*-
 3  # vim: set ft=bash:
 4  # shellcheck shell=bash
 5  
 6  ### Test Emacs mode detection for Bar.d modules and related files
 7  ### This test is informational only and always exits successfully.
 8  
 9  set -eu
10  
11  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12  REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
13  
14  echo "Testing Emacs mode detection (informational)..."
15  
16  # Test if emacs is available
17  if ! command -v emacs &>/dev/null; then
18      echo "WARNING: emacs not installed, skipping mode detection test"
19      exit 0
20  fi
21  
22  # Test each file
23  warnings=0
24  test_files=(
25      "Bar.d/help"
26      "Bar.d/cargo"
27      "Bar.d/git_lib"
28      "Barf"
29      "Barf.default"
30      "Pleasef.default"
31      "bar"
32  )
33  
34  for file in "${test_files[@]}"; do
35      test_file="$REPO_ROOT/$file"
36      
37      if [[ ! -f "$test_file" ]]; then
38          echo "WARNING: $file not found"
39          warnings=$((warnings + 1))
40          continue
41      fi
42      
43      # Use emacs to check mode detection via set-auto-mode
44      # Ignore errors since some emacs builds may lack sh-mode support
45      mode=$(emacs --batch \
46          --eval "(find-file \"$test_file\")" \
47          --eval '(message "MODE: %s" (symbol-name major-mode))' \
48          2>&1 | grep "^MODE:" | head -1 | sed 's/^MODE: //' || true)
49      
50      if [[ "$mode" == "sh-mode" ]]; then
51          echo "✓ $file detected as sh-mode"
52      elif [[ -z "$mode" ]]; then
53          echo "WARNING: Could not determine mode for $file"
54          warnings=$((warnings + 1))
55      else
56          echo "WARNING: $file detected as $mode (expected sh-mode)"
57          warnings=$((warnings + 1))
58      fi
59  done
60  
61  if [[ $warnings -gt 0 ]]; then
62      echo "WARNING: $warnings file(s) had issues with Emacs mode detection"
63  fi
64  
65  echo "Emacs mode detection test completed (exit status: success)"
66  exit 0