aboutsummaryrefslogtreecommitdiff
path: root/.ai/scripts/tests/lint-org-cli.bats
blob: b9faef68023699a0cb77e6632f3a51718b66e1af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bats
# lint-org.el must load standalone via `emacs --batch -q -l <path>` with no
# -L flag — that's how wrap-it-up and the /lint-org command invoke it. The
# require of wrap-org-table broke that once: the dependency resolved under
# make test's -L .ai/scripts but not from a bare -l load.

setup() {
    SCRIPTS_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
    TMPFILE="$(mktemp --suffix=.org)"
    printf '* H\n\n| a |\n|---|\n| ok |\n|---|\n' > "$TMPFILE"
}

teardown() {
    rm -f "$TMPFILE"
}

@test "lint-org.el loads and runs without -L on the load path" {
    run emacs --batch -q -l "$SCRIPTS_DIR/lint-org.el" --check "$TMPFILE"
    [ "$status" -eq 0 ]
    [[ "$output" == *"lint-org: file="* ]]
}

@test "lint-org.el default invocation is report-only — file untouched" {
    # bare #+begin_src is a mechanical fix (→ #+begin_example) that the old
    # default applied on disk; a linter reports, it doesn't write
    printf '* H\n\n#+begin_src\nx\n#+end_src\n' > "$TMPFILE"
    before="$(cat "$TMPFILE")"
    run emacs --batch -q -l "$SCRIPTS_DIR/lint-org.el" "$TMPFILE"
    [ "$status" -eq 0 ]
    [[ "$output" == *"would-fix"* ]]
    [ "$(cat "$TMPFILE")" = "$before" ]
}

@test "lint-org.el --fix applies mechanical fixes on disk" {
    printf '* H\n\n#+begin_src\nx\n#+end_src\n' > "$TMPFILE"
    run emacs --batch -q -l "$SCRIPTS_DIR/lint-org.el" --fix "$TMPFILE"
    [ "$status" -eq 0 ]
    grep -q '#+begin_example' "$TMPFILE"
}

@test "wrap-org-table.el loads and runs without -L on the load path" {
    run emacs --batch -q -l "$SCRIPTS_DIR/wrap-org-table.el" --width=120 "$TMPFILE"
    [ "$status" -eq 0 ]
    [[ "$output" == *"reformatted"* ]]
}