-
-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
535 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (C) 2012-2023 by László Nagy | ||
This file is part of Bear. | ||
Bear is a tool to generate compilation database for clang tooling. | ||
Bear is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Bear is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
use thiserror::Error; | ||
|
||
use crate::configuration::Configuration; | ||
use crate::execution::Execution; | ||
use crate::semantic::Semantic; | ||
|
||
mod any; | ||
mod exclude_or; | ||
mod configured; | ||
mod wrapper; | ||
mod matchers; | ||
|
||
#[derive(Error, Debug, PartialEq)] | ||
pub(crate) enum Error { | ||
#[error("Executable not recognized")] | ||
ExecutableFailure, | ||
#[error("Argument not recognized")] | ||
ArgumentFailure, | ||
#[error("Source file not found")] | ||
SourceNotFound, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub(crate) enum RecognitionResult { | ||
Recognized(Result<Semantic, Error>), | ||
NotRecognized, | ||
} | ||
|
||
trait Tool { | ||
fn recognize(&self, _: &Execution) -> RecognitionResult; | ||
} | ||
|
||
fn init_from(cfg: Configuration) -> Box<dyn Tool> { | ||
todo!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* Copyright (C) 2012-2023 by László Nagy | ||
This file is part of Bear. | ||
Bear is a tool to generate compilation database for clang tooling. | ||
Bear is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Bear is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
use crate::execution::Execution; | ||
use crate::tools::{Error, RecognitionResult, Tool}; | ||
use crate::tools::RecognitionResult::{NotRecognized, Recognized}; | ||
|
||
struct Any { | ||
tools: Vec<Box<dyn Tool>>, | ||
} | ||
|
||
impl Tool for Any { | ||
/// Any of the tool recognize the semantic, will be returned as result. | ||
fn recognize(&self, x: &Execution) -> RecognitionResult { | ||
for tool in &self.tools { | ||
match tool.recognize(x) { | ||
Recognized(result) => | ||
return Recognized(result), | ||
_ => continue, | ||
} | ||
} | ||
NotRecognized | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::collections::HashMap; | ||
use std::path::PathBuf; | ||
|
||
use crate::semantic::CompilerCall::Query; | ||
use crate::semantic::Semantic; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_when_no_match() { | ||
let sut = Any { | ||
tools: vec![ | ||
Box::new(MockTool::NotRecognize), | ||
Box::new(MockTool::NotRecognize), | ||
Box::new(MockTool::NotRecognize), | ||
] | ||
}; | ||
|
||
let input = any_execution(); | ||
|
||
match sut.recognize(&input) { | ||
NotRecognized => assert!(true), | ||
_ => assert!(false), | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_when_match() { | ||
let sut = Any { | ||
tools: vec![ | ||
Box::new(MockTool::NotRecognize), | ||
Box::new(MockTool::Recognize), | ||
Box::new(MockTool::NotRecognize), | ||
] | ||
}; | ||
|
||
let input = any_execution(); | ||
|
||
match sut.recognize(&input) { | ||
Recognized(Ok(_)) => assert!(true), | ||
_ => assert!(false) | ||
} | ||
} | ||
|
||
|
||
#[test] | ||
fn test_when_match_fails() { | ||
let sut = Any { | ||
tools: vec![ | ||
Box::new(MockTool::NotRecognize), | ||
Box::new(MockTool::RecognizeFailed), | ||
Box::new(MockTool::Recognize), | ||
Box::new(MockTool::NotRecognize), | ||
] | ||
}; | ||
|
||
let input = any_execution(); | ||
|
||
match sut.recognize(&input) { | ||
Recognized(Err(_)) => assert!(true), | ||
_ => assert!(false), | ||
} | ||
} | ||
|
||
enum MockTool { | ||
Recognize, | ||
RecognizeFailed, | ||
NotRecognize, | ||
} | ||
|
||
impl Tool for MockTool { | ||
fn recognize(&self, _: &Execution) -> RecognitionResult { | ||
match self { | ||
MockTool::Recognize => | ||
Recognized(Ok(Semantic::Compiler(Query))), | ||
MockTool::RecognizeFailed => | ||
Recognized(Err(Error::ExecutableFailure)), | ||
MockTool::NotRecognize => | ||
NotRecognized, | ||
} | ||
} | ||
} | ||
|
||
fn any_execution() -> Execution { | ||
Execution { | ||
executable: PathBuf::new(), | ||
arguments: vec![], | ||
working_dir: PathBuf::new(), | ||
environment: HashMap::new(), | ||
} | ||
} | ||
} |
Oops, something went wrong.