Skip to content

Commit

Permalink
Merge branch 'release/v0.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
cwd-k2 committed Jun 25, 2022
2 parents a52c746 + 6604432 commit bbc4e42
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
go.sum
.tmp
dist
titania-out
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.10.0] - 2022-06-26

### Added

- Option `--no-json`: do not print output json.

### Change

- Perf: Now titania.go doesn't hold input/output/code/... data.
- Hence, intermediate files should be always created now, and the default directory is `./titania-out`.

## [0.9.3] - 2021-06-24

### Added
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ The directories should contain `titania.json`, like below.
{ "pattern": "./source_code/main.*" },
{
"pattern": "./source_code/wrong_answer.rb",
"expect": { "default": "FAIL", "test_case/01": "PASS", "test_case/03": "EXECUTION TIMEOUT" }
"expect": {
"default": "FAIL",
"test_case/01": "PASS",
"test_case/03": "EXECUTION TIMEOUT"
}
},
{ "pattern": "./source_code/time_out.rb" },
{ "pattern": "./source_code/build_error.c", "expect": "BUILD FAILURE" }
Expand Down Expand Up @@ -235,15 +239,19 @@ You can narrow down tests by languages.

#### `--quiet`

Suppres runtime information output.
Suppress runtime information output.

#### `--no-json`

Do not print final output json.

#### `--pretty`

Pretty printing the output json.

#### `--tmpdir=DIRNAME`

You can set where to put the intermediate files when executing tests. If not specified, intermediate files will not be created.
You can set where to put the intermediate files when executing tests. Default is `./titania-out`.

#### `--maxjob=N`

Expand Down Expand Up @@ -299,4 +307,6 @@ Or, if you just want to know runtime information, below is the way you go (Like

```bash
$ titania.go [directories] > /dev/null
# or
$ titania.go --no-json [directories]
```
6 changes: 4 additions & 2 deletions cmd/titania.go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
)

const VERSION string = "v0.9.3"
const VERSION string = "v0.10.0"

func main() {
directories := optparse()
Expand All @@ -18,5 +18,7 @@ func main() {
}

final(uresults)
printjson(uresults)
if !nojson {
printjson(uresults)
}
}
6 changes: 5 additions & 1 deletion cmd/titania.go/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var (
prettyprint = false
nojson = false
)

func version() {
Expand All @@ -29,10 +30,11 @@ directories:
options:
-h, --help show this help message
-v, --version show version
--no-json do not print json
--pretty pretty print output json
--quiet quiet log
--lang=lang1[,lang2,...] language[s] to test
--tmpdir=DIRNAME set a directory where temporary files are put
--tmpdir=DIRNAME set a directory where temporary files are put (default: ./titania-out)
--maxjob=N set a maximum number of jobs to run concurrently (N > 0)
`)
}
Expand Down Expand Up @@ -95,6 +97,8 @@ func optparse() []string {
tester.SetQuiet(true)
case "--pretty":
prettyprint = true
case "--no-json":
nojson = true
case "--lang":
if len(os.Args) < i+3 {
usage()
Expand Down
15 changes: 13 additions & 2 deletions cmd/titania.go/wrapup.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,19 @@ func buildjson(w io.Writer, uresults []*tester.TestUnitResult) {
obj.SetString("time", cresult.Time)
obj.SetString("expect", cresult.Expect)
obj.SetString("result", cresult.Result)
obj.SetStringFromReader("output", cresult.Output)
obj.SetStringFromReader("others", cresult.Others)
// write output from file
if fp, err := os.Open(cresult.Output); err == nil {
obj.SetStringFromReader("output", bufio.NewReader(fp))
}
// write other info from files
buf := bytes.NewBuffer([]byte{})
for _, file := range cresult.Others {
if fp, err := os.Open(file); err == nil {
bufio.NewReader(fp).WriteTo(buf)
}
}
obj.SetStringFromReader("others", buf)
// errors (in this application)
obj.SetString("errors", cresult.Errors)
})
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/file/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package file

import (
"bufio"
"bytes"
"io"
"os"
)

// compare two files' contents
func Equal(a, b string) (bool, error) {
fpA, err := os.Open(a)
if err != nil {
return false, err
}
defer fpA.Close()

fpB, err := os.Open(b)
if err != nil {
return false, err
}
defer fpB.Close()

bytesA, err := io.ReadAll(bufio.NewReader(fpA))
if err != nil {
return false, nil
}

bytesB, err := io.ReadAll(bufio.NewReader(fpB))
if err != nil {
return false, nil
}

return bytes.Equal(bytesA, bytesB), nil
}
Loading

0 comments on commit bbc4e42

Please sign in to comment.