Skip to content

Add debug; add a test #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/node_modules/
/output/
package-lock.json
test/actual_output.txt
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Breaking changes:

New features:

- Added `debug` (#36)

Bugfixes:

Other improvements:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict"
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "npm run build && ./scripts/test"
},
"devDependencies": {
"eslint": "^7.15.0",
Expand Down
5 changes: 5 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e

pulp build -I test
node --input-type=module -e 'import { main } from "./output/Test.Main/index.js"; main();' > test/actual_output.txt 2>&1
diff -u test/expected_output.txt test/actual_output.txt
6 changes: 6 additions & 0 deletions src/Effect/Class/Console.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ info = liftEffect <<< EffConsole.info
infoShow :: forall m a. MonadEffect m => Show a => a -> m Unit
infoShow = liftEffect <<< EffConsole.infoShow

debug :: forall m. MonadEffect m => String -> m Unit
debug = liftEffect <<< EffConsole.debug

debugShow :: forall m a. MonadEffect m => Show a => a -> m Unit
debugShow = liftEffect <<< EffConsole.debugShow

time :: forall m. MonadEffect m => String -> m Unit
time = liftEffect <<< EffConsole.time

Expand Down
6 changes: 6 additions & 0 deletions src/Effect/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export const info = function (s) {
};
};

export const debug = function (s) {
return function () {
console.debug(s);
};
};

export const time = function (s) {
return function () {
console.time(s);
Expand Down
10 changes: 10 additions & 0 deletions src/Effect/Console.purs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ foreign import info
infoShow :: forall a. Show a => a -> Effect Unit
infoShow a = info (show a)

-- | Write an debug message to the console.
foreign import debug
:: String
-> Effect Unit

-- | Write an debug value to the console, using its `Show` instance to produce a
-- | `String`.
debugShow :: forall a. Show a => a -> Effect Unit
debugShow a = debug (show a)

-- | Start a named timer.
foreign import time :: String -> Effect Unit

Expand Down
14 changes: 14 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Test.Main where

import Prelude

import Effect (Effect)
import Effect.Class.Console as Console

main :: Effect Unit
main = do
Console.log "log"
Console.warn "warn"
Console.error "error"
Console.info "info"
Console.debug "debug"
5 changes: 5 additions & 0 deletions test/expected_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
log
warn
error
info
debug