Here is the code if you want to try it out:

x.nim file: 
    
    
    var x = 0
    if x > 1:
      echo "foo"
    echo "bar"
    
    
    Run

ct.sh file: 
    
    
    
    #!/bin/sh
    
    # Remove old coverage information.
    rm -rf *.info html ~/.cache/nim
    
    # Compile t.nim module with coverage instrumentation. Generate x exe.
    nim c --debugger:native --passC:--coverage --passL:--coverage x
    
    # Reset the coverage counters.
    lcov --base-directory . --directory ~/.cache/nim --zerocounters -q
    
    # Run the instrumented program.
    ./x
    
    # Read data files and generate x.info file with code coverage data.
    lcov --base-directory . --directory ~/.cache/nim -c -o x.info
    
    # Remove nim system libs from x.info coverage.
    lcov --remove t.info "*/lib/*" -o x.info
    
    # Generate html reports from the x.info file and put them in the html
    # directory.
    genhtml -o html x.info
    
    
    Run

Run ct.sh and open the html index file in your browser: 
    
    
    ./ct.sh
    
    
    Run

Reply via email to