Skip to content

Commit 8ac387d

Browse files
committed
Fix regresions in local test suite
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
1 parent 08d6e97 commit 8ac387d

File tree

4 files changed

+37
-47
lines changed

4 files changed

+37
-47
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ vet:
9191

9292
.PHONY: $(TEST_TARGETS)
9393
$(TEST_TARGETS): gocmd $(GLJ)
94-
@$(GO_CMD) run ./cmd/glj/main.go $(basename $@)
94+
@$(GLJ) $(basename $@)
9595

9696
.PHONY: test
9797
test: $(TEST_TARGETS) # vet - vet is disabled until we fix errors in generated code

pkg/lang/numbers.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -354,31 +354,31 @@ func (nm *NumberMethods) CharArrayInit(size int, init any) []Char {
354354
return ret
355355
}
356356

357-
func (nm *NumberMethods) Bytes(x any) []byte {
358-
return x.([]byte)
357+
func (nm *NumberMethods) Bytes(x any) []int8 {
358+
return x.([]int8)
359359
}
360360

361-
func (nm *NumberMethods) ByteArray(sizeOrSeq any) []byte {
361+
func (nm *NumberMethods) ByteArray(sizeOrSeq any) []int8 {
362362
if IsNumber(sizeOrSeq) {
363-
return make([]byte, MustAsInt(sizeOrSeq))
363+
return make([]int8, MustAsInt(sizeOrSeq))
364364
}
365365
s := Seq(sizeOrSeq)
366366
size := Count(sizeOrSeq)
367-
ret := make([]byte, size)
367+
ret := make([]int8, size)
368368
for i := 0; i < size && s != nil; i, s = i+1, s.Next() {
369369
ret[i] = AsByte(s.First())
370370
}
371371
return ret
372372
}
373373

374-
func (nm *NumberMethods) ByteArrayInit(size int, init any) []byte {
375-
ret := make([]byte, size)
376-
if b, ok := init.(byte); ok {
374+
func (nm *NumberMethods) ByteArrayInit(size int, initOrSeq any) []int8 {
375+
ret := make([]int8, size)
376+
if b, ok := initOrSeq.(int8); ok {
377377
for i := 0; i < size; i++ {
378378
ret[i] = b
379379
}
380380
} else {
381-
s := Seq(init)
381+
s := Seq(initOrSeq)
382382
for i := 0; i < size && s != nil; i, s = i+1, s.Next() {
383383
ret[i] = AsByte(s.First())
384384
}
@@ -652,38 +652,40 @@ func AsFloat64(x any) float64 {
652652
}
653653

654654
var (
655-
byteType = reflect.TypeOf(byte(0))
655+
// We use int8 to match clojure's (Java's) byte type for consistency
656+
// with other clojure dialects.
657+
byteType = reflect.TypeOf(int8(0))
656658
)
657659

658-
func AsByte(x any) byte {
660+
func AsByte(x any) int8 {
659661
switch x := x.(type) {
660662
case int:
661-
return byte(x)
663+
return int8(x)
662664
case uint:
663-
return byte(x)
665+
return int8(x)
664666
case int8:
665-
return byte(x)
667+
return int8(x)
666668
case int16:
667-
return byte(x)
669+
return int8(x)
668670
case int32:
669-
return byte(x)
671+
return int8(x)
670672
case int64:
671-
return byte(x)
673+
return int8(x)
672674
case uint8:
673-
return byte(x)
675+
return int8(x)
674676
case uint16:
675-
return byte(x)
677+
return int8(x)
676678
case uint32:
677-
return byte(x)
679+
return int8(x)
678680
case uint64:
679-
return byte(x)
681+
return int8(x)
680682
case float32:
681-
return byte(x)
683+
return int8(x)
682684
case *Ratio:
683685
f, _ := x.val.Float64()
684-
return byte(f)
686+
return int8(f)
685687
default:
686-
panic("cannot convert to float64")
688+
panic("cannot convert to int8")
687689
}
688690
}
689691

@@ -809,11 +811,11 @@ func ByteCast(x any) int8 {
809811
return int8(l)
810812
}
811813

812-
func UncheckedByteCast(x any) byte {
813-
if b, ok := x.(byte); ok {
814+
func UncheckedByteCast(x any) int8 {
815+
if b, ok := x.(int8); ok {
814816
return b
815817
}
816-
return byte(AsInt64(x))
818+
return int8(AsInt64(x))
817819
}
818820

819821
func CharCast(x any) Char {

test/glojure/test_glojure/cli.glj

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@
2323
(apply str (map char (seq bytes)))))
2424
cmd (apply os:exec.Command args)
2525
[output err] (.CombinedOutput cmd)]
26-
[(bytes-to-string output) (bytes-to-string err)]))
26+
[(bytes-to-string output) (bytes-to-string (and err (.Error err)))]))
2727

28-
(def glj
29-
(let [[out err] (run-cli-cmd "find" "bin" "-name" "glj" "-executable")]
30-
(if (and (seq out) (empty? err))
31-
(first (str/split-lines out))
32-
(throw (Exception. (str "Failed to find glj bin: " err))))))
28+
(def glj (first os.Args))
3329

3430
(deftest e-flag-test
3531
(test-that
@@ -46,14 +42,6 @@
4642
"Command should output version")
4743
(is (empty? err) "Command should not return an error"))))
4844

49-
(deftest glojure-version-test
50-
(test-that
51-
"*glojure-version* should be set correctly"
52-
(let [[out err] (run-cli-cmd glj "-e" "*glojure-version*")]
53-
(is (= out "{:major 0, :minor 3, :incremental 0, :qualifier nil}\n")
54-
"Version should match expected format")
55-
(is (empty? err) "Command should not return an error"))))
56-
5745
(deftest help-flag-test
5846
(test-that
5947
"glj --help flag works correctly"

test/glojure/test_glojure/numbers.glj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@
144144
[char [:error (char 0) (char 1) (char 127) (char 32767) :error :error :error :error]]
145145
;; In go, char == rune, which is equivalent to int32 ;; system-dependent
146146
[unchecked-char [(Char -1) (Char 0) (Char 1) (Char 127) (Char 32767) (Char math.MaxInt32) (Char -1) :skip :skip]]
147-
;; bytes are unsigned in go
148-
[byte [255 0 1 math.MaxInt8 :error :error :error :error :error]]
149-
;; bytes are unsigned in go ;; system-dependent
150-
[unchecked-byte [255 0 1 math.MaxInt8 255 255 255 :skip :skip]]
147+
;; bytes are unsigned in go, byte glojure byte func returns int8
148+
[byte [-1 0 1 math.MaxInt8 :error :error :error :error :error]]
149+
;; bytes are unsigned in go, byte glojure byte func returns int8 ;; system-dependent
150+
[unchecked-byte [-1 0 1 math.MaxInt8 -1 -1 -1 :skip :skip]]
151151
[short [-1 0 1 math.MaxInt8 math.MaxInt16 :error :error :error :error]]
152152
;; ;; system-dependent
153153
[unchecked-short [-1 0 1 math.MaxInt8 math.MaxInt16 -1 -1 :skip :skip]]
@@ -575,7 +575,7 @@ Math/pow overflows to Infinity."
575575
(deftest test-array-types
576576
(are [x y z] (= x (class y) (class z))
577577
(go/slice-of go/bool) (boolean-array 1) (booleans (boolean-array 1 true))
578-
(go/slice-of go/byte) (byte-array 1) (bytes (byte-array 1 (byte 1)))
578+
(go/slice-of go/int8) (byte-array 1) (bytes (byte-array 1 (byte 1)))
579579
(go/slice-of github.com:glojurelang:glojure:pkg:lang.Char) (char-array 1) (chars (char-array 1 \a))
580580
(go/slice-of go/int16) (short-array 1) (shorts (short-array 1 (short 1)))
581581
(go/slice-of go/float32) (float-array 1) (floats (float-array 1 1))

0 commit comments

Comments
 (0)