| name | add-tutorial |
| description | Scaffold a new tutorial example under fluca/tutorials/. Generates the source file, registers it in CMakeLists.txt, and verifies it builds and runs. |
Add Tutorial
Scaffold a new tutorial example following Fluca conventions.
Required Input
Ask the user for:
- Module — tutorial subdirectory (e.g.,
fd)
- Description — what the tutorial demonstrates
- Dependencies — which
fluca::* libraries to link
Steps
1. Determine next file number
ls fluca/tutorials/<module>/ex*.c
2. Generate source
#include <flucasys.h>
static const char help[] = "<Description>\n"
"Options:\n"
" -<opt> <type> : <desc>\n";
int main(int argc, char **argv)
{
PetscCall(FlucaInitialize(&argc, &argv, NULL, help));
PetscCall(FlucaFinalize());
}
Tutorials differ from tests:
- Use
/*TEST*/ blocks with run-only semantics (exit code 0 = pass, no golden output files)
- Parsed by
fluca_parse_tutorial_file() in FlucaTestUtils.cmake, which calls RunTutorial.cmake
- Typically longer, with comments explaining each step
- Use
SetFromOptions / ViewFromOptions for runtime configurability
- May use PETSc solvers (SNES, KSP) as part of the example
3. Add /*TEST*/ block
Append a /*TEST ... TEST*/ block at the end of the source file to register tutorial cases with ctest:
Each test: entry supports suffix (required), nsize (ignored), and args (optional). No output_file field — tutorials only check exit code.
4. Register in CMakeLists.txt
Add to TUTORIAL_SRCS in fluca/tutorials/<module>/CMakeLists.txt:
set(TUTORIAL_SRCS
ex1.c
...
ex<N>.c # <-- add here
)
The fluca_parse_tutorial_file() call in the foreach loop automatically picks up the new file.
For a new module, also:
- Create
fluca/tutorials/<module>/CMakeLists.txt following the pattern (include FlucaTestUtils and call fluca_parse_tutorial_file)
- Add
add_subdirectory(<module>) to fluca/tutorials/CMakeLists.txt
5. Build and verify
cmake build
cmake --build build
ctest --test-dir build -R "tutorials_<module>"
Checklist