From 4588d353e83134bbc94a37af9e527299fe450774 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 17 Oct 2023 15:06:16 -0500 Subject: [PATCH] Add more individual tests --- ...rect-import-transitive-dependency-test.txt | 23 +++ ...ck-direct-import-transitive-dependency.txt | 5 - test/Spago/Build.purs | 173 ++++++++++++------ 3 files changed, 141 insertions(+), 60 deletions(-) create mode 100644 test-fixtures/check-direct-import-transitive-dependency-test.txt diff --git a/test-fixtures/check-direct-import-transitive-dependency-test.txt b/test-fixtures/check-direct-import-transitive-dependency-test.txt new file mode 100644 index 000000000..97c52ddab --- /dev/null +++ b/test-fixtures/check-direct-import-transitive-dependency-test.txt @@ -0,0 +1,23 @@ +Reading Spago workspace configuration... +Read the package set from the registry + +✅ Selecting package to build: 7368613235362d34312f4e59746b7869335477336d33414d72 + +Downloading dependencies... +Building... + Src Lib All +Warnings 0 0 0 +Errors 0 0 0 + +✅ Build succeeded. + +Looking for unused and undeclared transitive dependencies... + +❌ Tests for package '7368613235362d34312f4e59746b7869335477336d33414d72' import the following transitive dependencies - please add them to the project dependencies, or remove the imports: + control + from `Test.Main`, which imports: + Control.Alt + + +Run the following command to install them all: + spago install --test-deps -p 7368613235362d34312f4e59746b7869335477336d33414d72 control diff --git a/test-fixtures/check-direct-import-transitive-dependency.txt b/test-fixtures/check-direct-import-transitive-dependency.txt index e77ac94da..638330861 100644 --- a/test-fixtures/check-direct-import-transitive-dependency.txt +++ b/test-fixtures/check-direct-import-transitive-dependency.txt @@ -13,11 +13,6 @@ Errors 0 0 0 Looking for unused and undeclared transitive dependencies... -❌ Sources for package '7368613235362d34312f4e59746b7869335477336d33414d72' declares unused dependencies - please remove them from the project config: - - console - - effect - - ❌ Sources for package '7368613235362d34312f4e59746b7869335477336d33414d72' import the following transitive dependencies - please add them to the project dependencies, or remove the imports: control from `Main`, which imports: diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index c05435ceb..a7ebf4883 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -101,69 +101,132 @@ spec = Spec.around withTempDir do } } } + addPedanticPackagesToTest = modifyPackageConfig \config -> + config + { package = config.package <#> \r -> r + { test = Just + { main: "Test.Main" + , pedantic_packages: Just true + , strict: Nothing + , censor_test_warnings: Nothing + , dependencies: maybe (Config.Dependencies Map.empty) _.dependencies r.test + , execArgs: r.test >>= _.execArgs + } + } + } - Spec.describe "fails when there are imports from transitive dependencies and" do - let - setupSrcTransitiveTests spago installConsoleAndEffect = do - spago [ "init", "--name", "7368613235362d34312f4e59746b7869335477336d33414d72" ] >>= shouldBeSuccess - spago [ "install", "maybe" ] >>= shouldBeSuccess - when installConsoleAndEffect do - spago [ "install", "--test-deps", "console", "effect" ] >>= shouldBeSuccess - FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) "module Main where\nimport Prelude\nimport Data.Maybe\nimport Control.Alt\nmain = unit" - -- get rid of "Compiling ..." messages and other compiler warnings - spago [ "build" ] >>= shouldBeSuccess + Spec.describe "fails when imports from transitive dependencies" do - Spec.it "passed --pedantic-packages CLI flag" \{ spago, fixture } -> do - setupSrcTransitiveTests spago true - spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-direct-import-transitive-dependency.txt") + Spec.describe "appear in the source package and" do - Spec.it "package config has 'pedantic_packages: true'" \{ spago, fixture } -> do - setupSrcTransitiveTests spago false - addPedanticPackagesToSrc - spago [ "build" ] >>= shouldBeFailureErr (fixture "check-direct-import-transitive-dependency.txt") + let + setupSrcTransitiveTests spago installConsoleAndEffect = do + spago [ "init", "--name", "7368613235362d34312f4e59746b7869335477336d33414d72" ] >>= shouldBeSuccess + spago [ "install", "maybe" ] >>= shouldBeSuccess + when installConsoleAndEffect do + spago [ "install", "--test-deps", "console", "effect" ] >>= shouldBeSuccess + FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) $ Array.intercalate "\n" + [ "module Main where" + , "import Prelude" + , "import Data.Maybe as Maybe" + , "import Effect as Effect" + , "import Effect.Console as Console" + , "import Control.Alt as Alt" + , "main = unit" + ] + -- get rid of "Compiling ..." messages and other compiler warnings + spago [ "build" ] >>= shouldBeSuccess + + Spec.it "passed --pedantic-packages CLI flag" \{ spago, fixture } -> do + setupSrcTransitiveTests spago true + spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-direct-import-transitive-dependency.txt") + + Spec.it "package config has 'pedantic_packages: true'" \{ spago, fixture } -> do + setupSrcTransitiveTests spago false + addPedanticPackagesToSrc + spago [ "build" ] >>= shouldBeFailureErr (fixture "check-direct-import-transitive-dependency.txt") + + Spec.describe "appear in the test package and" do - Spec.describe "warns about unused dependencies when" do - let - setupSrcUnusedDeps spago installConsoleAndEffect = do - spago [ "init", "--name", "7368613235362d2f444a2b4f56375435646a59726b53586548" ] >>= shouldBeSuccess - when installConsoleAndEffect do - spago [ "install", "--test-deps", "console", "effect" ] >>= shouldBeSuccess - FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) "module Main where\nimport Prelude\nmain = unit" - -- get rid of "Compiling ..." messages and other compiler warnings - spago [ "build" ] >>= shouldBeSuccess + let + setupTestTransitiveTests spago = do + spago [ "init", "--name", "7368613235362d34312f4e59746b7869335477336d33414d72" ] >>= shouldBeSuccess + spago [ "install", "maybe" ] >>= shouldBeSuccess + FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) $ Array.intercalate "\n" + [ "module Main where" + , "import Prelude" + , "import Data.Maybe as Maybe" + , "import Effect as Effect" + , "import Effect.Console as Console" + , "main = unit" + ] + FS.writeTextFile (Path.concat [ "test", "Test", "Main.purs" ]) $ Array.intercalate "\n" + [ "module Test.Main where" + , "import Prelude" + , "import Data.Maybe as Maybe" + , "import Effect as Effect" + , "import Effect.Console as Console" + , "import Control.Alt as Alt" + , "main = unit" + ] + -- get rid of "Compiling ..." messages and other compiler warnings + spago [ "build" ] >>= shouldBeSuccess + + Spec.it "passed --pedantic-packages CLI flag" \{ spago, fixture } -> do + setupTestTransitiveTests spago + spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-direct-import-transitive-dependency-test.txt") + + Spec.it "package config has 'pedantic_packages: true'" \{ spago, fixture } -> do + setupTestTransitiveTests spago + addPedanticPackagesToTest + spago [ "build" ] >>= shouldBeFailureErr (fixture "check-direct-import-transitive-dependency-test.txt") + + Spec.describe "fails with warnings about unused dependencies" do + + Spec.describe "in a source package when" do + + let + setupSrcUnusedDeps spago installConsoleAndEffect = do + spago [ "init", "--name", "7368613235362d2f444a2b4f56375435646a59726b53586548" ] >>= shouldBeSuccess + when installConsoleAndEffect do + spago [ "install", "--test-deps", "console", "effect" ] >>= shouldBeSuccess + FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) "module Main where\nimport Prelude\nmain = unit" + -- get rid of "Compiling ..." messages and other compiler warnings + spago [ "build" ] >>= shouldBeSuccess + + Spec.it "passing --pedantic-packages CLI flag" \{ spago, fixture } -> do + setupSrcUnusedDeps spago true + spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-unused-dependency.txt") - Spec.it "passing --pedantic-packages CLI flag" \{ spago, fixture } -> do - setupSrcUnusedDeps spago true - spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-unused-dependency.txt") + Spec.it "package config has 'pedantic_packages: true'" \{ spago, fixture } -> do + setupSrcUnusedDeps spago false + addPedanticPackagesToSrc + spago [ "build" ] >>= shouldBeFailureErr (fixture "check-unused-dependency.txt") - Spec.it "package config has 'pedantic_packages: true'" \{ spago, fixture } -> do - setupSrcUnusedDeps spago false - addPedanticPackagesToSrc - spago [ "build" ] >>= shouldBeFailureErr (fixture "check-unused-dependency.txt") + Spec.describe "in a test package when" do - Spec.it "package's test config has 'pedantic_packages: true' and test code has unused dependencies" \{ spago, fixture } -> do - spago [ "init", "--name", "7368613235362d2f444a2b4f56375435646a59726b53586548" ] >>= shouldBeSuccess - FS.writeTextFile (Path.concat [ "test", "Test", "Main.purs" ]) "module Test.Main where\nimport Prelude\nmain = unit" let - modifyPkgTestConfig pedantic = modifyPackageConfig \config -> - config - { package = config.package <#> \r -> r - { test = Just - { main: "Test.Main" - , pedantic_packages: Just pedantic - , strict: Nothing - , censor_test_warnings: Nothing - , dependencies: mkDependencies [ "newtype" ] - , execArgs: Nothing - } - } - } - modifyPkgTestConfig false - -- get rid of "Compiling ..." messages and other compiler warnings - spago [ "build" ] >>= shouldBeSuccess - -- now add pedantic - modifyPkgTestConfig true - spago [ "build" ] >>= shouldBeFailureErr (fixture "check-unused-test-dependency.txt") + setupTestUnusedDeps spago = do + spago [ "init", "--name", "7368613235362d2f444a2b4f56375435646a59726b53586548" ] >>= shouldBeSuccess + spago [ "install", "--test-deps", "newtype" ] >>= shouldBeSuccess + FS.writeTextFile (Path.concat [ "test", "Test", "Main.purs" ]) $ Array.intercalate "\n" + [ "module Test.Main where" + , "import Prelude" + , "import Effect as Effect" + , "import Effect.Console as Console" + , "main = unit" + ] + -- get rid of "Compiling ..." messages and other compiler warnings + spago [ "build" ] >>= shouldBeSuccess + + Spec.it "passing --pedantic-packages CLI flag" \{ spago, fixture } -> do + setupTestUnusedDeps spago + spago [ "build", "--pedantic-packages" ] >>= shouldBeFailureErr (fixture "check-unused-test-dependency.txt") + + Spec.it "package's test config has 'pedantic_packages: true'" \{ spago, fixture } -> do + setupTestUnusedDeps spago + addPedanticPackagesToTest + spago [ "build" ] >>= shouldBeFailureErr (fixture "check-unused-test-dependency.txt") {- Goal: