16
16
package main_test
17
17
18
18
import (
19
+ "encoding/json"
19
20
"testing"
20
21
21
22
"github.com/arduino/arduino-cli/internal/integrationtest"
22
23
"github.com/arduino/go-paths-helper"
23
24
"github.com/stretchr/testify/require"
25
+ semver "go.bug.st/relaxed-semver"
24
26
"go.bug.st/testsuite"
25
27
)
26
28
@@ -39,3 +41,44 @@ func TestHelp(t *testing.T) {
39
41
require .Empty (t , stderr )
40
42
require .Contains (t , string (stdout ), "Usage" )
41
43
}
44
+
45
+ func TestVersion (t * testing.T ) {
46
+ env := testsuite .NewEnvironment (t )
47
+ defer env .CleanUp ()
48
+
49
+ cli := integrationtest .NewArduinoCliWithinEnvironment (env , & integrationtest.ArduinoCLIConfig {
50
+ ArduinoCLIPath : paths .New (".." , ".." , ".." , "arduino-cli" ),
51
+ UseSharedStagingFolder : true ,
52
+ })
53
+
54
+ // Run version and check the output message
55
+ stdout , stderr , err := cli .Run ("version" )
56
+ require .NoError (t , err )
57
+ require .Contains (t , string (stdout ), "Version:" )
58
+ require .Contains (t , string (stdout ), "Commit:" )
59
+ require .Empty (t , stderr )
60
+
61
+ // Checks if "version --format json" has a json as an output
62
+ stdout , _ , err = cli .Run ("version" , "--format" , "json" )
63
+ require .NoError (t , err )
64
+ var jsonMap map [string ]string
65
+ err = json .Unmarshal (stdout , & jsonMap )
66
+ require .NoError (t , err )
67
+
68
+ // Checks if Application's value is arduino-cli
69
+ require .Equal (t , jsonMap ["Application" ], "arduino-cli" )
70
+
71
+ // Checks if VersionString's value is git-snapshot, nightly or a valid semantic versioning
72
+ switch version := jsonMap ["VersionString" ]; version {
73
+ case "git-snapshot" :
74
+ require .Contains (t , version , "git-snapshot" )
75
+ case "nigthly" :
76
+ require .Contains (t , version , "nightly" )
77
+ default :
78
+ _ , err = semver .Parse (version )
79
+ require .NoError (t , err )
80
+ }
81
+
82
+ // Checks if Commit's value is not empty
83
+ require .NotEmpty (t , jsonMap ["Commit" ])
84
+ }
0 commit comments