Skip to content

Commit c9de2e8

Browse files
committed
Tests: add testing Dockerfile. Impl fixes.
- tests/docker/Dockerfile: specifies full docker image containing all tools/languages (except matlab). - tests/docker-build.sh: build above image. - tests/docker-run.sh: launch above image. Example: ./tests/docker-run.sh make test^js^step2 - Various fixes across multiple languages: - Unicode fixes for bash and R on Ubuntu Utopic - readline history fixes for when ~/.mal-history is not available or readable/writable. No fatal errors. - fixes to work with perl 5.20 (and still perl 5.18)
1 parent 8569b2a commit c9de2e8

31 files changed

+259
-56
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ haskell/*.hi
4848
haskell/*.o
4949
lua/lib
5050
lua/linenoise.so
51+
nim/nimcache
52+
.lein
53+
.m2
54+
.ivy2
55+
.sbt

bash/printer.sh

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ _raw_string_pr_str () {
3838
local print_readably="${2}"
3939
if [[ "${s:0:1}" = "${__keyw}" ]]; then
4040
r=":${s:1}"
41+
elif [[ "${s:0:2}" = "${__keyw}" ]]; then
42+
r=":${s:2}"
4143
elif [ "${print_readably}" == "yes" ]; then
4244
s="${s//\\/\\\\}"
4345
r="\"${s//\"/\\\"}\""

bash/reader.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ READ_STR () {
149149
READLINE_EOF=
150150
READLINE_HISTORY_FILE=${HOME}/.mal-history
151151
READLINE () {
152-
history -r "${READLINE_HISTORY_FILE}"
152+
history -r "${READLINE_HISTORY_FILE}" 2>/dev/null || true
153153
read -r -e -p "${1}" r || return "$?"
154154
history -s -- "${r}"
155-
history -a "${READLINE_HISTORY_FILE}"
155+
history -a "${READLINE_HISTORY_FILE}" 2>/dev/null || true
156156
}
157157

158158
fi

bash/types.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ __mal_types_included=true
88
declare -A ANON
99

1010
__obj_magic=__5bal7
11-
__keyw=$(echo -en "\u029e")
11+
__keyw=$(echo -en "\xCA\x9E") # \u029E
1212
__obj_hash_code=${__obj_hash_code:-0}
1313

1414
__new_obj_hash_code () {

c/readline.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ int append_to_history() {
4545
#else
4646
HIST_ENTRY *he = history_get(history_length-1);
4747
FILE *fp = fopen(hf, "a");
48-
fprintf(fp, "%s\n", he->line);
49-
fclose(fp);
48+
if (fp) {
49+
fprintf(fp, "%s\n", he->line);
50+
fclose(fp);
51+
}
5052
#endif
5153
free(hf);
5254
}

clojure/src/readline.clj

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns readline
22
(:require [clojure.string :refer [split]]
3+
[clojure.java.io :refer [file]]
34
[net.n01se.clojure-jna :as jna]))
45

56
(defonce history-loaded (atom nil))
@@ -29,9 +30,11 @@
2930
(defn readline [prompt & [lib]]
3031
(when (not @history-loaded)
3132
(reset! history-loaded true)
32-
(load-history HISTORY-FILE))
33+
(when (.canRead (file HISTORY-FILE))
34+
(load-history HISTORY-FILE)))
3335
(let [line (readline-call prompt)]
3436
(when line
3537
(add-history line)
36-
(spit HISTORY-FILE (str line "\n") :append true))
38+
(when (.canWrite (file HISTORY-FILE))
39+
(spit HISTORY-FILE (str line "\n") :append true)))
3740
line))

coffee/node_readline.coffee

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ exports.readline = rlwrap.readline = (prompt = 'user> ') ->
2929
line = rllib.readline prompt
3030
if line
3131
rllib.add_history line
32-
fs.appendFileSync HISTORY_FILE, line + "\n"
32+
try
33+
fs.appendFileSync HISTORY_FILE, line + "\n"
34+
catch exc
35+
true
3336

3437
line
3538

haskell/Readline.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@ import qualified System.Console.Readline as RL
88
-- BSD license
99
--import qualified System.Console.Editline.Readline as RL
1010

11-
import System.Directory (getHomeDirectory)
11+
import Control.Monad (when)
12+
import System.Directory (getHomeDirectory, doesFileExist)
1213

1314
import System.IO (hGetLine, hFlush, hIsEOF, stdin, stdout)
15+
import System.IO.Error (tryIOError)
1416

1517
history_file = do
1618
home <- getHomeDirectory
1719
return $ home ++ "/.mal-history"
1820

1921
load_history = do
2022
hfile <- history_file
21-
content <- readFile hfile
22-
mapM RL.addHistory (lines content)
23+
fileExists <- doesFileExist hfile
24+
when fileExists $ do
25+
content <- readFile hfile
26+
mapM RL.addHistory (lines content)
27+
return ()
28+
return ()
2329

2430
readline prompt = do
2531
hfile <- history_file
2632
maybeLine <- RL.readline prompt
2733
case maybeLine of
2834
Just line -> do
29-
appendFile hfile (line ++ "\n")
3035
RL.addHistory line
36+
res <- tryIOError (appendFile hfile (line ++ "\n"))
3137
return maybeLine
3238
_ -> return maybeLine

js/node_readline.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ exports.readline = rlwrap.readline = function(prompt) {
3434
var line = rllib.readline(prompt);
3535
if (line) {
3636
rllib.add_history(line);
37-
fs.appendFileSync(HISTORY_FILE, line + "\n");
37+
try {
38+
fs.appendFileSync(HISTORY_FILE, line + "\n");
39+
} catch (exc) {
40+
// ignored
41+
}
3842
}
3943

4044
return line;

lua/readline.lua

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ M.raw = false
1010
function M.readline(prompt)
1111
if not history_loaded then
1212
history_loaded = true
13-
for line in io.lines(history_file) do
14-
LN.historyadd(line)
15-
end
13+
xpcall(function()
14+
for line in io.lines(history_file) do
15+
LN.historyadd(line)
16+
end
17+
end, function(exc)
18+
return true -- ignore the error
19+
end)
1620
end
1721

1822
if M.raw then
@@ -23,9 +27,13 @@ function M.readline(prompt)
2327
end
2428
if line then
2529
LN.historyadd(line)
26-
local f = io.open(history_file, "a")
27-
f:write(line.."\n")
28-
f:close()
30+
xpcall(function()
31+
local f = io.open(history_file, "a")
32+
f:write(line.."\n")
33+
f:close()
34+
end, function(exc)
35+
return true -- ignore the error
36+
end)
2937
end
3038
return line
3139
end

make/readline.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ __mal_readline_included := true
1010
# have readline history.
1111
READLINE_EOF :=
1212
READLINE_HISTORY_FILE := $${HOME}/.mal-history
13-
READLINE = $(eval __readline_temp := $(shell history -r $(READLINE_HISTORY_FILE); read -u 0 -r -e -p $(if $(1),$(1),"user> ") line && history -s -- "$${line}" && history -a $(READLINE_HISTORY_FILE) && echo "$${line}" || echo "__||EOF||__"))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))
13+
READLINE = $(eval __readline_temp := $(shell history -r $(READLINE_HISTORY_FILE); read -u 0 -r -e -p $(if $(1),$(1),"user> ") line && history -s -- "$${line}" && echo "$${line}" || echo "__||EOF||__"; history -a $(READLINE_HISTORY_FILE) 2>/dev/null || true))$(if $(filter __||EOF||__,$(__readline_temp)),$(eval READLINE_EOF := yes),$(__readline_temp))
1414

1515
endif

perl/printer.pm

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ sub _pr_str {
2222
}
2323
when(/^HashMap/) {
2424
my @elems = ();
25-
foreach my $key (keys $obj->{val}) {
25+
26+
foreach my $key (keys %{ $obj->{val} }) {
2627
push(@elems, _pr_str(String->new($key), $_r));
2728
push(@elems, _pr_str($obj->{val}->{$key}, $_r));
2829
}

perl/step2_eval.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sub eval_ast {
3838
}
3939
when (/^HashMap/) {
4040
my $new_hm = {};
41-
foreach my $k (keys($ast->{val})) {
41+
foreach my $k (keys( %{ $ast->{val} })) {
4242
$new_hm->{$k} = EVAL($ast->get($k), $env);
4343
}
4444
return HashMap->new($new_hm);

perl/step3_env.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ sub eval_ast {
3535
}
3636
when (/^HashMap/) {
3737
my $new_hm = {};
38-
foreach my $k (keys($ast->{val})) {
38+
foreach my $k (keys( %{ $ast->{val} })) {
3939
$new_hm->{$k} = EVAL($ast->get($k), $env);
4040
}
4141
return HashMap->new($new_hm);

perl/step4_if_fn_do.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sub eval_ast {
3636
}
3737
when (/^HashMap/) {
3838
my $new_hm = {};
39-
foreach my $k (keys($ast->{val})) {
39+
foreach my $k (keys( %{ $ast->{val} })) {
4040
$new_hm->{$k} = EVAL($ast->get($k), $env);
4141
}
4242
return HashMap->new($new_hm);

perl/step5_tco.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sub eval_ast {
3636
}
3737
when (/^HashMap/) {
3838
my $new_hm = {};
39-
foreach my $k (keys($ast->{val})) {
39+
foreach my $k (keys( %{ $ast->{val} })) {
4040
$new_hm->{$k} = EVAL($ast->get($k), $env);
4141
}
4242
return HashMap->new($new_hm);

perl/step6_file.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ sub eval_ast {
3636
}
3737
when (/^HashMap/) {
3838
my $new_hm = {};
39-
foreach my $k (keys($ast->{val})) {
39+
foreach my $k (keys( %{ $ast->{val} })) {
4040
$new_hm->{$k} = EVAL($ast->get($k), $env);
4141
}
4242
return HashMap->new($new_hm);

perl/step7_quote.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ sub eval_ast {
5959
}
6060
when (/^HashMap/) {
6161
my $new_hm = {};
62-
foreach my $k (keys($ast->{val})) {
62+
foreach my $k (keys( %{ $ast->{val} })) {
6363
$new_hm->{$k} = EVAL($ast->get($k), $env);
6464
}
6565
return HashMap->new($new_hm);

perl/step8_macros.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ sub eval_ast {
8282
}
8383
when (/^HashMap/) {
8484
my $new_hm = {};
85-
foreach my $k (keys($ast->{val})) {
85+
foreach my $k (keys( %{ $ast->{val} })) {
8686
$new_hm->{$k} = EVAL($ast->get($k), $env);
8787
}
8888
return HashMap->new($new_hm);

perl/step9_try.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ sub eval_ast {
8383
}
8484
when (/^HashMap/) {
8585
my $new_hm = {};
86-
foreach my $k (keys($ast->{val})) {
86+
foreach my $k (keys( %{ $ast->{val} })) {
8787
$new_hm->{$k} = EVAL($ast->get($k), $env);
8888
}
8989
return HashMap->new($new_hm);

perl/stepA_mal.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ sub eval_ast {
8383
}
8484
when (/^HashMap/) {
8585
my $new_hm = {};
86-
foreach my $k (keys($ast->{val})) {
86+
foreach my $k (keys( %{ $ast->{val} })) {
8787
$new_hm->{$k} = EVAL($ast->get($k), $env);
8888
}
8989
return HashMap->new($new_hm);

perl/types.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ sub _false_Q { return $_[0] eq $false }
102102

103103
{
104104
package Integer;
105-
sub new { my $class = shift; bless \$_[0] => $class }
105+
sub new { my $class = shift; bless \do { my $x=$_[0] }, $class }
106106
}
107107

108108

109109
{
110110
package Symbol;
111-
sub new { my $class = shift; bless \$_[0] => $class }
111+
sub new { my $class = shift; bless \do { my $x=$_[0] }, $class }
112112
}
113113
sub _symbol_Q { (ref $_[0]) =~ /^Symbol/ }
114114

php/readline.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ function mal_readline($prompt) {
99
// Load the history file
1010
if (! $history_loaded) {
1111
$history_loaded = true;
12-
if ($file = fopen($HISTORY_FILE, "r")) {
13-
while (!feof($file)) {
14-
$line = fgets($file);
15-
if ($line) { readline_add_history($line); }
12+
if (is_readable($HISTORY_FILE)) {
13+
if ($file = fopen($HISTORY_FILE, "r")) {
14+
while (!feof($file)) {
15+
$line = fgets($file);
16+
if ($line) { readline_add_history($line); }
17+
}
18+
fclose($file);
1619
}
17-
fclose($file);
1820
}
1921
}
2022

@@ -23,9 +25,11 @@ function mal_readline($prompt) {
2325
readline_add_history($line);
2426

2527
// Append to the history file
26-
if ($file = fopen($HISTORY_FILE, "a")) {
27-
fputs($file, $line . "\n");
28-
fclose($file);
28+
if (is_writable($HISTORY_FILE)) {
29+
if ($file = fopen($HISTORY_FILE, "a")) {
30+
fputs($file, $line . "\n");
31+
fclose($file);
32+
}
2933
}
3034

3135
return $line;

python/mal_readline.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def readline(prompt="user> "):
2525
pyreadline.add_history(line)
2626
with open(histfile, "a") as hf:
2727
hf.write(line + "\n")
28-
return line
28+
except IOError:
29+
pass
2930
except EOFError:
3031
return None
32+
return line

r/printer.r

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ if(!exists("..types..")) source("types.r")
2929
"character"={
3030
if (substring(exp,1,1) == "\u029e") {
3131
concat(":", substring(exp,2))
32+
} else if (substring(exp,1,8) == "<U+029E>") {
33+
# terrible hack, appears in 3.1.1 on Utopic
34+
concat(":", substring(exp,9))
3235
} else if (print_readably) {
3336
paste("\"",
3437
gsub("\\n", "\\\\n",

r/readline.r

+8-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@ readline <- function(prompt) {
2525
if (!.state$rl_history_loaded) {
2626
.state$rl_history_loaded <- TRUE
2727

28-
lines <- scan(HISTORY_FILE, what="", sep="\n", quiet=TRUE)
29-
for(add_line in lines) {
30-
.dyncall(.call_add_history, "Z)v", add_line)
28+
if (file.access(HISTORY_FILE, 4) == 0) {
29+
lines <- scan(HISTORY_FILE, what="", sep="\n", quiet=TRUE)
30+
for(add_line in lines) {
31+
.dyncall(.call_add_history, "Z)v", add_line)
32+
}
3133
}
3234
}
3335

3436
line <- .readline(prompt)
3537
if (is.null(line)) return(NULL)
3638
.dyncall(.call_add_history, "Z)v", line)
37-
write(line, file=HISTORY_FILE, append=TRUE)
39+
if (file.access(HISTORY_FILE, 2) == 0) {
40+
write(line, file=HISTORY_FILE, append=TRUE)
41+
}
3842

3943
line
4044
}

racket/readline.rkt

+13-9
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
(define HISTORY-FILE (format "~a/.mal-history" (find-system-path 'home-dir)))
1111

1212
(define (load-history path)
13-
(map
14-
(lambda (line) (readline:add-history line))
15-
(string-split
16-
(port->string (open-input-file path))
17-
#px"\n")))
13+
(with-handlers
14+
([exn:fail? (lambda (e) #t)])
15+
(map
16+
(lambda (line) (readline:add-history line))
17+
(string-split
18+
(port->string (open-input-file path))
19+
#px"\n"))))
1820

1921
(define (readline prompt)
2022
(when (not history-loaded)
@@ -25,8 +27,10 @@
2527
nil
2628
(begin
2729
(readline:add-history line)
28-
(with-output-to-file
29-
HISTORY-FILE
30-
(lambda () (printf "~a~n" line))
31-
#:exists 'append)
30+
(with-handlers
31+
([exn:fail? (lambda (e) #t)])
32+
(with-output-to-file
33+
HISTORY-FILE
34+
(lambda () (printf "~a~n" line))
35+
#:exists 'append))
3236
line))))

0 commit comments

Comments
 (0)