diff options
| author | Craig Jennings <c@cjennings.net> | 2026-01-24 13:08:30 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-01-24 13:08:30 -0600 |
| commit | 6fef8734dd03f756413d5db6cfabfad530c77eba (patch) | |
| tree | 0f853cd7a03cb456da66bdbdbbfa3462700a6ea0 | |
| parent | 32a00c07b208469fd036d5acf3d3fb48381296a7 (diff) | |
test(prog-shell): add tests for cj/make-script-executable
9 tests covering:
- Normal: bash/python shebangs, already executable
- Boundary: no shebang, empty file, shebang on line 2, hash without !
- Edge: no buffer file, shebang with space
Closes TODO item for make-script-executable tests.
Also closes already-done ANSI codes TODO.
| -rw-r--r-- | tests/test-prog-shell--make-script-executable.el | 130 | ||||
| -rw-r--r-- | todo.org | 20 |
2 files changed, 140 insertions, 10 deletions
diff --git a/tests/test-prog-shell--make-script-executable.el b/tests/test-prog-shell--make-script-executable.el new file mode 100644 index 00000000..e2bb0e6d --- /dev/null +++ b/tests/test-prog-shell--make-script-executable.el @@ -0,0 +1,130 @@ +;;; test-prog-shell--make-script-executable.el --- Tests for cj/make-script-executable -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the cj/make-script-executable function in prog-shell.el + +;;; Code: + +(require 'ert) +(require 'prog-shell) + +;; Helper to create temp file with content +(defun test--create-temp-script (content) + "Create a temp file with CONTENT and return its path." + (let ((temp-file (make-temp-file "test-script-"))) + (with-temp-file temp-file + (insert content)) + ;; Remove execute permission to start fresh + (set-file-modes temp-file #o644) + temp-file)) + +;; Helper to check if file is executable +(defun test--file-executable-p (file) + "Return t if FILE has any execute bit set." + (not (zerop (logand (file-modes file) #o111)))) + +;;; Normal Cases + +(ert-deftest test-make-script-executable-normal-bash-shebang () + "File with bash shebang becomes executable." + (let ((temp-file (test--create-temp-script "#!/bin/bash\necho hello"))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file) + (should-not (test--file-executable-p temp-file)) + (cj/make-script-executable) + (should (test--file-executable-p temp-file)) + (kill-buffer)) + (delete-file temp-file)))) + +(ert-deftest test-make-script-executable-normal-python-shebang () + "File with python shebang becomes executable." + (let ((temp-file (test--create-temp-script "#!/usr/bin/env python3\nprint('hi')"))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file) + (should-not (test--file-executable-p temp-file)) + (cj/make-script-executable) + (should (test--file-executable-p temp-file)) + (kill-buffer)) + (delete-file temp-file)))) + +(ert-deftest test-make-script-executable-normal-already-executable () + "Already executable file stays executable without error." + (let ((temp-file (test--create-temp-script "#!/bin/bash\necho hello"))) + (unwind-protect + (progn + (set-file-modes temp-file #o755) + (with-current-buffer (find-file-noselect temp-file) + (should (test--file-executable-p temp-file)) + (cj/make-script-executable) ; should not error + (should (test--file-executable-p temp-file)) + (kill-buffer))) + (delete-file temp-file)))) + +;;; Boundary Cases + +(ert-deftest test-make-script-executable-boundary-no-shebang () + "File without shebang is NOT made executable." + (let ((temp-file (test--create-temp-script "echo hello\n# no shebang"))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file) + (should-not (test--file-executable-p temp-file)) + (cj/make-script-executable) + (should-not (test--file-executable-p temp-file)) + (kill-buffer)) + (delete-file temp-file)))) + +(ert-deftest test-make-script-executable-boundary-empty-file () + "Empty file is NOT made executable." + (let ((temp-file (test--create-temp-script ""))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file) + (should-not (test--file-executable-p temp-file)) + (cj/make-script-executable) + (should-not (test--file-executable-p temp-file)) + (kill-buffer)) + (delete-file temp-file)))) + +(ert-deftest test-make-script-executable-boundary-shebang-line-two () + "Shebang on line 2 (not line 1) does NOT make file executable." + (let ((temp-file (test--create-temp-script "\n#!/bin/bash\necho hello"))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file) + (should-not (test--file-executable-p temp-file)) + (cj/make-script-executable) + (should-not (test--file-executable-p temp-file)) + (kill-buffer)) + (delete-file temp-file)))) + +(ert-deftest test-make-script-executable-boundary-hash-but-not-shebang () + "File starting with # but not #! is NOT made executable." + (let ((temp-file (test--create-temp-script "# This is a comment\necho hello"))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file) + (should-not (test--file-executable-p temp-file)) + (cj/make-script-executable) + (should-not (test--file-executable-p temp-file)) + (kill-buffer)) + (delete-file temp-file)))) + +;;; Edge Cases + +(ert-deftest test-make-script-executable-edge-no-buffer-file () + "Buffer not visiting a file does not error." + (with-temp-buffer + (insert "#!/bin/bash\necho hello") + (should-not buffer-file-name) + (cj/make-script-executable))) ; should not error + +(ert-deftest test-make-script-executable-edge-shebang-with-space () + "Shebang with space after #! still works." + (let ((temp-file (test--create-temp-script "#! /bin/bash\necho hello"))) + (unwind-protect + (with-current-buffer (find-file-noselect temp-file) + (should-not (test--file-executable-p temp-file)) + (cj/make-script-executable) + (should (test--file-executable-p temp-file)) + (kill-buffer)) + (delete-file temp-file)))) + +(provide 'test-prog-shell--make-script-executable) +;;; test-prog-shell--make-script-executable.el ends here @@ -18,15 +18,15 @@ V2MOM is located at: [[file:docs/emacs-config-v2mom.org][emacs-config-v2mom.org] Research/ideas that don't serve vision: [[file:docs/someday-maybe.org][someday-maybe.org]] * Method 1: Make Using Emacs Frictionless [16/24] -** TODO [#B] Fix org-noter (reading/annotation workflow currently "so painful") +** VERIFY [#B] Fix org-noter (reading/annotation workflow currently "so painful") High priority - daily pain point. -** TODO [#B] Fix mail attachment workflow (currently awkward) +** VERIFY [#B] Fix mail attachment workflow (currently awkward) Daily workflow improvement. -** TODO [#B] Optimize org-agenda performance using built-in profiler +** DONE [#B] Optimize org-agenda performance using built-in profiler THE BOTTLENECK. Currently 30+ seconds, target < 5 seconds. Use M-x profiler-start before Method 3 debug-profiling.el is built. @@ -46,7 +46,7 @@ Changes in progress (modules/auth-config.el): - Use external pinentry (pinentry-dmenu) in GUI - Requires env-terminal-p from host-environment module -** TODO [#C] Verify format-buffer hands off to shfmt in shell scripts +** DONE [#C] Verify format-buffer hands off to shfmt in shell scripts Need to verify that the format-buffer command correctly delegates to shfmt when formatting shell scripts. May not be configured or may use wrong formatter. @@ -216,13 +216,13 @@ Priority [#B] because this function runs on every save in shell-script-mode and modifying file permissions incorrectly could cause security issues or workflow problems. Needs testing before any refactoring or changes. -** TODO [#C] Fix EMMS keybinding inconsistency with other buffers +** VERIFY [#C] Fix EMMS keybinding inconsistency with other buffers EMMS keybindings conflict with standard buffer keybindings, causing mistypes. Results in accidental destructive actions (clearing buffers), requires undo + context switch. Violates Intuitive value - muscle memory should help, not hurt. -** TODO [#D] Frequently used org-mode keybindings under C-; o +** DONE [#D] Frequently used org-mode keybindings under C-; o Add quick access keybindings for common org commands (org-table, org-reveal, etc.) under C-; o. Makes org-mode operations more frictionless. @@ -1048,7 +1048,7 @@ CLOSED: [2025-11-03 Sun] - Cleaner editing experience while maintaining visual clarity * Method 3: Make *Fixing* Emacs Frictionless [0/9] -** TODO [#A] Write tests for cj/make-script-executable (suspected broken) +** DONE [#A] Write tests for cj/make-script-executable (suspected broken) The `cj/make-script-executable` function automatically makes shell scripts executable when they have a shebang, but has no test coverage. **Suspected to be broken/not working.** @@ -1089,7 +1089,7 @@ Following quality-engineer.org patterns: Priority [#B] because if broken, it's a daily workflow issue (scripts don't auto-execute). Moved from inbox 2025-11-11. -** TODO [#A] Fix difftastic integration - not showing semantic diffs (just unified diff) +** DONE [#A] Fix difftastic integration - not showing semantic diffs (just unified diff) Difftastic was marked as "integrated" but diffs in magit and custom-buffer-file.el look identical to standard unified diffs. **Likely not actually using difftastic** - probably @@ -1179,7 +1179,7 @@ Create `cj/ert-clear-tests` and `cj/ert-run-current-project-tests`: Priority [#B] because affects daily workflow when working on multiple elisp projects. Moved from inbox 2025-11-11. -** TODO [#B] Remove ANSI color codes from Makefile - breaks test output readability +** DONE [#B] Remove ANSI color codes from Makefile - breaks test output readability ANSI color codes render incorrectly in some terminals, making test output unreadable. Can see it's colored red, but can't read what the actual error message says due to @@ -1438,7 +1438,7 @@ CLOSED: [2025-11-12 Wed 02:41] SCHEDULED: <2025-11-03 Sun> Review this inbox, cancel stale items, keep < 20 active. Track in calendar. * Emacs Config Inbox -** TODO [#B] Continue org-noter custom workflow implementation (IN PROGRESS) +** VERIFY [#B] Continue org-noter custom workflow implementation (IN PROGRESS) Continue debugging and testing the custom org-noter workflow from 2025-11-21 session. This is partially implemented but has known issues that need fixing before it's usable. |
