[libcalamares] Tests for new CommandLine constructors
This commit is contained in:
parent
ae3e609024
commit
6770f781e3
@ -52,6 +52,8 @@ private Q_SLOTS:
|
||||
void testCommands();
|
||||
void testCommandExpansion_data();
|
||||
void testCommandExpansion(); // See also shellprocess tests
|
||||
void testCommandConstructors();
|
||||
void testCommandConstructorsYAML();
|
||||
|
||||
/** @section Test that all the UMask objects work correctly. */
|
||||
void testUmask();
|
||||
@ -300,6 +302,79 @@ LibCalamaresTests::testCommandExpansion()
|
||||
QCOMPARE( e.command(), expected );
|
||||
}
|
||||
|
||||
void
|
||||
LibCalamaresTests::testCommandConstructors()
|
||||
{
|
||||
const QString command( "do this" );
|
||||
Calamares::CommandLine c0( command );
|
||||
|
||||
QCOMPARE( c0.command(), command );
|
||||
QCOMPARE( c0.timeout(), Calamares::CommandLine::TimeoutNotSet() );
|
||||
QVERIFY( c0.environment().isEmpty() );
|
||||
|
||||
const QStringList env { "-la", "/tmp" };
|
||||
Calamares::CommandLine c1( command, env, Calamares::CommandLine::TimeoutNotSet() );
|
||||
|
||||
QCOMPARE( c1.command(), command );
|
||||
QCOMPARE( c1.timeout(), Calamares::CommandLine::TimeoutNotSet() );
|
||||
QVERIFY( !c1.environment().isEmpty() );
|
||||
QCOMPARE( c1.environment().count(), 2 );
|
||||
QCOMPARE( c1.environment(), env );
|
||||
}
|
||||
|
||||
void
|
||||
LibCalamaresTests::testCommandConstructorsYAML()
|
||||
{
|
||||
QTemporaryFile f;
|
||||
QVERIFY( f.open() );
|
||||
f.write( R"(---
|
||||
commands:
|
||||
- one-string-command
|
||||
- command: only-command
|
||||
- command: with-timeout
|
||||
timeout: 12
|
||||
- command: all-three
|
||||
timeout: 20
|
||||
environment:
|
||||
- PATH=/USER
|
||||
- DISPLAY=:0
|
||||
)" );
|
||||
f.close();
|
||||
bool ok = false;
|
||||
QVariantMap m = Calamares::YAML::load( f.fileName(), &ok );
|
||||
|
||||
QVERIFY( ok );
|
||||
QCOMPARE( m.count(), 1 );
|
||||
QCOMPARE( m[ "commands" ].toList().count(), 4 );
|
||||
|
||||
{
|
||||
// Take care! The second parameter is a bool, so "3" here means "true"
|
||||
Calamares::CommandList cmds( m[ "commands" ], 3 );
|
||||
QCOMPARE( cmds.defaultTimeout(), std::chrono::seconds( 10 ) );
|
||||
// But the 4 commands are there anyway
|
||||
QCOMPARE( cmds.count(), 4 );
|
||||
QCOMPARE( cmds.at( 0 ).command(), QString( "one-string-command" ) );
|
||||
QCOMPARE( cmds.at( 0 ).environment(), QStringList() );
|
||||
QCOMPARE( cmds.at( 0 ).timeout(), Calamares::CommandLine::TimeoutNotSet() );
|
||||
QCOMPARE( cmds.at( 1 ).command(), QString( "only-command" ) );
|
||||
QCOMPARE( cmds.at( 2 ).command(), QString( "with-timeout" ) );
|
||||
QCOMPARE( cmds.at( 2 ).environment(), QStringList() );
|
||||
QCOMPARE( cmds.at( 2 ).timeout(), std::chrono::seconds( 12 ) );
|
||||
|
||||
QStringList expectedEnvironment = { "PATH=/USER", "DISPLAY=:0" };
|
||||
QCOMPARE( cmds.at( 3 ).command(), QString( "all-three" ) );
|
||||
QCOMPARE( cmds.at( 3 ).environment(), expectedEnvironment );
|
||||
QCOMPARE( cmds.at( 3 ).timeout(), std::chrono::seconds( 20 ) );
|
||||
}
|
||||
|
||||
{
|
||||
Calamares::CommandList cmds( m[ "commands" ], true, std::chrono::seconds( 3 ) );
|
||||
QCOMPARE( cmds.defaultTimeout(), std::chrono::seconds( 3 ) );
|
||||
QCOMPARE( cmds.at( 0 ).timeout(), Calamares::CommandLine::TimeoutNotSet() );
|
||||
QCOMPARE( cmds.at( 2 ).timeout(), std::chrono::seconds( 12 ) );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LibCalamaresTests::testUmask()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user