From bb1dd212247a98fdf007f883de77ba7200a20e2b Mon Sep 17 00:00:00 2001 From: Ivan Bobev Date: Wed, 7 Aug 2019 19:24:07 +0300 Subject: [PATCH] Add an unit test for compilation without warnings An unit test which checks whether Nimble compiles without warnings is added. Checking for three warning types cleaned in previous commits is implemented: - [UnusedImport] cleaned in e8c7d5c - [Deprecated] cleaned in 3d6172e - [XDeclaredButNotUsed] cleaned in 7df2ef3 Other types of warnings easily can be added to the test by extending the warnings list. Related to #680 --- src/nimblepkg/nimscriptwrapper.nim | 2 +- tests/tester.nim | 39 ++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/nimblepkg/nimscriptwrapper.nim b/src/nimblepkg/nimscriptwrapper.nim index 3f7ba51..d1f8d7a 100644 --- a/src/nimblepkg/nimscriptwrapper.nim +++ b/src/nimblepkg/nimscriptwrapper.nim @@ -5,7 +5,7 @@ ## scripting language. import version, options, cli, tools -import hashes, json, os, strutils, tables, times, osproc +import hashes, json, os, strutils, tables, times, osproc, strtabs type Flags = TableRef[string, seq[string]] diff --git a/tests/tester.nim b/tests/tester.nim index 2629817..079d9f5 100644 --- a/tests/tester.nim +++ b/tests/tester.nim @@ -1,6 +1,6 @@ # Copyright (C) Dominik Picheta. All rights reserved. # BSD License. Look at license.txt for more info. -import osproc, unittest, strutils, os, sequtils, sugar +import osproc, unittest, strutils, os, sequtils, sugar, strformat # TODO: Each test should start off with a clean slate. Currently installed # packages are shared between each test which causes a multitude of issues @@ -10,6 +10,7 @@ var rootDir = getCurrentDir().parentDir() var nimblePath = rootDir / "src" / addFileExt("nimble", ExeExt) var installDir = rootDir / "tests" / "nimbleDir" const path = "../src/nimble" +const stringNotFound = -1 # Clear nimble dir. removeDir(installDir) @@ -863,9 +864,43 @@ test "do not install single dependency multiple times (#678)": check execNimble(["refresh"]).exitCode == QuitSuccess let (output, exitCode) = execNimble("install", "-y") check exitCode == QuitSuccess - check output.find("issue678_dependency_1@0.1.0 already exists") == -1 + let index = output.find("issue678_dependency_1@0.1.0 already exists") + check index == stringNotFound test "Passing command line arguments to a task (#633)": cd "issue633": var (output, exitCode) = execNimble("testTask --testTask") + check exitCode == QuitSuccess check output.contains("Got it") + +test "compilation without warnings": + const buildDir = "./buildDir/" + const filesToBuild = [ + "../src/nimble.nim", + "../src/nimblepkg/nimscriptapi.nim", + "./tester.nim", + ] + + proc execBuild(fileName: string): tuple[output: string, exitCode: int] = + result = execCmdEx(fmt"nim c -o:{buildDir} {fileName}") + + proc checkOutput(output: string): uint = + const warningsToCheck = [ + "[UnusedImport]", + "[Deprecated]", + "[XDeclaredButNotUsed]", + ] + + for line in output.splitLines(): + for warning in warningsToCheck: + if line.find(warning) != stringNotFound: + once: checkpoint("Detected warnings:") + checkpoint(line) + inc(result) + + var linesWithWarningsCount: uint = 0 + for file in filesToBuild: + let (output, exitCode) = execBuild(file) + check exitCode == QuitSuccess + linesWithWarningsCount += checkOutput(output) + check linesWithWarningsCount == 0