Skip to content

Commit

Permalink
test: enable more Yul tests (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Oct 21, 2024
1 parent 13c1326 commit bb2719a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
27 changes: 14 additions & 13 deletions tools/tester/src/solc/solidity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::path_contains;
use crate::utils::path_contains_curry;
use std::{
ffi::OsString,
fs,
Expand All @@ -7,50 +7,51 @@ use std::{
};

pub(crate) fn should_skip(path: &Path) -> Option<&'static str> {
if path_contains(path, "/libyul/") {
let path_contains = path_contains_curry(path);

if path_contains("/libyul/") {
return Some("actually a Yul test");
}

if path_contains(path, "/cmdlineTests/") {
if path_contains("/cmdlineTests/") {
return Some("CLI tests do not have the same format as everything else");
}

if path_contains(path, "/lsp/") {
if path_contains("/lsp/") {
return Some("LSP tests do not have the same format as everything else");
}

if path_contains(path, "/ASTJSON/") {
if path_contains("/ASTJSON/") {
return Some("no JSON AST");
}

if path_contains(path, "/functionDependencyGraphTests/") || path_contains(path, "/experimental")
{
if path_contains("/functionDependencyGraphTests/") || path_contains("/experimental") {
return Some("solidity experimental is not implemented");
}

// We don't parse licenses.
if path_contains(path, "/license/") {
if path_contains("/license/") {
return Some("licenses are not checked");
}

if path_contains(path, "natspec") {
if path_contains("natspec") {
return Some("natspec is not checked");
}

if path_contains(path, "_direction_override") {
if path_contains("_direction_override") {
return Some("Unicode direction override checks not implemented");
}

if path_contains(path, "max_depth_reached_") {
if path_contains("max_depth_reached_") {
return Some("recursion guard will not be implemented");
}

if path_contains(path, "wrong_compiler_") {
if path_contains("wrong_compiler_") {
return Some("Solidity pragma version is not checked");
}

// Directories starting with `_` are not tests.
if path_contains(path, "/_")
if path_contains("/_")
&& !path.components().last().unwrap().as_os_str().to_str().unwrap().starts_with('_')
{
return Some("supporting file");
Expand Down
35 changes: 16 additions & 19 deletions tools/tester/src/solc/yul.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
use crate::utils::path_contains;
use regex::Regex;
use std::{path::Path, sync::LazyLock};
use crate::utils::path_contains_curry;
use std::path::Path;

pub(crate) fn should_skip(path: &Path) -> Option<&'static str> {
if path_contains(path, "/recursion_depth.yul") {
let path_contains = path_contains_curry(path);

if path_contains("/recursion_depth.yul") {
return Some("recursion stack overflow");
}

if path_contains(path, "/verbatim") {
if path_contains("/verbatim") {
return Some("verbatim Yul builtin is not implemented");
}

if path_contains(path, "/period_in_identifier") || path_contains(path, "/dot_middle") {
if path_contains("/period_in_identifier")
|| path_contains("/dot_middle")
|| path_contains("/leading_and_trailing_dots")
{
// Why does Solc parse periods as part of Yul identifiers?
// `yul-identifier` is the same as `solidity-identifier`, which disallows periods:
// https://docs.soliditylang.org/en/latest/grammar.html#a4.SolidityLexer.YulIdentifier
return Some("not actually valid identifiers");
}

if path_contains(path, "objects/conflict_") || path_contains(path, "objects/code.yul") {
if path_contains("objects/conflict_") || path_contains("objects/code.yul") {
// Not the parser's job to check conflicting names.
return Some("not implemented in the parser");
}

if path_contains(".sol") {
return Some("not a Yul file");
}

let stem = path.file_stem().unwrap().to_str().unwrap();
#[rustfmt::skip]
if matches!(
Expand All @@ -45,6 +53,7 @@ pub(crate) fn should_skip(path: &Path) -> Option<&'static str> {
| "pc_disallowed"
// TODO: Not parser related, but should be implemented later.
| "for_statement_nested_continue"
| "linkersymbol_invalid_redefine_builtin"
// TODO: Not in the grammar, but docs are used to denote locations in the original src.
| "sourceLocations"
// TODO: EVM version-aware parsing.
Expand All @@ -57,17 +66,5 @@ pub(crate) fn should_skip(path: &Path) -> Option<&'static str> {
return Some("manually skipped");
};

if has_typed_identifier(path) {
return Some("typed identifiers are not implemented");
}

None
}

fn has_typed_identifier(path: &Path) -> bool {
static TYPED_IDENTIFIER_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\w+:\s*\w+").unwrap());

let Ok(s) = std::fs::read_to_string(path) else { return false };
TYPED_IDENTIFIER_RE.is_match(&s)
}
4 changes: 2 additions & 2 deletions tools/tester/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::Path;

pub(crate) fn path_contains(haystack: &Path, needle: &str) -> bool {
pub(crate) fn path_contains_curry(haystack: &Path) -> impl Fn(&str) -> bool + '_ {
let s = haystack.to_str().unwrap();
#[cfg(windows)]
let s = s.replace('\\', "/");
s.contains(needle)
move |needle| s.contains(needle)
}

0 comments on commit bb2719a

Please sign in to comment.