Skip to content

wenngle/nixt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nixt

Nixt is a unit-testing tool for Nixlang.

Installation

  • Add this repository to nixpkgs.overlays
  • Add nixt to environment.systemPackages or home.packages

Help

Run Nixlang unit-tests

Usage:
  nixt [options] [path]

Arguments:
  [path]           Path of source and tests (default: .)

Options:
  -d, --debug                Print debug information
  -v, --verbose              Print extra information
  -l, --list                 List discovered test suites
  -h, --help                 Show this help

Getting Started

The nixt CLI discovers and runs tests located at path:

# nixt ~/fooproj/src

Found 3 test suites
> always passes (/home/ldlework/fooproj/src/tests/always-pass.nix)
-- ✔ always true
> always fails (/home/ldlework/fooproj/src/tests/always-pass.nix)
-- ✗ always false
> syntax error (/home/ldlework/fooproj/src/tests/syntax-error.nix)
-- ✗ missing semicolon

⚠ 1 test PASSED but 2 tests FAILED ⚠

Adding in the -v/--verbose flag will show additional information on failed test cases:

# nixt -v ~/fooproj/src

Found 3 test suites
> always passes (/home/ldlework/fooproj/src/tests/always-pass.nix)
-- ✔ always true
> always fails (/home/ldlework/fooproj/src/tests/always-pass.nix)
-- ✗ always false
> syntax error (/home/ldlework/fooproj/src/tests/syntax-error.nix)
-- ✗ missing semicolon
error: syntax error, unexpected $end, expecting ';', at /home/ldlework/src/fooproj/src/options1.nix:10:2
(use '--show-trace' to show detailed location information)
⚠ 1 test PASSED but 2 tests FAILED ⚠

Two -v -v verbose flags implies --show-trace.

Writing Tests

Nixt tests are written in .nix files that:

  • Contain a function taking attrset args pkgs and nixt
  • Evaluate to a call to nixt.mkSuite
{ pkgs ? import <nixpkgs> {}, nixt }:

nixt.mkSuite "always passes" {
  "always true" = true;
}

nixt.mkSuite

mkSuite takes two arguments:

  • suite name/description
  • attrset of test cases

Each test case maps from case name/description to result.

Test case results should be a boolean specifying whether the case passed or failed.

Test cases may also throw a string to provide additional information about a failure.

About

Simple unit-testing for Nix

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nim 73.2%
  • Nix 26.8%