Skip to content

Commit 4a52be8

Browse files
committed
Boost tests for non-delimited optimizer sequence
1 parent ea78c8f commit 4a52be8

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

test/solc/CommandLineParser.cpp

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,25 @@ BOOST_AUTO_TEST_CASE(default_optimiser_sequence)
436436
BOOST_AUTO_TEST_CASE(valid_optimiser_sequences)
437437
{
438438
vector<string> validSequenceInputs {
439-
":", // Empty optimization sequence and empty cleanup sequence
440-
":fDn", // Empty optimization sequence and specified cleanup sequence
441-
"dhfoDgvulfnTUtnIf:", // Specified optimization sequence and empty cleanup sequence
442-
"dhfoDgvulfnTUtnIf:fDn", // Specified optimization sequence and cleanup sequence
443-
"dhfo[Dgvulfn]TUtnIf:f[D]n" // Specified and nested optimization and cleanup sequence
439+
":", // Empty optimization sequence and empty cleanup sequence
440+
":fDn", // Empty optimization sequence and specified cleanup sequence
441+
"dhfoDgvulfnTUtnIf:", // Specified optimization sequence and empty cleanup sequence
442+
"dhfoDgvulfnTUtnIf:fDn", // Specified optimization sequence and cleanup sequence
443+
"dhfo[Dgvulfn]TUtnIf:f[D]n", // Specified and nested optimization and cleanup sequence
444+
"dhfoDgvulfnTUtnIf", // Specified optimizer sequence only
445+
"iDu", // Short optimizer sequence
446+
"a[[a][[aa]aa[aa]][]]aaa[aa[aa[aa]]]a[a][a][a]a[a]" // Nested brackets
444447
};
445448

446-
vector<tuple<string, string>> expectedParsedSequences {
449+
vector<tuple<string, string>> const expectedParsedSequences {
447450
{"", ""},
448451
{"", "fDn"},
449452
{"dhfoDgvulfnTUtnIf", ""},
450453
{"dhfoDgvulfnTUtnIf", "fDn"},
451-
{"dhfo[Dgvulfn]TUtnIf", "f[D]n"}
454+
{"dhfo[Dgvulfn]TUtnIf", "f[D]n"},
455+
{"dhfoDgvulfnTUtnIf", OptimiserSettings::DefaultYulOptimiserCleanupSteps},
456+
{"iDu", OptimiserSettings::DefaultYulOptimiserCleanupSteps},
457+
{"a[[a][[aa]aa[aa]][]]aaa[aa[aa[aa]]]a[a][a][a]a[a]", OptimiserSettings::DefaultYulOptimiserCleanupSteps}
452458
};
453459

454460
BOOST_CHECK_EQUAL(validSequenceInputs.size(), expectedParsedSequences.size());
@@ -462,20 +468,46 @@ BOOST_AUTO_TEST_CASE(valid_optimiser_sequences)
462468
}
463469
}
464470

465-
BOOST_AUTO_TEST_CASE(invalid_nested_cleanup_sequence_delimiter)
471+
BOOST_AUTO_TEST_CASE(invalid_optimiser_sequences)
466472
{
467-
vector<string> commandLine {"solc", "contract.sol", "--optimize", "--yul-optimizations=dhfoDgvulfnTUt[nIf:fd]N"};
468-
string expectedMessage = "Invalid optimizer step sequence in --yul-optimizations: Cleanup sequence delimiter cannot be placed inside the brackets";
469-
auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedMessage; };
470-
BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage);
471-
}
473+
vector<string> const invalidSequenceInputs {
474+
"abcdefg{hijklmno}pqr[st]uvwxyz", // Invalid abbreviation
475+
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
476+
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
477+
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
478+
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
479+
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[a]"
480+
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
481+
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
482+
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
483+
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
484+
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", // Brackets nested too deep
485+
"a]a][", // Unbalanced closing bracket
486+
"a[a][", // Unbalanced opening bracket
487+
"dhfoDgvulfnTUt[nIf:fd]N", // Nested cleanup sequence delimiter
488+
"dhfoDgvulfnTU:tnIf:fdN" // Too many cleanup sequence delimiters
489+
};
472490

473-
BOOST_AUTO_TEST_CASE(too_many_cleanup_sequence_delimiters)
474-
{
475-
vector<string> commandLine {"solc", "contract.sol", "--optimize", "--yul-optimizations=dhfoDgvulfnTU:tnIf:fdN"};
476-
string expectedMessage = "Invalid optimizer step sequence in --yul-optimizations: Too many cleanup sequence delimiters";
477-
auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedMessage; };
478-
BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage);
491+
vector<string> const expectedErrorMessages {
492+
"'b' is not a valid step abbreviation",
493+
"Brackets nested too deep",
494+
"Unbalanced brackets",
495+
"Unbalanced brackets",
496+
"Cleanup sequence delimiter cannot be placed inside the brackets",
497+
"Too many cleanup sequence delimiters"
498+
};
499+
500+
BOOST_CHECK_EQUAL(invalidSequenceInputs.size(), expectedErrorMessages.size());
501+
502+
string const baseExpectedErrorMessage = "Invalid optimizer step sequence in --yul-optimizations: ";
503+
504+
for (size_t i = 0; i < invalidSequenceInputs.size(); ++i)
505+
{
506+
vector<string> const commandLineOptions = {"solc", "contract.sol", "--optimize", "--yul-optimizations=" + invalidSequenceInputs[i]};
507+
string const expectedErrorMessage = baseExpectedErrorMessage + expectedErrorMessages[i];
508+
auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedErrorMessage; };
509+
BOOST_CHECK_EXCEPTION(parseCommandLine(commandLineOptions), CommandLineValidationError, hasCorrectMessage);
510+
}
479511
}
480512

481513
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)