Skip to content
This repository has been archived by the owner on Feb 14, 2025. It is now read-only.

Commit

Permalink
updated rattler build recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
thatstoasty committed Aug 30, 2024
1 parent 99f31da commit 9c2179c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@ cython_debug/

# magic environments
.magic

# Rattler
output
39 changes: 39 additions & 0 deletions recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

context:
version: "13.4.2"

package:
name: "gojo"
version: 0.1.0

source:
- path: ./src

build:
script:
- mkdir -p ${PREFIX}/lib/mojo
- mojo package gojo -o ${PREFIX}/lib/mojo/gojo.mojopkg

tests:
- script:
# commands to run to test the package. If any of the commands
# returns with an error code, the test is considered failed.
- mojo package info/recipe/src/gojo -o info/recipe/test/gojo.mojopkg
- mojo test info/recipe/test/

# requirements:
# run:
# - mojo

files:
# Extra files to be copied to the test directory from the "work directory"
source:
- test/**/*

about:
homepage: https://github.com/thatstoasty/gojo
license: MIT
license_file: LICENSE
summary: Experiments in porting over Golang stdlib into Mojo.
repository: https://github.com/thatstoasty/gojo
4 changes: 3 additions & 1 deletion test/test_bufio_scanner.mojo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import testing
import pathlib
from gojo.bytes import buffer
from gojo.io import FileWrapper
from gojo.bufio import Reader, Scanner, scan_words, scan_bytes, scan_runes
Expand Down Expand Up @@ -102,7 +103,8 @@ def test_scan_bytes():

def test_file_wrapper_scanner():
# var test = MojoTest("testing io.FileWrapper and bufio.Scanner")
var file = FileWrapper("test/data/test_multiple_lines.txt", "r")
var test_file = str(pathlib._dir_of_current_file()) + "/data/test_multiple_lines.txt"
var file = FileWrapper(test_file, "r")

# Create a scanner from the reader
var scanner = Scanner(file^)
Expand Down
22 changes: 14 additions & 8 deletions test/test_file.mojo
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
from gojo.io import read_all, FileWrapper
from gojo.builtins.bytes import to_string
import pathlib
import testing


def test_read():
# var test = MojoTest("Testing FileWrapper.read")
var file = FileWrapper("test/data/test.txt", "r")
var test_file = str(pathlib._dir_of_current_file()) + "/data/test.txt"
var file = FileWrapper(test_file, "r")
var dest = List[UInt8, True](capacity=16)
_ = file.read(dest)
testing.assert_equal(to_string(dest), "12345\n")


def test_read_all():
# var test = MojoTest("Testing FileWrapper.read_all")
var file = FileWrapper("test/data/test_big_file.txt", "r")
var test_file = str(pathlib._dir_of_current_file()) + "/data/test_big_file.txt"
var file = FileWrapper(test_file, "r")
var result = file.read_all()
var bytes = result[0]
testing.assert_equal(len(bytes), 15359)
bytes.append(0)

with open("test/data/test_big_file.txt", "r") as f:
with open(test_file, "r") as f:
var expected = f.read()
testing.assert_equal(String(bytes), expected)


def test_io_read_all():
# var test = MojoTest("Testing io.read_all with FileWrapper")
var file = FileWrapper("test/data/test_big_file.txt", "r")
var test_file = str(pathlib._dir_of_current_file()) + "/data/test_big_file.txt"
var file = FileWrapper(test_file, "r")
var result = read_all(file)
var bytes = result[0]
testing.assert_equal(len(bytes), 15359)
bytes.append(0)

with open("test/data/test_big_file.txt", "r") as f:
with open(test_file, "r") as f:
var expected = f.read()
testing.assert_equal(String(bytes), expected)


def test_read_byte():
# var test = MojoTest("Testing FileWrapper.read_byte")
var file = FileWrapper("test/data/test.txt", "r")
var test_file = str(pathlib._dir_of_current_file()) + "/data/test.txt"
var file = FileWrapper(test_file, "r")
testing.assert_equal(int(file.read_byte()[0]), 49)


def test_write():
# var test = MojoTest("Testing FileWrapper.write")
var file = FileWrapper("test/data/test_write.txt", "w")
var test_file = str(pathlib._dir_of_current_file()) + "/data/test_write.txt"
var file = FileWrapper(test_file, "w")
var content = "12345"
var bytes_written = file.write(content.as_bytes_slice())
testing.assert_equal(bytes_written[0], 5)

with open("test/data/test_write.txt", "r") as f:
with open(test_file, "r") as f:
var expected = f.read()
testing.assert_equal(content, expected)

0 comments on commit 9c2179c

Please sign in to comment.