diff --git a/.gitignore b/.gitignore index 39ac6c3da..2d0b3cec3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ # editor related .idea/ + +# macOS related +.DS_Store diff --git a/waspc/.gitignore b/waspc/.gitignore index eab48d824..f0b0addec 100644 --- a/waspc/.gitignore +++ b/waspc/.gitignore @@ -13,3 +13,6 @@ module-graph.png .dir-locals.el .projectile .vscode + +# macOS related +.DS_Store diff --git a/waspc/README.md b/waspc/README.md index c4e43f131..06c5142cf 100644 --- a/waspc/README.md +++ b/waspc/README.md @@ -103,7 +103,7 @@ NOTE: Reload page if blank. 1. Create a new feature branch from `main`. 2. If you don't have a good/reliable working HLS (Haskell Language Server) in your IDE, you will want to instead run `./run ghcid` from the root of the project instead: this will run a process that watches the Haskell project and reports any Haskell compiler errors. Leave it running. NOTE: You will need to install `ghcid` globally first. You can do it with `cabal install ghcid`. -3. Do a change in the codebase (most often in `lib/` or `cli/` or `data/`) (together with tests if that makes sense: see "Tests"). +3. Do a change in the codebase (most often in `src/` or `cli/src/` or `data/`) (together with tests if that makes sense: see "Tests"). Fix any errors shown by HLS/`ghcid`. Rinse and repeat. 4. Once close to done, run `cabal test` to confirm that the project's tests are passing (both new and old). @@ -138,7 +138,7 @@ Others will comment on your design doc, and once it has gone through needed iter ## Codebase overview Wasp is implemented in Haskell. -Codebase is split into library (`src/`) and CLI (`cli/`). +Codebase is split into library (`src/`) and CLI (which itself has a library `cli/src/` and thin executable wrapper `cli/exe/`). CLI is actually `wasp` executable, and it uses the library, where most of the logic is. Wasp compiler takes .wasp files + everything in the `ext/` dir (JS, HTML, ...) and generates a web app that consists of client, server and database. @@ -172,8 +172,9 @@ On any changes you do to the source code of Wasp, Wasp project gets recompiled, ## Important directories (in waspc/) - src/ -> main source code, library -- cli/ -> rest of the source code, cli, uses library -- test/ -> tests +- cli/src/ -> rest of the source code, cli, uses library +- cli/exe/ -> thin executable wrapper around cli library code +- test/, e2e-test/, cli/test/ -> tests - data/Generator/templates/ -> mustache templates for the generated client/server. - examples/ -> example apps @@ -244,6 +245,8 @@ Tests are run with `cabal test`. They include both unit tests, and end-to-end te To run unit tests only, you can do `cabal test waspc-test` (or `./run test:unit`). To run individual unit test, you can do `cabal test waspc-test --test-options "-p \"Some test description to match\""` (or just `./run test:unit "Some test description to match"`). +To run cli tests only, you can do `cabal test cli-test` (or `./run test:cli`). + To run end-to-end tests only, you can do `cabal test e2e-test` (or `/run test:e2e`). ## Code analysis diff --git a/waspc/cli/Main.hs b/waspc/cli/exe/Main.hs similarity index 99% rename from waspc/cli/Main.hs rename to waspc/cli/exe/Main.hs index 57e7eed84..690f17b8a 100644 --- a/waspc/cli/Main.hs +++ b/waspc/cli/exe/Main.hs @@ -7,7 +7,7 @@ import Control.Monad (void) import Data.Char (isSpace) import Data.Version (showVersion) import Paths_waspc (version) -import System.Environment +import System.Environment (getArgs) import Wasp.Cli.Command (runCommand) import Wasp.Cli.Command.BashCompletion (bashCompletion, generateBashCompletionScript, printBashCompletionInstruction) import Wasp.Cli.Command.Build (build) diff --git a/waspc/cli/Wasp/Cli/Command.hs b/waspc/cli/src/Wasp/Cli/Command.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command.hs rename to waspc/cli/src/Wasp/Cli/Command.hs diff --git a/waspc/cli/Wasp/Cli/Command/BashCompletion.hs b/waspc/cli/src/Wasp/Cli/Command/BashCompletion.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/BashCompletion.hs rename to waspc/cli/src/Wasp/Cli/Command/BashCompletion.hs diff --git a/waspc/cli/Wasp/Cli/Command/Build.hs b/waspc/cli/src/Wasp/Cli/Command/Build.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Build.hs rename to waspc/cli/src/Wasp/Cli/Command/Build.hs diff --git a/waspc/cli/Wasp/Cli/Command/Call.hs b/waspc/cli/src/Wasp/Cli/Command/Call.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Call.hs rename to waspc/cli/src/Wasp/Cli/Command/Call.hs diff --git a/waspc/cli/Wasp/Cli/Command/Clean.hs b/waspc/cli/src/Wasp/Cli/Command/Clean.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Clean.hs rename to waspc/cli/src/Wasp/Cli/Command/Clean.hs diff --git a/waspc/cli/Wasp/Cli/Command/Common.hs b/waspc/cli/src/Wasp/Cli/Command/Common.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Common.hs rename to waspc/cli/src/Wasp/Cli/Command/Common.hs diff --git a/waspc/cli/Wasp/Cli/Command/Compile.hs b/waspc/cli/src/Wasp/Cli/Command/Compile.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Compile.hs rename to waspc/cli/src/Wasp/Cli/Command/Compile.hs diff --git a/waspc/cli/Wasp/Cli/Command/CreateNewProject.hs b/waspc/cli/src/Wasp/Cli/Command/CreateNewProject.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/CreateNewProject.hs rename to waspc/cli/src/Wasp/Cli/Command/CreateNewProject.hs diff --git a/waspc/cli/Wasp/Cli/Command/Db.hs b/waspc/cli/src/Wasp/Cli/Command/Db.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Db.hs rename to waspc/cli/src/Wasp/Cli/Command/Db.hs diff --git a/waspc/cli/Wasp/Cli/Command/Db/Migrate.hs b/waspc/cli/src/Wasp/Cli/Command/Db/Migrate.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Db/Migrate.hs rename to waspc/cli/src/Wasp/Cli/Command/Db/Migrate.hs diff --git a/waspc/cli/Wasp/Cli/Command/Deps.hs b/waspc/cli/src/Wasp/Cli/Command/Deps.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Deps.hs rename to waspc/cli/src/Wasp/Cli/Command/Deps.hs diff --git a/waspc/cli/Wasp/Cli/Command/Info.hs b/waspc/cli/src/Wasp/Cli/Command/Info.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Info.hs rename to waspc/cli/src/Wasp/Cli/Command/Info.hs diff --git a/waspc/cli/Wasp/Cli/Command/Message.hs b/waspc/cli/src/Wasp/Cli/Command/Message.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Message.hs rename to waspc/cli/src/Wasp/Cli/Command/Message.hs diff --git a/waspc/cli/Wasp/Cli/Command/Start.hs b/waspc/cli/src/Wasp/Cli/Command/Start.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Start.hs rename to waspc/cli/src/Wasp/Cli/Command/Start.hs diff --git a/waspc/cli/Wasp/Cli/Command/Telemetry.hs b/waspc/cli/src/Wasp/Cli/Command/Telemetry.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Telemetry.hs rename to waspc/cli/src/Wasp/Cli/Command/Telemetry.hs diff --git a/waspc/cli/Wasp/Cli/Command/Telemetry/Common.hs b/waspc/cli/src/Wasp/Cli/Command/Telemetry/Common.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Telemetry/Common.hs rename to waspc/cli/src/Wasp/Cli/Command/Telemetry/Common.hs diff --git a/waspc/cli/Wasp/Cli/Command/Telemetry/Project.hs b/waspc/cli/src/Wasp/Cli/Command/Telemetry/Project.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Telemetry/Project.hs rename to waspc/cli/src/Wasp/Cli/Command/Telemetry/Project.hs diff --git a/waspc/cli/Wasp/Cli/Command/Telemetry/User.hs b/waspc/cli/src/Wasp/Cli/Command/Telemetry/User.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Telemetry/User.hs rename to waspc/cli/src/Wasp/Cli/Command/Telemetry/User.hs diff --git a/waspc/cli/Wasp/Cli/Command/Watch.hs b/waspc/cli/src/Wasp/Cli/Command/Watch.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Command/Watch.hs rename to waspc/cli/src/Wasp/Cli/Command/Watch.hs diff --git a/waspc/cli/Wasp/Cli/Common.hs b/waspc/cli/src/Wasp/Cli/Common.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Common.hs rename to waspc/cli/src/Wasp/Cli/Common.hs diff --git a/waspc/cli/Wasp/Cli/Message.hs b/waspc/cli/src/Wasp/Cli/Message.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Message.hs rename to waspc/cli/src/Wasp/Cli/Message.hs diff --git a/waspc/cli/Wasp/Cli/Terminal.hs b/waspc/cli/src/Wasp/Cli/Terminal.hs similarity index 100% rename from waspc/cli/Wasp/Cli/Terminal.hs rename to waspc/cli/src/Wasp/Cli/Terminal.hs diff --git a/waspc/cli/test/TastyDiscoverDriver.hs b/waspc/cli/test/TastyDiscoverDriver.hs new file mode 100644 index 000000000..fdf62984b --- /dev/null +++ b/waspc/cli/test/TastyDiscoverDriver.hs @@ -0,0 +1,5 @@ +{-# OPTIONS_GHC -F -pgmF tasty-discover -optF --modules=*Test.hs #-} + +-- -optF --modules=*Test.hs tells tasty-discover to pick up only files that match *Test.hs. +-- I did not do this for any strong reason so we can remove it in the future if we figure out +-- it is too restrictive. diff --git a/waspc/cli/test/TerminalTest.hs b/waspc/cli/test/TerminalTest.hs new file mode 100644 index 000000000..6f430ed89 --- /dev/null +++ b/waspc/cli/test/TerminalTest.hs @@ -0,0 +1,12 @@ +module TerminalTest where + +import Test.Tasty.Hspec +import Wasp.Cli.Terminal + ( asWaspMessage, + ) + +-- TODO: Showing it can be done. Remove me when writing first real CLI test. +spec_terminalMessages :: Spec +spec_terminalMessages = do + it "can format messages of various kinds" $ do + asWaspMessage "Hello, world!" `shouldBe` "\n --- Hello, world! ---------------------------------------------------------------\n" diff --git a/waspc/run b/waspc/run index 81baaf39b..dda167661 100755 --- a/waspc/run +++ b/waspc/run @@ -22,6 +22,7 @@ BUILD_CMD="cabal build all" BUILD_ALL_CMD="cabal build all --enable-tests --enable-benchmarks" TEST_CMD="cabal test" TEST_UNIT_CMD="cabal test waspc-test" +TEST_CLI_CMD="cabal test cli-test" TEST_E2E_CMD="cabal test e2e-test" RUN_CMD="cabal run wasp-cli ${ARGS[@]}" GHCID_CMD="ghcid --command=cabal repl" @@ -61,6 +62,8 @@ print_usage () { "Executes all tests (unit + e2e). Builds the project first if needed." print_usage_cmd "test:unit [pattern]" \ "Executes only unit tests. Builds the project first if needed. If pattern is provided, it will run only tests whose description/name matches the pattern. Check https://github.com/UnkindPartition/tasty#patterns to learn more about valid patterns." + print_usage_cmd "test:cli" \ + "Executes only cli unit tests. Builds the project first if needed." print_usage_cmd "test:e2e" \ "Executes only e2e tests. Builds the project first if needed." print_usage_cmd "wasp-cli " \ @@ -114,6 +117,9 @@ case $COMMAND in echo_and_eval "$TEST_UNIT_CMD --test-options \"-p \\\"$TEST_PATTERN\\\"\"" fi + ;; + test:cli) + echo_and_eval "$TEST_CLI_CMD" ;; test:e2e) echo_and_eval "$TEST_E2E_CMD" diff --git a/waspc/waspc.cabal b/waspc/waspc.cabal index d0a968d5b..b510c722d 100644 --- a/waspc/waspc.cabal +++ b/waspc/waspc.cabal @@ -238,11 +238,9 @@ library Wasp.Generator.NpmInstall Wasp.Message - -executable wasp-cli - import: common-all, common-exe - hs-source-dirs: cli - main-is: Main.hs +library cli-lib + import: common-all + hs-source-dirs: cli/src build-depends: directory , base @@ -261,7 +259,8 @@ executable wasp-cli , utf8-string , uuid , waspc - other-modules: + other-modules: Paths_waspc + exposed-modules: Wasp.Cli.Command Wasp.Cli.Command.BashCompletion Wasp.Cli.Command.Build @@ -284,6 +283,17 @@ executable wasp-cli Wasp.Cli.Terminal Wasp.Cli.Command.Message Wasp.Cli.Message + +executable wasp-cli + import: common-all, common-exe + hs-source-dirs: cli/exe + main-is: Main.hs + build-depends: + base + , async + , waspc + , cli-lib + other-modules: Paths_waspc test-suite waspc-test @@ -374,6 +384,26 @@ test-suite e2e-test Tests.WaspMigrateTest Tests.WaspNewTest +test-suite cli-test + import: common-all, common-exe + type: exitcode-stdio-1.0 + hs-source-dirs: cli/test + main-is: TastyDiscoverDriver.hs + build-tool-depends: + tasty-discover:tasty-discover + build-depends: + , base + , waspc + , cli-lib + , QuickCheck ^>= 2.14 + , tasty ^>= 1.4.2 + -- tasty-hspec 1.1.7 introduces breaking changes, which is why we have < 1.1.7 . + , tasty-hspec >= 1.1 && < 1.1.7 + , tasty-quickcheck ^>= 0.10 + other-modules: + TerminalTest + Paths_waspc + benchmark waspc-benchmarks import: common-all, common-exe type: exitcode-stdio-1.0