[shellprocess] Improve CommandList

- Also allow a single string instead of a list
 - Add count() method to CommandList
 - Drop over-engineering, add more logging
 - Expand tests with some more examples
This commit is contained in:
Adriaan de Groot 2018-01-10 11:01:39 -05:00
parent 5f8fb655c4
commit b7fb24837a
4 changed files with 83 additions and 36 deletions

View file

@ -44,7 +44,7 @@ ShellProcessTests::initTestCase()
}
void
ShellProcessTests::testProcessList()
ShellProcessTests::testProcessListSampleConfig()
{
YAML::Node doc;
@ -62,4 +62,52 @@ ShellProcessTests::testProcessList()
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 2 );
}
void ShellProcessTests::testProcessListFromList()
{
YAML::Node doc = YAML::Load( R"(---
script:
- "ls /tmp"
- "ls /nonexistent"
- "/bin/false"
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 3 );
// Contains 1 bad element
doc = YAML::Load( R"(---
script:
- "ls /tmp"
- false
- "ls /nonexistent"
)" );
CommandList cl1(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl1.isEmpty() );
QCOMPARE( cl1.count(), 2 ); // One element ignored
}
void ShellProcessTests::testProcessListFromString()
{
YAML::Node doc = YAML::Load( R"(---
script: "ls /tmp"
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 1 );
// Not a string
doc = YAML::Load( R"(---
script: false
)" );
CommandList cl1(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( cl1.isEmpty() );
QCOMPARE( cl1.count(), 0 );
}