# Your first project

Create a small project, move a function into a second source file, and test it.
This guide is part of the Vex 0.4.0 documentation. Check the version of the
compiler you actually run; the [evidence guide](verification-evidence.md)
identifies the compiler used to check these examples.

## Before you start

Install or build the CLI using the [installation guide](installation.md).
Put the **directory containing** the `vex` executable on your `PATH`. For
example, in a POSIX shell, replace the path below with your real directory:

```bash
export PATH="/absolute/path/to/vex-directory:$PATH"
command -v vex
vex --version
```

If `command -v` prints nothing, fix the path first. If the executable fails to
start because of a missing shared library, follow the installation guide's
troubleshooting section before continuing.

## Create the project

From a directory where `greetings` does not already exist:

```bash
vex new greetings
cd greetings
```

All remaining commands in this guide run **from inside `greetings/`**. The
scaffold creates `vex.json`, `src/lib.vx`, and `tests/lib_test.vx`.

## Try a mutation error

Temporarily replace `src/lib.vx` with this program:

```vex [try-immutable.vx]
fn main(): i32 {
    let score = 32;
    score = score + 10;
    return 0;
}
```

Run `vex lint src/lib.vx`. The compiler rejects the assignment because `let`
creates an immutable binding; its diagnostic suggests `let!` for a mutable
one. Changing the declaration to `let! score = 32;` permits reassignment. See
[Variables](basics/variables.md) for the distinction.

## Split the program into two files

Create `src/score.vx`:

```vex [src/score.vx]
export fn add_bonus(score: i32): i32 {
    return score + 10;
}
```

Replace `src/lib.vx` with:

```vex [src/lib.vx]
import { add_bonus } from "./score.vx";

fn main(): i32 {
    $println(add_bonus(32));
    return 0;
}
```

The relative import is resolved from the importing file. `export` makes
`add_bonus` available to another module. Without it, lint reports that the
requested symbol is not exported. The [modules guide](modules.md) covers
other import and export forms.

Check and run the program:

```bash
vex lint src/lib.vx
vex run src/lib.vx
```

The program's stdout is:

```text
42
```

Lint checks the program; `run` also builds, links and starts it. Native build
or runtime diagnostics can appear separately from stdout.

## Add a test

Replace the generated `tests/lib_test.vx` with:

```vex [tests/lib_test.vx]
import { add_bonus } from "../src/score.vx";

fn test_add_bonus(): bool {
    return add_bonus(32) == 42;
}
```

The resulting tree is:

```text
greetings/
├── vex.json
├── src/
│   ├── lib.vx
│   └── score.vx
└── tests/
    └── lib_test.vx
```

Run the test directory, or select a file and a test name separately:

```bash
vex test tests/
vex test --run test_add_bonus tests/lib_test.vx
```

Both commands should report one passing `test_add_bonus` test. A file path
selects where tests are discovered; `--run` filters test names within that
selection. If the name filter selects nothing, the current runner reports no
test functions and can exit successfully: inspect the reported test count,
not just the process exit code. See [Testing](tooling/testing.md) for
discovery, glob, and selection rules.

## What you have built

The manifest identifies the project, `score.vx` exposes a small reusable API,
`lib.vx` chooses how to present its result, and the test checks the API without
depending on console output. Keep that separation as the program grows:
business logic belongs in importable functions, while the entry point handles
arguments, output, and process exit status.

The example uses small `i32` values. A real score API should define its allowed
range and overflow behavior before accepting untrusted values. Add tests at
those boundaries and for each failure path; one successful arithmetic case
does not define the application's complete contract.

Continue with [Modules](modules.md), [Error handling](error-handling.md),
and [Testing](tooling/testing.md).
