1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#![allow(clippy::doc_overindented_list_items)]
use super::build::{trace_filter_parser, trace_level_parser};
use aiken_lang::{
ast::{TraceLevel, Tracing},
test_framework::PropertyTest,
};
use aiken_project::{
telemetry::{CoverageMode, json_schema},
watch::{self, watch_project, with_project},
};
use rand::prelude::*;
use std::{path::PathBuf, process};
#[derive(clap::Args)]
#[clap(disable_version_flag(true))]
#[command(
alias = "test",
verbatim_doc_comment,
about = color_print::cstr!(r#"
Type-check an Aiken project and run any tests found.
Test results are printed as stylized outputs when `stdout` is a TTY-capable terminal. If it
isn't, (e.g. because you are redirecting the output to a file), test results are printed as
a JSON structured object. Use `--show-json-schema` to see the whole schema.
"#),
after_long_help = color_print::cstr!(r#"You are seeing the extended help. Use `-h` instead of `--help` for a more compact view.
"#
))]
pub struct Args {
/// Path to project
directory: Option<PathBuf>,
/// Deny warnings; warnings will be treated as errors
#[clap(short = 'D', long)]
deny: bool,
/// Silence warnings; warnings will not be printed
#[clap(short = 'S', long)]
silent: bool,
/// Skip tests; run only the type-checker
#[clap(short, long)]
skip_tests: bool,
/// When enabled, also pretty-print test UPLC on failure
#[clap(long)]
debug: bool,
/// When enabled, print-out the JSON-schema of the command output when the target isn't an
/// ANSI-capable terminal
#[clap(long, required = false)]
show_json_schema: bool,
/// When enabled, re-run the command on file changes instead of exiting
#[clap(long)]
watch: bool,
/// An initial seed to initialize the pseudo-random generator for property-tests.
#[clap(long, value_name = "UINT")]
seed: Option<u32>,
/// Maximum number of successful test run for considering a property-based test valid.
#[clap(long, default_value_t = PropertyTest::DEFAULT_MAX_SUCCESS, value_name="UINT")]
max_success: usize,
/// Display options for the property tests labels coverage.
///
/// - relative-to-labels:
/// Ratio of each label over the total number of labels.
/// Better when labels are mutually-exclusive and present in each test.
///
/// - relative-to-tests:
/// Ratio of each label over the total number of tests/iterations.
/// Better when labels are occasional and non-exclusive per test.
#[clap(
long,
short = 'P',
default_value_t = CoverageMode::default(),
value_parser = CoverageMode::parse,
value_name="COVERAGE_MODE",
verbatim_doc_comment
)]
property_coverage: CoverageMode,
/// Only run tests if they match any of these strings.
/// You can match a module with `-m aiken/list` or `-m list`.
/// You can match a test with `-m "aiken/list.{map}"` or `-m "aiken/option.{flatten_1}"`
#[clap(short, long, verbatim_doc_comment)]
match_tests: Option<Vec<String>>,
/// This is meant to be used with `--match-tests`.
/// It forces test names to match exactly
#[clap(short, long)]
exact_match: bool,
/// Environment to build against.
#[clap(long)]
env: Option<String>,
/// Filter traces to be included in the generated program(s).
///
/// - user-defined:
/// only consider traces that you've explicitly defined
/// either through the 'trace' keyword of via the trace-if-false
/// ('?') operator.
///
/// - compiler-generated:
/// only included internal traces generated by the
/// Aiken compiler, for example in usage of 'expect'.
///
/// - all:
/// include both user-defined and compiler-generated traces.
///
/// [default: all]
#[clap(short = 'f', long, value_parser=trace_filter_parser(), default_missing_value="all", verbatim_doc_comment, alias="filter_traces")]
trace_filter: Option<fn(TraceLevel) -> Tracing>,
/// Choose the verbosity level of traces:
///
/// - silent: disable traces altogether
/// - compact: only culprit line numbers are shown on failures
/// - verbose: enable full verbose traces as provided by the user or the compiler
///
/// [optional]
#[clap(short, long, value_parser=trace_level_parser(), default_value_t=TraceLevel::Verbose, verbatim_doc_comment)]
trace_level: TraceLevel,
/// When enabled, print execution units as plain numbers
#[clap(long)]
plain_numbers: bool,
}
pub fn exec(
Args {
directory,
deny,
silent,
skip_tests,
debug,
show_json_schema,
match_tests,
property_coverage,
exact_match,
watch,
trace_filter,
trace_level,
seed,
max_success,
env,
plain_numbers,
}: Args,
) -> miette::Result<()> {
if show_json_schema {
println!("{}", serde_json::to_string_pretty(&json_schema()).unwrap());
std::process::exit(0);
}
let mut rng = rand::rng();
let seed = seed.unwrap_or_else(|| rng.random());
let result = if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.check(
skip_tests,
match_tests.clone(),
debug,
exact_match,
seed,
max_success,
property_coverage,
match trace_filter {
Some(trace_filter) => trace_filter(trace_level),
None => Tracing::All(trace_level),
},
plain_numbers,
env.clone(),
)
})
} else {
with_project(directory.as_deref(), deny, silent, true, |p| {
p.check(
skip_tests,
match_tests.clone(),
debug,
exact_match,
seed,
max_success,
property_coverage,
match trace_filter {
Some(trace_filter) => trace_filter(trace_level),
None => Tracing::All(trace_level),
},
plain_numbers,
env.clone(),
)
})
};
result.map_err(|_| process::exit(1))
}