*** Settings ***
Library           OperatingSystem

*** Variables ***
${kcov}           %{WORKSPACE}/build/src/kcov
${out}            %{WORKSPACE}/kcov
${kcov_path}      %{WORKSPACE}
${xml_lookup}     ${kcov_path}/tests/tools/lookup-xml-node.py

*** Test Cases ***
too-few-arguments
    ${rc}=    Run and return RC    ${kcov} ${out}
    Should be equal as integers    ${rc}    1

wrong-arguments
    ${rc}=    Run and return RC    ${kcov} --abcd=efg ${out} tests-stripped
    Should be equal as integers    ${rc}    1

fork-no-wait
    ${no_kcov_rc}=    Run and return RC    ./fork_no_wait
    ${rc}=    Run and return RC    ${kcov} ${out} ./fork_no_wait
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/fork_no_wait/cobertura.xml fork_no_wait_c 20
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork_no_wait/cobertura.xml fork_no_wait_c 22
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork_no_wait/cobertura.xml fork_no_wait_c 24
    Should Contain    ${output}    1

fork
    ${no_kcov_rc}=    Run and return RC    ./fork
    ${rc}=    Run and return RC    ${kcov} ${out} ./fork
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 21
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 26
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 34
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 37
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 46
    Should Contain    ${output}    1

shared-library
    ${no_kcov_rc}=    Run and return RC    ./shared_library_test
    ${rc}=    Run and return RC    ${kcov} ${out} ./shared_library_test
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml main_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 5
    Should Contain    ${output}    1

shared-library-filter-out
    ${no_kcov_rc}=    Run and return RC    ./shared_library_test
    ${rc}=    Run and return RC    ${kcov} --exclude-pattern=solib ${out} ./shared_library_test
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml main_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 5
    Should Contain    ${output}    nocode

main-test
    ${no_kcov_rc}=    Run and return RC    ./main-tests
    ${rc}=    Run and return RC    ${kcov} ${out} ./main-tests
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 14
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 18
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 25
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file_c 6
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file_c 7
    Should Contain    ${output}    0

accumulate-data
    ${rc}=    Run and return RC    ${kcov} ${out} ./argv_dependent
    Should be equal as integers    ${rc}    0
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 5
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 11
    Should Contain    ${output}    0
    ${rc}=    Run and return RC    ${kcov} ${out} ./argv_dependent a
    Should be equal as integers    ${rc}    0
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 11
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 5
    Should Contain    ${output}    1

popen-test
    ${no_kcov_rc}=    Run and return RC    ./test_popen
    ${rc}=    Run and return RC    ${kcov} ${out} ./test_popen
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${kcov} ${out} ./test_popen
    Should Contain    ${output}    popen OK
