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
use crate::{
cli::*,
cli_types::*,
errors::{CLIError, TestError::ProgramFileDoesNotExist},
};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
inputs::*,
outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME},
root::Manifest,
source::{LibraryFile, MainFile, LIBRARY_FILENAME, MAIN_FILENAME, SOURCE_DIRECTORY_NAME},
};
use snarkvm_curves::edwards_bls12::Fq;
use clap::ArgMatches;
use std::{convert::TryFrom, env::current_dir, time::Instant};
#[derive(Debug)]
pub struct TestCommand;
impl CLI for TestCommand {
type Options = ();
type Output = ();
const ABOUT: AboutType = "Compile and run all tests in the current package";
const ARGUMENTS: &'static [ArgumentType] = &[];
const FLAGS: &'static [FlagType] = &[];
const NAME: NameType = "test";
const OPTIONS: &'static [OptionType] = &[];
const SUBCOMMANDS: &'static [SubCommandType] = &[];
#[cfg_attr(tarpaulin, skip)]
fn parse(_arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
Ok(())
}
#[cfg_attr(tarpaulin, skip)]
fn output(_options: Self::Options) -> Result<Self::Output, CLIError> {
let path = current_dir()?;
let manifest = Manifest::try_from(path.as_path())?;
let package_name = manifest.get_package_name();
let mut package_path = path;
if package_path.is_file() {
package_path.pop();
}
let mut file_path = package_path.clone();
file_path.push(SOURCE_DIRECTORY_NAME);
if MainFile::exists_at(&package_path) {
file_path.push(MAIN_FILENAME);
} else if LibraryFile::exists_at(&package_path) {
file_path.push(LIBRARY_FILENAME);
} else {
return Err(ProgramFileDoesNotExist(package_path.into()).into());
}
let mut output_directory = package_path.clone();
output_directory.push(OUTPUTS_DIRECTORY_NAME);
OutputsDirectory::create(&package_path)?;
let span = tracing::span!(tracing::Level::INFO, "Test");
let enter = span.enter();
let start = Instant::now();
let program =
Compiler::<Fq, EdwardsGroupType>::parse_program_without_input(package_name, file_path, output_directory)?;
let pairs = InputPairs::try_from(package_path.as_path())?;
let temporary_program = program;
let (passed, failed) = temporary_program.compile_test_constraints(pairs)?;
drop(enter);
if failed == 0 {
tracing::span!(tracing::Level::INFO, "Done").in_scope(|| {
tracing::info!(
"Tests passed in {} milliseconds. {} passed; {} failed;\n",
start.elapsed().as_millis(),
passed,
failed
);
});
} else {
tracing::span!(tracing::Level::ERROR, "Done").in_scope(|| {
tracing::error!(
"Tests failed in {} milliseconds. {} passed; {} failed;\n",
start.elapsed().as_millis(),
passed,
failed
);
});
};
Ok(())
}
}