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 identifies the compiler used to check these examples.
Before you start
Install or build the CLI using the installation guide. Put the directory containing the vex executable on your PATH. For example, in a POSIX shell, replace the path below with your real directory:
export PATH="/absolute/path/to/vex-directory:$PATH"
command -v vex
vex --versionIf 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:
vex new greetings
cd greetingsAll 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:
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 for the distinction.
Split the program into two files
Create src/score.vx:
export fn add_bonus(score: i32): i32 {
return score + 10;
}Replace src/lib.vx with:
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 covers other import and export forms.
Check and run the program:
vex lint src/lib.vx
vex run src/lib.vxThe program's stdout is:
42Lint 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:
import { add_bonus } from "../src/score.vx";
fn test_add_bonus(): bool {
return add_bonus(32) == 42;
}The resulting tree is:
greetings/
├── vex.json
├── src/
│ ├── lib.vx
│ └── score.vx
└── tests/
└── lib_test.vxRun the test directory, or select a file and a test name separately:
vex test tests/
vex test --run test_add_bonus tests/lib_test.vxBoth 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 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, Error handling, and Testing.