Skip to content

Commit

Permalink
Add json flag for check command
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley-Kilgore committed Sep 16, 2024
1 parent 47a15cf commit cef3276
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 91 deletions.
1 change: 1 addition & 0 deletions crates/aiken-lsp/src/server/lsp_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl LspProject {
PropertyTest::DEFAULT_MAX_SUCCESS,
Tracing::silent(),
None,
false,
);

self.project.restore(checkpoint);
Expand Down
29 changes: 22 additions & 7 deletions crates/aiken-project/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ where
uplc: bool,
tracing: Tracing,
env: Option<String>,
json: bool,
) -> Result<(), Vec<Error>> {
let options = Options {
code_gen_mode: CodeGenMode::Build(uplc),
tracing,
env,
json,
};

self.compile(options)
Expand All @@ -225,7 +227,7 @@ where

let mut modules = self.parse_sources(self.config.name.clone())?;

self.type_check(&mut modules, Tracing::silent(), None, false)?;
self.type_check(&mut modules, Tracing::silent(), None, false, false)?;

let destination = destination.unwrap_or_else(|| self.root.join("docs"));

Expand Down Expand Up @@ -267,6 +269,7 @@ where
property_max_success: usize,
tracing: Tracing,
env: Option<String>,
json: bool,
) -> Result<(), Vec<Error>> {
let options = Options {
tracing,
Expand All @@ -282,6 +285,7 @@ where
property_max_success,
}
},
json: json,
};

self.compile(options)
Expand Down Expand Up @@ -343,6 +347,7 @@ where
root: self.root.clone(),
name: self.config.name.to_string(),
version: self.config.version.clone(),
json: options.json,
});

let env = options.env.as_deref();
Expand All @@ -353,7 +358,7 @@ where

let mut modules = self.parse_sources(self.config.name.clone())?;

self.type_check(&mut modules, options.tracing, env, true)?;
self.type_check(&mut modules, options.tracing, env, true, options.json)?;

match options.code_gen_mode {
CodeGenMode::Build(uplc_dump) => {
Expand Down Expand Up @@ -400,7 +405,8 @@ where
self.collect_tests(verbose, match_tests, exact_match, options.tracing)?;

if !tests.is_empty() {
self.event_listener.handle_event(Event::RunningTests);
self.event_listener
.handle_event(Event::RunningTests { json: options.json });
}

let tests = self.run_tests(tests, seed, property_max_success);
Expand All @@ -427,8 +433,11 @@ where
})
.collect();

self.event_listener
.handle_event(Event::FinishedTests { seed, tests });
self.event_listener.handle_event(Event::FinishedTests {
seed,
tests,
json: options.json,
});

if !errors.is_empty() {
Err(errors)
Expand Down Expand Up @@ -629,7 +638,11 @@ where
Ok(blueprint)
}

fn with_dependencies(&mut self, parsed_packages: &mut ParsedModules) -> Result<(), Vec<Error>> {
fn with_dependencies(
&mut self,
parsed_packages: &mut ParsedModules,
json: bool,
) -> Result<(), Vec<Error>> {
let manifest = deps::download(&self.event_listener, &self.root, &self.config)?;

for package in manifest.packages {
Expand All @@ -640,6 +653,7 @@ where
root: lib.clone(),
name: package.name.to_string(),
version: package.version.clone(),
json,
});

self.read_package_source_files(&lib.join("lib"))?;
Expand Down Expand Up @@ -828,10 +842,11 @@ where
tracing: Tracing,
env: Option<&str>,
validate_module_name: bool,
json: bool,
) -> Result<(), Vec<Error>> {
let our_modules: BTreeSet<String> = modules.keys().cloned().collect();

self.with_dependencies(modules)?;
self.with_dependencies(modules, json)?;

for name in modules.sequence(&our_modules)? {
if let Some(module) = modules.remove(&name) {
Expand Down
2 changes: 2 additions & 0 deletions crates/aiken-project/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub struct Options {
pub code_gen_mode: CodeGenMode,
pub tracing: Tracing,
pub env: Option<String>,
pub json: bool,
}

impl Default for Options {
Expand All @@ -12,6 +13,7 @@ impl Default for Options {
code_gen_mode: CodeGenMode::NoOp,
tracing: Tracing::silent(),
env: None,
json: false,
}
}
}
Expand Down
Loading

0 comments on commit cef3276

Please sign in to comment.