# V7001 invalid_snapshot_name

URL: /docs/errors/V7001
Markdown: /docs/errors/V7001.md

> The literal name given to expect_snapshot cannot name a snapshot file (design §17.294 SS-13).

An error from the `verify` phase. `sakura explain V7001` prints this explanation offline.

The literal name given to `expect_snapshot` cannot name a snapshot file (design §17.294 SS-13).
A snapshot is stored at `tests/__snapshots__/<module>/<name>.snap`, so its name must be
letters, digits, `_`, `-` or `.`, and must not start with `.`. The test runner refuses such a
name when the test runs; a literal name is reported by `sakura check` before then. A computed
name is still checked only when the test runs.

Wrong:

```sakura
test "renders" { expect_snapshot("front page", 42) }
```

Fixed:

```sakura
test "renders" { expect_snapshot("front_page", 42) }
```

## Wrong program [#wrong-program]

[`compiler/tests/ui/V7001_invalid_snapshot_name.sak`](https://github.com/icantcodefyi/sakuralang/blob/main/compiler/tests/ui/V7001_invalid_snapshot_name.sak), which the compiler's ui suite runs through `sakura check`:

```sakura
// A literal snapshot name names a file under `tests/__snapshots__`, so the checker refuses one
// the test runner would refuse: a space, a leading `.` and the empty name. A computed name is
// checked when the test runs.
test "front page" {
  expect_snapshot("front_page", 1)
  expect_snapshot("front page", 1)
}

test "hidden" { expect_snapshot(".page", 2) }

test "unnamed" { expect_snapshot("", 3) }

test "computed" {
  let n = 4
  expect_snapshot("page-{n}.v2", n)
}
```

`sakura check --json` reports this record (pretty-printed; `$DIR` is the fixture's directory):

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:5caf2c170ea0a2a2",
  "code": "V7001",
  "severity": "error",
  "phase": "verify",
  "message": "snapshot name \"front page\" must be letters, digits, '_', '-' or '.'",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V7001_invalid_snapshot_name::test:front page",
  "spans": [
    {
      "uri": "file://$DIR/V7001_invalid_snapshot_name.sak",
      "content_hash": "sha256:5bc9a69edc411b871f2a01fe870a339c271f59b5cb959c4c1800c80f873a3d7d",
      "start_byte": 400,
      "end_byte": 412,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V7001",
  "fixes": []
}
```

## Fixed program [#fixed-program]

[`compiler/tests/ui/V7001_invalid_snapshot_name.fixed.sak`](https://github.com/icantcodefyi/sakuralang/blob/main/compiler/tests/ui/V7001_invalid_snapshot_name.fixed.sak), which `sakura check` accepts with no diagnostics:

```sakura
test "front page" {
  expect_snapshot("front_page", 1)
  expect_snapshot("front-page", 1)
}

test "hidden" { expect_snapshot("page", 2) }

test "unnamed" { expect_snapshot("unnamed.v1", 3) }

test "computed" {
  let n = 4
  expect_snapshot("page-{n}.v2", n)
}
```
