From eab2f6ba6b76346e400158d9b996e20f0bbb3dee Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 17 May 2019 13:42:19 -0400 Subject: [PATCH 1/5] Update tutorial.md --- docs/tutorial.md | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/docs/tutorial.md b/docs/tutorial.md index d3d33df..b5f90c3 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -54,18 +54,49 @@ git commit -m "added empty file" git push origin dev-echo ## Again this will be different for you ``` -After filling out the file, add it again, commit, and push it. Then you can open a pull request to merge with `wasmos/ash` branch. Make sure that in your pull request you include `fixes #issueNumber`, a handy drop down will help you find the right one after you type `#`. -Then open another issue to write tests for echo. Checkout `packages/ash/assembly/__tests__/echo.spec.ts` as a place to start. To test your AssemblyScript run `npx asp` +Next write tests for echo. Copy `packages/ash/assembly/__tests__/echo.spec.ts` to a new file with the name of your program. + +Now go ahead and also commit and push this as well. + +## Making a Pull Request +Once you have your initial commit to your development branch you can open a pull request, which starts the process of merging this branch with in this case `wasmos/ash`. This doesn't mean that the branch has to completely ready for merge, just that you intend of merging it. It also allows others, like me, to look at it and even colloborate with you on it. + +To get started make sure your pushed your branch, then head over to your fork of the repo, "https://github.com/githubusername/wasmos" and you should see above the contents a green button that asks if you want to open a pull request with the new branch you made. If this is not the case then just head over to the [main repo](https://github.com/WebAssemblyOS/wasmos) and click on Pull Requests above the contents (not the very top). + +Next it will ask you which branch to merge with pick `wasmos/ash`. Give it the name of your program and in the comment section include `fixes #YourIssueNumber`, a handy drop down will help you find the right one after you type `#`. If there are any conflict errors it's okay to still create the pull request as once you make it I can help correct it. + + +## Running tests + +To test your AssemblyScript run `npx asp -f "filename regex"`, e.g. `npx asp -f echo` would run just `echo.spec.ts` or any test with echo in the name. If this doesn't work try running `npm clean-install`, which will make sure you're using the latest verson of the testing framework, `as-pect`. + ## Other things to know -To access the file system there is a global that your file named `fs`, however, it is important that you include this in your tests, which defines it as the mock. This shouldn't be an issue if you copied `echo.spec.ts`. +To access the file system there is a global named `fs`. -`fs.open(path: string): fd` this returns a file descriptor, which is a 32 bit unsigned integer. It is the identifer a FileDescriptor class, which you can access by using `fs.get(fd: fd): FileDescriptor`. However, this is only for the mock so the "proper" api to pass it when reading or writing to the file. +`fs.openFile(path: string): fd` this returns a `WasiResult` , which either failed or contains the resulting file descriptor class. -e.g. ```ts -fs.writeString(fd: fd, str: string): void +let res = fs.openFile("/hello"); +if (res.failed){ + Console.Error(result.error.toString()) //prints the error code + return; +} +let file = res.result; //Now have access to the FileDescriptor + +``` +A FileDescriptor is a reference to a file and an offset. This means if you can have two FileDescriptor's open for the same file. Then each time you read or write to the file you move the offset or "seek". +```ts +file.writeString("Hello World\n"); //Writes a line to the file, which moves the file offset + +file.reset() // uses file.seek to move file offset to 0. +let line = file.readLine(); // Returns a WasiResult as the read could have fail, e.g. at end of file. +let hello = line.result; //Access the string. ``` -A FileDescriptor is a new reference to the file and an offset. This means if you can have two FileDescriptor's open for the same file. Then each time you read or write to the file you move the offset or "seek". + +To see the complete interface look at [types/wasa/index.d.ts](https://github.com/WebAssemblyOS/wasmos/blob/master/types/wasa/index.d.ts). + +Your test can import a premade file descriptor for stdout, stderr, and stdin is `packages/ash/assembly/__tests__/fixtures.ts`. This is handy because when print to stdout using `Console.write` or `Console.log`, Console has it's own file descriptor which updates it's offset after each write, whereas `stdout` will still point to the beginning of the file. + From 2805885087c97252dacc4bf8045eb459478fa9c5 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 17 May 2019 13:45:13 -0400 Subject: [PATCH 2/5] Update tutorial.md --- docs/tutorial.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/tutorial.md b/docs/tutorial.md index b5f90c3..f70cf8c 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -37,8 +37,9 @@ If you have fastforwarded to the new HEAD from the main repo, you should do `git ## Making a new branch For this tutorial, I'll be implementing `echo.ts`, which will be in the `packages/ash/assembly/bin` -Now that you are caught up, you need to make a new branch for what task you are working on. If you haven't already pick one from [here](https://github.com/WebAssemblyOS/wasmos/issues/19) to work on and make an issue [here](https://github.com/WebAssemblyOS/wasmos/issues). -For example, +Now that you are caught up, you need to make a new branch for what task you are working on. If you haven't already pick one from [here](https://github.com/WebAssemblyOS/wasmos/issues/19) to work on and make an issue [here](https://github.com/WebAssemblyOS/wasmos/issues) that references the first issue, e.g. "see #19" this will create a link in #19 that points to the new issue, this way you can look at #19 to see which ones have been taken. + +Next: ``` git checkout -b dev-echo # this creates and switches to the new branch From da7f0bec89889122a88753a2cbb986e86f67cb15 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 17 May 2019 13:51:27 -0400 Subject: [PATCH 3/5] Update tutorial.md --- docs/tutorial.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/tutorial.md b/docs/tutorial.md index f70cf8c..ab909b7 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -72,6 +72,7 @@ Next it will ask you which branch to merge with pick `wasmos/ash`. Give it the To test your AssemblyScript run `npx asp -f "filename regex"`, e.g. `npx asp -f echo` would run just `echo.spec.ts` or any test with echo in the name. If this doesn't work try running `npm clean-install`, which will make sure you're using the latest verson of the testing framework, `as-pect`. +You can use `as-pect`'s build in print function using `log("hello world")`. It's very handy and can be used in your program. If you need to print something other than a string you have to provide the type, e.g. `log(42)`. ## Other things to know From ce655172d4e65942b45a48a6d2e62d1381ea6981 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 20 May 2019 11:25:01 -0400 Subject: [PATCH 4/5] fixed initialized flag --- packages/assemblyscript/assembly/wasa/mock/fs/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/assemblyscript/assembly/wasa/mock/fs/index.ts b/packages/assemblyscript/assembly/wasa/mock/fs/index.ts index 83f18dd..4f320a2 100644 --- a/packages/assemblyscript/assembly/wasa/mock/fs/index.ts +++ b/packages/assemblyscript/assembly/wasa/mock/fs/index.ts @@ -20,6 +20,7 @@ export class fs { static get fs(): FileSystem { if (!fs.initialized) { fs._fs.init(); + fs.initialized = true; } return fs._fs; } From 7e5ab0a20dd9b8ed5c36625cde82c751d545bbb0 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 20 May 2019 11:38:26 -0400 Subject: [PATCH 5/5] fix jsonfs test Now it has to manually initialize the fs --- packages/ash/assembly/__tests__/jsonfs.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ash/assembly/__tests__/jsonfs.spec.ts b/packages/ash/assembly/__tests__/jsonfs.spec.ts index 45525e7..5e39ba2 100644 --- a/packages/ash/assembly/__tests__/jsonfs.spec.ts +++ b/packages/ash/assembly/__tests__/jsonfs.spec.ts @@ -8,6 +8,7 @@ describe("fs from JSON", (): void => { beforeEach(() => { fs.fs = new FileSystem(); + fs.fs.init(); });