Skip to content

Commit

Permalink
Fix the issue of illegal invocation of private_generics in the module…
Browse files Browse the repository at this point in the history
… without throwing an error. (#345) (#351)

Check if private_generics is used correctly in the integration-test.

Resume using datatest for testing.

cargo fmt

Change the path of the datatest library.
  • Loading branch information
steelgeek091 committed Jun 26, 2023
1 parent 4b14551 commit 55373ef
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ derive-syn-parse = "0.1.5"
unescape = "0.1.0"
tempfile = "3.2.0"
regex = "1.8.4"
walkdir = "2.3.3"


# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
Expand Down
5 changes: 5 additions & 0 deletions crates/rooch-integration-test-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ bcs = { workspace = true }
clap = { features = [ "derive",], workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
codespan-reporting = { workspace = true }
regex = { workspace = true }
datatest-stable = { workspace = true }
walkdir = { workspace = true }

move-binary-format = { workspace = true }
move-bytecode-utils = { workspace = true }
Expand All @@ -40,6 +44,7 @@ moveos-stdlib = { workspace = true }
moveos-stdlib-builder = { workspace = true }
moveos = { workspace = true }
moveos-types = { workspace = true }
moveos-verifier = { workspace = true }

rooch-framework = { workspace = true }
rooch-genesis = { workspace = true }
Expand Down
70 changes: 69 additions & 1 deletion crates/rooch-integration-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

use clap::Parser;
use codespan_reporting::diagnostic::Severity;
use codespan_reporting::term::termcolor::Buffer;
use move_command_line_common::address::NumericalAddress;
use move_command_line_common::files::verify_and_create_named_address_mapping;
use move_command_line_common::{address::ParsedAddress, values::ParsableValue};
use move_compiler::compiled_unit::CompiledUnitEnum;
Expand All @@ -20,7 +23,11 @@ use moveos_types::object::ObjectID;
use moveos_types::state::StateChangeSet;
use moveos_types::state_resolver::AnnotatedStateReader;
use moveos_types::transaction::{MoveAction, MoveOSTransaction, TransactionOutput};
use moveos_verifier::build::build_model;
use moveos_verifier::metadata::run_extended_checks;
use regex::Regex;
use rooch_genesis::RoochGenesis;
use std::path::PathBuf;
use std::{collections::BTreeMap, path::Path};

pub struct MoveOSTestRunner<'a> {
Expand Down Expand Up @@ -310,7 +317,68 @@ pub fn run_test_impl<'a>(
path: &Path,
fully_compiled_program_opt: Option<&'a FullyCompiledProgram>,
) -> Result<(), Box<dyn std::error::Error + 'static>> {
moveos::moveos_test_runner::run_test_impl::<MoveOSTestRunner>(path, fully_compiled_program_opt)
moveos::moveos_test_runner::run_test_impl::<MoveOSTestRunner>(
path,
fully_compiled_program_opt,
None,
)
}

pub fn iterate_directory(path: &Path) -> impl Iterator<Item = PathBuf> {
walkdir::WalkDir::new(path)
.into_iter()
.map(::std::result::Result::unwrap)
.filter(|entry| {
entry.file_type().is_file()
&& entry
.file_name()
.to_str()
.map_or(false, |s| !s.starts_with('.')) // Skip hidden files
})
.map(|entry| entry.path().to_path_buf())
}

// Perform extended checks to ensure that the dependencies of the Move files are compiled correctly.
pub fn run_integration_test_with_extended_check(
path: &Path,
fully_compiled_program_opt: Option<&FullyCompiledProgram>,
data: &BTreeMap<String, String>,
) -> Result<(), Box<dyn std::error::Error + 'static>> {
let dep_package_path = path.parent().unwrap().parent().unwrap();

let mut named_account_address_map = BTreeMap::new();
let _ = data
.iter()
.map(|(key, value)| {
let account_address = NumericalAddress::parse_str(value.as_str()).unwrap();
named_account_address_map.insert(key.clone(), account_address.into_inner());
})
.collect::<Vec<_>>();

let global_env = build_model(dep_package_path, named_account_address_map, None).unwrap();

let _ = run_extended_checks(&global_env);

let extended_checks_error = {
if global_env.diag_count(Severity::Warning) > 0 {
let mut buffer = Buffer::no_color();
global_env.report_diag(&mut buffer, Severity::Warning);
let buffer_output = String::from_utf8_lossy(buffer.as_slice()).to_string();
let re = Regex::new("(/.*)(.move:[0-9]+:[0-9]+)").unwrap();
Some(
re.replace(buffer_output.as_str(), "/tmp/tempfile$2".to_string())
.to_string(),
)
} else {
None
}
};

moveos::moveos_test_runner::run_test_impl::<MoveOSTestRunner>(
path,
fully_compiled_program_opt,
extended_checks_error,
)
}

fn tx_output_to_str(output: TransactionOutput) -> String {
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rust-version = { workspace = true }
anyhow = { workspace = true }
bcs = { workspace = true }
clap = { features = [ "derive",], workspace = true }
datatest-stable = { git = "https://github.com/starcoinorg/diem-devtools", branch = "feature/pub-test-opts" }
datatest-stable = { git = "https://github.com/rooch-network/diem-devtools", branch = "feature/pub-test-opts" }
tokio = { features = ["full"], workspace = true }
dirs = { workspace = true }
serde = { workspace = true }
Expand Down
18 changes: 15 additions & 3 deletions crates/rooch/src/commands/move_cli/commands/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ impl IntegrationTest {
},
}];

let program_res = construct_pre_compiled_lib(targets, None, move_compiler::Flags::empty())?;
let program_res =
construct_pre_compiled_lib(targets.clone(), None, move_compiler::Flags::empty())?;
let pre_compiled_lib = match program_res {
Ok(af) => af,
Err((files, errors)) => {
Expand All @@ -202,16 +203,27 @@ impl IntegrationTest {
return Ok(());
}

let named_address_map = targets.get(0).unwrap().named_address_map.clone();
let mut named_address_string_map = BTreeMap::new();
let _ = named_address_map
.iter()
.map(|(key, value)| {
named_address_string_map.insert(key.clone(), value.to_string());
})
.collect::<Vec<_>>();

let requirements = datatest_stable::Requirements::new(
move |path| {
rooch_integration_test_runner::run_test_impl(
move |path, data| {
rooch_integration_test_runner::run_integration_test_with_extended_check(
path,
G_PRE_COMPILED_LIB.lock().unwrap().as_ref(),
data,
)
},
"integration-test333".to_string(),
tests_dir.display().to_string(),
r".*\.move".to_string(),
named_address_string_map,
);
if self.update_baseline {
std::env::set_var(UPDATE_BASELINE, "true");
Expand Down
5 changes: 5 additions & 0 deletions moveos/moveos/src/moveos_test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ fn display_return_values(return_values: SerializedReturnValues) -> Option<String
pub fn run_test_impl<'a, Adapter>(
path: &Path,
fully_compiled_program_opt: Option<&'a FullyCompiledProgram>,
additional_output: Option<String>,
) -> Result<(), Box<dyn std::error::Error>>
where
Adapter: MoveOSTestAdapter<'a>,
Expand All @@ -695,6 +696,10 @@ where
SyntaxChoice::Source
};
let mut output = String::new();
if let Some(value) = additional_output {
writeln!(output, "{}", value).unwrap();
}

let mut tasks = taskify::<
TaskCommand<
Adapter::ExtraInitArgs,
Expand Down

0 comments on commit 55373ef

Please sign in to comment.